





















@@ -98,9 +98,9 @@ function createGatewaySubagentRunFixture(params?: { allowGatewaySubagentBinding?
9898}
9999100100function expectFunctionKeys(value: Record<string, unknown>, keys: readonly string[]) {
101-expect(value).toEqual(
102-expect.objectContaining(Object.fromEntries(keys.map((key) => [key, expect.any(Function)]))),
103-);
101+for (const key of keys) {
102+expect(typeof value[key]).toBe("function");
103+}
104104}
105105106106function expectRunCommandOutcome(params: {
@@ -188,21 +188,23 @@ describe("plugin runtime command execution", () => {
188188it("maps deprecated runtime.system.requestHeartbeatNow to an immediate compatibility wake", async () => {
189189vi.useFakeTimers();
190190resetHeartbeatWakeStateForTests();
191-const handler = vi.fn(async () => ({ status: "skipped" as const, reason: "disabled" }));
191+const handler = vi.fn(async (_request: Parameters<typeof requestHeartbeat>[0]) => ({
192+status: "skipped" as const,
193+reason: "disabled",
194+}));
192195setHeartbeatWakeHandler(handler);
193196try {
194197createPluginRuntime().system.requestHeartbeatNow({
195198reason: "legacy-plugin",
196199coalesceMs: 0,
197200});
198201await vi.advanceTimersByTimeAsync(1);
199-expect(handler).toHaveBeenCalledWith(
200-expect.objectContaining({
201-source: "other",
202-intent: "immediate",
203-reason: "legacy-plugin",
204-}),
205-);
202+const request = handler.mock.calls[0]?.[0] as
203+| { source?: string; intent?: string; reason?: string }
204+| undefined;
205+expect(request?.source).toBe("other");
206+expect(request?.intent).toBe("immediate");
207+expect(request?.reason).toBe("legacy-plugin");
206208} finally {
207209resetHeartbeatWakeStateForTests();
208210vi.useRealTimers();
@@ -317,11 +319,6 @@ describe("plugin runtime command execution", () => {
317319{
318320name: "exposes runtime.modelAuth with raw and runtime-ready auth helpers",
319321assert: (runtime: ReturnType<typeof createPluginRuntime>) => {
320-expect(runtime.modelAuth).toMatchObject({
321-getApiKeyForModel: expect.any(Function),
322-getRuntimeAuthForModel: expect.any(Function),
323-resolveApiKeyForProvider: expect.any(Function),
324-});
325322expectFunctionKeys(runtime.modelAuth, [
326323"getApiKeyForModel",
327324"getRuntimeAuthForModel",
@@ -363,24 +360,23 @@ describe("plugin runtime command execution", () => {
363360mode: "api-key",
364361});
365362366-await expect(
367-runtime.modelAuth.getApiKeyForModel({
368-model: model as never,
369- cfg,
370-workspaceDir: "/tmp/workspace",
371-agentDir: "/tmp/agent",
372-store: { version: 1, profiles: {} },
373-} as never),
374-).resolves.toMatchObject({ apiKey: "model-key" });
375-await expect(
376-runtime.modelAuth.resolveApiKeyForProvider({
377-provider: "workspace-cloud",
378- cfg,
379-workspaceDir: "/tmp/workspace",
380-agentDir: "/tmp/agent",
381-store: { version: 1, profiles: {} },
382-} as never),
383-).resolves.toMatchObject({ apiKey: "provider-key" });
363+const modelAuth = await runtime.modelAuth.getApiKeyForModel({
364+model: model as never,
365+ cfg,
366+workspaceDir: "/tmp/workspace",
367+agentDir: "/tmp/agent",
368+store: { version: 1, profiles: {} },
369+} as never);
370+expect(modelAuth.apiKey).toBe("model-key");
371+372+const providerAuth = await runtime.modelAuth.resolveApiKeyForProvider({
373+provider: "workspace-cloud",
374+ cfg,
375+workspaceDir: "/tmp/workspace",
376+agentDir: "/tmp/agent",
377+store: { version: 1, profiles: {} },
378+} as never);
379+expect(providerAuth.apiKey).toBe("provider-key");
384380385381expect(runtimeModelAuthMocks.getApiKeyForModel).toHaveBeenCalledWith({
386382 model,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。