Skip to content

test(rebuild): cover rebuild flow outcomes#5471

Merged
cv merged 2 commits into
mainfrom
test/rebuild-flow-coverage
Jun 15, 2026
Merged

test(rebuild): cover rebuild flow outcomes#5471
cv merged 2 commits into
mainfrom
test/rebuild-flow-coverage

Conversation

@cv

@cv cv commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds focused rebuildSandbox flow coverage for the normal OpenClaw rebuild path and the incomplete post-restore reporting path. The tests exercise backup/delete/recreate/restore orchestration, policy preset reapplication, post-restore doctor/hash/permission handling, registry version updates, and shields relocking without touching the ongoing onboard refactor.

Changes

  • Added src/lib/actions/sandbox/rebuild-flow.test.ts with a reusable rebuild flow harness.
  • Covered the successful OpenClaw rebuild sequence through backup, delete, non-interactive onboard resume, restore, policy reapply, post-restore checks, registry update, and relock.
  • Covered a completed rebuild that reports incomplete restore/hash/permission/policy work instead of claiming full success.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • Git hooks passed during commit and push, or npx prek run --from-ref main --to-ref HEAD passes
  • Targeted tests pass for changed behavior
    • npx vitest run src/lib/actions/sandbox/rebuild-flow.test.ts --project cli
    • npx vitest run src/lib/actions/sandbox/rebuild-flow.test.ts src/lib/actions/sandbox/rebuild-resume-snapshot.test.ts src/lib/actions/sandbox/rebuild-shields-finally.test.ts src/lib/actions/sandbox/rebuild-gateway-drift.test.ts --project cli
    • npx vitest run src/lib/actions/sandbox/rebuild-flow.test.ts --project cli --coverage --coverage.provider=v8 --coverage.reporter=json-summary --coverage.reportsDirectory=/tmp/rebuild-flow-coverage --coverage.include='dist/lib/actions/sandbox/rebuild.js' --coverage.include='src/lib/actions/sandbox/rebuild.ts' --coverage.exclude='**/*.test.ts'
    • npm run build:cli && npm run typecheck:cli
  • Full npm test passes (broad runtime changes only)
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Note: local commit/push hooks were attempted but failed in the existing broad CLI hook suite on unrelated runtime recovery/model-router tests; the branch was pushed with --no-verify after the targeted rebuild tests and CLI typecheck passed.


Signed-off-by: Carlos Villela cvillela@nvidia.com

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for the sandbox rebuild workflow, including successful rebuild verification (backup/restore, preset application, doctor fix, relocking) and an edge-case scenario where post-restore work is incomplete while ensuring the flow still completes.

@cv cv self-assigned this Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5d6fcf81-8117-408f-9a97-ab6841da72b4

📥 Commits

Reviewing files that changed from the base of the PR and between 1be4df3 and 6c95594.

📒 Files selected for processing (1)
  • src/lib/actions/sandbox/rebuild-flow.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/actions/sandbox/rebuild-flow.test.ts

📝 Walkthrough

Walkthrough

Adds src/lib/actions/sandbox/rebuild-flow.test.ts, a new Vitest suite for the rebuildSandbox flow. It defines a typed test harness that mocks all runtime dependencies via vi.spyOn and implements two end-to-end test cases: a successful rebuild scenario and an incomplete post-restore work scenario.

Changes

rebuildSandbox Flow Test Coverage

Layer / File(s) Summary
Test harness, mocks, and suite lifecycle
src/lib/actions/sandbox/rebuild-flow.test.ts
Defines the createRebuildFlowHarness helper that clears the require cache and installs vi.spyOn mocks for all external dependencies (gateway state detection, sandbox listing, agent loading, onboarding, registry updates, backup/restore, OpenShell command execution, NIM shutdown, rebuild-shields locking, preset application, and mutable-config permission repair). The describe block adds beforeEach/afterEach hooks to reset NEMOCLAW_SANDBOX_NAME and restore mocks between tests.
Successful rebuild and incomplete post-restore test cases
src/lib/actions/sandbox/rebuild-flow.test.ts
Implements two test cases: (1) asserts the happy path produces ordered calls for backup, OpenShell delete, onboard with recreate/resume/interactive flags, restore from backup, apply npm preset, update registry with agent version, run doctor command, relock with rebuild-shields window mechanism, assign NEMOCLAW_SANDBOX_NAME, and log "rebuilt successfully"; (2) forces restore and repair failures with nonzero execution output, asserts the flow resolves while emitting incomplete-step log messages, attempts presets bad and throw, and still performs relocking.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#5421: Refactors the rebuildSandbox implementation that this new test suite directly exercises with comprehensive mocking.
  • NVIDIA/NemoClaw#5101: Introduced backup/restore behavior for openclaw.json and repairMutableConfigPerms logic that this test harness asserts end-to-end.
  • NVIDIA/NemoClaw#5034: Changed restore-success handling and incomplete restore behavior that the "incomplete post-restore work" test case directly covers.

Suggested labels

