

























@@ -40,6 +40,17 @@ function createUsableOAuthExpiry(): number {
4040return Date.now() + 30 * 60 * 1000;
4141}
424243+function requireRecord(value: unknown, label: string): Record<string, unknown> {
44+if (!value || typeof value !== "object") {
45+throw new Error(`expected ${label}`);
46+}
47+return value as Record<string, unknown>;
48+}
49+50+function requireProfile(store: AuthProfileStore, profileId: string): Record<string, unknown> {
51+return requireRecord(store.profiles[profileId], profileId);
52+}
53+4354describe("auth external oauth helpers", () => {
4455beforeEach(() => {
4556resolveExternalAuthProfilesWithPluginsMock.mockReset();
@@ -63,11 +74,10 @@ describe("auth external oauth helpers", () => {
63746475const store = overlayExternalOAuthProfiles(createStore());
657666-expect(store.profiles["openai-codex:default"]).toMatchObject({
67-type: "oauth",
68-provider: "openai-codex",
69-access: "access-token",
70-});
77+const profile = requireProfile(store, "openai-codex:default");
78+expect(profile.type).toBe("oauth");
79+expect(profile.provider).toBe("openai-codex");
80+expect(profile.access).toBe("access-token");
7181});
72827383it("passes config and CLI scope through overlay resolution", () => {
@@ -84,12 +94,12 @@ describe("auth external oauth helpers", () => {
8494externalCliProviderIds: ["openai-codex"],
8595});
869687-expect(resolveExternalAuthProfilesWithPluginsMock).toHaveBeenCalledWith(
88-expect.objectContaining({
89-config: cfg,
90-context: expect.objectContaining({ config: cfg }),
91-}),
97+const resolveParams = requireRecord(
98+resolveExternalAuthProfilesWithPluginsMock.mock.calls[0]?.[0],
99+"resolve external auth params",
92100);
101+expect(resolveParams.config).toBe(cfg);
102+expect(requireRecord(resolveParams.context, "resolve context").config).toBe(cfg);
93103expect(readCodexCliCredentialsCachedMock).toHaveBeenCalledTimes(1);
94104});
95105@@ -169,11 +179,10 @@ describe("auth external oauth helpers", () => {
169179}),
170180);
171181172-expect(overlaid.profiles["openai-codex:default"]).toMatchObject({
173-access: "stale-store-access-token",
174-refresh: "stale-store-refresh-token",
175-accountId: "acct-cli",
176-});
182+const profile = requireProfile(overlaid, "openai-codex:default");
183+expect(profile.access).toBe("stale-store-access-token");
184+expect(profile.refresh).toBe("stale-store-refresh-token");
185+expect(profile.accountId).toBe("acct-cli");
177186});
178187179188it("keeps healthy local oauth even when external cli has a fresher token", () => {
@@ -195,10 +204,9 @@ describe("auth external oauth helpers", () => {
195204}),
196205);
197206198-expect(overlaid.profiles["openai-codex:default"]).toMatchObject({
199-access: "healthy-local-access-token",
200-refresh: "healthy-local-refresh-token",
201-});
207+const profile = requireProfile(overlaid, "openai-codex:default");
208+expect(profile.access).toBe("healthy-local-access-token");
209+expect(profile.refresh).toBe("healthy-local-refresh-token");
202210});
203211204212it("keeps explicit local non-oauth auth over external cli oauth overlays", () => {
@@ -220,11 +228,10 @@ describe("auth external oauth helpers", () => {
220228}),
221229);
222230223-expect(overlaid.profiles["openai-codex:default"]).toMatchObject({
224-type: "api_key",
225-provider: "openai-codex",
226-key: "sk-local",
227-});
231+const profile = requireProfile(overlaid, "openai-codex:default");
232+expect(profile.type).toBe("api_key");
233+expect(profile.provider).toBe("openai-codex");
234+expect(profile.key).toBe("sk-local");
228235});
229236230237it("keeps expired local oauth when external cli belongs to a different account", () => {
@@ -248,10 +255,9 @@ describe("auth external oauth helpers", () => {
248255}),
249256);
250257251-expect(overlaid.profiles["openai-codex:default"]).toMatchObject({
252-access: "expired-local-access-token",
253-refresh: "expired-local-refresh-token",
254-accountId: "acct-local",
255-});
258+const profile = requireProfile(overlaid, "openai-codex:default");
259+expect(profile.access).toBe("expired-local-access-token");
260+expect(profile.refresh).toBe("expired-local-refresh-token");
261+expect(profile.accountId).toBe("acct-local");
256262});
257263});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。