Skip to content
Closed
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
8 changes: 1 addition & 7 deletions scripts/checks/legacy-sandbox-transports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ const REVIEWED_SITE_TUPLES = [
["src/lib/share-command.ts", "sshfs-command", 1],
["src/lib/shields/index.ts", "privileged-sandbox-exec", 4],
["src/lib/shields/mutable-config-repair.ts", "privileged-sandbox-exec", 2],
["src/lib/state/openclaw-config-restore-input.ts", "ssh-command", 1],
["src/lib/state/openclaw-plugin-restore.ts", "ssh-command", 2],
["src/lib/state/openclaw-plugin-restore.ts", "ssh-temp-config", 1],
["src/lib/state/openclaw-plugin-restore.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/state/sandbox.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/state/sandbox.ts", "openshell-ssh-config", 1],
["src/lib/state/sandbox.ts", "ssh-command", 4],
["src/lib/state/sandbox.ts", "ssh-temp-config", 1],
["src/lib/state/state-file-restore.ts", "ssh-command", 1],
["src/lib/state/user-managed-files-probe.ts", "grpc-cli-read-only-fallback", 1],
["src/lib/tunnel/sandbox-gateway-stop.ts", "docker-exec-command", 2],
] as const satisfies readonly ReviewedSiteTuple[];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/actions/sandbox/rebuild-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async function rebuildSandboxUnlocked(
durableConfig.webSearchConfig,
);

