Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4b7a4a2
refactor(cli): extract sandbox live state helpers
cv May 2, 2026
2ce87dd
refactor(cli): extract sandbox skill install action
cv May 2, 2026
4cd3cf3
refactor(cli): extract sandbox connect action
cv May 3, 2026
e9dd46e
refactor(cli): extract sandbox status action
cv May 3, 2026
aab6c86
refactor(cli): extract sandbox doctor action
cv May 3, 2026
8908521
refactor(cli): extract sandbox destroy action
cv May 3, 2026
56e4f05
refactor(cli): extract sandbox rebuild action
cv May 3, 2026
8bf1958
refactor(cli): extract upgrade sandboxes action
cv May 3, 2026
38eb84d
refactor(cli): remove runtime bridge
cv May 3, 2026
b2ad5da
refactor(cli): remove legacy dispatch fallbacks
cv May 3, 2026
edd2650
refactor(cli): expose explicit main entrypoint
cv May 3, 2026
a15da95
refactor(cli): add oclif examples for utility commands
cv May 3, 2026
4f57ebb
refactor(cli): validate logs flags with oclif
cv May 3, 2026
8b2d077
refactor(cli): improve sandbox diagnostic command metadata
cv May 3, 2026
a09cc51
refactor(cli): tighten policy and channel parser validation
cv May 3, 2026
75857dc
refactor(cli): improve snapshot command metadata
cv May 3, 2026
11c0676
refactor(cli): require skill install path in oclif
cv May 3, 2026
05f9eca
refactor(cli): add lifecycle confirmation flag aliases
cv May 3, 2026
4ebeae4
refactor(cli): split share into oclif subcommands
cv May 3, 2026
7d72437
Revert "refactor(cli): split share into oclif subcommands"
cv May 3, 2026
0ee5ca5
refactor(cli): split share into oclif subcommands
cv May 3, 2026
928219c
refactor(cli): model debug flags with oclif
cv May 3, 2026
36cce5e
refactor(cli): model onboard flags with oclif
cv May 3, 2026
702afb1
docs: sync oclif UX command reference
cv May 3, 2026
3224350
refactor(cli): extract public argv normalizer
cv May 3, 2026
cd4cdb8
refactor(cli): rename oclif dispatch module
cv May 3, 2026
9499ca6
refactor(cli): normalize policy command ids
cv May 3, 2026
42028ef
test(cli): require oclif command metadata
cv May 3, 2026
a05c6b3
refactor(cli): return typed debug parse results
cv May 3, 2026
1875fe9
refactor(cli): add public command display ids
cv May 3, 2026
36f1dbe
refactor(cli): use oclif summaries in root help
cv May 3, 2026
78bfd5a
refactor(cli): table-drive sandbox dispatch
cv May 3, 2026
96ce61f
refactor(cli): normalize gateway token command id
cv May 3, 2026
266ebc9
refactor(cli): render public oclif help
cv May 3, 2026
dc98994
refactor(cli): add shared oclif command base
cv May 3, 2026
d0d2a70
refactor(cli): use oclif flag relationships
cv May 3, 2026
8396c06
refactor(cli): pass lifecycle typed options
cv May 3, 2026
1532b19
refactor(cli): parse durations with oclif flags
cv May 3, 2026
7c0445a
refactor(cli): project public help through oclif
cv May 3, 2026
3978c32
test(cli): cover oclif metadata routing helpers
cv May 3, 2026
591eabb
test(cli): cover global oclif command adapters
cv May 3, 2026
8a6ecbc
test(cli): cover sandbox oclif command adapters
cv May 3, 2026
e5aa22f
refactor(cli): split share oclif commands
cv May 3, 2026
e179336
test(cli): narrow sandbox logs coverage ignores
cv May 3, 2026
a629813
test(cli): cover remaining global oclif adapters
cv May 3, 2026
c5954e7
test(cli): cover credentials oclif adapter
cv May 3, 2026
3380de9
test(cli): cover runtime utility helpers
cv May 3, 2026
f60a190
test(cli): improve global adapter coverage
cv May 3, 2026
78a16d1
merge: sync simple global adapter coverage
cv May 3, 2026
a58dc90
merge: sync credentials adapter coverage
cv May 3, 2026
034454f
merge: include credentials adapter coverage
cv May 3, 2026
28bc497
merge: sync combined global adapter coverage
cv May 3, 2026
e9ed6ba
test(cli): cover global action facade
cv May 3, 2026
00b288c
merge: sync global action facade coverage
cv May 3, 2026
7bd5f32
test(cli): stabilize coverage dist sourcemaps
cv May 4, 2026
d4b55d9
test(cli): rebaseline clean-dist function coverage
cv May 4, 2026
b872474
refactor(cli): extract maintenance image helpers
cv May 4, 2026
4965762
refactor(cli): extract upgrade sandbox helpers
cv May 4, 2026
9acd660
refactor(cli): extract sandbox destroy helpers
cv May 4, 2026
b6c0f5a
test(cli): allow clean coverage variance
cv May 4, 2026
5c98bd1
merge: sync coverage stabilization
cv May 4, 2026
4754f3e
merge: sync maintenance helper extraction
cv May 4, 2026
96f0758
merge: sync upgrade helper extraction
cv May 4, 2026
5920d5b
test(cli): keep destroy helpers outside coverage ratchet
cv May 4, 2026
3c29e55
merge(main): reconcile sandbox destroy helpers
cv May 5, 2026
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
49 changes: 17 additions & 32 deletions src/lib/sandbox-destroy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import {
createSystemDeps as createSessionDeps,
getActiveSandboxSessions,
} from "./sandbox-session-state";
import { stripAnsi } from "./openshell";
import {
getSandboxDeleteOutcome,
shouldCleanupGatewayAfterDestroy,
shouldStopHostServicesAfterDestroy,
} from "./sandbox-destroy-helpers";
import { G, R, YW } from "./terminal-style";

