



















@@ -120,6 +120,28 @@ function createStartOptions(
120120};
121121}
122122123+async function expectPathMissing(filePath: string): Promise<void> {
124+try {
125+await fs.access(filePath);
126+} catch (error) {
127+expect((error as NodeJS.ErrnoException).code).toBe("ENOENT");
128+return;
129+}
130+throw new Error(`Expected missing path: ${filePath}`);
131+}
132+133+type AuthProfileStore = ReturnType<typeof loadAuthProfileStoreForSecretsRuntime>;
134+type AuthProfileCredential = AuthProfileStore["profiles"][string];
135+136+function expectOAuthProfile(
137+profile: AuthProfileCredential | undefined,
138+): Extract<AuthProfileCredential, { type: "oauth" }> {
139+if (!profile || profile.type !== "oauth") {
140+throw new Error("Expected OAuth auth profile");
141+}
142+return profile;
143+}
144+123145describe("bridgeCodexAppServerStartOptions", () => {
124146it("sets agent-owned CODEX_HOME and HOME for local app-server launches", async () => {
125147const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-app-server-"));
@@ -214,9 +236,7 @@ describe("bridgeCodexAppServerStartOptions", () => {
214236clearEnv: ["FOO", "CODEX_API_KEY", "OPENAI_API_KEY"],
215237});
216238expect(startOptions.clearEnv).toEqual(["FOO"]);
217-await expect(fs.access(path.join(agentDir, "harness-auth"))).rejects.toMatchObject({
218-code: "ENOENT",
219-});
239+await expectPathMissing(path.join(agentDir, "harness-auth"));
220240} finally {
221241await fs.rm(agentDir, { recursive: true, force: true });
222242}
@@ -987,13 +1007,13 @@ describe("bridgeCodexAppServerStartOptions", () => {
9871007});
98810089891009expect(oauthMocks.refreshOpenAICodexToken).toHaveBeenCalledWith("main-refresh-token");
990-await expect(fs.access(childAuthPath)).rejects.toMatchObject({ code: "ENOENT" });
991-expect(loadAuthProfileStoreForSecretsRuntime().profiles["openai-codex:work"]).toMatchObject({
992-type: "oauth",
993- provider: "openai-codex",
994- access: "main-refreshed-access-token",
995- refresh: "main-refreshed-refresh-token",
996-});
1010+await expectPathMissing(childAuthPath);
1011+const mainProfile = expectOAuthProfile(
1012+loadAuthProfileStoreForSecretsRuntime().profiles["openai-codex:work"],
1013+);
1014+expect(mainProfile?.provider).toBe("openai-codex");
1015+expect(mainProfile?.access).toBe("main-refreshed-access-token");
1016+expect(mainProfile?.refresh).toBe("main-refreshed-refresh-token");
9971017} finally {
9981018await fs.rm(root, { recursive: true, force: true });
9991019}
@@ -1056,19 +1076,17 @@ describe("bridgeCodexAppServerStartOptions", () => {
10561076});
1057107710581078expect(oauthMocks.refreshOpenAICodexToken).toHaveBeenCalledWith("main-owner-refresh-token");
1059-expect(loadAuthProfileStoreForSecretsRuntime().profiles["openai-codex:work"]).toMatchObject({
1060-type: "oauth",
1061-provider: "openai-codex",
1062-access: "main-refreshed-access-token",
1063-refresh: "main-refreshed-refresh-token",
1064-});
1065-const child = JSON.parse(await fs.readFile(childAuthPath, "utf8")) as {
1066-profiles: Record<string, { access?: string; refresh?: string }>;
1067-};
1068-expect(child.profiles["openai-codex:work"]).toMatchObject({
1069-access: "child-stale-access-token",
1070-refresh: "child-stale-refresh-token",
1071-});
1079+const mainProfile = expectOAuthProfile(
1080+loadAuthProfileStoreForSecretsRuntime().profiles["openai-codex:work"],
1081+);
1082+expect(mainProfile?.provider).toBe("openai-codex");
1083+expect(mainProfile?.access).toBe("main-refreshed-access-token");
1084+expect(mainProfile?.refresh).toBe("main-refreshed-refresh-token");
1085+const childProfile = expectOAuthProfile(
1086+loadAuthProfileStoreForSecretsRuntime(childAgentDir).profiles["openai-codex:work"],
1087+);
1088+expect(childProfile?.access).toBe("child-stale-access-token");
1089+expect(childProfile?.refresh).toBe("child-stale-refresh-token");
10721090} finally {
10731091await fs.rm(root, { recursive: true, force: true });
10741092}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。