Skip to content

fix(test): update connect tests for readiness poll behavior from #466 - #2198

Merged
cv merged 1 commit into
mainfrom
prekshi/fix-connect-tests-after-pr-466
Apr 21, 2026
Merged

cv merged 1 commit into
mainfrom
prekshi/fix-connect-tests-after-pr-466

Conversation

@prekshivyas

@prekshivyas prekshivyas commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PR #466 (merged today at 19:01 UTC) changed nemoclaw <name> connect to poll openshell sandbox list for readiness instead of exiting immediately when the sandbox phase isn't Ready. Three pre-existing test files still encoded the old behavior and are now failing on every PR rebased onto main — including post-merge CI on main itself.

Observable in CI by:

  • test/sandbox-connect-inference.test.ts — 2 assertions expecting result.status === 0 get null (child process hits 15s spawnSync timeout)
  • test/sandbox-stuck-recovery.test.ts — 2 failures (same timeout symptom + stale message assertions)
  • test/reboot-identity-drift.test.ts — 4 failures (same timeout symptom)

Root cause

The fake openshell binaries in these tests emit sandbox list output with only a name column:

if (args[0] === "sandbox" && args[1] === "list") {
  process.stdout.write("${sandboxName}\n");
  process.exit(0);
}

The new readiness poll (src/nemoclaw.ts) calls parseSandboxStatus(output, name) which needs [name, status, age] columns to extract a status. With only a name, it returns null → loop treats as "unknown" → polls until the test's spawnSync timeout kills the child.

Changes

1. sandbox list mocks updated in all three files to emit a proper status column.

  • sandbox-connect-inference.test.ts and reboot-identity-drift.test.ts always return "${name} Ready 2m ago" (they test the happy path).
  • sandbox-stuck-recovery.test.ts uses the parameterized ${phase} its setupFixture already accepts.

2. sandbox-stuck-recovery.test.ts: "stuck in Provisioning" test rewritten for the new behavior.
The old assertions checked for "stuck in 'Provisioning' phase" + "process crash inside the sandbox" + "rebuild --yes" — messages that came from ensureLiveSandboxOrExit's non-Ready branch. #466 bypasses that for connect via { allowNonReadyPhase: true }, so those messages no longer fire. New assertions:

  • NEMOCLAW_CONNECT_TIMEOUT=3 via new extraEnv param on runCli so the readiness poll times out in 3s instead of 120s
  • Asserts "Waiting for sandbox '…' to be ready" + "Timed out" + "NEMOCLAW_CONNECT_TIMEOUT" override hint

3. sandbox-stuck-recovery.test.ts: companion test added for the terminal-state exit path that #466 introduced but lacked a behavioral test. Failed phase should exit immediately with logs --follow and status recovery hints (covers the second branch of the TERMINAL check).

The status subcommand test in sandbox-stuck-recovery.test.ts is untouched — status still exits on non-Ready phases; #466 only changed connect.

Testing

Type of Change

  • Code change for a new feature, bug fix, or refactor.

Checklist

Signed-off-by: Prekshi Vyas [email protected]

Summary by CodeRabbit

  • Tests
    • Updated sandbox list command mock output to include status and timing details
    • Improved connection timeout error messages with helpful debugging command suggestions
    • Enhanced test infrastructure to support environment variable injection for connection timeout testing

