Skip to content
20 changes: 10 additions & 10 deletions ci/e2e-assertion-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
"testFileCount": 77,
"liveFileCount": 189,
"direct": {
"expectCalls": 1285,
"matcherAssertions": 1265,
"expectCalls": 1283,
"matcherAssertions": 1263,
"nodeAssertions": 109,
"namedAssertionHelpers": 423,
"namedAssertionHelpers": 421,
"failCalls": 0,
"throwGuards": 50,
"objectFieldAssertions": 184,
"assertionPoints": 2031,
"assertionPoints": 2027,
"generatedProbeBlocks": 89,
"generatedProbeConditions": 212
},
"unique": {
"expectCalls": 1715,
"matcherAssertions": 1690,
"expectCalls": 1713,
"matcherAssertions": 1688,
"nodeAssertions": 132,
"namedAssertionHelpers": 669,
"namedAssertionHelpers": 667,
"failCalls": 1,
"throwGuards": 531,
"objectFieldAssertions": 266,
"assertionPoints": 3289,
"assertionPoints": 3285,
"generatedProbeBlocks": 218,
"generatedProbeConditions": 724
},
Expand Down Expand Up @@ -62,7 +62,7 @@
"test/e2e/live/dgx-express.test.ts": [35,45,46,64,3],
"test/e2e/live/double-onboard.test.ts": [46,51,46,51,0],
"test/e2e/live/external-gateway-health.test.ts": [4,5,4,11,0],
"test/e2e/live/full-e2e.test.ts": [27,30,28,60,8],
"test/e2e/live/full-e2e.test.ts": [26,29,27,59,8],
"test/e2e/live/gpu-double-onboard.test.ts": [21,24,21,27,1],
"test/e2e/live/gpu-e2e.test.ts": [36,44,69,90,3],
"test/e2e/live/hermes-discord.test.ts": [9,19,16,58,12],
Expand Down Expand Up @@ -112,7 +112,7 @@
"test/e2e/live/registry-targets.test.ts": [2,4,5,24,0],
"test/e2e/live/sandbox-operations.test.ts": [2,11,9,50,6],
"test/e2e/live/sandbox-rlimits-connect.test.ts": [1,1,1,1,0],
"test/e2e/live/sandbox-survival.test.ts": [4,11,4,11,0],
"test/e2e/live/sandbox-survival.test.ts": [3,8,4,9,0],
"test/e2e/live/sessions-agents-cli.test.ts": [19,28,20,31,0],
"test/e2e/live/skill-agent.test.ts": [7,9,8,10,0],
"test/e2e/live/snapshot-commands.test.ts": [5,5,5,5,0],
Expand Down
59 changes: 59 additions & 0 deletions test/e2e/fixtures/native-plugin-evidence.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { randomUUID } from "node:crypto";

import { isObjectRecord } from "../../../src/lib/core/json-types.ts";
import { shellQuote } from "../../../src/lib/core/shell-quote.ts";
import {
openClawFinalAgentResponse,
parseOpenClawJsonDocuments,
projectOpenClawAgentCompletion,
} from "../../../src/lib/openclaw/agent-json-provenance.ts";
import type { SandboxClient } from "./clients/sandbox.ts";
import { captureNativePluginFailureReadiness } from "./native-plugin-failure-diagnostics.ts";
import { pollUntil } from "./polling.ts";

export type NativePluginVersion = "v1" | "v2";
export const NATIVE_PLUGIN_ID = "nemoclaw-e2e-tool";
Expand Down Expand Up @@ -147,3 +152,57 @@ export function nativeToolCallOutcome(
? "succeeded"
: "pending";
}

export interface NativePluginInvocationOptions {
sandboxName: string;
version: NativePluginVersion;
artifactName: string;
env: NodeJS.ProcessEnv;
turnTimeoutMs: number;
audit: { attempts: number; delayMs: number; timeoutMs: number };
}

