























@@ -56,6 +56,53 @@ async function sendEmptyModelList(harness: ReturnType<typeof createClientHarness
5656harness.send({ id: modelList.id, result: { data: [] } });
5757}
585859+function firstMockArg(mock: unknown, label: string): unknown {
60+const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.at(0);
61+if (!call) {
62+throw new Error(`Expected ${label} first call`);
63+}
64+return call[0];
65+}
66+67+function bridgeStartOptionsCall() {
68+return firstMockArg(mocks.bridgeCodexAppServerStartOptions, "bridge start options") as {
69+agentDir?: string;
70+authProfileId?: string;
71+config?: unknown;
72+startOptions: { command?: string; commandSource?: string };
73+};
74+}
75+76+function applyAuthProfileCall() {
77+return firstMockArg(mocks.applyCodexAppServerAuthProfile, "apply auth profile") as {
78+agentDir?: string;
79+authProfileId?: string;
80+config?: unknown;
81+};
82+}
83+84+function resolveAuthProfileCall() {
85+return firstMockArg(mocks.resolveCodexAppServerAuthProfileIdForAgent, "resolve auth profile") as {
86+agentDir?: string;
87+authProfileId?: string;
88+config?: unknown;
89+};
90+}
91+92+function managedStartOptionsCall() {
93+return firstMockArg(mocks.resolveManagedCodexAppServerStartOptions, "managed start options") as {
94+command?: string;
95+commandSource?: string;
96+};
97+}
98+99+function clientStartCall(startSpy: unknown) {
100+return firstMockArg(startSpy, "CodexAppServerClient.start") as {
101+command?: string;
102+commandSource?: string;
103+};
104+}
105+59106describe("shared Codex app-server client", () => {
60107beforeAll(async () => {
61108({ listCodexAppServerModels } = await import("./models.js"));
@@ -145,9 +192,9 @@ describe("shared Codex app-server client", () => {
145192await sendEmptyModelList(harness);
146193147194await expect(listPromise).resolves.toEqual({ models: [] });
148-const [bridgeCall] = mocks.bridgeCodexAppServerStartOptions.mock.calls[0] ?? [];
195+const bridgeCall = bridgeStartOptionsCall();
149196expect(bridgeCall?.authProfileId).toBe("openai-codex:work");
150-const [applyCall] = mocks.applyCodexAppServerAuthProfile.mock.calls[0] ?? [];
197+const applyCall = applyAuthProfileCall();
151198expect(applyCall?.authProfileId).toBe("openai-codex:work");
152199});
153200@@ -165,16 +212,16 @@ describe("shared Codex app-server client", () => {
165212await sendEmptyModelList(harness);
166213167214await expect(listPromise).resolves.toEqual({ models: [] });
168-const [resolveCall] = mocks.resolveCodexAppServerAuthProfileIdForAgent.mock.calls[0] ?? [];
215+const resolveCall = resolveAuthProfileCall();
169216expect(resolveCall).toStrictEqual({
170217authProfileId: undefined,
171218agentDir: "/tmp/openclaw-agent",
172219 config,
173220});
174-const [bridgeCall] = mocks.bridgeCodexAppServerStartOptions.mock.calls[0] ?? [];
221+const bridgeCall = bridgeStartOptionsCall();
175222expect(bridgeCall?.authProfileId).toBe("openai-codex:work");
176223expect(bridgeCall?.config).toBe(config);
177-const [applyCall] = mocks.applyCodexAppServerAuthProfile.mock.calls[0] ?? [];
224+const applyCall = applyAuthProfileCall();
178225expect(applyCall?.authProfileId).toBe("openai-codex:work");
179226expect(applyCall?.config).toBe(config);
180227});
@@ -192,10 +239,10 @@ describe("shared Codex app-server client", () => {
192239await sendEmptyModelList(harness);
193240194241await expect(listPromise).resolves.toEqual({ models: [] });
195-const [bridgeCall] = mocks.bridgeCodexAppServerStartOptions.mock.calls[0] ?? [];
242+const bridgeCall = bridgeStartOptionsCall();
196243expect(bridgeCall?.agentDir).toBe("/tmp/openclaw-agent-nova");
197244expect(bridgeCall?.authProfileId).toBe("openai-codex:work");
198-const [applyCall] = mocks.applyCodexAppServerAuthProfile.mock.calls[0] ?? [];
245+const applyCall = applyAuthProfileCall();
199246expect(applyCall?.agentDir).toBe("/tmp/openclaw-agent-nova");
200247expect(applyCall?.authProfileId).toBe("openai-codex:work");
201248});
@@ -214,13 +261,13 @@ describe("shared Codex app-server client", () => {
214261await sendEmptyModelList(harness);
215262216263await expect(listPromise).resolves.toEqual({ models: [] });
217-const [managedCall] = mocks.resolveManagedCodexAppServerStartOptions.mock.calls[0] ?? [];
264+const managedCall = managedStartOptionsCall();
218265expect(managedCall?.command).toBe("codex");
219266expect(managedCall?.commandSource).toBe("managed");
220-const [bridgeCall] = mocks.bridgeCodexAppServerStartOptions.mock.calls[0] ?? [];
267+const bridgeCall = bridgeStartOptionsCall();
221268expect(bridgeCall?.startOptions.command).toBe("/cache/openclaw/codex");
222269expect(bridgeCall?.startOptions.commandSource).toBe("resolved-managed");
223-const [startCall] = startSpy.mock.calls[0] ?? [];
270+const startCall = clientStartCall(startSpy);
224271expect(startCall?.command).toBe("/cache/openclaw/codex");
225272expect(startCall?.commandSource).toBe("resolved-managed");
226273});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。