Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 31 additions & 1 deletion src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3685,11 +3685,26 @@ async function createSandbox(

const previousEntry: SandboxEntry | null = registry.getSandbox(sandboxName);
const previousPolicies = previousEntry?.policies ?? null;
if (previousPolicies && previousPolicies.length > 0) {
if (shouldCarryPreviousPolicies(previousPolicies)) {
onboardSession.updateSession((current: Session) => {
current.policyPresets = previousPolicies;
return current;
});
} else {
onboardSession.updateSession((current: Session) => {
current.policyPresets = null;
return current;
});
if (
Array.isArray(previousPolicies) &&
previousPolicies.length > 0 &&
isNonInteractive() &&
(process.env.NEMOCLAW_POLICY_PRESETS || "").trim().length > 0
) {
note(
` [non-interactive] NEMOCLAW_POLICY_PRESETS overrides previous presets on recreate (was: ${previousPolicies.join(", ")}).`,
);
}
}

note(` Deleting and recreating sandbox '${sandboxName}'...`);
Expand Down Expand Up @@ -5741,6 +5756,20 @@ function arePolicyPresetsApplied(sandboxName: string, selectedPresets: string[]
return selectedPresets.every((preset) => applied.has(preset));
}

// Skip carrying previous policies forward on --recreate-sandbox when the user
// explicitly set NEMOCLAW_POLICY_PRESETS for the new run (#2675).
function shouldCarryPreviousPolicies(
previousPolicies: string[] | null | undefined,
options: { nonInteractive?: boolean; envPolicyPresetsRaw?: string } = {},
): boolean {
if (!Array.isArray(previousPolicies) || previousPolicies.length === 0) return false;
const nonInteractive = options.nonInteractive ?? isNonInteractive();
const envRaw = (
options.envPolicyPresetsRaw ?? process.env.NEMOCLAW_POLICY_PRESETS ?? ""
).trim();
return !(nonInteractive && envRaw.length > 0);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

/**
* Prompt the user to select a policy tier (restricted / balanced / open).
* Uses the same radio-style TUI as presetsCheckboxSelector (single-select).
Expand Down Expand Up @@ -7738,6 +7767,7 @@ module.exports = {
isNonInteractive,
isOpenclawReady,
arePolicyPresetsApplied,
shouldCarryPreviousPolicies,
getSuggestedPolicyPresets,
computeSetupPresetSuggestions,
LOCAL_INFERENCE_PROVIDERS,
Expand Down
25 changes: 25 additions & 0 deletions test/onboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ type OnboardTestInternals = {
flavor: "openai" | "anthropic",
) => string;
parsePolicyPresetEnv: (value: string | null) => string[];
shouldCarryPreviousPolicies: (
previousPolicies: string[] | null | undefined,
options?: { nonInteractive?: boolean; envPolicyPresetsRaw?: string },
) => boolean;
patchStagedDockerfile: ShimFn<void>;
pullAndResolveBaseImageDigest: () => { digest: string; ref: string } | null;
SANDBOX_BASE_IMAGE: string;
Expand Down Expand Up @@ -164,6 +168,7 @@ const {
isLoopbackHostname,
normalizeProviderBaseUrl,
parsePolicyPresetEnv,
shouldCarryPreviousPolicies,
patchStagedDockerfile,
pullAndResolveBaseImageDigest,
SANDBOX_BASE_IMAGE,
Expand Down Expand Up @@ -281,6 +286,26 @@ describe("onboard helpers", () => {
expect(getSuggestedPolicyPresets({})).not.toContain("local-inference");
});

describe("shouldCarryPreviousPolicies (#2675)", () => {
it("drops previous policies when NEMOCLAW_POLICY_PRESETS overrides on recreate", () => {
expect(
shouldCarryPreviousPolicies(["npm"], {
nonInteractive: true,
envPolicyPresetsRaw: "pypi",
}),
).toBe(false);
});

it("ignores env var in interactive mode (previous list still wins)", () => {
expect(
shouldCarryPreviousPolicies(["npm"], {
nonInteractive: false,
envPolicyPresetsRaw: "pypi",
}),
).toBe(true);
});
});

describe("computeSetupPresetSuggestions", () => {
const known = [
"npm",
Expand Down
Loading