/** Exercise the plugin through normal agent admission and read host-owned execution records. */
export async function nativePluginAgentInvocationOutcome(
sandbox: Pick<SandboxClient, "exec" | "execShell">,
options: NativePluginInvocationOptions,
): Promise<"pending" | "succeeded" | "failed"> {
const { sandboxName, artifactName, env } = options;
const toolName = nativeToolName(options.version);
const turn = await sandbox.exec(
sandboxName,
[
"openclaw",
"agent",
"--agent",
"main",
"--json",
"--thinking",
"off",
"--session-id",
`e2e-plugin-${randomUUID()}`,
"-m",
`Run the local ${toolName} tool once with no arguments.`,
],
{ artifactName, env, timeoutMs: options.turnTimeoutMs },
);
await captureNativePluginFailureReadiness(sandbox, turn, sandboxName, artifactName, env);
if (turn.exitCode !== 0) return "failed";
const runId = completedAgentRunId(turn.stdout);
// Audit persistence is asynchronous. Poll only the read-only page, never replay the agent turn.
const audit = await pollUntil({
artifactPrefix: `${artifactName}-audit`,
attempts: options.audit.attempts,
delayMs: options.audit.delayMs,
probe: async (_attempt, auditArtifact) => {
const page = await sandbox.exec(
sandboxName,
["openclaw", "audit", "--run", runId, "--kind", "tool_action", "--limit", "100", "--json"],
{ artifactName: auditArtifact, env, timeoutMs: options.audit.timeoutMs },
);
return page.exitCode === 0 ? nativeToolCallOutcome(page.stdout, runId, toolName) : "failed";
},
accept: (outcome) => outcome !== "pending",
});
return audit.value;
}
50 changes: 9 additions & 41 deletions test/e2e/live/full-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { approveOpenClawAdminScope } from "./openclaw-admin-scope.ts";
import fs from "node:fs";
import { randomUUID } from "node:crypto";
import { buildSandboxInferenceChatCommand } from "../fixtures/inference-adapter.ts";
import os from "node:os";
import path from "node:path";
Expand Down Expand Up @@ -65,11 +64,9 @@ import { parseOpenClawJsonDocuments } from "../../../src/lib/openclaw/agent-json
import { fullE2eGateway, withOwnedFullE2eGateway } from "../fixtures/full-e2e-gateway.ts";
import { captureNativePluginFailureReadiness } from "../fixtures/native-plugin-failure-diagnostics.ts";
import {
completedAgentRunId,
nativePluginAgentInvocationOutcome,
nativePluginPresent,
nativeToolCallOutcome,
NATIVE_PLUGIN_ID,
nativeToolName,
nativePluginWriteScript,
type NativePluginVersion,
} from "../fixtures/native-plugin-evidence.ts";
Expand Down Expand Up @@ -229,49 +226,20 @@ async function waitForSandboxStatus(host: HostCliClient): Promise<ShellProbeResu
return status.value;
}

/** Exercise the plugin through normal agent admission and inspect host-owned execution records. */
async function invokeNativePlugin(
sandbox: SandboxClient,
version: NativePluginVersion,
artifactName: string,
): Promise<void> {
const toolName = nativeToolName(version);
const result = await sandbox.exec(
SANDBOX_NAME,
[
"openclaw",
"agent",
"--agent",
"main",
"--json",
"--thinking",
"off",
"--session-id",
`e2e-plugin-${randomUUID()}`,
"-m",
`Run the local ${toolName} tool once with no arguments.`,
],
{ artifactName, env: env(), timeoutMs: FIRST_TURN_TIMEOUT_MS },
);
await captureNativePluginFailureReadiness(sandbox, result, SANDBOX_NAME, artifactName, env());
expect(result.exitCode, resultText(result)).toBe(0);
const runId = completedAgentRunId(result.stdout);
// Audit persistence is asynchronous. Poll only the read-only page, never replay the agent turn.
const audit = await pollUntil({
artifactPrefix: `${artifactName}-audit`,
attempts: 5,
delayMs: 1_000,
probe: async (_attempt, auditArtifact) => {
const page = await sandbox.exec(
SANDBOX_NAME,
["openclaw", "audit", "--run", runId, "--kind", "tool_action", "--limit", "100", "--json"],
{ artifactName: auditArtifact, env: env(), timeoutMs: 30_000 },
);
return page.exitCode === 0 ? nativeToolCallOutcome(page.stdout, runId, toolName) : "failed";
},
accept: (outcome) => outcome !== "pending",
const outcome = await nativePluginAgentInvocationOutcome(sandbox, {
sandboxName: SANDBOX_NAME,
version,
artifactName,
env: env(),
turnTimeoutMs: FIRST_TURN_TIMEOUT_MS,
audit: { attempts: 5, delayMs: 1_000, timeoutMs: 30_000 },
});
expect(audit.value, "the plugin tool must start and succeed in this agent run").toBe("succeeded");
expect(outcome, "the plugin tool must start and succeed in this agent run").toBe("succeeded");
}

async function exerciseNativeOpenClawPluginVersion(
Expand Down
121 changes: 27 additions & 94 deletions test/e2e/live/sandbox-survival.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import fs from "node:fs";
import path from "node:path";

import { shellQuote } from "../../../src/lib/core/shell-quote.ts";
import { parseOpenClawJsonDocuments } from "../../../src/lib/openclaw/agent-json-provenance.ts";
import { execTimeout, testTimeout } from "../../helpers/timeouts.ts";
import {
SANDBOX_SURVIVAL_FINAL_DESTROY_TIMEOUT_MS,
SANDBOX_SURVIVAL_GATEWAY_DESTROY_TIMEOUT_MS,
SANDBOX_SURVIVAL_INSTALL_TIMEOUT_MS,
SANDBOX_SURVIVAL_LIFECYCLE_READINESS,
SANDBOX_SURVIVAL_MARKER_PATHS,
SANDBOX_SURVIVAL_NATIVE_PLUGIN_AUDIT,
SANDBOX_SURVIVAL_NATIVE_PLUGIN_TURN_TIMEOUT_MS,
SANDBOX_SURVIVAL_NATIVE_READINESS,
SANDBOX_SURVIVAL_OPENSHELL_DELETE_TIMEOUT_MS,
SANDBOX_SURVIVAL_POST_DESTROY_LIST_TIMEOUT_MS,
Expand All @@ -36,10 +36,15 @@ import {
} from "../fixtures/clients/index.ts";
import { expect, test } from "../fixtures/e2e-test.ts";
import { requireHostedInferenceConfig } from "../fixtures/hosted-inference.ts";
import {
nativePluginAgentInvocationOutcome,
nativePluginWriteScript,
} from "../fixtures/native-plugin-evidence.ts";
import { REPO_ROOT } from "../fixtures/paths.ts";
import type { NemoClawInstance } from "../fixtures/phases/index.ts";
import type { SandboxMarker } from "../fixtures/phases/state-validation.ts";
import { pollUntil } from "../fixtures/polling.ts";
import { approveOpenClawAdminScope } from "./openclaw-admin-scope.ts";

const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-survival";
const DASHBOARD_PORT = Number(process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789");
Expand All @@ -57,21 +62,6 @@ function installEnv(hostedEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
};
}

async function expectSandboxExecAlive(
sandboxName: string,
exec: (
script: string,
artifactName: string,
) => Promise<{ stdout: string; stderr: string; exitCode: number | null }>,
artifactName: string,
): Promise<void> {
const alive = await exec("echo alive", artifactName);
expect(
alive.exitCode === 0 && alive.stdout.trim() === "alive",
`${sandboxName} exec failed: ${resultText(alive)}`,
).toBe(true);
}

async function waitForNativeAgentReady(
exec: (
script: string,
Expand All @@ -93,77 +83,6 @@ async function waitForNativeAgentReady(
});
}

function nativeSurvivalPluginInstallScript(): string {
const packageJson = JSON.stringify({
name: "@nemoclaw/e2e-survival-plugin",
version: "1.0.0",
type: "module",
main: "index.js",
files: ["index.js", "openclaw.plugin.json"],
openclaw: { extensions: ["./index.js"] },
peerDependencies: { openclaw: ">=2026.7.1" },
});
const manifest = JSON.stringify({
id: "e2e-survival-plugin",
name: "E2E Survival Plugin",
version: "1.0.0",
description: "Native stop/start persistence fixture",
activation: { onStartup: true },
contracts: { tools: ["survival_probe"] },
configSchema: { type: "object", properties: {}, additionalProperties: false },
});
const entrypoint = `const plugin = {
id: "e2e-survival-plugin",
name: "E2E Survival Plugin",
version: "1.0.0",
register(api) {
api.registerTool({
name: "survival_probe",
label: "Survival Probe",
description: "Prove a native plugin remains executable after OpenShell stop/start.",
parameters: { type: "object", properties: {}, additionalProperties: false },
async execute() {
const details = { survived: true };
return { content: [{ type: "text", text: JSON.stringify(details) }], details };
},
});
},
};
export default plugin;
`;
return [
"set -eu",
"source_dir=/sandbox/e2e-survival-plugin-source",
'rm -rf -- "$source_dir"',
'mkdir -p -- "$source_dir"',
`printf '%s' ${shellQuote(packageJson)} > "$source_dir/package.json"`,
`printf '%s' ${shellQuote(manifest)} > "$source_dir/openclaw.plugin.json"`,
`printf '%s' ${shellQuote(entrypoint)} > "$source_dir/index.js"`,
'HOME=/sandbox openclaw plugins install --force --accept-capabilities "$source_dir"',
].join("\n");
}

async function expectNativeSurvivalPluginInvocation(
exec: (
script: string,
artifactName: string,
) => Promise<{ stdout: string; stderr: string; exitCode: number | null }>,
): Promise<void> {
const invocation = await exec(
`. /tmp/nemoclaw-proxy-env.sh && printf 'header = "Authorization: Bearer %s"\\n' "$OPENCLAW_GATEWAY_TOKEN" | curl --noproxy '*' --max-time 30 --silent --show-error --fail-with-body --config - -H 'Content-Type: application/json' --data '{"agentId":"main","tool":"survival_probe","args":{}}' "http://127.0.0.1:\${OPENCLAW_GATEWAY_PORT:-18789}/tools/invoke"`,
"post-openshell-start-native-plugin-invoke",
);
const document = parseOpenClawJsonDocuments(invocation.stdout)[0] as
| { ok?: boolean; result?: { details?: { survived?: boolean } } }
| undefined;
expect(
invocation.exitCode === 0 &&
document?.ok === true &&
document.result?.details?.survived === true,
resultText(invocation),
).toBe(true);
}

test(
"OpenShell stop/start preserves native agent state",
{
Expand Down Expand Up @@ -318,7 +237,6 @@ test(
});

progress.phase("prove baseline sandbox access and native agent readiness");
await expectSandboxExecAlive(SANDBOX_NAME, execShell, "baseline-sandbox-exec-alive");
await waitForNativeAgentReady(execShell, "baseline-native-agent-ready", DASHBOARD_PORT);

progress.phase("write persistent OpenClaw markers");
Expand All @@ -330,10 +248,7 @@ test(
await stateValidation.writeSandboxMarkers(instance, markers);
await stateValidation.expectSandboxMarkers(instance, markers, "pre-restart-marker-read");
progress.phase("install a native OpenClaw plugin package");
await execShell(
nativeSurvivalPluginInstallScript(),
"pre-openshell-stop-native-plugin-install",
);
await execShell(nativePluginWriteScript("v1"), "pre-openshell-stop-native-plugin-install");

progress.phase("stop the sandbox through OpenShell");
const stop = await sandbox.openshell(["sandbox", "stop", "-g", "nemoclaw", SANDBOX_NAME], {
Expand Down Expand Up @@ -364,7 +279,25 @@ test(
markers,
"post-openshell-start-marker-read",
);
await expectNativeSurvivalPluginInvocation(execShell);
await approveOpenClawAdminScope(
host,
sandbox,
SANDBOX_NAME,
{ ...buildAvailabilityProbeEnv(), ...hosted.env },
[apiKey],
false,
);
const pluginOutcome = await nativePluginAgentInvocationOutcome(sandbox, {
sandboxName: SANDBOX_NAME,
version: "v1",
artifactName: "post-openshell-start-native-plugin-invoke",
env: sandboxAccessEnv(),
turnTimeoutMs: SANDBOX_SURVIVAL_NATIVE_PLUGIN_TURN_TIMEOUT_MS,
audit: SANDBOX_SURVIVAL_NATIVE_PLUGIN_AUDIT,
});
expect(pluginOutcome, "the plugin tool must start and succeed in this agent run").toBe(
"succeeded",
);

progress.phase("destroy the sandbox");
await sandbox.cleanupSandbox(SANDBOX_NAME, {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/mock-parity.json
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@
{
"live": "test/e2e/live/sandbox-survival.test.ts",
"fast": [
"test/e2e/support/sandbox-survival-timeout-contract.test.ts",
"test/e2e/support/native-plugin-evidence.test.ts",
"src/lib/onboard/machine/finalization-deps.test.ts",
"src/lib/actions/sandbox/destroy-flow.test.ts",
"test/agents/native-gateway-lifecycle.test.ts",
Expand Down
Loading
Loading