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
41 changes: 37 additions & 4 deletions src/lib/actions/sandbox/status-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const requireDist = createRequire(import.meta.url);
const statusModulePath = "../../../../dist/lib/actions/sandbox/status.js";

type StatusFlowHarness = {
checkAgentVersionSpy: MockInstance;
getActiveSandboxSessionsSpy: MockInstance;
getSandboxDockerRuntimeSpy: MockInstance;
logSpy: MockInstance;
Expand Down Expand Up @@ -39,7 +40,15 @@ const baseSandboxEntry = {
agentVersion: "0.1.0",
};

function createStatusFlowHarness(options: { lookupState?: "present" | "missing" } = {}) {
function createStatusFlowHarness(
options: {
lookupState?: "present" | "missing";
sandboxEntry?: Partial<Omit<typeof baseSandboxEntry, "agentVersion">> & {
agent?: string | null;
agentVersion?: string | null;
};
} = {},
) {
delete require.cache[requireDist.resolve(statusModulePath)];

const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
Expand Down Expand Up @@ -74,15 +83,17 @@ function createStatusFlowHarness(options: { lookupState?: "present" | "missing"
recoverySandboxVia: "docker unpause",
};

vi.spyOn(registry, "getSandbox").mockReturnValue(baseSandboxEntry);
const sandboxEntry = { ...baseSandboxEntry, ...options.sandboxEntry };

vi.spyOn(registry, "getSandbox").mockReturnValue(sandboxEntry);
vi.spyOn(statusPreflight, "getSandboxStatusPreflight").mockResolvedValue({
failure: null,
failureLayer: null,
suppressInferenceProbe: false,
exitCode: 0,
});
vi.spyOn(statusSnapshot, "collectSandboxStatusSnapshot").mockResolvedValue({
sb: baseSandboxEntry,
sb: sandboxEntry,
lookup,
rpcIssue: null,
currentModel: "nvidia/nemotron-live",
Expand Down Expand Up @@ -129,7 +140,7 @@ function createStatusFlowHarness(options: { lookupState?: "present" | "missing"
container: null,
});
vi.spyOn(nim, "shouldShowNimLine").mockReturnValue(true);
vi.spyOn(sandboxVersion, "checkAgentVersion").mockReturnValue({
const checkAgentVersionSpy = vi.spyOn(sandboxVersion, "checkAgentVersion").mockReturnValue({
sandboxVersion: "0.1.0",
expectedVersion: "0.2.0",
isStale: true,
Expand All @@ -149,6 +160,7 @@ function createStatusFlowHarness(options: { lookupState?: "present" | "missing"
logSpy.mockClear();

return {
checkAgentVersionSpy,
getActiveSandboxSessionsSpy,
getSandboxDockerRuntimeSpy,
logSpy,
Expand Down Expand Up @@ -201,6 +213,27 @@ describe("showSandboxStatus flow", () => {
expect(exitSpy).not.toHaveBeenCalled();
});

it("probes terminal runtime agent version when cached metadata is missing", async () => {
const harness = createStatusFlowHarness({
sandboxEntry: {
agent: "langchain-deepagents-code",
agentVersion: null,
},
});

await expect(harness.showSandboxStatus("alpha")).resolves.toBeUndefined();

const output = harness.logSpy.mock.calls.map((call) => String(call[0])).join("\n");
expect(output).toContain("Harness: LangChain Deep Agents Code (terminal)");
expect(output).toContain("Agent: LangChain Deep Agents Code v0.1.0");
expect(output).toContain("Update:");
expect(output).toContain("Run `nemoclaw alpha rebuild` to upgrade");
expect(harness.checkAgentVersionSpy).toHaveBeenCalledWith("alpha", {
forceProbe: true,
skipProbe: false,
});
});

it("preserves the registry entry and exits when the live gateway is missing the sandbox", async () => {
const harness = createStatusFlowHarness({ lookupState: "missing" });

Expand Down
13 changes: 10 additions & 3 deletions src/lib/actions/sandbox/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ export {
} from "./status-snapshot";

/**
* Returns true when status can validate a cached agent version against the running sandbox.
* Returns true when status can validate an agent version against the running sandbox.
*/
function shouldProbeSandboxRuntimeVersion(
lookup: SandboxGatewayState,
sandbox: registry.SandboxEntry,
agentRuntimeKind: string,
): boolean {
return lookup.state === "present" && Boolean(sandbox.agentVersion);
return (
lookup.state === "present" && (Boolean(sandbox.agentVersion) || agentRuntimeKind === "terminal")
);
}

// True when sandbox GPU is enabled but no CUDA-usability proof has confirmed it
Expand Down Expand Up @@ -263,7 +266,11 @@ export async function showSandboxStatus(sandboxName: string): Promise<void> {

// Agent version check
try {
const shouldProbeRuntimeVersion = shouldProbeSandboxRuntimeVersion(lookup, sb);
const shouldProbeRuntimeVersion = shouldProbeSandboxRuntimeVersion(
lookup,
sb,
statusAgent.agentRuntime,
);
const versionCheck = sandboxVersion.checkAgentVersion(sandboxName, {
forceProbe: shouldProbeRuntimeVersion,
skipProbe: !shouldProbeRuntimeVersion,
Expand Down
Loading