Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 97 additions & 3 deletions .github/workflows/e2e-vitest-scenarios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
SCENARIOS: ${{ inputs.scenarios }}
run: |
set -euo pipefail
allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest,sandbox-survival-vitest"
allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,sandbox-rebuild-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest,sandbox-survival-vitest"
if [ -n "${JOBS}" ] && [ -n "${SCENARIOS}" ]; then
echo "::error::Use either scenarios or jobs, not both." >&2
exit 1
Expand Down Expand Up @@ -93,12 +93,12 @@ jobs:
SCENARIOS: ${{ inputs.scenarios }}
run: |
set -euo pipefail
allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest,sandbox-survival-vitest"
allowed_jobs="openshell-version-pin-vitest,onboard-negative-paths-vitest,skill-agent-vitest,inference-routing-vitest,credential-migration-vitest,runtime-overrides-vitest,hermes-e2e-vitest,hermes-root-entrypoint-smoke-vitest,network-policy-vitest,rebuild-openclaw-vitest,sandbox-rebuild-vitest,token-rotation-vitest,launchable-smoke-vitest,openclaw-tui-chat-correlation-vitest,gateway-guard-recovery,double-onboard-vitest,issue-4434-tui-unreachable-inference-vitest,model-router-provider-routed-inference-vitest,sandbox-survival-vitest"
args=(--emit-live-matrix)
matrix=""
hermes_selected=false
registry_scenarios=()
free_standing_scenarios=(openshell-version-pin onboard-negative-paths skill-agent inference-routing runtime-overrides hermes-e2e hermes-root-entrypoint-smoke network-policy rebuild-openclaw token-rotation openclaw-tui-chat-correlation double-onboard issue-4434-tui-unreachable-inference model-router-provider-routed-inference sandbox-survival)
free_standing_scenarios=(openshell-version-pin onboard-negative-paths skill-agent inference-routing runtime-overrides hermes-e2e hermes-root-entrypoint-smoke network-policy rebuild-openclaw sandbox-rebuild token-rotation openclaw-tui-chat-correlation double-onboard issue-4434-tui-unreachable-inference model-router-provider-routed-inference sandbox-survival)
is_free_standing_scenario() {
local id="$1"
local known
Expand Down Expand Up @@ -975,6 +975,99 @@ jobs:
if-no-files-found: ignore
retention-days: 14

sandbox-rebuild-vitest:
needs: [validate-jobs, generate-matrix]
if: ${{ (inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',sandbox-rebuild-vitest,') || contains(format(',{0},', inputs.scenarios), ',sandbox-rebuild,') }}
runs-on: ubuntu-latest
timeout-minutes: 90
env:
E2E_ARTIFACT_DIR: ${{ github.workspace }}/e2e-artifacts/vitest/sandbox-rebuild
NEMOCLAW_CLI_BIN: ${{ github.workspace }}/bin/nemoclaw.js
NEMOCLAW_RUN_E2E_SCENARIOS: "1"
NEMOCLAW_NON_INTERACTIVE: "1"
NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1"
OPENSHELL_GATEWAY: nemoclaw
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false

- name: Authenticate to Docker Hub
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
if [[ -z "${DOCKERHUB_USERNAME}" || -z "${DOCKERHUB_TOKEN}" ]]; then
echo "::notice::Docker Hub credentials not configured; continuing with anonymous pulls."
exit 0
fi
login_succeeded=0
for attempt in 1 2 3; do
if echo "${DOCKERHUB_TOKEN}" | timeout 30s docker login docker.io --username "${DOCKERHUB_USERNAME}" --password-stdin; then
login_succeeded=1
break
fi
if [[ "$attempt" -lt 3 ]]; then
echo "::warning::Docker Hub login attempt ${attempt} failed; retrying."
sleep 5
fi
done
if [[ "$login_succeeded" -ne 1 ]]; then
echo "::warning::Docker Hub login failed after 3 attempts; continuing with anonymous pulls."
fi

- name: Set up Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0
with:
node-version: 22
cache: npm

- name: Install root dependencies
run: npm ci --ignore-scripts

- name: Build CLI
run: npm run build:cli

- name: Install OpenShell
env:
NEMOCLAW_NON_INTERACTIVE: "1"
run: |
set -euo pipefail
env -u DOCKER_CONFIG -u DOCKERHUB_USERNAME -u DOCKERHUB_TOKEN -u NVIDIA_API_KEY -u GITHUB_TOKEN bash scripts/install-openshell.sh

- name: Run sandbox rebuild live test
env:
NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }}
run: |
set -euo pipefail
export PATH="$HOME/.local/bin:$HOME/.npm-global/bin:$PATH"
if command -v openshell >/dev/null 2>&1; then
OPENSHELL_BIN="$(command -v openshell)"
elif [ -x "$HOME/.local/bin/openshell" ]; then
OPENSHELL_BIN="$HOME/.local/bin/openshell"
else
echo "::error::OpenShell CLI not found after install"
ls -la /usr/local/bin/openshell "$HOME/.local/bin/openshell" 2>&1 || true
exit 1
fi
export OPENSHELL_BIN
"$OPENSHELL_BIN" --version
npx vitest run --project e2e-scenarios-live \
test/e2e-scenario/live/sandbox-rebuild.test.ts \
--silent=false --reporter=default

