Skip to content
Merged
2 changes: 2 additions & 0 deletions src/lib/credentials-cli-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

Comment on lines +4 to +5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Narrow the coverage suppression scope in this file.

Line 4 starts a file-wide ignore region, but this module contains non-trivial runtime and error-path logic. Blanket suppression here will hide useful branch coverage signals.

♻️ Proposed fix
-/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/credentials-cli-command.ts` around lines 4 - 5, The file currently
begins with a file-wide "/* v8 ignore start */" which suppresses coverage for
the entire module; narrow this by removing the top-level ignore and instead wrap
the minimal thin oclif adapter code in a paired "/* v8 ignore start */" and "/*
v8 ignore end */" block (e.g., the adapter function/class for oclif in this
module such as CredentialsCliCommand or the specific adapter helper) so runtime
and error-path logic outside that adapter remains instrumented; ensure the
ignore pair is balanced and placed only around the adapter lines.

import type { StdioOptions } from "node:child_process";

import { Args, Command, Flags } from "@oclif/core";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/debug-cli-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

Comment on lines +4 to +5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Avoid file-wide coverage ignore for behaviorful debug logic.

Line 4 suppresses coverage for the entire module, including default-sandbox resolution and OpenShell probe warning paths. That makes regressions harder to catch in this command.

♻️ Proposed fix
-/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/debug-cli-command.ts` around lines 4 - 5, Remove the file-wide
coverage ignore comment (the "v8 ignore start" banner) from
src/lib/debug-cli-command.ts and narrow coverage suppressions only to the
specific thin oclif adapter bits that truly cannot be unit-tested; leave the
default-sandbox resolution flow and the OpenShell probe warning code covered by
tests. Concretely, delete the global ignore comment and instead add targeted
ignore markers only around the thin oclif adapter bootstrap lines (the small
adapter block) so functions handling default-sandbox resolution and the
OpenShell probe warning remain instrumented and testable.

import { Command } from "@oclif/core";

import type { CaptureOpenshellResult } from "./openshell";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/gateway-token-cli-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

import { Args, Command, Flags } from "@oclif/core";

import { runGatewayTokenCommand } from "./gateway-token-command";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/list-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

import { Command, Flags } from "@oclif/core";

import { getSandboxInventory, renderSandboxInventoryText } from "./inventory-commands";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/maintenance-cli-commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapters covered through CLI integration tests. */

import { Command, Flags } from "@oclif/core";

type RuntimeBridge = {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/oclif-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
SandboxPolicyListCommand,
SandboxStatusCommand,
} from "./sandbox-inspection-cli-command";
import SandboxLogsCommand from "./sandbox-logs-cli-command";
import ShareCommand from "./share-command";
import SkillInstallCliCommand from "./skill-install-cli-command";
import StatusCommand from "./status-command";
import {
DeprecatedStartCommand,
Expand All @@ -39,7 +41,9 @@ export default {
list: ListCommand,
"sandbox:channels:list": SandboxChannelsListCommand,
"sandbox:config:get": SandboxConfigGetCommand,
"sandbox:logs": SandboxLogsCommand,
"sandbox:policy-list": SandboxPolicyListCommand,
"sandbox:skill:install": SkillInstallCliCommand,
"sandbox:status": SandboxStatusCommand,
share: ShareCommand,
status: StatusCommand,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/sandbox-inspection-cli-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapters covered through CLI integration tests. */

import { Args, Command, Flags } from "@oclif/core";

import { CLI_NAME } from "./branding";
Expand Down
21 changes: 21 additions & 0 deletions src/lib/sandbox-logs-cli-command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

import SandboxLogsCommand, {
setSandboxLogsRuntimeBridgeFactoryForTest,
} from "./sandbox-logs-cli-command";

const rootDir = process.cwd();

describe("SandboxLogsCommand", () => {
it("runs sandbox logs with the follow flag", async () => {
const sandboxLogs = vi.fn();
setSandboxLogsRuntimeBridgeFactoryForTest(() => ({ sandboxLogs }));

await SandboxLogsCommand.run(["alpha", "--follow"], rootDir);

expect(sandboxLogs).toHaveBeenCalledWith("alpha", true);
});
});
46 changes: 46 additions & 0 deletions src/lib/sandbox-logs-cli-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif wrapper covered through CLI integration tests. */

import { Args, Command, Flags } from "@oclif/core";

type RuntimeBridge = {
sandboxLogs: (sandboxName: string, follow: boolean) => void;
};

let runtimeBridgeFactory = (): RuntimeBridge => require("../nemoclaw") as RuntimeBridge;

export function setSandboxLogsRuntimeBridgeFactoryForTest(
factory: () => RuntimeBridge,
): void {
runtimeBridgeFactory = factory;
}

function getRuntimeBridge(): RuntimeBridge {
return runtimeBridgeFactory();
}

export default class SandboxLogsCommand extends Command {
static id = "sandbox:logs";
static strict = true;
static summary = "Stream sandbox logs";
static description = "Show OpenClaw gateway logs and OpenShell audit logs for a sandbox.";
static usage = ["<name> logs [--follow]"];
static args = {
sandboxName: Args.string({
name: "sandbox",
description: "Sandbox name",
required: true,
}),
};
static flags = {
help: Flags.help({ char: "h" }),
follow: Flags.boolean({ description: "Follow logs until interrupted" }),
};

public async run(): Promise<void> {
const { args, flags } = await this.parse(SandboxLogsCommand);
getRuntimeBridge().sandboxLogs(args.sandboxName, flags.follow === true);
}
}
30 changes: 30 additions & 0 deletions src/lib/skill-install-cli-command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

import SkillInstallCliCommand, {
setSkillInstallRuntimeBridgeFactoryForTest,
} from "./skill-install-cli-command";

const rootDir = process.cwd();

describe("SkillInstallCliCommand", () => {
it("runs skill install with the legacy install argv shape", async () => {
const sandboxSkillInstall = vi.fn().mockResolvedValue(undefined);
setSkillInstallRuntimeBridgeFactoryForTest(() => ({ sandboxSkillInstall }));

await SkillInstallCliCommand.run(["alpha", "/tmp/my-skill"], rootDir);

expect(sandboxSkillInstall).toHaveBeenCalledWith("alpha", ["install", "/tmp/my-skill"]);
});

it("lets legacy skill install validation report a missing path", async () => {
const sandboxSkillInstall = vi.fn().mockResolvedValue(undefined);
setSkillInstallRuntimeBridgeFactoryForTest(() => ({ sandboxSkillInstall }));

await SkillInstallCliCommand.run(["alpha"], rootDir);

expect(sandboxSkillInstall).toHaveBeenCalledWith("alpha", ["install"]);
});
});
53 changes: 53 additions & 0 deletions src/lib/skill-install-cli-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif wrapper covered through CLI integration tests. */

import { Args, Command, Flags } from "@oclif/core";

type RuntimeBridge = {
sandboxSkillInstall: (sandboxName: string, args?: string[]) => Promise<void>;
};

let runtimeBridgeFactory = (): RuntimeBridge => require("../nemoclaw") as RuntimeBridge;

export function setSkillInstallRuntimeBridgeFactoryForTest(
factory: () => RuntimeBridge,
): void {
runtimeBridgeFactory = factory;
}

function getRuntimeBridge(): RuntimeBridge {
return runtimeBridgeFactory();
}

export default class SkillInstallCliCommand extends Command {
static id = "sandbox:skill:install";
static strict = true;
static summary = "Deploy a skill directory to the sandbox";
static description = "Validate a local SKILL.md directory and upload it to a running sandbox.";
static usage = ["<name> skill install <path>"];
static args = {
sandboxName: Args.string({
name: "sandbox",
description: "Sandbox name",
required: true,
}),
skillPath: Args.string({
name: "path",
description: "Skill directory or direct path to SKILL.md",
required: false,
}),
};
static flags = {
help: Flags.help({ char: "h" }),
};

public async run(): Promise<void> {
const { args } = await this.parse(SkillInstallCliCommand);
await getRuntimeBridge().sandboxSkillInstall(
args.sandboxName,
args.skillPath ? ["install", args.skillPath] : ["install"],
);
}
}
2 changes: 2 additions & 0 deletions src/lib/status-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

import { Command, Flags } from "@oclif/core";

import { showStatusCommand } from "./inventory-commands";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/tunnel-commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapters covered through CLI integration tests. */

import { Command, Flags } from "@oclif/core";

import { CLI_NAME } from "./branding";
Expand Down
2 changes: 2 additions & 0 deletions src/lib/uninstall-cli-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

/* v8 ignore start -- thin oclif adapter covered through CLI integration tests. */

import { spawnSync } from "node:child_process";

import { Command } from "@oclif/core";
Expand Down
25 changes: 22 additions & 3 deletions src/nemoclaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,9 @@ exports.recoverNamedGatewayRuntime = recoverNamedGatewayRuntime;
exports.recoverRegistryEntries = recoverRegistryEntries;
exports.runOpenshell = runOpenshell;
exports.sandboxChannelsList = sandboxChannelsList;
exports.sandboxLogs = sandboxLogs;
exports.sandboxPolicyList = sandboxPolicyList;
exports.sandboxSkillInstall = sandboxSkillInstall;
exports.sandboxStatus = sandboxStatus;
exports.ensureLiveSandboxOrExit = ensureLiveSandboxOrExit;
exports.G = G;
Expand Down Expand Up @@ -4152,7 +4154,11 @@ const [cmd, ...args] = process.argv.slice(2);
await runOclif("sandbox:status", [cmd, ...actionArgs]);
break;
case "logs":
sandboxLogs(cmd, actionArgs.includes("--follow"));
if (hasHelpFlag(actionArgs)) {
printSandboxActionUsage("logs [--follow]");
break;
}
await runOclif("sandbox:logs", [cmd, ...actionArgs]);
break;
case "policy-add":
await sandboxPolicyAdd(cmd, actionArgs);
Expand All @@ -4177,9 +4183,22 @@ const [cmd, ...args] = process.argv.slice(2);
}
await runOclif("sandbox:gateway-token", [cmd, ...actionArgs]);
break;
case "skill":
await sandboxSkillInstall(cmd, actionArgs);
case "skill": {
const skillSub = actionArgs[0];
const skillArgs = actionArgs.slice(1);
if (!skillSub || skillSub === "help" || skillSub === "--help" || skillSub === "-h") {
await sandboxSkillInstall(cmd, actionArgs);
} else if (skillSub === "install") {
if (hasHelpFlag(skillArgs)) {
await sandboxSkillInstall(cmd, actionArgs);
} else {
await runOclif("sandbox:skill:install", [cmd, ...skillArgs]);
}
} else {
await sandboxSkillInstall(cmd, actionArgs);
}
break;
}
case "rebuild":
await sandboxRebuild(cmd, actionArgs);
break;
Expand Down
6 changes: 6 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ describe("CLI dispatch", () => {
expect(r.code).toBe(0);
expect(r.out).toContain("Usage: nemoclaw <sandbox> skill install <path>");
expect(r.out).toContain("Deploy a skill directory");
expect(r.out).not.toContain("sandbox:skill:install");
expect(r.out).not.toContain("--help");
expect(r.out).not.toContain("No SKILL.md found");
});
Expand Down Expand Up @@ -832,6 +833,11 @@ describe("CLI dispatch", () => {
expect(status.out).toContain("<name> status");
expect(status.out).not.toContain("sandbox:status");

const logs = runWithEnv("alpha logs --help", { HOME: home });
expect(logs.code).toBe(0);
expect(logs.out).toContain("<name> logs [--follow]");
expect(logs.out).not.toContain("sandbox:logs");

const policy = runWithEnv("alpha policy-list --help", { HOME: home });
expect(policy.code).toBe(0);
expect(policy.out).toContain("<name> policy-list");
Expand Down
4 changes: 2 additions & 2 deletions test/nemoclaw-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ describe("nemoclaw-start persistent gateway log hardening", () => {
it("creates a regular read-only persistent log mirror and refuses unsafe paths", () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-persistent-log-"));
const gatewayLog = path.join(tmpDir, "gateway.log");
const persistentLog = path.join(tmpDir, "logs", "gateway-persistent.log");
const scriptPath = path.join(tmpDir, "run.sh");
fs.writeFileSync(gatewayLog, "initial gateway line\n");
fs.writeFileSync(
Expand All @@ -577,7 +578,7 @@ describe("nemoclaw-start persistent gateway log hardening", () => {
"start_persistent_gateway_log_mirror",
"sleep 0.2",
`printf '%s\\n' later-line >> ${JSON.stringify(gatewayLog)}`,
"sleep 0.4",
`for _ in {1..30}; do grep -Fq later-line ${JSON.stringify(persistentLog)} 2>/dev/null && break; sleep 0.1; done`,
'kill "$GATEWAY_LOG_PERSIST_PID" 2>/dev/null || true',
'wait "$GATEWAY_LOG_PERSIST_PID" 2>/dev/null || true',
"printf 'PID=%s\\n' \"$GATEWAY_LOG_PERSIST_PID\"",
Expand All @@ -589,7 +590,6 @@ describe("nemoclaw-start persistent gateway log hardening", () => {
const result = spawnSync("bash", [scriptPath], { encoding: "utf-8", timeout: 5000 });
expect(result.status).toBe(0);
expect(result.stdout).toContain("PID=");
const persistentLog = path.join(tmpDir, "logs", "gateway-persistent.log");
const stat = fs.statSync(persistentLog);
expect(stat.isFile()).toBe(true);
expect((stat.mode & 0o777).toString(8)).toBe("644");
Expand Down
1 change: 1 addition & 0 deletions test/repro-2681-group-writable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe("Issue #2681 — mutable OpenClaw config permissions", () => {
[
"set -euo pipefail",
'id() { if [ "${1:-}" = "-u" ]; then printf "0"; else command id "$@"; fi; }',
'stat() { if [ "${1:-}" = "-c" ] && [ "${2:-}" = "%U" ]; then printf "sandbox\\n"; else command stat "$@"; fi; }',
normalizeMutableConfigPermsFor(configDir),
"normalize_mutable_config_perms",
].join("\n"),
Expand Down
Loading