Skip to content

Commit cc35627

Browse files
committed
fix: harden telegram and loader contracts
1 parent ff0481a commit cc35627

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

extensions/telegram/src/bot.create-telegram-bot.test-harness.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ vi.mock("grammy", () => ({
214214
}));
215215

216216
const runnerHoisted = vi.hoisted(() => ({
217-
sequentializeMiddleware: vi.fn(),
218-
sequentializeSpy: vi.fn(),
217+
sequentializeMiddleware: vi.fn(async (_ctx: unknown, next?: () => Promise<void>) => {
218+
if (typeof next === "function") {
219+
await next();
220+
}
221+
}),
222+
sequentializeSpy: vi.fn(() => runnerHoisted.sequentializeMiddleware),
219223
throttlerSpy: vi.fn(() => "throttler"),
220224
}));
221225
export const sequentializeSpy: AnyMock = runnerHoisted.sequentializeSpy;
@@ -355,7 +359,14 @@ beforeEach(() => {
355359
listSkillCommandsForAgents.mockReset();
356360
listSkillCommandsForAgents.mockReturnValue([]);
357361
middlewareUseSpy.mockReset();
362+
runnerHoisted.sequentializeMiddleware.mockReset();
363+
runnerHoisted.sequentializeMiddleware.mockImplementation(async (_ctx, next) => {
364+
if (typeof next === "function") {
365+
await next();
366+
}
367+
});
358368
sequentializeSpy.mockReset();
369+
sequentializeSpy.mockImplementation(() => runnerHoisted.sequentializeMiddleware);
359370
botCtorSpy.mockReset();
360371
sequentializeKey = undefined;
361372
});

src/plugins/contracts/loader.contract.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22
import { withBundledPluginAllowlistCompat } from "../bundled-compat.js";
3+
import { loadPluginManifestRegistry } from "../manifest-registry.js";
34
import { __testing as providerTesting } from "../providers.js";
45
import { resolvePluginWebSearchProviders } from "../web-search-providers.js";
56
import { providerContractCompatPluginIds, webSearchProviderContractRegistry } from "./registry.js";
67
import { uniqueSortedStrings } from "./testkit.js";
78

9+
function resolveBundledManifestProviderPluginIds() {
10+
return uniqueSortedStrings(
11+
loadPluginManifestRegistry({})
12+
.plugins.filter((plugin) => plugin.origin === "bundled" && plugin.providers.length > 0)
13+
.map((plugin) => plugin.id),
14+
);
15+
}
16+
817
describe("plugin loader contract", () => {
918
beforeEach(() => {
1019
vi.restoreAllMocks();
1120
});
1221

1322
it("keeps bundled provider compatibility wired to the provider registry", () => {
1423
const providerPluginIds = uniqueSortedStrings(providerContractCompatPluginIds);
24+
const manifestProviderPluginIds = resolveBundledManifestProviderPluginIds();
1525
const compatPluginIds = providerTesting.resolveBundledProviderCompatPluginIds({
1626
config: {
1727
plugins: {
@@ -29,18 +39,22 @@ describe("plugin loader contract", () => {
2939
pluginIds: compatPluginIds,
3040
});
3141

42+
expect(providerPluginIds).toEqual(manifestProviderPluginIds);
43+
expect(uniqueSortedStrings(compatPluginIds)).toEqual(manifestProviderPluginIds);
3244
expect(uniqueSortedStrings(compatPluginIds)).toEqual(expect.arrayContaining(providerPluginIds));
3345
expect(compatConfig?.plugins?.allow).toEqual(expect.arrayContaining(providerPluginIds));
3446
});
3547

3648
it("keeps vitest bundled provider enablement wired to the provider registry", () => {
3749
const providerPluginIds = uniqueSortedStrings(providerContractCompatPluginIds);
50+
const manifestProviderPluginIds = resolveBundledManifestProviderPluginIds();
3851
const compatConfig = providerTesting.withBundledProviderVitestCompat({
3952
config: undefined,
4053
pluginIds: providerPluginIds,
4154
env: { VITEST: "1" } as NodeJS.ProcessEnv,
4255
});
4356

57+
expect(providerPluginIds).toEqual(manifestProviderPluginIds);
4458
expect(compatConfig?.plugins).toMatchObject({
4559
enabled: true,
4660
allow: expect.arrayContaining(providerPluginIds),

0 commit comments

Comments
 (0)