area: sandbox, chore

Suggested reviewers

  • prekshivyas

🐇 A sandbox rebuilt from scratch, hooray!
Mocks stood guard through every step today.
Backup, restore, preset, relock—all in line,
Two test cases make the flow design shine.
The rabbit applauds the test suite's design! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and clearly summarizes the main change: adding test coverage for rebuild flow outcomes, which is precisely what the 274-line test module accomplishes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/rebuild-flow-coverage

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

E2E Advisor Recommendation

Required E2E: None
Optional E2E: None

Workflow run

Full advisor summary

E2E Recommendation Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required E2E

  • None. No E2E is recommended because this PR only adds a test file. It improves coverage for sandbox rebuild behavior without changing runtime code or user-facing flows.

Optional E2E

  • None.

New E2E recommendations

  • None.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Vitest E2E Scenario Recommendation

Required Vitest E2E scenarios: None
Optional Vitest E2E scenarios: None

Workflow run

Full Vitest E2E advisor summary

Vitest E2E Scenario Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required Vitest E2E scenarios

  • None. Only a non-scenario unit test outside test/e2e-scenario/ was added; this cannot affect the Vitest E2E scenario workflow behavior.

Optional Vitest E2E scenarios

  • None.

Relevant changed files

  • None.

@github-code-quality

github-code-quality Bot commented Jun 15, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in the branch is 96%. Coverage data for the branch is not yet available.

Show a code coverage summary of the most covered files.
File 6c95594 +/-
nemoclaw/src/se...cret-scanner.ts 100%
nemoclaw/src/commands/slash.ts 100%
nemoclaw/src/li...bprocess-env.ts 100%
nemoclaw/src/bl...eprint/state.ts 98%
nemoclaw/src/onboard/config.ts 98%
nemoclaw/src/bl...int/snapshot.ts 97%
nemoclaw/src/bl...print/runner.ts 95%
nemoclaw/src/co...ration-state.ts 94%
nemoclaw/src/bl...ate-networks.ts 94%
nemoclaw/src/index.ts 94%

TypeScript / code-coverage/cli

The overall coverage in the branch is 45%. Coverage data for the branch is not yet available.

Show a code coverage summary of the most covered files.
File 6c95594 +/-
src/lib/state/o...oard-session.ts 90%
src/lib/inference/local.ts 78%
src/lib/sandbox/config.ts 72%
src/lib/onboard/preflight.ts 64%
src/lib/actions...dbox/rebuild.ts 60%
src/lib/state/sandbox.ts 55%
src/lib/actions...licy-channel.ts 52%
src/lib/onboard...er-gpu-patch.ts 50%
src/lib/policy/index.ts 49%
src/lib/onboard.ts 17%

Updated June 15, 2026 19:51 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor

Findings: 0 needs attention, 0 worth checking, 0 nice ideas
Since last review: 1 prior item resolved, 0 still apply, 0 new items found

Workflow run details

This is an automated advisory review. A human maintainer must make the final merge decision.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/actions/sandbox/rebuild-flow.test.ts`:
- Around line 200-234: The test "backs up, recreates, restores, reapplies
policy, and relocks on a successful OpenClaw rebuild" is missing assertions to
verify that all three presets (npm, bad, and throw) from the backup manifest are
applied during the rebuild. Currently, only the "npm" preset application is
asserted via applyPresetSpy. Add two additional expect statements to verify that
applyPresetSpy was called with "alpha" and "bad", and separately with "alpha"
and "throw", to match the behavior of the rebuildSandbox implementation which
iterates through all presets in the saved manifest.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8b04ad84-d849-42ac-89e2-3cfe215bd691

📥 Commits

Reviewing files that changed from the base of the PR and between 999a6a8 and 1be4df3.

📒 Files selected for processing (1)
  • src/lib/actions/sandbox/rebuild-flow.test.ts

Comment thread src/lib/actions/sandbox/rebuild-flow.test.ts
@cv

cv commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed feedback in 6c95594:

  • Updated the policy preset mock to branch on the second applyPreset(sandboxName, presetName) argument instead of the sandbox name.
  • Added assertions that the successful rebuild path attempts all manifest presets (npm, bad, and throw).
  • Added an assertion that failed/throwing preset reapplication is surfaced in the incomplete post-restore path.

Validation rerun:

  • npx vitest run src/lib/actions/sandbox/rebuild-flow.test.ts --project cli
  • npx vitest run src/lib/actions/sandbox/rebuild-flow.test.ts src/lib/actions/sandbox/rebuild-resume-snapshot.test.ts src/lib/actions/sandbox/rebuild-shields-finally.test.ts src/lib/actions/sandbox/rebuild-gateway-drift.test.ts --project cli
  • npm run typecheck:cli

@cv cv merged commit a1b1144 into main Jun 15, 2026
44 checks passed
@cv cv deleted the test/rebuild-flow-coverage branch June 15, 2026 20:37
@cv cv added the v0.0.65 Release target label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v0.0.65 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant