test: add unit tests for onboard, logs, and connect modules#279
test: add unit tests for onboard, logs, and connect modules#279kagura-agent wants to merge 4 commits intoNVIDIA:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds multiple Vitest unit-test suites and a test-helpers module covering CLI connect, logs, onboard config persistence, and API key validation/masking. All changes are test-only; no runtime code or public exported declarations were modified. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
nemoclaw/src/commands/connect.test.ts (1)
23-62: Consider extracting shared logger/spawn test helpers.
captureLoggerandmockSpawnProcare effectively duplicated innemoclaw/src/commands/logs.test.ts. Moving them into a small test utility module will reduce drift and simplify future updates.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nemoclaw/src/commands/connect.test.ts` around lines 23 - 62, Extract the duplicated test helpers captureLogger and mockSpawnProc into a shared test utility module (e.g., export captureLogger and mockSpawnProc from a new tests/utils or similar module), update both tests that currently define them (references: captureLogger, mockSpawnProc) to import them from that module, and remove the local definitions; ensure the mockSpawnProc implementation and its use of vi.mocked(spawn).mockReturnValue and the returned proc shape are preserved so existing tests (like in connect.test.ts and logs.test.ts) continue to work without other changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@nemoclaw/src/onboard/validate.test.ts`:
- Around line 39-41: The apiKey fixture in validate.test.ts (the constant apiKey
next to endpoint) is a realistic key-shaped string triggering secret scanners;
replace it with a clearly non-secret placeholder (e.g., "test-api-key" or
"API_KEY_PLACEHOLDER") so it no longer matches key patterns, keep endpoint
untouched, and run the test suite to confirm validate.test.ts still passes
(search for the symbols endpoint and apiKey to update all references).
---
Nitpick comments:
In `@nemoclaw/src/commands/connect.test.ts`:
- Around line 23-62: Extract the duplicated test helpers captureLogger and
mockSpawnProc into a shared test utility module (e.g., export captureLogger and
mockSpawnProc from a new tests/utils or similar module), update both tests that
currently define them (references: captureLogger, mockSpawnProc) to import them
from that module, and remove the local definitions; ensure the mockSpawnProc
implementation and its use of vi.mocked(spawn).mockReturnValue and the returned
proc shape are preserved so existing tests (like in connect.test.ts and
logs.test.ts) continue to work without other changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2abd63f0-8dea-41d5-ad3e-5f27c8c11e0a
📒 Files selected for processing (4)
nemoclaw/src/commands/connect.test.tsnemoclaw/src/commands/logs.test.tsnemoclaw/src/onboard/config.test.tsnemoclaw/src/onboard/validate.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
nemoclaw/src/commands/connect.test.ts (1)
57-65: Make the spawn-error expectations explicit.These cases only assert the specific error text.
nemoclaw/src/commands/connect.tsalso resolves that branch as exit code1, so this path may emit the genericexited with code ...guidance afterward. Please assert either presence or absence of that follow-up message so the error path is actually pinned down.Also applies to: 67-75
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nemoclaw/src/commands/connect.test.ts` around lines 57 - 65, The tests in connect.test.ts that mock spawn errors (using mockSpawnProc and vi.mocked(spawn)) currently only assert the specific ENOENT error text; update each test (the one at 57-65 and the similar one at 67-75) to also assert the expected behavior regarding the follow-up "exited with code" guidance emitted by cliConnect: explicitly check that the logger output either contains the exit-code guidance when the branch in connect.ts resolves with exit code 1, or assert that it does not appear if the ENOENT branch should suppress it—i.e., after calling cliConnect({ sandbox: "openclaw", logger }) capture lines.join("\n") and add an expectation for presence or absence of the "exited with code" message so the error path is fully pinned down.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@nemoclaw/src/commands/logs.test.ts`:
- Around line 55-72: The mockExec helper currently invokes the exec callback
with a single result object but real Node exec callbacks used by promisify have
signature (err, stdout, stderr); update mockExec to call callback(err, stdout,
stderr) so tests mirror production: in mockExec, when response is an Error call
callback(response, "", response.message) and when response is a string call
callback(null, response, ""), and keep the
vi.mocked(exec).mockImplementation((...) => { ... }) cast; alternatively, mock
the small async wrapper that your code actually imports instead of exec but
ensure the exported function matches the (err, stdout, stderr) contract used by
promisify.
---
Nitpick comments:
In `@nemoclaw/src/commands/connect.test.ts`:
- Around line 57-65: The tests in connect.test.ts that mock spawn errors (using
mockSpawnProc and vi.mocked(spawn)) currently only assert the specific ENOENT
error text; update each test (the one at 57-65 and the similar one at 67-75) to
also assert the expected behavior regarding the follow-up "exited with code"
guidance emitted by cliConnect: explicitly check that the logger output either
contains the exit-code guidance when the branch in connect.ts resolves with exit
code 1, or assert that it does not appear if the ENOENT branch should suppress
it—i.e., after calling cliConnect({ sandbox: "openclaw", logger }) capture
lines.join("\n") and add an expectation for presence or absence of the "exited
with code" message so the error path is fully pinned down.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bc340548-a9bc-4440-9e5e-361db8f2940a
📒 Files selected for processing (4)
nemoclaw/src/commands/connect.test.tsnemoclaw/src/commands/logs.test.tsnemoclaw/src/onboard/validate.test.tsnemoclaw/src/test-helpers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- nemoclaw/src/onboard/validate.test.ts
|
Re: CodeRabbit review feedback on
All review items addressed. ✅ |
Add 35 new tests across 4 test files covering critical paths that previously had zero test coverage: - onboard/validate: API key validation (success, HTTP errors, timeouts, network failures) and key masking - onboard/config: save/load round-trip, missing file handling, config clearing - commands/logs: sandbox state detection, spawn argument construction, --follow/--lines/--run-id flags, error handling - commands/connect: spawn arguments, openshell errors, exit codes All tests follow the existing status.test.ts conventions (vitest, vi.mock, captureLogger). Total suite: 57 tests (22 existing + 35 new). No source files modified.
Address code review feedback:
- Extract captureLogger and mockSpawnProc into src/test-helpers.ts
to eliminate duplication between connect.test.ts and logs.test.ts
- Replace realistic API key fixture ('nvapi-...') in validate.test.ts
with 'test-api-key-placeholder' to avoid secret scanner triggers
Address second CodeRabbit review: spawn errors resolve with exit
code 1, which triggers the follow-up 'exited with code' guidance.
Tests now assert both the error message and the exit guidance.
Also explain why mockExec's callback shape is correct — Node's
promisify(exec) resolves with { stdout, stderr }, matching the
existing status.test.ts pattern.
- Fix mockExec callback signature in logs.test.ts to use the real
Node exec signature (err, stdout, stderr) instead of (err, {stdout, stderr})
- Attach util.promisify.custom to the mocked exec so promisify(exec)
correctly folds the three-arg callback into {stdout, stderr}, matching
the real Node implementation
- connect.test.ts already asserts 'exited with code' follow-up messages
(addressed in prior commit)
9039579 to
6e64ccc
Compare
|
Closing to consolidate — these unit tests were submitted during my early learning phase and may not match current project conventions. Happy to resubmit more focused test coverage if maintainers are interested. |
Summary
Adds 35 new unit tests across 4 test files, covering critical modules that previously had zero test coverage. Complements the existing
status.test.ts(22 tests) to bring the total to 57 tests.No source files were modified — this PR only adds test files.
New test files
src/onboard/validate.test.tsvalidateApiKey: successful validation, HTTP 401/403/500, timeout (AbortError), network failure, non-Error rejection, trailing-slash stripping, body truncation.maskApiKey: short keys,nvapi-prefix, regular keys, boundary lengths.src/onboard/config.test.tssaveOnboardConfig/loadOnboardConfiground-trip, overwrite behavior, missing file returnsnull,clearOnboardConfigremoves file, no-throw on missing file.src/commands/logs.test.tsopenshellspawn args,--followadds-f,--linessets-n,--run-idshows run info, state fallback, sandbox name from state, spawn error handling.src/commands/connect.test.tsENOENT→ "openshell not found" error, generic spawn error, non-zero exit code logging, success/null exit code handling.Why these modules
The onboard flow is where the majority of user-facing bugs originate (#22, #93, #152, #197, #201, #208, #210, #245). With CI now running on PRs (#261), these tests will catch regressions in the most sensitive code paths.
Test conventions
All tests follow the patterns established in
status.test.ts:vi.mockfornode:fsandnode:child_processcaptureLogger()pattern for output assertionsresetAllMocks()inbeforeEachVerification
Summary by CodeRabbit