diff --git a/src/lib/global-oclif-command-adapters.test.ts b/src/lib/global-oclif-command-adapters.test.ts new file mode 100644 index 00000000000..45dc44f70c8 --- /dev/null +++ b/src/lib/global-oclif-command-adapters.test.ts @@ -0,0 +1,115 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ + buildListCommandDeps: vi.fn(), + buildStatusCommandDeps: vi.fn(), + getSandboxInventory: vi.fn(), + getStatusReport: vi.fn(), + renderSandboxInventoryText: vi.fn(), + runBackupAllAction: vi.fn(), + runGarbageCollectImagesAction: vi.fn(), + runOnboardAction: vi.fn(), + runSetupAction: vi.fn(), + runSetupSparkAction: vi.fn(), + runUpgradeSandboxesAction: vi.fn(), + showStatusCommand: vi.fn(), +})); + +vi.mock("./inventory-commands", () => ({ + getSandboxInventory: mocks.getSandboxInventory, + getStatusReport: mocks.getStatusReport, + renderSandboxInventoryText: mocks.renderSandboxInventoryText, + showStatusCommand: mocks.showStatusCommand, +})); + +vi.mock("./list-command-deps", () => ({ + buildListCommandDeps: mocks.buildListCommandDeps, +})); + +vi.mock("./status-command-deps", () => ({ + buildStatusCommandDeps: mocks.buildStatusCommandDeps, +})); + +vi.mock("./global-cli-actions", () => ({ + runBackupAllAction: mocks.runBackupAllAction, + runGarbageCollectImagesAction: mocks.runGarbageCollectImagesAction, + runOnboardAction: mocks.runOnboardAction, + runSetupAction: mocks.runSetupAction, + runSetupSparkAction: mocks.runSetupSparkAction, + runUpgradeSandboxesAction: mocks.runUpgradeSandboxesAction, +})); + +import ListCommand from "./list-command"; +import { + BackupAllCommand, + GarbageCollectImagesCommand, + UpgradeSandboxesCommand, +} from "./maintenance-cli-commands"; +import { OnboardCliCommand, SetupCliCommand, SetupSparkCliCommand } from "./onboard-cli-commands"; +import StatusCommand from "./status-command"; + +const rootDir = process.cwd(); + +describe("global oclif command adapters", () => { + beforeEach(() => { + vi.clearAllMocks(); + mocks.buildListCommandDeps.mockReturnValue({ getLiveInference: vi.fn() }); + mocks.buildStatusCommandDeps.mockReturnValue({ statusDeps: true }); + mocks.getSandboxInventory.mockResolvedValue({ sandboxes: [] }); + mocks.getStatusReport.mockReturnValue({ sandboxes: [] }); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("runs list through inventory helpers", async () => { + await ListCommand.run([], rootDir); + + expect(mocks.buildListCommandDeps).toHaveBeenCalledWith(); + expect(mocks.getSandboxInventory).toHaveBeenCalledWith({ getLiveInference: expect.any(Function) }); + expect(mocks.renderSandboxInventoryText).toHaveBeenCalledWith( + { sandboxes: [] }, + expect.any(Function), + null, + ); + }); + + it("runs status through status helpers", async () => { + await StatusCommand.run([], rootDir); + + expect(mocks.buildStatusCommandDeps).toHaveBeenCalledWith(rootDir); + expect(mocks.showStatusCommand).toHaveBeenCalledWith({ statusDeps: true }); + }); + + it("maps maintenance flags to typed action options", async () => { + await BackupAllCommand.run([], rootDir); + await UpgradeSandboxesCommand.run(["--check", "--yes"], rootDir); + await GarbageCollectImagesCommand.run(["--dry-run", "--force"], rootDir); + + expect(mocks.runBackupAllAction).toHaveBeenCalledWith(); + expect(mocks.runUpgradeSandboxesAction).toHaveBeenCalledWith({ + auto: false, + check: true, + yes: true, + }); + expect(mocks.runGarbageCollectImagesAction).toHaveBeenCalledWith({ + dryRun: true, + force: true, + yes: false, + }); + }); + + it("maps onboard-family flags into the compatibility action arguments", async () => { + await OnboardCliCommand.run(["--name", "alpha", "--resume"], rootDir); + await SetupCliCommand.run(["--fresh"], rootDir); + await SetupSparkCliCommand.run(["--control-ui-port", "18080"], rootDir); + + expect(mocks.runOnboardAction).toHaveBeenCalledWith(["--resume", "--name", "alpha"]); + expect(mocks.runSetupAction).toHaveBeenCalledWith(["--fresh"]); + expect(mocks.runSetupSparkAction).toHaveBeenCalledWith(["--control-ui-port", "18080"]); + }); +}); diff --git a/src/lib/list-command.ts b/src/lib/list-command.ts index 8117fbe11fd..07a05b0b2af 100644 --- a/src/lib/list-command.ts +++ b/src/lib/list-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 { getSandboxInventory, renderSandboxInventoryText } from "./inventory-commands"; import { NemoClawCommand } from "./nemoclaw-oclif-command"; import { buildListCommandDeps } from "./list-command-deps"; diff --git a/src/lib/maintenance-cli-commands.ts b/src/lib/maintenance-cli-commands.ts index 8d78963cf5b..d21fd3dcc39 100644 --- a/src/lib/maintenance-cli-commands.ts +++ b/src/lib/maintenance-cli-commands.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 adapters covered through CLI integration tests. */ - import { Flags } from "@oclif/core"; import { diff --git a/src/lib/onboard-cli-commands.ts b/src/lib/onboard-cli-commands.ts index a3cb55f7124..84697261ac6 100644 --- a/src/lib/onboard-cli-commands.ts +++ b/src/lib/onboard-cli-commands.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 adapters covered through CLI integration tests. */ - import { Command, Flags } from "@oclif/core"; import { runOnboardAction, runSetupAction, runSetupSparkAction } from "./global-cli-actions"; diff --git a/src/lib/status-command.ts b/src/lib/status-command.ts index cc2dc3e822f..e0e4e85181d 100644 --- a/src/lib/status-command.ts +++ b/src/lib/status-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 { getStatusReport, showStatusCommand } from "./inventory-commands"; import { NemoClawCommand } from "./nemoclaw-oclif-command"; import { buildStatusCommandDeps } from "./status-command-deps";