


























@@ -145,15 +145,20 @@ function makeForwardedRuntimePlan(overrides: RuntimePlanOverrides = {}): AgentRu
145145146146type MockWithCalls = {
147147mock: {
148-calls: Array<Array<unknown>>;
148+calls: ReadonlyArray<ReadonlyArray<unknown>>;
149149};
150150};
151151152-function mockCallArg(mock: MockWithCalls, callIndex = 0, argIndex = 0): unknown {
153-const call = mock.mock.calls.at(callIndex);
152+function mockCall(mock: MockWithCalls, callIndex = 0): ReadonlyArray<unknown> {
153+const call = mock.mock.calls[callIndex];
154154if (!call) {
155155throw new Error(`Expected mock call ${callIndex}`);
156156}
157+return call;
158+}
159+160+function mockCallArg(mock: MockWithCalls, callIndex = 0, argIndex = 0): unknown {
161+const call = mockCall(mock, callIndex);
157162if (argIndex >= call.length) {
158163throw new Error(`Expected mock call ${callIndex} argument ${argIndex}`);
159164}
@@ -257,14 +262,14 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
257262});
258263259264expect(mockedEnsureAuthProfileStore).not.toHaveBeenCalled();
260-const authStoreCall = mockedEnsureAuthProfileStoreWithoutExternalProfiles.mock.calls.at(0) as
261-| [string | undefined, { allowKeychainPrompt?: boolean } | undefined]
262- | undefined;
263-expect(typeof authStoreCall?.[0]).toBe("string");
264-expect(
265-String(authStoreCall?.[0]).replaceAll("\\", "/").endsWith("/.openclaw/agents/main/agent"),
266-).toBe(true);
267-expect(authStoreCall?.[1]).toEqual({ allowKeychainPrompt: false });
265+const [agentDir, authStoreOptions] = mockCall(
266+mockedEnsureAuthProfileStoreWithoutExternalProfiles,
267+) as [string | undefined, { allowKeychainPrompt?: boolean } | undefined];
268+expect(typeof agentDir).toBe("string");
269+expect(String(agentDir).replaceAll("\\", "/").endsWith("/.openclaw/agents/main/agent")).toBe(
270+true,
271+);
272+expect(authStoreOptions).toEqual({ allowKeychainPrompt: false });
268273});
269274270275it("forwards optional attempt params and the runtime plan into one attempt call", async () => {
@@ -297,9 +302,7 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
297302expect(typeof forwardedTools.normalize).toBe("function");
298303const forwardedTransport = expectRecordFields(forwardedPlan.transport, {});
299304expect(typeof forwardedTransport.resolveExtraParams).toBe("function");
300-const attemptParams = mockedRunEmbeddedAttempt.mock.calls.at(0)?.[0] as
301-| EmbeddedRunAttemptParams
302-| undefined;
305+const attemptParams = mockCallArg(mockedRunEmbeddedAttempt) as EmbeddedRunAttemptParams;
303306expect(attemptParams?.runtimePlan).toBe(runtimePlan);
304307expect(attemptParams?.internalEvents).toBe(internalEvents);
305308});
@@ -395,12 +398,15 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
395398forwardedAuthProfileId: "openai-codex:work",
396399},
397400});
398-const harnessParams = pluginRunAttempt.mock.calls.at(0)?.[0];
401+const harnessParams = mockCallArg(pluginRunAttempt) as {
402+runtimePlan?: unknown;
403+authProfileStore?: { profiles?: Record<string, unknown> };
404+};
399405expect(harnessParams?.runtimePlan).toBe(runtimePlan);
400-expect(Object.keys(harnessParams?.authProfileStore.profiles ?? {})).toEqual([
401- "openai-codex:work",
402-]);
403-expectRecordFields(harnessParams?.authProfileStore.profiles["openai-codex:work"], {
406+const authProfileStore = expectRecordFields(harnessParams.authProfileStore, {});
407+const authProfiles = expectRecordFields(authProfileStore.profiles, {});
408+expect(Object.keys(authProfiles)).toEqual(["openai-codex:work"]);
409+expectRecordFields(authProfiles["openai-codex:work"], {
404410provider: "openai-codex",
405411});
406412});
@@ -472,7 +478,7 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
472478forwardedAuthProfileId: "openai-codex:work",
473479},
474480});
475-const harnessParams = pluginRunAttempt.mock.calls.at(0)?.[0];
481+const harnessParams = mockCallArg(pluginRunAttempt) as { runtimePlan?: unknown };
476482expect(harnessParams?.runtimePlan).toBe(runtimePlan);
477483expect(mockedMarkAuthProfileSuccess).toHaveBeenCalledTimes(1);
478484const [[successParams]] = mockedMarkAuthProfileSuccess.mock.calls as unknown as Array<
@@ -549,7 +555,7 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
549555forwardedAuthProfileId: "openai-codex:default",
550556},
551557});
552-const harnessParams = pluginRunAttempt.mock.calls.at(0)?.[0];
558+const harnessParams = mockCallArg(pluginRunAttempt) as { runtimePlan?: unknown };
553559expect(harnessParams?.runtimePlan).toBe(runtimePlan);
554560});
555561@@ -622,7 +628,7 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
622628forwardedAuthProfileId: "openai-codex:default",
623629},
624630});
625-const harnessParams = pluginRunAttempt.mock.calls.at(0)?.[0];
631+const harnessParams = mockCallArg(pluginRunAttempt) as { runtimePlan?: unknown };
626632expect(harnessParams?.runtimePlan).toBe(runtimePlan);
627633});
628634@@ -707,12 +713,15 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => {
707713forwardedAuthProfileId: "openai:personal",
708714},
709715});
710-const harnessParams = pluginRunAttempt.mock.calls.at(0)?.[0];
716+const harnessParams = mockCallArg(pluginRunAttempt) as {
717+runtimePlan?: unknown;
718+authProfileStore?: { profiles?: Record<string, unknown> };
719+};
711720expect(harnessParams?.runtimePlan).toBe(runtimePlan);
712-expect(Object.keys(harnessParams?.authProfileStore.profiles ?? {})).toEqual([
713- "openai:personal",
714-]);
715-expectRecordFields(harnessParams?.authProfileStore.profiles["openai:personal"], {
721+const authProfileStore = expectRecordFields(harnessParams.authProfileStore, {});
722+const authProfiles = expectRecordFields(authProfileStore.profiles, {});
723+expect(Object.keys(authProfiles)).toEqual(["openai:personal"]);
724+expectRecordFields(authProfiles["openai:personal"], {
716725provider: "openai-codex",
717726});
718727});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。