const restored = runRebuildRestorePhase({
const restored = await runRebuildRestorePhase({
sandboxName,
targetAgentType: rebuildAgent || "openclaw",
targetImageIsCustom: Boolean(fromDockerfile),
Expand Down
21 changes: 16 additions & 5 deletions src/lib/actions/sandbox/rebuild-restore-forwarding.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";
import path from "node:path";

import { afterEach, describe, expect, it, vi } from "vitest";

import * as sandboxState from "../../state/sandbox";
import { runRebuildRestorePhase } from "./rebuild-restore-phase";

const fixtures: string[] = [];

afterEach(() => {
for (const fixture of fixtures.splice(0)) {
fs.rmSync(fixture, { recursive: true, force: true });
}
vi.restoreAllMocks();
});

describe("rebuild restore target forwarding", () => {
it("forwards the recreated target identity and explicit custom-image capability", () => {
it("forwards the recreated target identity and explicit custom-image capability", async () => {
const backupPath = fs.mkdtempSync(path.join(process.cwd(), ".nemoclaw-rebuild-restore-"));
fs.chmodSync(backupPath, 0o700);
fixtures.push(backupPath);
vi.spyOn(console, "log").mockImplementation(() => undefined);
const restoreRecreatedSandboxState = vi
.spyOn(sandboxState, "restoreRecreatedSandboxState")
.mockReturnValue({
.mockResolvedValue({
success: true,
restoredDirs: [],
restoredFiles: [],
failedDirs: [],
failedFiles: [],
});

runRebuildRestorePhase({
await runRebuildRestorePhase({
sandboxName: "alpha",
targetAgentType: "langchain-deepagents-code",
targetImageIsCustom: true,
backupManifest: { agentType: "openclaw", backupPath: "/tmp/rebuild-backup" } as never,
backupManifest: { agentType: "openclaw", backupPath } as never,
policyPresets: [],
customPolicies: [],
reconcileManagedDcodeObservability: false,
log: vi.fn(),
});

expect(restoreRecreatedSandboxState).toHaveBeenCalledWith("alpha", "/tmp/rebuild-backup", {
expect(restoreRecreatedSandboxState).toHaveBeenCalledWith("alpha", backupPath, {
targetAgentType: "langchain-deepagents-code",
allowCustomImageWholeStateFileRestore: true,
});
Expand Down
74 changes: 37 additions & 37 deletions src/lib/actions/sandbox/rebuild-restore-phase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe("rebuild policy restore fidelity", () => {
vi.restoreAllMocks();
});

it("surfaces a fresh OpenClaw plugin registry precondition failure", () => {
it("surfaces a fresh OpenClaw plugin registry precondition failure", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const log = vi.fn();
vi.spyOn(sandboxState, "restoreRecreatedSandboxState").mockReturnValue({
vi.spyOn(sandboxState, "restoreRecreatedSandboxState").mockResolvedValue({
success: false,
restoredDirs: [],
restoredFiles: [],
Expand All @@ -53,7 +53,7 @@ describe("rebuild policy restore fidelity", () => {
error: "could not read fresh OpenClaw plugin install registry",
});

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: { agentType: "openclaw", backupPath: "/tmp/rebuild-backup" } as never,
policyPresets: [],
Expand All @@ -71,13 +71,13 @@ describe("rebuild policy restore fidelity", () => {
);
});

it("replays custom web-policy names from exact content instead of same-name built-ins", () => {
it("replays custom web-policy names from exact content instead of same-name built-ins", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(console, "error").mockImplementation(() => undefined);
const parsePresetPolicyKeys = vi.spyOn(policies, "parsePresetPolicyKeys");
const restoreRecreatedSandboxState = vi
.spyOn(sandboxState, "restoreRecreatedSandboxState")
.mockReturnValue({
.mockResolvedValue({
success: true,
restoredDirs: [],
restoredFiles: [],
Expand All @@ -91,7 +91,7 @@ describe("rebuild policy restore fidelity", () => {
content: `network_policies:\n ${name}-custom:\n name: ${name}-custom\n`,
sourcePath: `/tmp/${name}.yaml`,
}));
const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: {
agentType: "openclaw",
Expand Down Expand Up @@ -122,9 +122,9 @@ describe("rebuild policy restore fidelity", () => {
expect(parsePresetPolicyKeys).not.toHaveBeenCalled();
});

it("replays captured registry custom policies during stale recovery without a backup", () => {
it("replays captured registry custom policies during stale recovery without a backup", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(sandboxState, "restoreSandboxState").mockReturnValue({
vi.spyOn(sandboxState, "restoreSandboxState").mockResolvedValue({
success: true,
restoredDirs: [],
restoredFiles: [],
Expand All @@ -139,7 +139,7 @@ describe("rebuild policy restore fidelity", () => {
sourcePath: "/tmp/custom-egress.yaml",
},
];
const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -158,7 +158,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.finalPresets).toEqual(["custom-egress"]);
});

it("leaves generated MCP policy replay exclusively to MCP restoration", () => {
it("leaves generated MCP policy replay exclusively to MCP restoration", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
const applyPresetContent = vi.spyOn(policies, "applyPresetContent").mockReturnValue(true);
const genuineCustomPolicy = {
Expand All @@ -172,7 +172,7 @@ describe("rebuild policy restore fidelity", () => {
"network_policies:\n mcp-bridge-search:\n endpoints:\n - host: mcp.example.com\n allowed_ips: [203.0.113.10]\n",
sourcePath: MCP_BRIDGE_POLICY_SOURCE,
};
const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -192,7 +192,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.failedPresets).toEqual([]);
});

it("removes an observability preset introduced while rebuilding a restricted sandbox", () => {
it("removes an observability preset introduced while rebuilding a restricted sandbox", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(console, "error").mockImplementation(() => undefined);
vi.spyOn(policies, "applyPreset").mockReturnValue(true);
Expand All @@ -201,7 +201,7 @@ describe("rebuild policy restore fidelity", () => {
.mockReturnValueOnce("absent");
const removePreset = vi.spyOn(policies, "removePreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["npm"],
Expand All @@ -218,15 +218,15 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("retains an observed exact built-in when post-removal verification is unavailable", () => {
it("retains an observed exact built-in when post-removal verification is unavailable", async () => {
vi.spyOn(console, "error").mockImplementation(() => undefined);
vi.spyOn(policies, "applyPreset").mockReturnValue(true);
vi.spyOn(policies, "getPresetContentGatewayState")
.mockReturnValueOnce("match")
.mockReturnValueOnce(null);
vi.spyOn(policies, "removePreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["npm"],
Expand All @@ -239,7 +239,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(false);
});

it("accounts for known failed additions without treating a narrower live set as unverified", () => {
it("accounts for known failed additions without treating a narrower live set as unverified", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(console, "error").mockImplementation(() => undefined);
vi.spyOn(policies, "applyPreset")
Expand All @@ -256,7 +256,7 @@ describe("rebuild policy restore fidelity", () => {
throw new Error("apply failed");
});

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["npm", "bad", "throw"],
Expand All @@ -272,12 +272,12 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("keeps reconciliation unverified when a reported successful addition is missing live", () => {
it("keeps reconciliation unverified when a reported successful addition is missing live", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(console, "error").mockImplementation(() => undefined);
vi.spyOn(policies, "applyPreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["observability-otlp-local"],
Expand All @@ -292,13 +292,13 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(false);
});

it("retains target built-in attribution when exact post-apply verification is unavailable", () => {
it("retains target built-in attribution when exact post-apply verification is unavailable", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(console, "error").mockImplementation(() => undefined);
vi.spyOn(policies, "applyPreset").mockReturnValue(true);
vi.spyOn(policies, "getPresetContentGatewayState").mockReturnValue(null);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["observability-otlp-local"],
Expand All @@ -311,10 +311,10 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(false);
});

it("does not remove or persist DCode base-policy keys detected as broad presets", () => {
it("does not remove or persist DCode base-policy keys detected as broad presets", async () => {
const removePreset = vi.spyOn(policies, "removePreset");

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -329,7 +329,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("leaves a same-name custom observability policy outside built-in narrowing", () => {
it("leaves a same-name custom observability policy outside built-in narrowing", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
const applyPresetContent = vi.spyOn(policies, "applyPresetContent").mockReturnValue(true);
const removePreset = vi.spyOn(policies, "removePreset");
Expand All @@ -339,7 +339,7 @@ describe("rebuild policy restore fidelity", () => {
sourcePath: "/tmp/operator-collector.yaml",
};

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -359,7 +359,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("leaves a differently named custom policy owning observability egress outside built-in narrowing", () => {
it("leaves a differently named custom policy owning observability egress outside built-in narrowing", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
const applyPresetContent = vi.spyOn(policies, "applyPresetContent").mockReturnValue(true);
const exactState = vi.spyOn(policies, "getPresetContentGatewayState").mockReturnValue("match");
Expand All @@ -371,7 +371,7 @@ describe("rebuild policy restore fidelity", () => {
sourcePath: "/tmp/corp-otel.yaml",
};

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -392,7 +392,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("removes an exact inner built-in behind a same-name custom with a different key", () => {
it("removes an exact inner built-in behind a same-name custom with a different key", async () => {
vi.spyOn(console, "log").mockImplementation(() => undefined);
const customPolicy = {
name: "observability-otlp-local",
Expand All @@ -405,7 +405,7 @@ describe("rebuild policy restore fidelity", () => {
.mockReturnValueOnce("absent");
const removePreset = vi.spyOn(policies, "removePreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["observability-otlp-local"],
Expand All @@ -421,7 +421,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("removes an exact inner built-in when overlapping custom replay fails", () => {
it("removes an exact inner built-in when overlapping custom replay fails", async () => {
vi.spyOn(console, "error").mockImplementation(() => undefined);
const customPolicy = {
name: "corp-otel",
Expand All @@ -434,7 +434,7 @@ describe("rebuild policy restore fidelity", () => {
.mockReturnValueOnce("absent");
const removePreset = vi.spyOn(policies, "removePreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -451,7 +451,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(true);
});

it("leaves drift untouched and unverified when successful custom ownership is not exact", () => {
it("leaves drift untouched and unverified when successful custom ownership is not exact", async () => {
vi.spyOn(console, "error").mockImplementation(() => undefined);
const customPolicy = {
name: "corp-otel",
Expand All @@ -462,7 +462,7 @@ describe("rebuild policy restore fidelity", () => {
vi.spyOn(policies, "getPresetContentGatewayState").mockReturnValue("drift");
const removePreset = vi.spyOn(policies, "removePreset");

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: [],
Expand All @@ -476,7 +476,7 @@ describe("rebuild policy restore fidelity", () => {
expect(result.policyPresetReconciliationVerified).toBe(false);
});

it("retains separate built-in attribution when same-name custom removal is unverified", () => {
it("retains separate built-in attribution when same-name custom removal is unverified", async () => {
vi.spyOn(console, "error").mockImplementation(() => undefined);
const customPolicy = {
name: "observability-otlp-local",
Expand All @@ -489,7 +489,7 @@ describe("rebuild policy restore fidelity", () => {
.mockReturnValueOnce(null);
vi.spyOn(policies, "removePreset").mockReturnValue(true);

const result = runStandardRebuildRestorePhase({
const result = await runStandardRebuildRestorePhase({
sandboxName: "alpha",
backupManifest: null,
policyPresets: ["observability-otlp-local"],
Expand All @@ -514,7 +514,7 @@ describe("rebuild policy restore fidelity", () => {
});
});

it("keeps finalized custom-only policy state empty after exact replay", () => {
it("keeps finalized custom-only policy state empty after exact replay", async () => {
expect(resolveRestoredPolicyRegistryState({ policyPresetsFinalized: true }, [], [])).toEqual({
policies: [],
policyPresetsFinalized: true,
Expand All @@ -525,7 +525,7 @@ describe("rebuild policy restore fidelity", () => {
).toBeUndefined();
});

it("retains the force-skipped backup warning in the successful final summary", () => {
it("retains the force-skipped backup warning in the successful final summary", async () => {
const writeLine = vi.fn();

printSuccessfulRebuildSummary(
Expand Down
Loading
Loading