- name: Upload sandbox rebuild artifacts
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: e2e-vitest-scenarios-sandbox-rebuild
path: e2e-artifacts/vitest/sandbox-rebuild/
include-hidden-files: false
if-no-files-found: ignore
retention-days: 14

double-onboard-vitest:
needs: validate-jobs
if: ${{ (inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',double-onboard-vitest,') }}
Expand Down Expand Up @@ -1587,6 +1680,7 @@ jobs:
hermes-root-entrypoint-smoke-vitest,
network-policy-vitest,
rebuild-openclaw-vitest,
sandbox-rebuild-vitest,
token-rotation-vitest,
launchable-smoke-vitest,
double-onboard-vitest,
Expand Down
86 changes: 86 additions & 0 deletions test/e2e-scenario/fixtures/phases/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const DOCKER_PROBE_TIMEOUT_MS = 15_000;
// the gateway recovery path retries. Keep the budget generous; the
// bug is independent of latency.
const STATUS_TIMEOUT_MS = 5 * 60_000;
const REBUILD_TIMEOUT_MS = 20 * 60_000;
const SANDBOX_READY_ATTEMPTS = 30;
const SANDBOX_READY_DELAY_MS = 5_000;

export type LifecycleProfile = "post-reboot-recovery";

Expand Down Expand Up @@ -57,6 +60,42 @@ export interface LifecycleResult {
steps: Array<{ id: string; results: ShellProbeResult[] }>;
}

export interface RebuildSandboxOptions {
artifactName?: string;
env?: NodeJS.ProcessEnv;
redactionValues?: string[];
timeoutMs?: number;
verbose?: boolean;
}

export interface SandboxReadyAfterRebuildOptions {
attempts?: number;
delayMs?: number;
env?: NodeJS.ProcessEnv;
artifactNamePrefix?: string;
timeoutMs?: number;
}

function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function instanceName(instance: NemoClawInstance | string): string {
const name = typeof instance === "string" ? instance : instance.sandboxName;
return name;
}

function stripAnsi(text: string): string {
return text.replace(/\u001b\[[0-9;]*m/g, "");
}

function outputContainsReadySandbox(result: ShellProbeResult, sandboxName: string): boolean {
const escaped = sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`${escaped}.*\\bReady\\b`, "i").test(
stripAnsi(`${result.stdout}\n${result.stderr}`),
);
Comment on lines +92 to +96

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Require an exact sandbox-name match in the readiness probe.

Line 93 currently treats any row containing the requested name as a prefix match, so e2e-x-dev Ready would satisfy readiness for e2e-x. Because assertSandboxReadyAfterRebuild() stops polling on that condition, the live rebuild scenario can pass against the wrong sandbox row and hide a failed rebuild.

Suggested fix
 function outputContainsReadySandbox(result: ShellProbeResult, sandboxName: string): boolean {
   const escaped = sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
-  return new RegExp(`${escaped}.*\\bReady\\b`, "i").test(
+  return new RegExp(`^\\s*${escaped}(?:\\s|$).*\\bReady\\b`, "im").test(
     stripAnsi(`${result.stdout}\n${result.stderr}`),
   );
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function outputContainsReadySandbox(result: ShellProbeResult, sandboxName: string): boolean {
const escaped = sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`${escaped}.*\\bReady\\b`, "i").test(
stripAnsi(`${result.stdout}\n${result.stderr}`),
);
function outputContainsReadySandbox(result: ShellProbeResult, sandboxName: string): boolean {
const escaped = sandboxName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(`^\\s*${escaped}(?:\\s|$).*\\bReady\\b`, "im").test(
stripAnsi(`${result.stdout}\n${result.stderr}`),
);
}
🧰 Tools
🪛 ast-grep (0.43.0)

[warning] 92-92: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(${escaped}.*\\bReady\\b, "i")
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e-scenario/fixtures/phases/lifecycle.ts` around lines 91 - 95, The
readiness probe in outputContainsReadySandbox currently treats the sandboxName
as a prefix so names like "e2e-x-dev" match "e2e-x"; update the check in
outputContainsReadySandbox to require an exact sandbox-name token on a single
line before the Ready token (e.g., iterate over lines of
stripAnsi(`${result.stdout}\n${result.stderr}`) and for each line test a regex
that anchors the sandbox name as a separate token—such as
/^\s*<escaped>\b\s+.*\bReady\b/i—so only the exact sandbox row satisfies
readiness; reference the function outputContainsReadySandbox (and callers like
assertSandboxReadyAfterRebuild) when making the change.

}

export class LifecyclePhaseFixture {
constructor(
private readonly host: HostCliClient,
Expand All @@ -65,6 +104,53 @@ export class LifecyclePhaseFixture {
private readonly gateway?: GatewayClient,
) {}

async rebuildSandbox(
instance: NemoClawInstance | string,
options: RebuildSandboxOptions = {},
): Promise<ShellProbeResult> {
const sandboxName = instanceName(instance);
const args = [sandboxName, "rebuild", "--yes"];
if (options.verbose) args.push("--verbose");
const result = await this.host.nemoclaw(args, {
artifactName: options.artifactName ?? `lifecycle-rebuild-${sandboxName}`,
env: {
...buildAvailabilityProbeEnv(),
...(options.env ?? {}),
},
redactionValues: options.redactionValues,
timeoutMs: options.timeoutMs ?? REBUILD_TIMEOUT_MS,
});
assertExitZero(result, `nemoclaw ${sandboxName} rebuild --yes`);
return result;
}

async assertSandboxReadyAfterRebuild(
instance: NemoClawInstance | string,
options: SandboxReadyAfterRebuildOptions = {},
): Promise<ShellProbeResult> {
const sandboxName = instanceName(instance);
const attempts = options.attempts ?? SANDBOX_READY_ATTEMPTS;
const delayMs = options.delayMs ?? SANDBOX_READY_DELAY_MS;
const env = { ...buildAvailabilityProbeEnv(), ...(options.env ?? {}) };
let last: ShellProbeResult | undefined;
for (let attempt = 1; attempt <= attempts; attempt += 1) {
const artifactPrefix = options.artifactNamePrefix ?? `lifecycle-rebuild-ready-${sandboxName}`;
last = await this.sandbox.list({
artifactName: `${artifactPrefix}-${attempt}`,
env,
timeoutMs: options.timeoutMs ?? 30_000,
});
if (last.exitCode === 0 && outputContainsReadySandbox(last, sandboxName)) {
return last;
}
if (attempt < attempts) await sleep(delayMs);
}
const detail = last ? `${last.stdout}\n${last.stderr}`.trim() : "no probe result";
throw new Error(
`sandbox ${sandboxName} did not become Ready after rebuild within ${attempts} attempts: ${detail}`,
);
}

async simulate(
profile: LifecycleProfile,
instance: NemoClawInstance,
Expand Down
22 changes: 14 additions & 8 deletions test/e2e-scenario/fixtures/phases/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,23 @@ export class OnboardingPhaseFixture {
}
}

async destroySandbox(sandboxName: string, artifactName?: string): Promise<ShellProbeResult> {
validateSandboxName(sandboxName);
const result = await this.host.nemoclaw([sandboxName, "destroy", "--yes"], {
artifactName: artifactName ?? `cleanup-destroy-${artifactLabel(sandboxName)}`,
env: buildAvailabilityProbeEnv(),
timeoutMs: DEFAULT_TIMEOUT_MS,
});
if (result.exitCode !== 0 && !hasMissingSandboxDeleteSignature(result)) {
assertExitZero(result, `cleanup destroy sandbox ${sandboxName}`);
}
return result;
}

private registerSandboxCleanup(sandboxName: string): void {
if (!this.cleanup) return;
this.cleanup.add(`destroy NemoClaw sandbox ${sandboxName}`, async () => {
const result = await this.host.nemoclaw([sandboxName, "destroy", "--yes"], {
artifactName: `cleanup-destroy-${artifactLabel(sandboxName)}`,
env: buildAvailabilityProbeEnv(),
timeoutMs: DEFAULT_TIMEOUT_MS,
});
if (result.exitCode !== 0 && !hasMissingSandboxDeleteSignature(result)) {
assertExitZero(result, `cleanup destroy sandbox ${sandboxName}`);
}
await this.destroySandbox(sandboxName);
});
}

Expand Down
Loading
Loading