Skip to content

test(cli): scope module resets to mocked policy cases - #134364

Merged
steipete merged 1 commit into
mainfrom
codex/test-cli-policy-mock-lifetime
Aug 31, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/test-cli-policy-mock-lifetime

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

CLI policy tests reset the module cache after every case, although only two cases install module mocks. The remaining cases use immutable imports and fresh policy inputs.

Why this approach?

Move reset/unmock ownership into those two cases. Each begins with a clean module cache, keeps its query-qualified fresh import, and restores the mock and cache in finally. This reduces 48 resets to four and 48 unmock calls to two without changing test inputs or outcomes.

User impact

Test-only cleanup; production +0/-0, tests +50/-47. All 48 changed-file cases and 123 assertion sites remain, including deep catalog overrides and suppressed-output guards.

Evidence

All 58 policy/startup/path-matching tests pass before and after through the default runner routes. Full changed-file checks and Codex autoreview pass after formatting. The original mock introduction, later query-qualified import change and runner cleanup were checked. Reset counts are structural; no elapsed-time improvement is claimed.

node scripts/run-vitest.mjs src/cli/command-path-policy.test.ts src/cli/command-startup-policy.test.ts src/cli/command-execution-startup.test.ts src/cli/command-path-matches.test.ts

@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 31, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 2:20 PM ET / 18:20 UTC.

ClawSweeper review

What this changes

The PR scopes Vitest module resets and mock cleanup to the two CLI policy tests that temporarily mock a policy dependency.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking findings. The two module-mock tests now establish and clean up their own mutable Vitest state, while the other cases retain immutable imported resolvers; this is a focused, behavior-neutral test cleanup. This maintainer-authored PR should remain open for normal landing review.

Priority: P3
Reviewed head: eaff5ddd77210dcf2675a6c71f262c2311668935

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, coherent test-isolation refactor with no identified correctness or security defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored, test-only cleanup does not require the external-contributor real-behavior proof gate; the relevant evidence is targeted test-state isolation.
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, test-only cleanup does not require the external-contributor real-behavior proof gate; the relevant evidence is targeted test-state isolation.
Evidence reviewed 6 items Scoped cleanup covers every local module mock: The full changed test files contain exactly one module mock each; both now reset before mocking and use finally to unmock and reset after the assertions.
The mocked import is intentionally cache-busted: The shared helper imports a query-qualified URL and documents that Vitest keys module instances by the full URL, matching the two tests' fresh-import setup.
The production decision chain is unchanged: The path-policy resolver reads the declarative catalog, while the startup resolver consumes its result; the PR changes neither production owner.
Findings None None.
Security None None.

How this fits together

CLI startup first derives a command-path policy, then turns it into startup behavior such as config validation and plugin loading. The affected tests mock a catalog or policy dependency only to verify exceptional resolver branches.

flowchart LR
  Input[CLI arguments] --> Path[Command-path policy]
  Catalog[Command catalog] --> Path
  Path --> Startup[Startup policy]
  Startup --> Behavior[CLI bootstrap behavior]
  TestMocks[Scoped test mocks] --> Path
  TestMocks --> Startup
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the submitted patch is coherent and has no actionable defect.
Agent review details

Security

None.

PR surface

Tests +3. Total +3 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 50 47 +3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 50 47 +3

Review metrics

Metric Value Why it matters
Production versus test LOC production +0/-0; tests +50/-47 All introduced lines are test-local try/finally cleanup; no runtime or public contract changes.

Technical review

Best possible solution:

Keep cleanup ownership local to the two tests that install module mocks, preserving their clean setup and guaranteed teardown without resetting unrelated cases.

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

Not applicable: this PR refactors test-state lifetime rather than reporting a user-facing runtime defect. The changed tests are structurally source-verifiable, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Cleanup now belongs to the only two tests that mutate module mocking state; the alternative suite-wide hook resets unaffected non-mocked cases in a non-isolated runner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 127ae428ece0.

Labels

Label changes:

  • add P3: This is a focused test-maintenance cleanup with no production behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored, test-only cleanup does not require the external-contributor real-behavior proof gate; the relevant evidence is targeted test-state isolation.

Label justifications:

  • P3: This is a focused test-maintenance cleanup with no production behavior 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, test-only cleanup does not require the external-contributor real-behavior proof gate; the relevant evidence is targeted test-state isolation.

Evidence

What I checked:

Likely related people:

  • steipete: 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.

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer landing review is complete. I read the full latest ClawSweeper review (18:20 UTC): no actionable findings or Rank-up moves remain. The two mutable mock lifecycles own their setup and finally cleanup; all 58 focused policy/startup/execution/path-matcher tests passed before and after, full changed checks passed, and Codex autoreview is clean. Exact-head CI and Workflow Sanity are green. Production +0/-0; tests +50/-47. Proceeding through the native landing gates under the requested test-maintenance batch.

@steipete
steipete merged commit e2c92fc into main Aug 31, 2026
119 checks passed
@steipete
steipete deleted the codex/test-cli-policy-mock-lifetime branch August 31, 2026 18:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged through the native landing workflow: prepared head eaff5dd became e2c92fce4d8b.

The automatic completion comment hit GitHub's API quota after the merge. After the reset, native read-only reconciliation confirmed the accepted merge, and the current comment list contained no completion marker or duplicate landing comment. This records completion without repeating the merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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