Skip to content

refactor(cli): reuse environment snapshots in tests - #159669

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/slop40k-06-20260927
Oct 6, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/slop40k-06-20260927

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

CLI tests duplicate environment snapshot and restoration code across 17 files. This is maintainer-approved standalone test maintenance requested by @vincentkoc; the deliverable is reuse of the existing captureEnv helper while preserving each test’s isolation and coverage.

User Impact

No user-visible behavior change, configuration change, migration, or new action.

Why This Change Was Made

The existing helper preserves the original capture moment, key order, undefined deletion, empty strings, and cleanup placement. Current main’s rewritten tests and removed obsolete cases stay intact; three originally changed files now match main.

Current validation also exposed an unused private CallBrief type re-export introduced by #165716. This PR removes that one redundant export; the local import and canonical schema/brief exports remain.

Final scope: tests +67/−160 (93 fewer lines); production +0/−1; 228 total changed lines.

Evidence

  • Current test composition against 6693bb9665ced2a4fea3e286f62acfd0116e2c72: all 400 cases across 17 changed test files passed, one worker per file, Linux x64 / Node 24.19.0. Those exact test postimages remain unchanged after the type-only export deletion.
  • The complete five-case ClawHub install suite passed in original order both with this refactor and with only that file’s environment substitution reversed: 5/5 each, including the strict persisted-record assertion when telemetry is unavailable.
  • Earlier candidate and original-environment runs both reproduced the install-record failure. Current main contains stale-worker admission and opening-path lifecycle repairs from fix(state): retire stale workers before replacement admission #159944 and fix(state): prevent writes to retired database paths #159834. The current uninstrumented pair passes without weakening assertions; the original actor identity was not captured, so this does not assert a definitive original inode-reuse cause.
  • Focused source review and fresh autoreview: no actionable findings.
  • Formatting, four selected core test-type graphs, both canonical extension source type graphs, all three dead-export scans, native scoped lint and git diff --check passed. Lint reported zero warnings/errors. The one-line export repair resolves the inherited dead-export failure.
  • A separate raw package-boundary type invocation failed because it mixed generated and source SDK declarations without that runner’s preparation. It is retained as an invalid-context diagnostic, not a passing check; the two type graphs selected by the native changed-file plan subsequently passed.
  • Hosted CI for the refreshed exact head will attach after publication; local proof is not a CI waiver.
Per-file measured cost

Each command was node scripts/run-vitest.mjs src/cli/<file> --maxWorkers=1 --reporter=json --outputFile=<report>. Wall time includes wrapper/startup overhead. The ClawHub install candidate also includes the required 15m 11.3s native E2E build; its 951.743s wall time is not a performance comparison with the warm control (42.557s wall, 12.543s file).

File under src/cli Passed Wall seconds Test-file seconds
cli-utils.test.ts 49 27.255 0.189
command-startup-policy.test.ts 18 2.449 0.062
daemon-cli/restart-health-client.test.ts 10 28.022 2.154
directory-cli.test.ts 57 27.642 0.876
gateway-cli/task-supervisor.test.ts 16 2.866 0.123
node-cli/identity.test.ts 3 25.161 1.160
plugins-cli.clawhub-install.e2e.test.ts 5 951.743 10.098
plugins-cli.uninstall.test.ts 16 31.125 8.280
plugins-cli.update.test.ts 33 32.006 8.104
plugins-search-command.clawhub.e2e.test.ts 1 47.917 14.158
program/error-output.test.ts 51 3.463 0.282
program/help.test.ts 8 3.279 0.101
program/parent-default-help.test.ts 2 3.102 0.054
program/preaction.test.ts 90 33.817 0.289
program/subcli-descriptors.test.ts 4 3.000 0.404
route.test.ts 27 2.582 0.069
update-cli.finalizer.test.ts 10 41.366 13.851

@vincentkoc vincentkoc self-assigned this Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: M labels Sep 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 27, 2026 13:30
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 11:11 AM ET / 15:11 UTC (Revision 3).

ClawSweeper review

What this changes

The branch replaces handwritten environment restoration in CLI tests with the existing snapshot helper and removes an unused private voice-call type re-export.

Merge readiness

✅ Ready for maintainer review

Keep open: the central cleanup remains useful and distinct from current main, sponsorship is now recorded, and no actionable introduced defect was found.

Priority: P3
Reviewed head: ebd7bd034171c19758a81464a7b95abcdcdfd2f5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving cleanup with recorded validation and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored maintenance changes test environment cleanup and deletes an unused private type-only export; the external-contributor runtime proof gate does not apply. Recorded focused tests are supplemental validation. No authority or stored-data contract changes require additional proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored maintenance changes test environment cleanup and deletes an unused private type-only export; the external-contributor runtime proof gate does not apply. Recorded focused tests are supplemental validation. No authority or stored-data contract changes require additional proof.
Evidence reviewed 8 items Pinned introduced change: The complete pinned base-to-head diff preserves environment key selection, capture timing, restoration order, cleanup placement, test scenarios, and assertions. The only production change deletes a type-only re-export.
Existing restoration owner: captureEnv captures values immediately in an insertion-ordered Map. Restoration deletes undefined values and writes every defined string, including empty strings. Its module has no import-time environment mutation.
Private export boundary: The removed CallBrief re-export is in the plugin's private source module. Its local import, OutboundCallOptions.brief, and canonical call-brief exports remain intact; the inspected public plugin barrel does not expose this re-export.
Findings None None.
Security None None.

How this fits together

CLI tests temporarily change process environment variables to exercise command behavior. The shared snapshot helper restores the captured values during cleanup so subsequent tests retain their original environment.

flowchart TD
  A[Original environment] --> B[Capture selected keys]
  B --> C[Exercise CLI behavior]
  C --> D[Restore captured values]
  D --> E{Original value defined?}
  E -->|Yes| F[Restore original string]
  E -->|No| G[Delete environment key]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1, Tests -93. Total -94 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 1 0 1 -1
Tests 17 67 160 -93
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 67 161 -94

Review metrics

None.

Technical review

Best possible solution:

Use the existing environment snapshot owner throughout these tests while preserving their isolation, assertions, and lifecycle ordering.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR consolidates test cleanup rather than reporting a product failure; the pinned diff preserves the exercised scenarios.

Is this the best way to solve the issue?

Yes: reusing the existing helper removes duplicate restoration logic without introducing a competing owner or changing cleanup semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 27d3746e3c80.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is bounded internal maintenance with no introduced user-visible behavior, configuration, or migration change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored maintenance changes test environment cleanup and deletes an unused private type-only export; the external-contributor runtime proof gate does not apply. Recorded focused tests are supplemental validation. No authority or stored-data contract changes require additional proof.

Evidence

What I checked:

  • Pinned introduced change: The complete pinned base-to-head diff preserves environment key selection, capture timing, restoration order, cleanup placement, test scenarios, and assertions. The only production change deletes a type-only re-export. (src/cli/route.test.ts:62, ebd7bd034171)
  • Existing restoration owner: captureEnv captures values immediately in an insertion-ordered Map. Restoration deletes undefined values and writes every defined string, including empty strings. Its module has no import-time environment mutation. (src/test-utils/env.ts:15, ebd7bd034171)
  • Private export boundary: The removed CallBrief re-export is in the plugin's private source module. Its local import, OutboundCallOptions.brief, and canonical call-brief exports remain intact; the inspected public plugin barrel does not expose this re-export. (extensions/voice-call/src/types.ts:2, ebd7bd034171)
  • Partial overlap already merged: GitHub verifies fix(voice-call): unblock unused-export checks #166147 as merged at fetched main 27d3746. It contains the same private type-export deletion, but does not implement the CLI test cleanup. The remaining cleanup therefore still warrants review. (extensions/voice-call/src/types.ts:2, 27d3746e3c80)
  • Re-review sponsorship resolved: The previous completed review had no findings and requested sponsorship. The captured updated body explicitly records maintainer-requested standalone maintenance, and live REST metadata confirms MEMBER author association and assignment to vincentkoc. The earlier sponsorship warning is not re-raised. (CONTRIBUTING.md:23, ebd7bd034171)
  • Recorded validation and failure disposition: The captured PR body reports 400 passing cases, per-file timings, selected type graphs, lint, formatting, and dead-export checks. The ClawHub install suite passed in original order both with and without this environment substitution. Earlier failures are retained with related merged storage repairs, rather than attributed definitively to this refactor. These are contributor-recorded results; this read-only review ran no tests. (ebd7bd034171)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-27T13:36:38.416Z sha 1dccafb :: blocked before merge. :: none
  • reviewed 2026-09-27T13:51:24.745Z sha 1dccafb :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added the channel: voice-call Channel integration: voice-call label Oct 6, 2026
@vincentkoc
vincentkoc merged commit 9b26242 into main Oct 6, 2026
118 checks passed
@vincentkoc
vincentkoc deleted the refactor/slop40k-06-20260927 branch October 6, 2026 17:03
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
* refactor(cli): reuse environment snapshots in tests

* refactor(cli): refresh environment snapshot cleanup

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call cli CLI command changes P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant