
























@@ -28,6 +28,14 @@ const {
2828 formatProviderAuthProfileApiKeyWithPluginMock,
2929} = getOAuthProviderRuntimeMocks();
303031+function requireOAuthCredential(store: AuthProfileStore, profileId: string): OAuthCredential {
32+const profile = store.profiles[profileId];
33+if (!profile || profile.type !== "oauth") {
34+throw new Error(`expected OAuth credential for ${profileId}`);
35+}
36+return profile;
37+}
38+3139vi.mock("@mariozechner/pi-ai/oauth", () => ({
3240getOAuthProviders: () => [{ id: "anthropic" }, { id: "openai-codex" }],
3341getOAuthApiKey: vi.fn(async (provider: string, credentials: Record<string, OAuthCredential>) => {
@@ -113,11 +121,10 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () =>
113121const mainRaw = JSON.parse(
114122await fs.readFile(path.join(mainAgentDir, "auth-profiles.json"), "utf8"),
115123) as AuthProfileStore;
116-expect(mainRaw.profiles[profileId]).toMatchObject({
117-access: "sub-refreshed-access",
118-refresh: "sub-refreshed-refresh",
119-expires: freshExpiry,
120-});
124+const mainCredential = requireOAuthCredential(mainRaw, profileId);
125+expect(mainCredential.access).toBe("sub-refreshed-access");
126+expect(mainCredential.refresh).toBe("sub-refreshed-refresh");
127+expect(mainCredential.expires).toBe(freshExpiry);
121128});
122129123130it("does not mirror when refresh was performed from the main agent itself", async () => {
@@ -154,11 +161,10 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () =>
154161const mainRaw = JSON.parse(
155162await fs.readFile(path.join(mainAgentDir, "auth-profiles.json"), "utf8"),
156163) as AuthProfileStore;
157-expect(mainRaw.profiles[profileId]).toMatchObject({
158-access: "main-refreshed-access",
159-refresh: "main-refreshed-refresh",
160-expires: freshExpiry,
161-});
164+const mainCredential = requireOAuthCredential(mainRaw, profileId);
165+expect(mainCredential.access).toBe("main-refreshed-access");
166+expect(mainCredential.refresh).toBe("main-refreshed-refresh");
167+expect(mainCredential.expires).toBe(freshExpiry);
162168expect(refreshProviderOAuthCredentialWithPluginMock).toHaveBeenCalledTimes(1);
163169});
164170@@ -326,19 +332,17 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () =>
326332const subRaw = JSON.parse(
327333await fs.readFile(path.join(subAgentDir, "auth-profiles.json"), "utf8"),
328334) as AuthProfileStore;
329-expect(subRaw.profiles[profileId]).toMatchObject({
330-access: "local-stale-access",
331-refresh: "local-stale-refresh",
332-});
335+const subCredential = requireOAuthCredential(subRaw, profileId);
336+expect(subCredential.access).toBe("local-stale-access");
337+expect(subCredential.refresh).toBe("local-stale-refresh");
333338334339const mainRaw = JSON.parse(
335340await fs.readFile(path.join(mainAgentDir, "auth-profiles.json"), "utf8"),
336341) as AuthProfileStore;
337-expect(mainRaw.profiles[profileId]).toMatchObject({
338-access: "main-owner-refreshed-access",
339-refresh: "main-owner-refreshed-refresh",
340-expires: freshExpiry,
341-});
342+const mainCredential = requireOAuthCredential(mainRaw, profileId);
343+expect(mainCredential.access).toBe("main-owner-refreshed-access");
344+expect(mainCredential.refresh).toBe("main-owner-refreshed-refresh");
345+expect(mainCredential.expires).toBe(freshExpiry);
342346});
343347344348it("inherits main-agent credentials via the catch-block fallback when refresh throws after main becomes fresh", async () => {
@@ -406,9 +410,7 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () =>
406410const subRaw = JSON.parse(
407411await fs.readFile(path.join(subAgentDir, "auth-profiles.json"), "utf8"),
408412) as AuthProfileStore;
409-expect(subRaw.profiles[profileId]).toMatchObject({
410-access: "cached-access-token",
411-});
413+expect(requireOAuthCredential(subRaw, profileId).access).toBe("cached-access-token");
412414});
413415414416it("mirrors refreshed credentials produced by the plugin-refresh path", async () => {
@@ -446,10 +448,9 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () =>
446448const mainRaw = JSON.parse(
447449await fs.readFile(path.join(mainAgentDir, "auth-profiles.json"), "utf8"),
448450) as AuthProfileStore;
449-expect(mainRaw.profiles[profileId]).toMatchObject({
450-access: "plugin-refreshed-access",
451-refresh: "plugin-refreshed-refresh",
452-expires: freshExpiry,
453-});
451+const mainCredential = requireOAuthCredential(mainRaw, profileId);
452+expect(mainCredential.access).toBe("plugin-refreshed-access");
453+expect(mainCredential.refresh).toBe("plugin-refreshed-refresh");
454+expect(mainCredential.expires).toBe(freshExpiry);
454455});
455456});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。