




























@@ -43,6 +43,36 @@ function makeStore(profileId?: string, credential?: OAuthCredential): AuthProfil
4343};
4444}
454546+function expectSingleProfileCredential(
47+profiles: ReturnType<typeof resolveExternalCliAuthProfiles>,
48+profileId: string,
49+) {
50+expect(profiles).toHaveLength(1);
51+expect(profiles[0]?.profileId).toBe(profileId);
52+expect(profiles[0]?.credential).toBeTruthy();
53+return profiles[0]?.credential as Record<string, unknown>;
54+}
55+56+function expectCredentialFields(
57+credential: Record<string, unknown> | undefined,
58+expected: Record<string, unknown>,
59+) {
60+expect(credential).toBeTruthy();
61+for (const [key, value] of Object.entries(expected)) {
62+expect(credential?.[key]).toBe(value);
63+}
64+}
65+66+function expectReaderPolicyCall(mock: { mock: { calls: unknown[][] } }) {
67+expect(mock.mock.calls).toHaveLength(1);
68+const [arg] = mock.mock.calls[0] ?? [];
69+expect(arg).toBeTruthy();
70+if (!arg || typeof arg !== "object") {
71+throw new Error("Expected CLI reader options");
72+}
73+expect((arg as { allowKeychainPrompt?: unknown }).allowKeychainPrompt).toBe(false);
74+}
75+4676describe("external cli oauth resolution", () => {
4777beforeEach(async () => {
4878vi.resetModules();
@@ -258,17 +288,15 @@ describe("external cli oauth resolution", () => {
258288providerIds: ["openai-codex"],
259289});
260290261-expect(profiles).toEqual([
291+expectCredentialFields(
292+expectSingleProfileCredential(profiles, OPENAI_CODEX_DEFAULT_PROFILE_ID),
262293{
263-profileId: OPENAI_CODEX_DEFAULT_PROFILE_ID,
264-credential: expect.objectContaining({
265-provider: "openai-codex",
266-access: "codex-cli-access",
267-refresh: "codex-cli-refresh",
268-accountId: "acct-codex",
269-}),
294+provider: "openai-codex",
295+access: "codex-cli-access",
296+refresh: "codex-cli-refresh",
297+accountId: "acct-codex",
270298},
271-]);
299+);
272300});
273301274302it("keeps any existing default codex oauth over Codex CLI bootstrap credentials", () => {
@@ -324,17 +352,12 @@ describe("external cli oauth resolution", () => {
324352providerIds: ["claude-cli"],
325353});
326354327-expect(profiles).toEqual([
328-{
329-profileId: CLAUDE_CLI_PROFILE_ID,
330-credential: expect.objectContaining({
331-type: "oauth",
332-provider: "claude-cli",
333-access: "claude-cli-access",
334-refresh: "claude-cli-refresh",
335-}),
336-},
337-]);
355+expectCredentialFields(expectSingleProfileCredential(profiles, CLAUDE_CLI_PROFILE_ID), {
356+type: "oauth",
357+provider: "claude-cli",
358+access: "claude-cli-access",
359+refresh: "claude-cli-refresh",
360+});
338361});
339362340363it("skips external cli readers outside the scoped provider set", () => {
@@ -382,15 +405,10 @@ describe("external cli oauth resolution", () => {
382405}),
383406);
384407385-expect(profiles).toEqual([
386-{
387-profileId: CLAUDE_CLI_PROFILE_ID,
388-credential: expect.objectContaining({
389-provider: "claude-cli",
390-access: "claude-cli-fresh-access",
391-}),
392-},
393-]);
408+expectCredentialFields(expectSingleProfileCredential(profiles, CLAUDE_CLI_PROFILE_ID), {
409+provider: "claude-cli",
410+access: "claude-cli-fresh-access",
411+});
394412});
395413396414it("passes non-prompting keychain policy to scoped Claude CLI credential reads", () => {
@@ -407,18 +425,11 @@ describe("external cli oauth resolution", () => {
407425allowKeychainPrompt: false,
408426});
409427410-expect(profiles).toEqual([
411-{
412-profileId: CLAUDE_CLI_PROFILE_ID,
413-credential: expect.objectContaining({
414-type: "oauth",
415-provider: "claude-cli",
416-}),
417-},
418-]);
419-expect(mocks.readClaudeCliCredentialsCached).toHaveBeenCalledWith(
420-expect.objectContaining({ allowKeychainPrompt: false }),
421-);
428+expectCredentialFields(expectSingleProfileCredential(profiles, CLAUDE_CLI_PROFILE_ID), {
429+type: "oauth",
430+provider: "claude-cli",
431+});
432+expectReaderPolicyCall(mocks.readClaudeCliCredentialsCached);
422433expect(mocks.readCodexCliCredentialsCached).not.toHaveBeenCalled();
423434expect(mocks.readMiniMaxCliCredentialsCached).not.toHaveBeenCalled();
424435});
@@ -437,18 +448,14 @@ describe("external cli oauth resolution", () => {
437448allowKeychainPrompt: false,
438449});
439450440-expect(profiles).toEqual([
451+expectCredentialFields(
452+expectSingleProfileCredential(profiles, OPENAI_CODEX_DEFAULT_PROFILE_ID),
441453{
442-profileId: OPENAI_CODEX_DEFAULT_PROFILE_ID,
443-credential: expect.objectContaining({
444-type: "oauth",
445-provider: "openai-codex",
446-}),
454+type: "oauth",
455+provider: "openai-codex",
447456},
448-]);
449-expect(mocks.readCodexCliCredentialsCached).toHaveBeenCalledWith(
450-expect.objectContaining({ allowKeychainPrompt: false }),
451457);
458+expectReaderPolicyCall(mocks.readCodexCliCredentialsCached);
452459expect(mocks.readClaudeCliCredentialsCached).not.toHaveBeenCalled();
453460expect(mocks.readMiniMaxCliCredentialsCached).not.toHaveBeenCalled();
454461});
@@ -495,7 +502,7 @@ describe("external cli oauth resolution", () => {
495502const profilesById = new Map(
496503profiles.map((profile) => [profile.profileId, profile.credential]),
497504);
498-expect(profilesById.get(MINIMAX_CLI_PROFILE_ID)).toMatchObject({
505+expectCredentialFields(profilesById.get(MINIMAX_CLI_PROFILE_ID) as Record<string, unknown>, {
499506access: "minimax-fresh-access",
500507refresh: "minimax-fresh-refresh",
501508});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。