Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion src/lib/actions/sandbox/gateway-select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ describe("selectSandboxOwningGateway", () => {
expect(selected).toEqual({ outcome: "selected", gatewayName: "nemoclaw-8091" });
expect(run).toHaveBeenCalledWith(
["gateway", "select", "nemoclaw-8091"],
expect.objectContaining({ ignoreError: true }),
expect.objectContaining({
ignoreError: true,
stdio: ["inherit", "pipe", "inherit"],
}),
);
});

it("replays selection output through the parent stdout writer", () => {
vi.spyOn(registry, "getSandbox").mockReturnValue({ gatewayPort: 8080 } as never);
const output = "\u001b[32m✓ Active gateway set to 'nemoclaw'\u001b[0m\n";
const run = vi.fn(() => ({ status: 0, stdout: output }) as never);
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);

expect(selectSandboxOwningGateway("alpha", run)).toEqual({
outcome: "selected",
gatewayName: "nemoclaw",
});
expect(write).toHaveBeenCalledWith(output);
});

it("keeps the bare default gateway name for a default-port sandbox", () => {
vi.spyOn(registry, "getSandbox").mockReturnValue({ gatewayPort: 8080 } as never);
const run = vi.fn(() => ({ status: 0 }) as never);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/actions/sandbox/gateway-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export function selectSandboxOwningGateway(
if (!targetGatewayName) return { outcome: "unregistered", gatewayName: null };
const result = run(["gateway", "select", targetGatewayName], {
ignoreError: true,
stdio: ["inherit", "pipe", "inherit"],
timeout: OPENSHELL_OPERATION_TIMEOUT_MS,
});
if (result.stdout) process.stdout.write(result.stdout);
if (result.error || result.status !== 0) {
return { outcome: "failed", gatewayName: targetGatewayName };
}
Expand Down
5 changes: 5 additions & 0 deletions test/cli/sandbox-status-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ describe("CLI sandbox status JSON output", testTimeoutOptions(20_000), () => {
path.join(localBin, "openshell"),
[
"#!/usr/bin/env bash",
'if [ "$1" = "gateway" ] && [ "$2" = "select" ]; then',
" printf \"\\033[32m✓ Active gateway set to 'nemoclaw'\\033[0m\\n\"",
" exit 0",
"fi",
'if [ "$1" = "inference" ] && [ "$2" = "get" ]; then',
" echo 'Gateway inference:'",
" echo",
Expand Down Expand Up @@ -168,6 +172,7 @@ describe("CLI sandbox status JSON output", testTimeoutOptions(20_000), () => {
expect(r.out.trim().endsWith("}")).toBe(true);
expect(r.out).not.toContain("Sandbox: ");
expect(r.out).not.toContain("Nonexistent flag: --json");
expect(r.out).not.toContain("Active gateway set");

const parsed = JSON.parse(r.out);
expect(parsed).toMatchObject({
Expand Down
Loading