


























@@ -56,6 +56,38 @@ function createRuntime() {
5656};
5757}
585859+type MockCalls = { mock: { calls: Array<Array<unknown>> } };
60+61+function mockCall(mock: MockCalls, callIndex = 0): Array<unknown> {
62+const call = mock.mock.calls[callIndex];
63+if (!call) {
64+throw new Error(`expected mock call ${callIndex}`);
65+}
66+return call;
67+}
68+69+function mockArg(mock: MockCalls, callIndex = 0, argIndex = 0): Record<string, unknown> {
70+const arg = mockCall(mock, callIndex)[argIndex];
71+if (!arg || typeof arg !== "object") {
72+throw new Error(`expected mock arg at call ${callIndex}, arg ${argIndex}`);
73+}
74+return arg as Record<string, unknown>;
75+}
76+77+function expectWorkspaceDir(value: unknown) {
78+expect(typeof value).toBe("string");
79+expect((value as string).length).toBeGreaterThan(0);
80+}
81+82+function expectConfigDefaults(value: unknown) {
83+const config = value as { agents?: unknown };
84+expect(config.agents).toEqual({ defaults: {} });
85+}
86+87+function expectRuntimeErrorIncludes(runtime: ReturnType<typeof createRuntime>, text: string) {
88+expect(runtime.error.mock.calls.some(([message]) => String(message).includes(text))).toBe(true);
89+}
90+5991describe("applyNonInteractivePluginProviderChoice", () => {
6092it("loads plugin providers for provider-plugin auth choices", async () => {
6193const runtime = createRuntime();
@@ -79,18 +111,11 @@ describe("applyNonInteractivePluginProviderChoice", () => {
7911180112expect(resolveOwningPluginIdsForProvider).toHaveBeenCalledOnce();
81113expect(resolvePreferredProviderForAuthChoice).not.toHaveBeenCalled();
82-expect(resolveOwningPluginIdsForProvider).toHaveBeenCalledWith(
83-expect.objectContaining({
84-provider: "vllm",
85-}),
86-);
114+expect(mockArg(resolveOwningPluginIdsForProvider).provider).toBe("vllm");
87115expect(resolvePluginProviders).toHaveBeenCalledOnce();
88-expect(resolvePluginProviders).toHaveBeenCalledWith(
89-expect.objectContaining({
90-onlyPluginIds: ["vllm"],
91-includeUntrustedWorkspacePlugins: false,
92-}),
93-);
116+const providersInput = mockArg(resolvePluginProviders);
117+expect(providersInput.onlyPluginIds).toEqual(["vllm"]);
118+expect(providersInput.includeUntrustedWorkspacePlugins).toBe(false);
94119expect(resolveProviderPluginChoice).toHaveBeenCalledOnce();
95120expect(runNonInteractive).toHaveBeenCalledOnce();
96121expect(result).toEqual({ plugins: { allow: ["vllm"] } });
@@ -111,10 +136,9 @@ describe("applyNonInteractivePluginProviderChoice", () => {
111136112137expect(result).toBeNull();
113138expect(resolvePreferredProviderForAuthChoice).not.toHaveBeenCalled();
114-expect(runtime.error).toHaveBeenCalledWith(
115-expect.stringContaining(
116-'Auth choice "provider-plugin:workspace-provider:api-key" was not matched to a trusted provider plugin.',
117-),
139+expectRuntimeErrorIncludes(
140+runtime,
141+'Auth choice "provider-plugin:workspace-provider:api-key" was not matched to a trusted provider plugin.',
118142);
119143expect(runtime.exit).toHaveBeenCalledWith(1);
120144});
@@ -138,33 +162,22 @@ describe("applyNonInteractivePluginProviderChoice", () => {
138162});
139163140164expect(result).toBeNull();
141-expect(runtime.error).toHaveBeenCalledWith(
142-expect.stringContaining(
143-'Auth choice "workspace-provider-api-key" matched a provider plugin that is not trusted or enabled for setup.',
144-),
165+expectRuntimeErrorIncludes(
166+runtime,
167+'Auth choice "workspace-provider-api-key" matched a provider plugin that is not trusted or enabled for setup.',
145168);
146169expect(runtime.exit).toHaveBeenCalledWith(1);
147-expect(resolvePluginProviders).toHaveBeenCalledWith(
148-expect.objectContaining({
149-includeUntrustedWorkspacePlugins: false,
150-}),
151-);
170+expect(mockArg(resolvePluginProviders).includeUntrustedWorkspacePlugins).toBe(false);
152171expect(resolveProviderPluginChoice).toHaveBeenCalledTimes(1);
153172expect(resolvePluginProviders).toHaveBeenCalledTimes(1);
154-expect(resolveManifestProviderAuthChoice).toHaveBeenCalledWith(
155-"workspace-provider-api-key",
156-expect.objectContaining({
157-includeUntrustedWorkspacePlugins: false,
158-}),
159-);
160-expect(resolveManifestProviderAuthChoice).toHaveBeenCalledWith(
161-"workspace-provider-api-key",
162-expect.objectContaining({
163-config: expect.objectContaining({ agents: { defaults: {} } }),
164-workspaceDir: expect.any(String),
165-includeUntrustedWorkspacePlugins: true,
166-}),
167-);
173+expect(mockCall(resolveManifestProviderAuthChoice, 0)[0]).toBe("workspace-provider-api-key");
174+const trustedManifestInput = mockArg(resolveManifestProviderAuthChoice, 0, 1);
175+expect(trustedManifestInput.includeUntrustedWorkspacePlugins).toBe(false);
176+expect(mockCall(resolveManifestProviderAuthChoice, 1)[0]).toBe("workspace-provider-api-key");
177+const untrustedManifestInput = mockArg(resolveManifestProviderAuthChoice, 1, 1);
178+expectConfigDefaults(untrustedManifestInput.config);
179+expectWorkspaceDir(untrustedManifestInput.workspaceDir);
180+expect(untrustedManifestInput.includeUntrustedWorkspacePlugins).toBe(true);
168181});
169182170183it("limits setup-provider resolution to owning plugin ids without pre-enabling them", async () => {
@@ -189,13 +202,10 @@ describe("applyNonInteractivePluginProviderChoice", () => {
189202toApiKeyCredential: vi.fn(),
190203});
191204192-expect(resolvePluginProviders).toHaveBeenCalledWith(
193-expect.objectContaining({
194-config: expect.objectContaining({ agents: { defaults: {} } }),
195-onlyPluginIds: ["demo-plugin"],
196-includeUntrustedWorkspacePlugins: false,
197-}),
198-);
205+const providersInput = mockArg(resolvePluginProviders);
206+expectConfigDefaults(providersInput.config);
207+expect(providersInput.onlyPluginIds).toEqual(["demo-plugin"]);
208+expect(providersInput.includeUntrustedWorkspacePlugins).toBe(false);
199209expect(runNonInteractive).toHaveBeenCalledOnce();
200210expect(result).toEqual({ plugins: { allow: ["demo-plugin"] } });
201211});
@@ -214,17 +224,10 @@ describe("applyNonInteractivePluginProviderChoice", () => {
214224toApiKeyCredential: vi.fn(),
215225});
216226217-expect(resolvePreferredProviderForAuthChoice).toHaveBeenCalledWith(
218-expect.objectContaining({
219-choice: "openai-api-key",
220-includeUntrustedWorkspacePlugins: false,
221-}),
222-);
223-expect(resolvePluginProviders).toHaveBeenCalledWith(
224-expect.objectContaining({
225-includeUntrustedWorkspacePlugins: false,
226-}),
227-);
227+const preferenceInput = mockArg(resolvePreferredProviderForAuthChoice);
228+expect(preferenceInput.choice).toBe("openai-api-key");
229+expect(preferenceInput.includeUntrustedWorkspacePlugins).toBe(false);
230+expect(mockArg(resolvePluginProviders).includeUntrustedWorkspacePlugins).toBe(false);
228231});
229232230233it("ensures Codex after a non-interactive OpenAI provider choice sets the default model", async () => {
@@ -260,14 +263,11 @@ describe("applyNonInteractivePluginProviderChoice", () => {
260263});
261264262265expect(runNonInteractive).toHaveBeenCalledOnce();
263-expect(ensureCodexRuntimePluginForModelSelection).toHaveBeenCalledWith(
264-expect.objectContaining({
265-cfg: selectedConfig,
266-model: "openai/gpt-5.5",
267- runtime,
268-workspaceDir: expect.any(String),
269-}),
270-);
266+const ensureInput = mockArg(ensureCodexRuntimePluginForModelSelection);
267+expect(ensureInput.cfg).toBe(selectedConfig);
268+expect(ensureInput.model).toBe("openai/gpt-5.5");
269+expect(ensureInput.runtime).toBe(runtime);
270+expectWorkspaceDir(ensureInput.workspaceDir);
271271expect(result).toBe(installedConfig);
272272});
273273});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。