PR #466 changed `nemoclaw <name> connect` to poll `openshell sandbox
list` for readiness instead of exiting immediately when the sandbox
phase isn't Ready. Three pre-existing test files still encoded the old
behavior and are now failing on every PR that rebases onto main:

- test/sandbox-connect-inference.test.ts
- test/sandbox-stuck-recovery.test.ts
- test/reboot-identity-drift.test.ts

Root cause: the fake openshell mocks emit `sandbox list` output with
only a name column (`process.stdout.write("<name>\\n")`). The new
readiness poll calls `parseSandboxStatus(output, name)` which needs at
least `[name, status, age]` to parse a status — so it always returns
null, falls back to "unknown", and the connect loop hangs until the
test's 15s spawnSync timeout kills the child (exit status: null).

Changes:

1. All three files: update the fake `openshell sandbox list` mock to
   emit a proper status column, e.g. `"${name}   Ready   2m ago"`.
   - connect-inference + reboot-identity-drift always return Ready
     (they test the happy path; nothing about phase transitions).
   - sandbox-stuck-recovery uses the parameterized `${phase}` since
     its setupFixture already takes a phase argument.

2. sandbox-stuck-recovery.test.ts: the "stuck in Provisioning" connect
   test was asserting the old pre-#466 message chain ("stuck in
   'Provisioning' phase" + "process crash inside the sandbox" +
   "rebuild --yes"). Those messages no longer fire for `connect`
   because ensureLiveSandboxOrExit is now called with
   {allowNonReadyPhase: true}. Rewrote the test to:

   - Set NEMOCLAW_CONNECT_TIMEOUT=3 so the readiness poll exits
     quickly instead of waiting the 120s default.
   - Assert the new timeout path: "Waiting for sandbox 'X' to be
     ready" + "Timed out" + "NEMOCLAW_CONNECT_TIMEOUT" override hint.

3. sandbox-stuck-recovery.test.ts: added a companion test for the
   terminal-state exit path that #466 introduced but wasn't covered —
   Failed phase should exit immediately (no timeout wait) with the
   `logs --follow` and `status` recovery hints in both branches of the
   terminal-state check.

Also extended runCli() with an optional extraEnv param to pass
NEMOCLAW_CONNECT_TIMEOUT cleanly.

The `status` subcommand's recovery-hint assertion is unchanged:
`status` still exits on non-Ready phases; #466 only changed `connect`.

Verified:
- `npm test` — 2061 passed, 12 skipped (was failing on these 3 files
  against main post-#466).
- Targeted run on the three files: 13 tests, 13 passed.
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 00523b31-848b-41f7-beaa-053e317bd138

📥 Commits

Reviewing files that changed from the base of the PR and between 49ec895 and bbca89d.

📒 Files selected for processing (3)
  • test/reboot-identity-drift.test.ts
  • test/sandbox-connect-inference.test.ts
  • test/sandbox-stuck-recovery.test.ts

📝 Walkthrough

Walkthrough

Three test files updated to enhance mock output for the openshell sandbox list command, including sandbox status and age columns. Additionally, sandbox-stuck-recovery.test.ts extends the runCli function to accept optional environment variables and refines test assertions for connection timeout and failure state scenarios.

Changes

Cohort / File(s) Summary
Sandbox list mock output format
test/reboot-identity-drift.test.ts, test/sandbox-connect-inference.test.ts, test/sandbox-stuck-recovery.test.ts
Updated the mocked openshell sandbox list command output to include status and age columns alongside the sandbox name (e.g., "${sandboxName} Ready 2m ago\n" or with dynamic phase).
Test timeout behavior and environment variables
test/sandbox-stuck-recovery.test.ts
Extended runCli to accept optional extraEnv parameter for injecting environment variables into spawned processes. Updated "Provisioning" connect test to verify timeout behavior with NEMOCLAW_CONNECT_TIMEOUT. Updated "terminal failure state" test assertions to expect diagnostic commands and failure state messaging instead of recovery hints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 The tests now shine with better mocks so bright,
With status columns dancing in the light!
Timeouts are caught, environments flow free,
Sandbox recovery blooms like clover and tree. 🍀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.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 clearly and specifically summarizes the main change: updating connect tests to align with readiness poll behavior from PR #466.
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 prekshi/fix-connect-tests-after-pr-466

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

@cv
cv enabled auto-merge (squash) April 21, 2026 19:55
@cv
cv merged commit 0deb4a3 into main Apr 21, 2026
15 checks passed
@prekshivyas
prekshivyas deleted the prekshi/fix-connect-tests-after-pr-466 branch April 21, 2026 19:55
@cv cv added the v0.0.22 label Apr 21, 2026
brandonpelfrey pushed a commit that referenced this pull request Apr 21, 2026
## Summary

Fixes the lingering `sandbox-stuck-recovery.test.ts > connect times out
with guidance when sandbox is stuck in Provisioning` failure on
`wsl-e2e` that has been red on `main` since #466 merged. My earlier
#2198 fixed the sibling tests but this one kept hitting the CI
test-budget ceiling.

Fixes #2204.

## Root cause

Not a mock-script bug — the mocks for `sandbox list` already return the
phase string that `parseSandboxStatus` expects, and the tests pass
cleanly on macOS and the Linux `checks` job.

The failure is WSL-specific timing:

- `NEMOCLAW_EXEC_TIMEOUT=30000` caps each outer `spawnSync` to the CLI
at 30 seconds.
- WSL process-spawn overhead is high: each mocked `openshell` invocation
is a fresh Node.js child process, and the CLI makes 4+ of these
(`sandbox get`, `policy get --full`, `inference get`, first `sandbox
list`) before the readiness poll loop from #466 starts.
- The 3 sibling tests in `sandbox-stuck-recovery.test.ts` that skip the
poll loop were passing at **26–28s** on WSL — already within a few
seconds of the ceiling.
- The failing test is the only one that sets
`NEMOCLAW_CONNECT_TIMEOUT=3`, so it actually enters the poll loop
(pre-poll + 3s sleep + final poll + "Timed out" print). That pushes
total runtime past 30s on WSL runners, so the outer `spawnSync` kills
the CLI before the "Timed out" guidance prints.

The `Status: unknown` artifact mentioned in #2204 is the CLI's display
fallback `parseSandboxStatus(poll, ...) || "unknown"` kicking in after
the child was killed mid-poll — not a missing subcommand in the mocks.

## Changes

- `.github/workflows/wsl-e2e.yaml`: bump `NEMOCLAW_EXEC_TIMEOUT` from
`30000` to `60000`, aligned with the existing
`NEMOCLAW_TEST_TIMEOUT=60000`. Short comment explains why WSL needs the
larger ceiling.

## Why this is the right fix

- **Zero impact on fast runners.** Tests that finish in a few seconds on
macOS/Linux return early; they don't pay for the larger ceiling.
- **No product-code change.** Only the WSL CI outer-spawn budget moves.
- **Targeted to the actual bottleneck.** The CLI isn't hanging — it's
slow on WSL spawn. Bumping the budget matches the structural overhead.

## Considered and rejected

- **Patching the mocks** (the #2204 hypothesis). No new subcommand is
invoked; the mocks are correct.
- **Reducing pre-poll overhead in product code** (e.g. skipping `policy
get --full` on connect). Out of scope, risks regressing real behavior.
- **Dropping `NEMOCLAW_CONNECT_TIMEOUT` from the test.** The test
asserts timeout behavior — it must enter the poll.
- **Bumping `macos-e2e`.** Not needed; those jobs pass comfortably.

## Type of Change

- [x] Code change (bug fix — CI config only)

## Verification

- [x] Local \`npx vitest run test/sandbox-stuck-recovery.test.ts
test/sandbox-connect-inference.test.ts --project cli\` — 7/7 pass in
7.6s
- [x] \`npx prek run --files .github/workflows/wsl-e2e.yaml\` — clean
- [ ] **Real validation: this PR's \`wsl-e2e\` check must go green.**

## AI Disclosure

- [x] AI-assisted — tool: Claude Code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Improved Windows Subsystem for Linux (WSL) test reliability by
adjusting execution timeout settings to account for system overhead.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Prekshi Vyas <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants