From b0293019e93537dfdb8a8d58c9e23a3f143b1046 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 12:06:36 -0400 Subject: [PATCH 1/7] test(e2e): audit hotfix stabilizer parity --- .../live/channels-add-remove.test.ts | 5 +- .../live/kimi-inference-compat-helpers.ts | 105 ++++++++++++++++-- .../live/kimi-inference-compat.test.ts | 2 +- .../live/openclaw-inference-switch.test.ts | 14 ++- .../kimi-inference-compat-helpers.test.ts | 57 ++++++++++ 5 files changed, 167 insertions(+), 16 deletions(-) diff --git a/test/e2e-scenario/live/channels-add-remove.test.ts b/test/e2e-scenario/live/channels-add-remove.test.ts index af58ebfce81..f0ce33fe769 100644 --- a/test/e2e-scenario/live/channels-add-remove.test.ts +++ b/test/e2e-scenario/live/channels-add-remove.test.ts @@ -383,6 +383,7 @@ liveTest( "post-add rebuild reuses the gateway-stored inference credential when NVIDIA_INFERENCE_API_KEY is absent", "post-add rebuild applies the Telegram policy preset and renders openclaw.json channel state", "channels remove telegram removes provider, policy, registry plan, and rendered channel state after rebuild", + "post-remove rebuild does not use stale Telegram host env inputs that would stage a fresh channel add", ], }); @@ -497,8 +498,8 @@ liveTest( expectHostTelegramPlan("removed", "after channels remove"); const rebuildRemove = await host.nemoclaw([SANDBOX_NAME, "rebuild", "--yes"], { - artifactName: "phase-5-rebuild-after-remove", - env: channelEnv({ NVIDIA_INFERENCE_API_KEY: apiKey }), + artifactName: "phase-5-rebuild-after-remove-without-telegram-env", + env: baseEnv({ NVIDIA_INFERENCE_API_KEY: apiKey }), redactionValues: secretsToRedact, timeoutMs: REBUILD_TIMEOUT_MS, }); diff --git a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts index 35b87b2651b..025f557618c 100644 --- a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts +++ b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts @@ -422,14 +422,27 @@ export function parseConfig(raw: string): { }; } -export async function assertTrajectory(sandbox: SandboxClient): Promise { - const checkScript = String.raw`import json, pathlib, sys +export interface KimiTrajectorySummary { + errors: string[]; + finalStatus?: unknown; + finalTextCount: number; + roles: unknown[]; + sourceCommands: unknown[]; + strictMockExpectations: boolean; + toolMetaCommandSet: string[]; + toolMetaInvalidValues: unknown[]; + toolMetasCount: number; +} + +export function buildKimiTrajectoryCheckScript(strictMockExpectations: boolean): string { + return String.raw`import json, pathlib, re, sys +strict_mock = __STRICT_MOCK__ root=pathlib.Path('/sandbox/.openclaw') base=pathlib.Path('/sandbox/.openclaw/agents/main/sessions') session=base/'e2e-kimi-tools.jsonl' trajectory=base/'e2e-kimi-tools.trajectory.jsonl' if not session.exists() or not trajectory.exists(): - print(json.dumps({'error':'missing session/trajectory','files':[str(p) for p in root.rglob('*e2e-kimi-tools*.jsonl')]})) + print(json.dumps({'errors':['missing session/trajectory'],'files':[str(p) for p in root.rglob('*e2e-kimi-tools*.jsonl')]})) sys.exit(1) session_items=[json.loads(line) for line in session.read_text().splitlines() if line.strip()] trajectory_items=[json.loads(line) for line in trajectory.read_text().splitlines() if line.strip()] @@ -438,17 +451,35 @@ artifacts=[item for item in trajectory_items if item.get('type')=='trace.artifac if len(artifacts)!=1: errors.append(f'trace.artifacts count={len(artifacts)}') data=(artifacts[-1].get('data') if artifacts else {}) or {} metas=data.get('toolMetas') or [] +meta_commands=[m.get('meta') for m in metas] +meta_commands_str=[command for command in meta_commands if isinstance(command, str)] +invalid_meta_commands=[command for command in meta_commands if not isinstance(command, str)] +expected_round=['hostname','date','uptime'] +expected_command_set=sorted(expected_round) if data.get('finalStatus')!='success': errors.append(f'finalStatus={data.get("finalStatus")!r}') -if len(metas)!=3: errors.append(f'toolMetas count={len(metas)}') -if [m.get('toolName') for m in metas] != ['exec','exec','exec']: errors.append('tool names mismatch') -if sorted(m.get('meta') for m in metas) != ['date','hostname','uptime']: errors.append('tool command set mismatch') +min_metas = 3 if strict_mock else 1 +if len(metas) < min_metas: errors.append(f'toolMetas count={len(metas)} expected_at_least={min_metas}') +if any(m.get('toolName') != 'exec' for m in metas): errors.append('tool names mismatch') messages=[item.get('message',{}) for item in session_items if item.get('type')=='message'] assistant_tool_messages=[m for m in messages if m.get('role')=='assistant' and any(b.get('type')=='toolCall' for b in m.get('content',[]))] source=[] for m in assistant_tool_messages: source.extend(b.get('arguments',{}).get('command') for b in m.get('content',[]) if b.get('type')=='toolCall') -if source != ['hostname','date','uptime']: errors.append(f'source commands={source!r}') -if any(isinstance(c,str) and ';' in c for c in source): errors.append('combined semicolon command remains') +if not source: errors.append('source assistant did not record any exec commands') +if strict_mock: + if invalid_meta_commands: + errors.append(f'toolMeta meta values are not all strings: {invalid_meta_commands!r}') + elif sorted(set(meta_commands_str)) != expected_command_set: + errors.append(f'tool command set={sorted(set(meta_commands_str))!r}') + if len(source) < len(expected_round) or len(source) % len(expected_round) != 0: + errors.append(f'source commands={source!r}') + else: + for offset in range(0, len(source), len(expected_round)): + if source[offset:offset + len(expected_round)] != expected_round: + errors.append(f'source commands={source!r}') + break +combined=[c for c in source if isinstance(c,str) and re.search(r';|&&|\|\||[\r\n]', c)] +if combined: errors.append(f'combined shell command remains: {combined!r}') raw=session.read_text()+trajectory.read_text() for token in ['abandoned','want me to continue']: if token in raw.lower(): errors.append(f'contains {token}') @@ -458,16 +489,66 @@ for field in ['aborted','externalAbort','timedOut','idleTimedOut','timedOutDurin def normalize_final_text(value): return value.strip().removesuffix('.') if isinstance(value, str) else value final_texts=data.get('assistantTexts') or [] -if not final_texts or normalize_final_text(final_texts[-1]) != 'hostname, date, and uptime completed successfully': errors.append('final text mismatch') +expected_final_text='hostname, date, and uptime completed successfully' +if strict_mock and (not final_texts or expected_final_text not in normalize_final_text(final_texts[-1])): + errors.append('final text mismatch') +elif not final_texts: + errors.append('missing final assistant text') roles=[m.get('role') for m in messages] if not ('toolResult' in roles and roles[-1]=='assistant'): errors.append('final assistant not after tool result') -print(json.dumps({'errors':errors,'source':source,'toolMetas':metas,'roles':roles}, indent=2)) -sys.exit(1 if errors else 0)`; +summary={ + 'errors': errors, + 'finalStatus': data.get('finalStatus'), + 'finalTextCount': len(final_texts), + 'roles': roles, + 'sourceCommands': source, + 'strictMockExpectations': strict_mock, + 'toolMetaCommandSet': sorted(set(meta_commands_str)), + 'toolMetaInvalidValues': invalid_meta_commands, + 'toolMetasCount': len(metas), +} +print(json.dumps(summary, indent=2)) +sys.exit(1 if errors else 0)`.replace("__STRICT_MOCK__", strictMockExpectations ? "True" : "False"); +} + +export function assertKimiTrajectorySummary(summary: KimiTrajectorySummary): void { + expect(summary.errors).toEqual([]); + expect(summary.finalStatus).toBe("success"); + expect(summary.finalTextCount).toBeGreaterThan(0); + expect(summary.roles).toContain("toolResult"); + expect(summary.roles.at(-1)).toBe("assistant"); + expect(summary.sourceCommands.length).toBeGreaterThan(0); + expect(summary.sourceCommands).not.toEqual( + expect.arrayContaining([expect.stringMatching(/;|&&|\|\||[\r\n]/)]), + ); + expect(summary.toolMetasCount).toBeGreaterThanOrEqual(summary.strictMockExpectations ? 3 : 1); + if (summary.strictMockExpectations) { + const expectedRound = ["hostname", "date", "uptime"]; + expect(summary.toolMetaInvalidValues).toEqual([]); + expect(summary.toolMetaCommandSet).toEqual(["date", "hostname", "uptime"]); + expect(summary.sourceCommands.length % expectedRound.length).toBe(0); + for (let index = 0; index < summary.sourceCommands.length; index += expectedRound.length) { + expect(summary.sourceCommands.slice(index, index + expectedRound.length)).toEqual( + expectedRound, + ); + } + } +} + +export async function assertTrajectory( + sandbox: SandboxClient, + mode: KimiInferenceMode, +): Promise { + const checkScript = buildKimiTrajectoryCheckScript(mode === "mock"); const encoded = Buffer.from(checkScript, "utf8").toString("base64"); const trajectory = await sandbox.execShell( SANDBOX_NAME, trustedSandboxShellScript(`python3 -c "$(printf %s '${encoded}' | base64 -d)"`), - { artifactName: "kimi-trajectory-tool-splitting-check", env: env(), timeoutMs: 60_000 }, + { + artifactName: "kimi-trajectory-tool-splitting-check", + env: env({}, { mode }), + timeoutMs: 60_000, + }, ); expect(trajectory.exitCode, resultText(trajectory)).toBe(0); } diff --git a/test/e2e-scenario/live/kimi-inference-compat.test.ts b/test/e2e-scenario/live/kimi-inference-compat.test.ts index 8b128e17ec6..5fd9b8af927 100644 --- a/test/e2e-scenario/live/kimi-inference-compat.test.ts +++ b/test/e2e-scenario/live/kimi-inference-compat.test.ts @@ -119,7 +119,7 @@ test.skipIf(!shouldRunLiveE2EScenarios())( }, ); expect(toolAgent.exitCode, resultText(toolAgent)).toBe(0); - await assertTrajectory(sandbox); + await assertTrajectory(sandbox, mode); await assertKimiUpstreamTraffic({ fake, host, mode, apiKey }); }, ); diff --git a/test/e2e-scenario/live/openclaw-inference-switch.test.ts b/test/e2e-scenario/live/openclaw-inference-switch.test.ts index 170967e9457..996c3e70068 100644 --- a/test/e2e-scenario/live/openclaw-inference-switch.test.ts +++ b/test/e2e-scenario/live/openclaw-inference-switch.test.ts @@ -660,6 +660,12 @@ function collectOpenClawAgentText(value: unknown, parts: string[], visited: Set< } } +function agentReplyContainsToken(reply: string, expected: string): boolean { + const compactReply = reply.replace(/\s+/gu, "").toUpperCase(); + const compactExpected = expected.replace(/\s+/gu, "").toUpperCase(); + return compactExpected.length > 0 && compactReply.includes(compactExpected); +} + function parseOpenClawAgentText(raw: string): string { if (!raw.trim()) return ""; const parts: string[] = []; @@ -739,7 +745,7 @@ exit "$rc" }); const [raw = "", warnings = ""] = result.stdout.split("\n__NEMOCLAW_AGENT_STDERR__\n", 2); const reply = parseOpenClawAgentText(raw); - if (result.exitCode === 0 && /\bPONG\b/i.test(reply)) return "ok"; + if (result.exitCode === 0 && agentReplyContainsToken(reply, "PONG")) return "ok"; if (result.exitCode === 124) { return { skipped: "OpenClaw agent turn timed out after switch; route/config checks already passed", @@ -755,6 +761,12 @@ exit "$rc" ); } +test("openclaw-inference-switch agent reply matching tolerates wrapped PONG", () => { + expect(agentReplyContainsToken("P\nO N G", "PONG")).toBe(true); + expect(agentReplyContainsToken("wrapped: p o\nng", "PONG")).toBe(true); + expect(agentReplyContainsToken("PANG", "PONG")).toBe(false); +}); + function isTransientInferenceSetFailure(text: string): boolean { return /timed? out|timeout|ETIMEDOUT|ECONNRESET|EAI_AGAIN|ENOTFOUND|failed to connect|error sending request|failed to verify inference endpoint|502|503|504|temporar/i.test( text, diff --git a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts index c06d9030e60..bb31e082192 100644 --- a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts +++ b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts @@ -4,6 +4,8 @@ import { describe, expect, it } from "vitest"; import { + assertKimiTrajectorySummary, + buildKimiTrajectoryCheckScript, env, kimiAgentEnv, kimiOnboardEnv, @@ -74,4 +76,59 @@ describe("Kimi inference compatibility mode selection", () => { it("keeps legacy NEMOCLAW_KIMI_USE_MOCK=0 as temporary public-nvidia alias", () => { expect(resolveKimiInferenceMode({ NEMOCLAW_KIMI_USE_MOCK: "0" })).toBe("public-nvidia"); }); + + it("keeps mock Kimi trajectory checks strict for split hostname/date/uptime calls", () => { + const script = buildKimiTrajectoryCheckScript(true); + expect(script).toContain("strict_mock = True"); + expect(script).toContain("tool command set"); + expect(script).toContain("source commands"); + expect(script).toContain("final text mismatch"); + + assertKimiTrajectorySummary({ + errors: [], + finalStatus: "success", + finalTextCount: 1, + roles: ["assistant", "toolResult", "assistant"], + sourceCommands: ["hostname", "date", "uptime"], + strictMockExpectations: true, + toolMetaCommandSet: ["date", "hostname", "uptime"], + toolMetaInvalidValues: [], + toolMetasCount: 3, + }); + }); + + it("allows public Kimi trajectories with fewer safe exec calls but no combined shell", () => { + const script = buildKimiTrajectoryCheckScript(false); + expect(script).toContain("strict_mock = False"); + expect(script).toContain("min_metas = 3 if strict_mock else 1"); + expect(script).toContain("combined shell command remains"); + + assertKimiTrajectorySummary({ + errors: [], + finalStatus: "success", + finalTextCount: 1, + roles: ["assistant", "toolResult", "assistant"], + sourceCommands: ["hostname"], + strictMockExpectations: false, + toolMetaCommandSet: ["hostname"], + toolMetaInvalidValues: [null], + toolMetasCount: 1, + }); + }); + + it("rejects combined shell commands in both mock and public Kimi trajectory summaries", () => { + expect(() => + assertKimiTrajectorySummary({ + errors: [], + finalStatus: "success", + finalTextCount: 1, + roles: ["assistant", "toolResult", "assistant"], + sourceCommands: ["hostname; date; uptime"], + strictMockExpectations: false, + toolMetaCommandSet: ["hostname; date; uptime"], + toolMetaInvalidValues: [], + toolMetasCount: 1, + }), + ).toThrow(); + }); }); From febce42323c5e7e7e6d434d479be9ea383ccce58 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 12:52:16 -0400 Subject: [PATCH 2/7] fix(onboard): pass manifests to channel availability --- src/lib/onboard/messaging-channel-setup.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/onboard/messaging-channel-setup.ts b/src/lib/onboard/messaging-channel-setup.ts index 7dfe4165312..4d9cce4dd6e 100644 --- a/src/lib/onboard/messaging-channel-setup.ts +++ b/src/lib/onboard/messaging-channel-setup.ts @@ -69,7 +69,10 @@ const getMessagingInputValue = (input: ChannelInputSpec): string | null => { */ export function detectMessagingChannelsFromEnv(agent: AgentDefinition | null = null): string[] { const manifestRegistry = createBuiltInChannelManifestRegistry(); - const availabilityContext = getMessagingManifestAvailabilityContext(agent); + const availabilityContext = getMessagingManifestAvailabilityContext( + agent, + manifestRegistry.list(), + ); const availableChannels = manifestRegistry.listAvailable(availabilityContext); return availableChannels .filter((manifest) => hasMessagingManifestRequiredInputs(manifest, getMessagingInputValue)) From 88b92475bd4d715cc5a3afa892d2d4a08dd57138 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 13:11:47 -0400 Subject: [PATCH 3/7] fix(e2e): tighten parity token guards --- .../live/kimi-inference-compat-helpers.ts | 7 +++-- .../live/openclaw-inference-switch.test.ts | 14 +++++++-- .../kimi-inference-compat-helpers.test.ts | 30 ++++++++++--------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts index 025f557618c..9a49bb5e47c 100644 --- a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts +++ b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts @@ -466,6 +466,8 @@ source=[] for m in assistant_tool_messages: source.extend(b.get('arguments',{}).get('command') for b in m.get('content',[]) if b.get('type')=='toolCall') if not source: errors.append('source assistant did not record any exec commands') +invalid_source_commands=[c for c in source if not isinstance(c,str)] +if invalid_source_commands: errors.append(f'source commands are not all strings: {invalid_source_commands!r}') if strict_mock: if invalid_meta_commands: errors.append(f'toolMeta meta values are not all strings: {invalid_meta_commands!r}') @@ -478,7 +480,7 @@ if strict_mock: if source[offset:offset + len(expected_round)] != expected_round: errors.append(f'source commands={source!r}') break -combined=[c for c in source if isinstance(c,str) and re.search(r';|&&|\|\||[\r\n]', c)] +combined=[c for c in source if isinstance(c,str) and re.search(r';|&&?|\|\|?|[\r\n]', c)] if combined: errors.append(f'combined shell command remains: {combined!r}') raw=session.read_text()+trajectory.read_text() for token in ['abandoned','want me to continue']: @@ -518,8 +520,9 @@ export function assertKimiTrajectorySummary(summary: KimiTrajectorySummary): voi expect(summary.roles).toContain("toolResult"); expect(summary.roles.at(-1)).toBe("assistant"); expect(summary.sourceCommands.length).toBeGreaterThan(0); + expect(summary.sourceCommands.every((command) => typeof command === "string")).toBe(true); expect(summary.sourceCommands).not.toEqual( - expect.arrayContaining([expect.stringMatching(/;|&&|\|\||[\r\n]/)]), + expect.arrayContaining([expect.stringMatching(/;|&&?|\|\|?|[\r\n]/)]), ); expect(summary.toolMetasCount).toBeGreaterThanOrEqual(summary.strictMockExpectations ? 3 : 1); if (summary.strictMockExpectations) { diff --git a/test/e2e-scenario/live/openclaw-inference-switch.test.ts b/test/e2e-scenario/live/openclaw-inference-switch.test.ts index 996c3e70068..6b301169826 100644 --- a/test/e2e-scenario/live/openclaw-inference-switch.test.ts +++ b/test/e2e-scenario/live/openclaw-inference-switch.test.ts @@ -661,9 +661,15 @@ function collectOpenClawAgentText(value: unknown, parts: string[], visited: Set< } function agentReplyContainsToken(reply: string, expected: string): boolean { - const compactReply = reply.replace(/\s+/gu, "").toUpperCase(); - const compactExpected = expected.replace(/\s+/gu, "").toUpperCase(); - return compactExpected.length > 0 && compactReply.includes(compactExpected); + const normalizedExpected = expected.replace(/\s+/gu, "").toUpperCase(); + if (!normalizedExpected) return false; + const tokenPattern = normalizedExpected + .replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + .split("") + .join("\\s*"); + return new RegExp(String.raw`(^|[^\p{L}\p{N}_])${tokenPattern}(?=$|[^\p{L}\p{N}_])`, "u").test( + reply.toUpperCase(), + ); } function parseOpenClawAgentText(raw: string): string { @@ -765,6 +771,8 @@ test("openclaw-inference-switch agent reply matching tolerates wrapped PONG", () expect(agentReplyContainsToken("P\nO N G", "PONG")).toBe(true); expect(agentReplyContainsToken("wrapped: p o\nng", "PONG")).toBe(true); expect(agentReplyContainsToken("PANG", "PONG")).toBe(false); + expect(agentReplyContainsToken("SPONGE", "PONG")).toBe(false); + expect(agentReplyContainsToken("pingpong", "PONG")).toBe(false); }); function isTransientInferenceSetFailure(text: string): boolean { diff --git a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts index bb31e082192..0ed51c11190 100644 --- a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts +++ b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts @@ -116,19 +116,21 @@ describe("Kimi inference compatibility mode selection", () => { }); }); - it("rejects combined shell commands in both mock and public Kimi trajectory summaries", () => { - expect(() => - assertKimiTrajectorySummary({ - errors: [], - finalStatus: "success", - finalTextCount: 1, - roles: ["assistant", "toolResult", "assistant"], - sourceCommands: ["hostname; date; uptime"], - strictMockExpectations: false, - toolMetaCommandSet: ["hostname; date; uptime"], - toolMetaInvalidValues: [], - toolMetasCount: 1, - }), - ).toThrow(); + it("rejects unsafe or malformed source commands in both mock and public trajectory summaries", () => { + for (const sourceCommands of [["hostname; date; uptime"], ["hostname | date"], [null]]) { + expect(() => + assertKimiTrajectorySummary({ + errors: [], + finalStatus: "success", + finalTextCount: 1, + roles: ["assistant", "toolResult", "assistant"], + sourceCommands, + strictMockExpectations: false, + toolMetaCommandSet: ["hostname"], + toolMetaInvalidValues: [], + toolMetasCount: 1, + }), + ).toThrow(); + } }); }); From a6944950c2ce157bf1fe1b95b09df228baaa0f19 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 13:21:25 -0400 Subject: [PATCH 4/7] fix(e2e): avoid added conditional in token matcher --- test/e2e-scenario/live/openclaw-inference-switch.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/e2e-scenario/live/openclaw-inference-switch.test.ts b/test/e2e-scenario/live/openclaw-inference-switch.test.ts index 6b301169826..a77133ae93a 100644 --- a/test/e2e-scenario/live/openclaw-inference-switch.test.ts +++ b/test/e2e-scenario/live/openclaw-inference-switch.test.ts @@ -662,13 +662,15 @@ function collectOpenClawAgentText(value: unknown, parts: string[], visited: Set< function agentReplyContainsToken(reply: string, expected: string): boolean { const normalizedExpected = expected.replace(/\s+/gu, "").toUpperCase(); - if (!normalizedExpected) return false; const tokenPattern = normalizedExpected .replace(/[.*+?^${}()|[\]\\]/g, "\\$&") .split("") .join("\\s*"); - return new RegExp(String.raw`(^|[^\p{L}\p{N}_])${tokenPattern}(?=$|[^\p{L}\p{N}_])`, "u").test( - reply.toUpperCase(), + return ( + normalizedExpected.length > 0 && + new RegExp(String.raw`(^|[^\p{L}\p{N}_])${tokenPattern}(?=$|[^\p{L}\p{N}_])`, "u").test( + reply.toUpperCase(), + ) ); } From 6776ea4c1eed15daee5c3964678c2e3334de8131 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 13:35:08 -0400 Subject: [PATCH 5/7] fix(e2e): address advisor parity gaps --- .../live/channels-add-remove.test.ts | 4 ++-- .../live/kimi-inference-compat-helpers.ts | 10 ++++++---- .../live/openclaw-inference-switch.test.ts | 16 +++++----------- .../kimi-inference-compat-helpers.test.ts | 13 +++++++++++-- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/test/e2e-scenario/live/channels-add-remove.test.ts b/test/e2e-scenario/live/channels-add-remove.test.ts index f0ce33fe769..b69e85cf143 100644 --- a/test/e2e-scenario/live/channels-add-remove.test.ts +++ b/test/e2e-scenario/live/channels-add-remove.test.ts @@ -498,8 +498,8 @@ liveTest( expectHostTelegramPlan("removed", "after channels remove"); const rebuildRemove = await host.nemoclaw([SANDBOX_NAME, "rebuild", "--yes"], { - artifactName: "phase-5-rebuild-after-remove-without-telegram-env", - env: baseEnv({ NVIDIA_INFERENCE_API_KEY: apiKey }), + artifactName: "phase-5-rebuild-after-remove-with-stale-telegram-env", + env: channelEnv({ NVIDIA_INFERENCE_API_KEY: apiKey }), redactionValues: secretsToRedact, timeoutMs: REBUILD_TIMEOUT_MS, }); diff --git a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts index 9a49bb5e47c..fc17ac48ce5 100644 --- a/test/e2e-scenario/live/kimi-inference-compat-helpers.ts +++ b/test/e2e-scenario/live/kimi-inference-compat-helpers.ts @@ -480,8 +480,9 @@ if strict_mock: if source[offset:offset + len(expected_round)] != expected_round: errors.append(f'source commands={source!r}') break -combined=[c for c in source if isinstance(c,str) and re.search(r';|&&?|\|\|?|[\r\n]', c)] -if combined: errors.append(f'combined shell command remains: {combined!r}') +safe_source_commands=[c for c in source if isinstance(c,str) and c in expected_round] +unsafe_source_commands=[c for c in source if isinstance(c,str) and c not in expected_round] +if unsafe_source_commands: errors.append(f'unsafe source command remains: {unsafe_source_commands!r}') raw=session.read_text()+trajectory.read_text() for token in ['abandoned','want me to continue']: if token in raw.lower(): errors.append(f'contains {token}') @@ -521,8 +522,9 @@ export function assertKimiTrajectorySummary(summary: KimiTrajectorySummary): voi expect(summary.roles.at(-1)).toBe("assistant"); expect(summary.sourceCommands.length).toBeGreaterThan(0); expect(summary.sourceCommands.every((command) => typeof command === "string")).toBe(true); - expect(summary.sourceCommands).not.toEqual( - expect.arrayContaining([expect.stringMatching(/;|&&?|\|\|?|[\r\n]/)]), + const safeSourceCommands = new Set(["hostname", "date", "uptime"]); + expect(summary.sourceCommands.every((command) => safeSourceCommands.has(command as string))).toBe( + true, ); expect(summary.toolMetasCount).toBeGreaterThanOrEqual(summary.strictMockExpectations ? 3 : 1); if (summary.strictMockExpectations) { diff --git a/test/e2e-scenario/live/openclaw-inference-switch.test.ts b/test/e2e-scenario/live/openclaw-inference-switch.test.ts index 29ec941db53..5d0353c75f7 100644 --- a/test/e2e-scenario/live/openclaw-inference-switch.test.ts +++ b/test/e2e-scenario/live/openclaw-inference-switch.test.ts @@ -704,17 +704,9 @@ function collectOpenClawAgentText(value: unknown, parts: string[], visited: Set< } function agentReplyContainsToken(reply: string, expected: string): boolean { + const normalizedReply = reply.replace(/\s+/gu, "").toUpperCase(); const normalizedExpected = expected.replace(/\s+/gu, "").toUpperCase(); - const tokenPattern = normalizedExpected - .replace(/[.*+?^${}()|[\]\\]/g, "\\$&") - .split("") - .join("\\s*"); - return ( - normalizedExpected.length > 0 && - new RegExp(String.raw`(^|[^\p{L}\p{N}_])${tokenPattern}(?=$|[^\p{L}\p{N}_])`, "u").test( - reply.toUpperCase(), - ) - ); + return normalizedExpected.length > 0 && normalizedReply === normalizedExpected; } function parseOpenClawAgentText(raw: string): string { @@ -814,7 +806,9 @@ exit "$rc" test("openclaw-inference-switch agent reply matching tolerates wrapped PONG", () => { expect(agentReplyContainsToken("P\nO N G", "PONG")).toBe(true); - expect(agentReplyContainsToken("wrapped: p o\nng", "PONG")).toBe(true); + expect(agentReplyContainsToken("wrapped: p o\nng", "PONG")).toBe(false); + expect(agentReplyContainsToken("the answer is PONG", "PONG")).toBe(false); + expect(agentReplyContainsToken("PONG because the route works", "PONG")).toBe(false); expect(agentReplyContainsToken("PANG", "PONG")).toBe(false); expect(agentReplyContainsToken("SPONGE", "PONG")).toBe(false); expect(agentReplyContainsToken("pingpong", "PONG")).toBe(false); diff --git a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts index 0ed51c11190..b65abea7f2c 100644 --- a/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts +++ b/test/e2e-scenario/support-tests/kimi-inference-compat-helpers.test.ts @@ -101,7 +101,7 @@ describe("Kimi inference compatibility mode selection", () => { const script = buildKimiTrajectoryCheckScript(false); expect(script).toContain("strict_mock = False"); expect(script).toContain("min_metas = 3 if strict_mock else 1"); - expect(script).toContain("combined shell command remains"); + expect(script).toContain("unsafe source command remains"); assertKimiTrajectorySummary({ errors: [], @@ -117,7 +117,16 @@ describe("Kimi inference compatibility mode selection", () => { }); it("rejects unsafe or malformed source commands in both mock and public trajectory summaries", () => { - for (const sourceCommands of [["hostname; date; uptime"], ["hostname | date"], [null]]) { + for (const sourceCommands of [ + ["hostname; date; uptime"], + ["hostname | date"], + ["hostname $(date)"], + ["hostname `date`"], + ["hostname > /tmp/out"], + ["cat < /etc/passwd"], + ["whoami"], + [null], + ]) { expect(() => assertKimiTrajectorySummary({ errors: [], From 4aea8cf43ff055cc269d6a6ee0284f750adfbf14 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 14:06:38 -0400 Subject: [PATCH 6/7] fix(inference): retain compatible endpoint metadata --- src/lib/actions/inference-set.test.ts | 65 +++++++++++++++++++++++++++ src/lib/actions/inference-set.ts | 39 +++++++++++++--- 2 files changed, 97 insertions(+), 7 deletions(-) diff --git a/src/lib/actions/inference-set.test.ts b/src/lib/actions/inference-set.test.ts index 853cefbfabb..2af26596a51 100644 --- a/src/lib/actions/inference-set.test.ts +++ b/src/lib/actions/inference-set.test.ts @@ -665,6 +665,71 @@ describe("runInferenceSet", () => { }); }); + it("uses same-provider custom endpoint session metadata when switching only the model", async () => { + const config: ConfigObject = { + agents: { defaults: { model: { primary: "inference/nvidia/nvidia/nemotron-3-ultra" } } }, + models: { + providers: { + inference: { + baseUrl: "https://inference.local/v1", + api: "openai-completions", + models: [ + { + id: "nvidia/nvidia/nemotron-3-ultra", + name: "inference/nvidia/nvidia/nemotron-3-ultra", + }, + ], + }, + }, + }, + }; + const deps = createDeps({ + config, + entry: { + name: "alpha", + agent: "openclaw", + provider: "compatible-endpoint", + model: "nvidia/nvidia/nemotron-3-ultra", + endpointUrl: null, + credentialEnv: null, + preferredInferenceApi: null, + }, + session: baseSession({ + provider: "compatible-endpoint", + model: "nvidia/nvidia/nemotron-3-ultra", + endpointUrl: "https://inference-api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }), + }); + + await runInferenceSet( + { + provider: "compatible-endpoint", + model: "nvidia/nvidia/nemotron-3-super-v3", + noVerify: true, + }, + deps, + ); + + expect(deps.calls.updateSandbox.mock.calls.at(-1)).toEqual([ + "alpha", + expect.objectContaining({ + provider: "compatible-endpoint", + model: "nvidia/nvidia/nemotron-3-super-v3", + endpointUrl: "https://inference-api.nvidia.com/v1", + credentialEnv: "COMPATIBLE_API_KEY", + preferredInferenceApi: "openai-completions", + }), + ]); + expect(deps.getSession()).toMatchObject({ + provider: "compatible-endpoint", + model: "nvidia/nvidia/nemotron-3-super-v3", + endpointUrl: "https://inference.local/v1", + preferredInferenceApi: "openai-completions", + }); + }); + it("rejects custom-compatible provider switches without trusted endpoint metadata", async () => { const deps = createDeps({ config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 5a14af0a238..efcbd6bd02f 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -366,6 +366,15 @@ function isCustomCompatibleProvider(provider: string): boolean { return provider === "compatible-endpoint" || provider === "compatible-anthropic-endpoint"; } +function metadataFromSession(session: onboardSession.Session): RegistryInferenceMetadata { + return { + endpointUrl: session.endpointUrl ?? null, + credentialEnv: session.credentialEnv ?? null, + preferredInferenceApi: session.preferredInferenceApi ?? null, + nimContainer: session.nimContainer ?? null, + }; +} + function matchingSessionMetadata(options: { session: onboardSession.Session | null; sandboxName: string; @@ -381,12 +390,23 @@ function matchingSessionMetadata(options: { ) { return null; } - return { - endpointUrl: session.endpointUrl, - credentialEnv: session.credentialEnv ?? null, - preferredInferenceApi: session.preferredInferenceApi ?? null, - nimContainer: session.nimContainer ?? null, - }; + return metadataFromSession(session); +} + +function matchingProviderSessionMetadata(options: { + session: onboardSession.Session | null; + sandboxName: string; + provider: string; +}): RegistryInferenceMetadata | null { + const { session, sandboxName, provider } = options; + if ( + session?.sandboxName !== sandboxName || + session.provider !== provider || + !session.endpointUrl + ) { + return null; + } + return metadataFromSession(session); } function registryMetadataForProviderSwitch(options: { @@ -398,12 +418,17 @@ function registryMetadataForProviderSwitch(options: { }): RegistryInferenceMetadata { const { entry, provider, model, sandboxName, session } = options; if (entry.provider === provider) { - return { + const entryMetadata = { endpointUrl: entry.endpointUrl ?? null, credentialEnv: entry.credentialEnv ?? null, preferredInferenceApi: entry.preferredInferenceApi ?? null, nimContainer: entry.nimContainer ?? null, }; + if (isCustomCompatibleProvider(provider) && !entryMetadata.endpointUrl) { + const sessionMetadata = matchingProviderSessionMetadata({ session, sandboxName, provider }); + if (sessionMetadata) return sessionMetadata; + } + return entryMetadata; } const sessionMetadata = matchingSessionMetadata({ session, sandboxName, provider, model }); if (sessionMetadata) return sessionMetadata; From a937ae81195e5e440b6438fc757989542312d038 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Fri, 26 Jun 2026 16:17:50 -0400 Subject: [PATCH 7/7] fix(e2e): pass compatible switch metadata --- .../live/openclaw-inference-switch.test.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/e2e-scenario/live/openclaw-inference-switch.test.ts b/test/e2e-scenario/live/openclaw-inference-switch.test.ts index d36b43085ed..d0134f45f31 100644 --- a/test/e2e-scenario/live/openclaw-inference-switch.test.ts +++ b/test/e2e-scenario/live/openclaw-inference-switch.test.ts @@ -835,12 +835,22 @@ async function runInferenceSetWithRetry( switchEndpointUrl: string | null, ): Promise { const attempts = parsePositiveIntEnv("NEMOCLAW_SWITCH_SET_ATTEMPTS", 3); + const compatibleCredentialEnv = (() => { + switch (SWITCH_PROVIDER) { + case "compatible-endpoint": + return "COMPATIBLE_API_KEY"; + case "compatible-anthropic-endpoint": + return "COMPATIBLE_ANTHROPIC_API_KEY"; + default: + return null; + } + })(); const compatibleMetadataArgs = switchEndpointUrl ? [ "--endpoint-url", switchEndpointUrl, "--credential-env", - "COMPATIBLE_ANTHROPIC_API_KEY", + compatibleCredentialEnv ?? "", "--inference-api", SWITCH_INFERENCE_API, ] @@ -972,11 +982,10 @@ RUN_OPENCLAW_INFERENCE_SWITCH_TEST( endpointUrl: mockProvider.endpointUrl, }); } - const switchEndpointUrl = await ensureCompatibleAnthropicSwitchProvider( - host, - home, - mockProvider, - ); + const switchEndpointUrl = + SWITCH_PROVIDER === "compatible-endpoint" + ? hosted.endpointUrl + : await ensureCompatibleAnthropicSwitchProvider(host, home, mockProvider); const pidBefore = await openclawGatewayPid(sandbox, home); const switchResult = await runInferenceSetWithRetry(host, home, [apiKey], switchEndpointUrl);