Repository navigation
refactor(cli): extract onboard command handler #1710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6ba95a4
refactor(cli): extract onboard command handler
cv a8adfc6
merge: sync main into onboard-command refactor
cv b8d0f75
Merge branch 'main' into refactor/onboard-command-ts-redo
cv 455f31b
Merge remote-tracking branch 'origin/main' into refactor/onboard-comm…
cv b1c9577
fix(cli): address onboard command review feedback
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| // 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 { | ||
| parseOnboardArgs, | ||
| runDeprecatedOnboardAliasCommand, | ||
| runOnboardCommand, | ||
| } from "../../dist/lib/onboard-command"; | ||
|
|
||
| describe("onboard command", () => { | ||
| it("parses onboard flags", () => { | ||
| expect( | ||
| parseOnboardArgs( | ||
| ["--non-interactive", "--resume", "--yes-i-accept-third-party-software"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toEqual({ | ||
| nonInteractive: true, | ||
| resume: true, | ||
| recreateSandbox: false, | ||
| fromDockerfile: null, | ||
| acceptThirdPartySoftware: true, | ||
| agent: null, | ||
| dangerouslySkipPermissions: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("accepts the env-based third-party notice acknowledgement", () => { | ||
| expect( | ||
| parseOnboardArgs( | ||
| [], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: { NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" }, | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toEqual({ | ||
| nonInteractive: false, | ||
| resume: false, | ||
| recreateSandbox: false, | ||
| fromDockerfile: null, | ||
| acceptThirdPartySoftware: true, | ||
| agent: null, | ||
| dangerouslySkipPermissions: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("runs onboard with parsed options", async () => { | ||
| const runOnboard = vi.fn(async () => {}); | ||
| await runOnboardCommand({ | ||
| args: ["--resume"], | ||
| noticeAcceptFlag: "--yes-i-accept-third-party-software", | ||
| noticeAcceptEnv: "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| env: {}, | ||
| runOnboard, | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }); | ||
| expect(runOnboard).toHaveBeenCalledWith({ | ||
| nonInteractive: false, | ||
| resume: true, | ||
| recreateSandbox: false, | ||
| fromDockerfile: null, | ||
| acceptThirdPartySoftware: false, | ||
| agent: null, | ||
| dangerouslySkipPermissions: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("prints usage and skips onboarding for --help", async () => { | ||
| const runOnboard = vi.fn(async () => {}); | ||
| const lines: string[] = []; | ||
| await runOnboardCommand({ | ||
| args: ["--help"], | ||
| noticeAcceptFlag: "--yes-i-accept-third-party-software", | ||
| noticeAcceptEnv: "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| env: {}, | ||
| runOnboard, | ||
| log: (message = "") => lines.push(message), | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }); | ||
| expect(runOnboard).not.toHaveBeenCalled(); | ||
| expect(lines.join("\n")).toContain("Usage: nemoclaw onboard"); | ||
| expect(lines.join("\n")).toContain("--from <Dockerfile>"); | ||
| expect(lines.join("\n")).toContain("--agent <name>"); | ||
| expect(lines.join("\n")).toContain("--dangerously-skip-permissions"); | ||
| }); | ||
|
|
||
| it("parses --from <Dockerfile>", () => { | ||
| expect( | ||
| parseOnboardArgs( | ||
| ["--resume", "--from", "/tmp/Custom.Dockerfile"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toEqual({ | ||
| nonInteractive: false, | ||
| resume: true, | ||
| recreateSandbox: false, | ||
| fromDockerfile: "/tmp/Custom.Dockerfile", | ||
| acceptThirdPartySoftware: false, | ||
| agent: null, | ||
| dangerouslySkipPermissions: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("exits when --from is missing its Dockerfile path", () => { | ||
| expect(() => | ||
| parseOnboardArgs( | ||
| ["--from"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(`exit:${code}`); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toThrow("exit:1"); | ||
| }); | ||
|
|
||
| it("exits with usage on unknown args", () => { | ||
| const errors: string[] = []; | ||
| expect(() => | ||
| parseOnboardArgs( | ||
| ["--bad-flag"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| error: (message = "") => errors.push(message), | ||
| exit: ((code: number) => { | ||
| throw new Error(`exit:${code}`); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toThrow("exit:1"); | ||
| expect(errors.join("\n")).toContain("Unknown onboard option(s): --bad-flag"); | ||
| expect(errors.join("\n")).toContain("Usage: nemoclaw onboard"); | ||
| }); | ||
|
|
||
| it("parses --agent and --dangerously-skip-permissions", () => { | ||
| expect( | ||
| parseOnboardArgs( | ||
| ["--agent", "openclaw", "--dangerously-skip-permissions"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| listAgents: () => ["openclaw", "hermes"], | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toEqual({ | ||
| nonInteractive: false, | ||
| resume: false, | ||
| recreateSandbox: false, | ||
| fromDockerfile: null, | ||
| acceptThirdPartySoftware: false, | ||
| agent: "openclaw", | ||
| dangerouslySkipPermissions: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects unknown --agent values", () => { | ||
| const errors: string[] = []; | ||
| expect(() => | ||
| parseOnboardArgs( | ||
| ["--agent", "bogus"], | ||
| "--yes-i-accept-third-party-software", | ||
| "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| { | ||
| env: {}, | ||
| listAgents: () => ["openclaw", "hermes"], | ||
| error: (message = "") => errors.push(message), | ||
| exit: ((code: number) => { | ||
| throw new Error(`exit:${code}`); | ||
| }) as never, | ||
| }, | ||
| ), | ||
| ).toThrow("exit:1"); | ||
| expect(errors.join("\n")).toContain("Unknown agent 'bogus'"); | ||
| }); | ||
|
|
||
| it("prints the setup-spark deprecation text before delegating", async () => { | ||
| const lines: string[] = []; | ||
| const runOnboard = vi.fn(async () => {}); | ||
| await runDeprecatedOnboardAliasCommand({ | ||
| kind: "setup-spark", | ||
| args: [], | ||
| noticeAcceptFlag: "--yes-i-accept-third-party-software", | ||
| noticeAcceptEnv: "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| env: {}, | ||
| runOnboard, | ||
| log: (message = "") => lines.push(message), | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }); | ||
| expect(lines.join("\n")).toContain("setup-spark` is deprecated"); | ||
| expect(lines.join("\n")).toContain("Use `nemoclaw onboard` instead"); | ||
| expect(runOnboard).toHaveBeenCalledTimes(1); | ||
| expect(runOnboard).toHaveBeenCalledWith({ | ||
| nonInteractive: false, | ||
| resume: false, | ||
| recreateSandbox: false, | ||
| fromDockerfile: null, | ||
| acceptThirdPartySoftware: false, | ||
| agent: null, | ||
| dangerouslySkipPermissions: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("prints the setup deprecation text before delegating", async () => { | ||
| const lines: string[] = []; | ||
| const runOnboard = vi.fn(async () => {}); | ||
| await runDeprecatedOnboardAliasCommand({ | ||
| kind: "setup", | ||
| args: [], | ||
| noticeAcceptFlag: "--yes-i-accept-third-party-software", | ||
| noticeAcceptEnv: "NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE", | ||
| env: {}, | ||
| runOnboard, | ||
| log: (message = "") => lines.push(message), | ||
| error: () => {}, | ||
| exit: ((code: number) => { | ||
| throw new Error(String(code)); | ||
| }) as never, | ||
| }); | ||
| expect(lines.join("\n")).toContain("`nemoclaw setup` is deprecated"); | ||
| expect(lines.join("\n")).toContain("Use `nemoclaw onboard` instead"); | ||
| expect(runOnboard).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.