type SpawnLikeResult = {
status: number | null;
stdout?: string;
stderr?: string;
};

type DockerRmi = (tag: string, opts?: { ignoreError?: boolean }) => { status: number | null };

type RemoveSandboxImageDeps = {
Expand Down Expand Up @@ -81,23 +79,6 @@ function hasNoLiveSandboxes(): boolean {
return parseLiveSandboxNames(liveList.output).size === 0;
}

function isMissingSandboxDeleteResult(output = ""): boolean {
return /\bNotFound\b|\bNot Found\b|sandbox not found|sandbox .* not found|sandbox .* not present|sandbox does not exist|no such sandbox/i.test(
stripAnsi(output),
);
}

export function getSandboxDeleteOutcome(deleteResult: SpawnLikeResult): {
output: string;
alreadyGone: boolean;
} {
const output = `${deleteResult.stdout || ""}${deleteResult.stderr || ""}`.trim();
return {
output,
alreadyGone: deleteResult.status !== 0 && isMissingSandboxDeleteResult(output),
};
}

function cleanupSandboxServices(
sandboxName: string,
{ stopHostServices = false }: { stopHostServices?: boolean } = {},
Expand Down Expand Up @@ -248,10 +229,12 @@ export async function destroySandbox(
process.exit(deleteResult.status || 1);
}

const shouldStopHostServices =
(deleteResult.status === 0 || alreadyGone) &&
registry.listSandboxes().sandboxes.length === 1 &&
!!registry.getSandbox(sandboxName);
const deleteSucceededOrAlreadyGone = deleteResult.status === 0 || alreadyGone;
const shouldStopHostServices = shouldStopHostServicesAfterDestroy({
deleteSucceededOrAlreadyGone,
registeredSandboxCount: registry.listSandboxes().sandboxes.length,
sandboxStillRegistered: !!registry.getSandbox(sandboxName),
});

cleanupSandboxServices(sandboxName, { stopHostServices: shouldStopHostServices });
const removed = removeSandboxRegistryEntry(sandboxName);
Expand All @@ -263,10 +246,12 @@ export async function destroySandbox(
});
}
if (
(deleteResult.status === 0 || alreadyGone) &&
removed &&
registry.listSandboxes().sandboxes.length === 0 &&
hasNoLiveSandboxes()
shouldCleanupGatewayAfterDestroy({
deleteSucceededOrAlreadyGone,
removedRegistryEntry: removed,
noRegisteredSandboxes: registry.listSandboxes().sandboxes.length === 0,
noLiveSandboxes: hasNoLiveSandboxes(),
})
) {
cleanupGatewayAfterLastSandbox();
}
Expand Down
70 changes: 70 additions & 0 deletions src/lib/sandbox-destroy-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

import {
getSandboxDeleteOutcome,
isMissingSandboxDeleteOutput,
shouldCleanupGatewayAfterDestroy,
shouldStopHostServicesAfterDestroy,
} from "./sandbox-destroy-helpers";

