diff --git a/src/lib/credentials-cli-command-source.test.ts b/src/lib/credentials-cli-command-source.test.ts new file mode 100644 index 00000000000..655c236e801 --- /dev/null +++ b/src/lib/credentials-cli-command-source.test.ts @@ -0,0 +1,82 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ + prompt: vi.fn().mockResolvedValue("yes"), + recoverNamedGatewayRuntime: vi.fn().mockResolvedValue({ recovered: true }), + runOpenshellProviderCommand: vi.fn(), +})); + +vi.mock("./credentials", () => ({ prompt: mocks.prompt })); +vi.mock("./global-cli-actions", () => ({ + recoverNamedGatewayRuntime: mocks.recoverNamedGatewayRuntime, + runOpenshellProviderCommand: mocks.runOpenshellProviderCommand, +})); + +import { + CredentialsCommand, + CredentialsListCommand, + CredentialsResetCommand, +} from "./credentials-cli-command"; + +const rootDir = process.cwd(); + +describe("credentials oclif adapter source coverage", () => { + beforeEach(() => { + vi.clearAllMocks(); + mocks.recoverNamedGatewayRuntime.mockResolvedValue({ recovered: true }); + mocks.runOpenshellProviderCommand.mockReturnValue({ status: 0, stdout: "nvidia-prod\n" }); + }); + + it("prints top-level credentials usage", async () => { + const log = vi.spyOn(console, "log").mockImplementation(() => {}); + + await CredentialsCommand.run([], rootDir); + + const output = log.mock.calls.map((call) => String(call[0] ?? "")).join("\n"); + log.mockRestore(); + expect(output).toContain("Usage: nemoclaw credentials "); + expect(output).toContain("reset [--yes]"); + }); + + it("lists credential providers while hiding messaging bridge providers", async () => { + mocks.runOpenshellProviderCommand.mockReturnValue({ + status: 0, + stdout: "alpha-telegram-bridge\nnvidia-prod\nopenai-prod\n", + }); + const log = vi.spyOn(console, "log").mockImplementation(() => {}); + + await CredentialsListCommand.run([], rootDir); + + expect(mocks.recoverNamedGatewayRuntime).toHaveBeenCalledWith(); + expect(mocks.runOpenshellProviderCommand).toHaveBeenCalledWith(["provider", "list", "--names"], { + ignoreError: true, + stdio: ["ignore", "pipe", "pipe"], + timeout: 30_000, + }); + const output = log.mock.calls.map((call) => String(call[0] ?? "")).join("\n"); + log.mockRestore(); + expect(output).toContain("nvidia-prod"); + expect(output).toContain("openai-prod"); + expect(output).toContain("1 per-sandbox messaging bridge"); + expect(output).not.toContain("alpha-telegram-bridge\n"); + }); + + it("deletes provider credentials with --yes", async () => { + const log = vi.spyOn(console, "log").mockImplementation(() => {}); + + await CredentialsResetCommand.run(["nvidia-prod", "--yes"], rootDir); + + expect(mocks.prompt).not.toHaveBeenCalled(); + expect(mocks.runOpenshellProviderCommand).toHaveBeenCalledWith(["provider", "delete", "nvidia-prod"], { + ignoreError: true, + stdio: ["ignore", "pipe", "pipe"], + timeout: 30_000, + }); + const output = log.mock.calls.map((call) => String(call[0] ?? "")).join("\n"); + log.mockRestore(); + expect(output).toContain("Removed provider 'nvidia-prod'"); + }); +}); diff --git a/src/lib/credentials-cli-command.ts b/src/lib/credentials-cli-command.ts index a9349d463fe..f8a0ade4f16 100644 --- a/src/lib/credentials-cli-command.ts +++ b/src/lib/credentials-cli-command.ts @@ -1,8 +1,6 @@ // 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 { CLI_DISPLAY_NAME, CLI_NAME } from "./branding";