test: tighten auth profile assertions · openclaw/openclaw@8eaca55
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -59,18 +59,18 @@ describe("auth profiles read-only external auth overlay", () => {
|
59 | 59 | const loaded = loadAuthProfileStoreForRuntime(agentDir, { readOnly: true }); |
60 | 60 | |
61 | 61 | expect(resolveExternalAuthProfilesWithPluginsMock).toHaveBeenCalled(); |
62 | | -expect(loaded.profiles["minimax-portal:default"]).toMatchObject({ |
63 | | -type: "oauth", |
64 | | -provider: "minimax-portal", |
65 | | -}); |
| 62 | +expect(loaded.profiles["minimax-portal:default"]?.type).toBe("oauth"); |
| 63 | +expect(loaded.profiles["minimax-portal:default"]?.provider).toBe("minimax-portal"); |
66 | 64 | |
67 | 65 | const persisted = JSON.parse(fs.readFileSync(authPath, "utf8")) as AuthProfileStore; |
68 | 66 | expect(persisted.profiles["minimax-portal:default"]).toBeUndefined(); |
69 | | -expect(persisted.profiles["openai:default"]).toMatchObject({ |
70 | | -type: "api_key", |
71 | | -provider: "openai", |
72 | | -key: "sk-test", |
73 | | -}); |
| 67 | +const persistedOpenAiProfile = persisted.profiles["openai:default"]; |
| 68 | +expect(persistedOpenAiProfile?.type).toBe("api_key"); |
| 69 | +if (persistedOpenAiProfile?.type !== "api_key") { |
| 70 | +throw new Error("expected persisted OpenAI API key profile"); |
| 71 | +} |
| 72 | +expect(persistedOpenAiProfile.provider).toBe("openai"); |
| 73 | +expect(persistedOpenAiProfile.key).toBe("sk-test"); |
74 | 74 | } finally { |
75 | 75 | fs.rmSync(agentDir, { recursive: true, force: true }); |
76 | 76 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -33,17 +33,18 @@ describe("overlayRuntimeExternalOAuthProfiles", () => {
|
33 | 33 | }, |
34 | 34 | ]); |
35 | 35 | |
36 | | -expect(overlaid.profiles["openai-codex:default"]).toMatchObject({ |
37 | | -access: "access-1", |
38 | | -}); |
| 36 | +const overlaidCodexProfile = overlaid.profiles["openai-codex:default"]; |
| 37 | +expect(overlaidCodexProfile?.type).toBe("oauth"); |
| 38 | +if (overlaidCodexProfile?.type !== "oauth") { |
| 39 | +throw new Error("expected overlaid Codex OAuth profile"); |
| 40 | +} |
| 41 | +expect(overlaidCodexProfile.access).toBe("access-1"); |
39 | 42 | expect(store.profiles["openai-codex:default"]).toBeUndefined(); |
40 | 43 | |
41 | 44 | overlaid.profiles["openai:default"].provider = "mutated"; |
42 | 45 | overlaid.order!.openai.push("mutated"); |
43 | 46 | |
44 | | -expect(store.profiles["openai:default"]).toMatchObject({ |
45 | | -provider: "openai", |
46 | | -}); |
| 47 | +expect(store.profiles["openai:default"]?.provider).toBe("openai"); |
47 | 48 | expect(store.order?.openai).toEqual(["openai:default"]); |
48 | 49 | expect(structuredCloneSpy).not.toHaveBeenCalled(); |
49 | 50 | } finally { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -890,18 +890,14 @@ describe("markAuthProfileFailure — WHAM-aware Codex cooldowns", () => {
|
890 | 890 | await markCodexFailureAt({ store, now }); |
891 | 891 | |
892 | 892 | expect(fetchMock).toHaveBeenCalledTimes(1); |
893 | | -expect(fetchMock).toHaveBeenCalledWith( |
894 | | -"https://chatgpt.com/backend-api/wham/usage", |
895 | | -expect.objectContaining({ |
896 | | -method: "GET", |
897 | | -headers: expect.objectContaining({ |
898 | | -Authorization: "Bearer codex-access-token", |
899 | | -"ChatGPT-Account-Id": "acct_test_123", |
900 | | -originator: "openclaw", |
901 | | -"User-Agent": expect.stringMatching(/^openclaw\//), |
902 | | -}), |
903 | | -}), |
904 | | -); |
| 893 | +const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit]; |
| 894 | +expect(url).toBe("https://chatgpt.com/backend-api/wham/usage"); |
| 895 | +expect(init.method).toBe("GET"); |
| 896 | +const headers = init.headers as Record<string, string>; |
| 897 | +expect(headers.Authorization).toBe("Bearer codex-access-token"); |
| 898 | +expect(headers["ChatGPT-Account-Id"]).toBe("acct_test_123"); |
| 899 | +expect(headers.originator).toBe("openclaw"); |
| 900 | +expect(headers["User-Agent"]).toMatch(/^openclaw\//); |
905 | 901 | expect(store.usageStats?.["openai-codex:default"]?.cooldownUntil).toBe(now + expectedMs); |
906 | 902 | }); |
907 | 903 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。