describe("sandbox destroy helpers", () => {
it("detects missing sandbox delete output", () => {
expect(isMissingSandboxDeleteOutput("Error: sandbox alpha not found")).toBe(true);
expect(isMissingSandboxDeleteOutput("\u001b[31mNotFound\u001b[0m: missing")).toBe(true);
expect(isMissingSandboxDeleteOutput("permission denied")).toBe(false);
});

it("classifies delete outcomes", () => {
expect(getSandboxDeleteOutcome({ status: 1, stderr: "Error: sandbox alpha not found" })).toEqual({
output: "Error: sandbox alpha not found",
alreadyGone: true,
});
expect(getSandboxDeleteOutcome({ status: 1, stdout: "boom" })).toEqual({
output: "boom",
alreadyGone: false,
});
expect(getSandboxDeleteOutcome({ status: 0, stdout: "deleted" })).toEqual({
output: "deleted",
alreadyGone: false,
});
});

it("decides when host services should stop before final registry removal", () => {
expect(
shouldStopHostServicesAfterDestroy({
deleteSucceededOrAlreadyGone: true,
registeredSandboxCount: 1,
sandboxStillRegistered: true,
}),
).toBe(true);
expect(
shouldStopHostServicesAfterDestroy({
deleteSucceededOrAlreadyGone: true,
registeredSandboxCount: 2,
sandboxStillRegistered: true,
}),
).toBe(false);
});

it("decides when gateway cleanup should run after destroy", () => {
expect(
shouldCleanupGatewayAfterDestroy({
deleteSucceededOrAlreadyGone: true,
removedRegistryEntry: true,
noRegisteredSandboxes: true,
noLiveSandboxes: true,
}),
).toBe(true);
expect(
shouldCleanupGatewayAfterDestroy({
deleteSucceededOrAlreadyGone: true,
removedRegistryEntry: true,
noRegisteredSandboxes: true,
noLiveSandboxes: false,
}),
).toBe(false);
});
});
57 changes: 57 additions & 0 deletions src/lib/sandbox-destroy-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- pure helper tests exercise this module; orchestration coverage still runs through dist. */

import { stripAnsi } from "./openshell";

export type SpawnLikeResult = {
status: number | null;
stdout?: string;
stderr?: string;
};

export function isMissingSandboxDeleteOutput(output = ""): boolean {
return /\bNotFound\b|\bNot Found\b|sandbox not found|sandbox .* not found|sandbox .* not present|sandbox does not exist|no such sandbox/i.test(
stripAnsi(output),
);
}

export function getSandboxDeleteOutcome(deleteResult: SpawnLikeResult): {
output: string;
alreadyGone: boolean;
} {
const output = `${deleteResult.stdout || ""}${deleteResult.stderr || ""}`.trim();
return {
output,
alreadyGone: deleteResult.status !== 0 && isMissingSandboxDeleteOutput(output),
};
}

export function shouldStopHostServicesAfterDestroy(input: {
deleteSucceededOrAlreadyGone: boolean;
registeredSandboxCount: number;
sandboxStillRegistered: boolean;
}): boolean {
return (
input.deleteSucceededOrAlreadyGone &&
input.registeredSandboxCount === 1 &&
input.sandboxStillRegistered
);
}

export function shouldCleanupGatewayAfterDestroy(input: {
deleteSucceededOrAlreadyGone: boolean;
removedRegistryEntry: boolean;
noRegisteredSandboxes: boolean;
noLiveSandboxes: boolean;
}): boolean {
return (
input.deleteSucceededOrAlreadyGone &&
input.removedRegistryEntry &&
input.noRegisteredSandboxes &&
input.noLiveSandboxes
);
}

/* v8 ignore stop */
3 changes: 2 additions & 1 deletion src/lib/sandbox-rebuild-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import * as policies from "./policies";
import * as registry from "./registry";
import { resolveOpenshell } from "./resolve-openshell";
import { parseLiveSandboxNames } from "./runtime-recovery";
import { getSandboxDeleteOutcome, removeSandboxRegistryEntry } from "./sandbox-destroy-action";
import { getSandboxDeleteOutcome } from "./sandbox-destroy-helpers";
import { removeSandboxRegistryEntry } from "./sandbox-destroy-action";
import { executeSandboxCommand } from "./sandbox-process-recovery-action";
import {
createSystemDeps as createSessionDeps,
Expand Down
2 changes: 1 addition & 1 deletion test/image-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import fs from "node:fs";
import path from "node:path";

import {
getSandboxDeleteOutcome,
removeSandboxImage,
removeSandboxRegistryEntry,
} from "../src/lib/sandbox-destroy-action";
import { getSandboxDeleteOutcome } from "../src/lib/sandbox-destroy-helpers";
import { normalizeGarbageCollectImagesOptions } from "../src/lib/lifecycle-options";
import { help as renderRootHelp } from "../src/lib/root-help-action";

Expand Down
Loading