


























@@ -18,6 +18,20 @@ vi.mock("./auth-profiles/external-auth.js", () => ({
1818syncPersistedExternalCliAuthProfiles: <T>(store: T) => store,
1919}));
202021+function requireRecord(value: unknown, label: string): Record<string, unknown> {
22+if (!value || typeof value !== "object") {
23+throw new Error(`expected ${label} to be an object`);
24+}
25+return value as Record<string, unknown>;
26+}
27+28+function expectProfileFields(profile: unknown, expected: Record<string, unknown>): void {
29+const actual = requireRecord(profile, "auth profile");
30+for (const [key, value] of Object.entries(expected)) {
31+expect(actual[key]).toEqual(value);
32+}
33+}
34+2135describe("saveAuthProfileStore", () => {
2236it("strips plaintext when keyRef/tokenRef are present", async () => {
2337const structuredCloneSpy = vi.spyOn(globalThis, "structuredClone");
@@ -98,7 +112,7 @@ describe("saveAuthProfileStore", () => {
98112},
99113]);
100114101-expect(ensureAuthProfileStore(agentDir).profiles["anthropic:default"]).toMatchObject({
115+expectProfileFields(ensureAuthProfileStore(agentDir).profiles["anthropic:default"], {
102116access: "access-1",
103117refresh: "refresh-1",
104118});
@@ -118,15 +132,15 @@ describe("saveAuthProfileStore", () => {
118132119133saveAuthProfileStore(rotatedStore, agentDir);
120134121-expect(ensureAuthProfileStore(agentDir).profiles["anthropic:default"]).toMatchObject({
135+expectProfileFields(ensureAuthProfileStore(agentDir).profiles["anthropic:default"], {
122136access: "access-2",
123137refresh: "refresh-2",
124138});
125139126140const persisted = JSON.parse(await fs.readFile(resolveAuthStorePath(agentDir), "utf8")) as {
127141profiles: Record<string, { access?: string; refresh?: string }>;
128142};
129-expect(persisted.profiles["anthropic:default"]).toMatchObject({
143+expectProfileFields(persisted.profiles["anthropic:default"], {
130144access: "access-2",
131145refresh: "refresh-2",
132146});
@@ -215,7 +229,7 @@ describe("saveAuthProfileStore", () => {
215229});
216230217231const localUpdateStore = ensureAuthProfileStoreForLocalUpdate(childAgentDir);
218-expect(localUpdateStore.profiles["openai-codex:default"]).toMatchObject({
232+expectProfileFields(localUpdateStore.profiles["openai-codex:default"], {
219233type: "oauth",
220234refresh: "main-refresh-token",
221235});
@@ -232,7 +246,7 @@ describe("saveAuthProfileStore", () => {
232246const child = JSON.parse(await fs.readFile(childAuthPath, "utf8")) as {
233247profiles: Record<string, unknown>;
234248};
235-expect(child.profiles["openai:default"]).toMatchObject({
249+expectProfileFields(child.profiles["openai:default"], {
236250type: "api_key",
237251provider: "openai",
238252});
@@ -251,7 +265,7 @@ describe("saveAuthProfileStore", () => {
251265},
252266});
253267254-expect(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"]).toMatchObject({
268+expectProfileFields(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"], {
255269type: "oauth",
256270access: "main-refreshed-access-token",
257271refresh: "main-refreshed-refresh-token",
@@ -287,7 +301,7 @@ describe("saveAuthProfileStore", () => {
287301});
288302289303const localUpdateStore = ensureAuthProfileStoreForLocalUpdate(childAgentDir);
290-expect(localUpdateStore.profiles["openai-codex:default"]).toMatchObject({
304+expectProfileFields(localUpdateStore.profiles["openai-codex:default"], {
291305type: "oauth",
292306refresh: "main-old-refresh-token",
293307});
@@ -319,12 +333,12 @@ describe("saveAuthProfileStore", () => {
319333const child = JSON.parse(await fs.readFile(childAuthPath, "utf8")) as {
320334profiles: Record<string, unknown>;
321335};
322-expect(child.profiles["openai:default"]).toMatchObject({
336+expectProfileFields(child.profiles["openai:default"], {
323337type: "api_key",
324338provider: "openai",
325339});
326340expect(child.profiles["openai-codex:default"]).toBeUndefined();
327-expect(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"]).toMatchObject({
341+expectProfileFields(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"], {
328342type: "oauth",
329343access: "main-refreshed-access-token",
330344refresh: "main-refreshed-refresh-token",
@@ -380,11 +394,11 @@ describe("saveAuthProfileStore", () => {
380394expect(child.profiles["openai-codex:default"]).toBeUndefined();
381395382396const runtime = ensureAuthProfileStore(childAgentDir);
383-expect(runtime.profiles["openai:default"]).toMatchObject({
397+expectProfileFields(runtime.profiles["openai:default"], {
384398type: "api_key",
385399provider: "openai",
386400});
387-expect(runtime.profiles["openai-codex:default"]).toMatchObject({
401+expectProfileFields(runtime.profiles["openai-codex:default"], {
388402type: "oauth",
389403access: "main-access-token",
390404refresh: "main-refresh-token",
@@ -403,7 +417,7 @@ describe("saveAuthProfileStore", () => {
403417},
404418});
405419406-expect(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"]).toMatchObject({
420+expectProfileFields(ensureAuthProfileStore(childAgentDir).profiles["openai-codex:default"], {
407421type: "oauth",
408422access: "main-refreshed-access-token",
409423refresh: "main-refreshed-refresh-token",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。