Skip to content

fix(test): prevent new incomplete first-party module mocks - #164673

Merged
steipete merged 3 commits into
mainfrom
fix/mock-export-ratchet-spd10
Oct 4, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/mock-export-ratchet-spd10

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Stops new closed first-party mock factories from creating the missing-export failures that escaped PR selection eight times on 2026-10-03.

User Impact

No product behavior changes. New test mocks must preserve real module exports or explain why isolation requires a closed mock; existing tests are not mass-rewritten.

Why This Change Was Made

The static guard checks literal first-party vi.mock and vi.doMock factories in the existing check, check-changed, and CI ratchet owners. A factory must return or spread the real module through importOriginal or same-module vi.importActual, or use an immediately preceding one-line exception with a reason:

// mock-isolation: Keep this fixture isolated from the real singleton state.
vi.mock("./state.js", () => ({ readState: vi.fn() }));

Pass-through is recommended for export completeness. importOriginal and vi.importActual can return a separate module instance for stateful singletons, so closed mocks remain appropriate where isolation is the contract; those use the annotation. This caveat and the annotation are documented in the writing-tests guide.

Peter approved the initial exact shrink-only baseline on 2026-10-03. The original reviewed baseline had 10,843 factories. Its initial PR snapshot had 10,852; upstream main changes before landing required a further 17 additions and seven removals, producing 10,862 factories in the final bootstrap snapshot. All added identities already exist on the comparison main revision. The generator rejects candidate-only additions, and a published baseline may only shrink. Fingerprints include source, resolved target, factory and local definitions, and duplicate ordinal; existing debt cannot authorize a different mock. No new job, dependency, permission, or repository setting is introduced.

This is independent of the selection fix in #164666 and targets main directly.

Evidence

  • Linux check-changed passed in 444 seconds, including scripts/root types, deadcode scans, changed lint, and guards. Full test-types passed in 1,094 seconds, boundary lint in 102 seconds; source-contracts and architecture also passed.
  • Whole unit-fast passed 16,459 tests, tooling-isolated 371. Existing shared-helper importer coverage and all test cases/assertions are preserved.
  • Guard regressions cover baseline expansion, duplicate identities, staged manifests, old-base bootstrap, wrong-module/unawaited spreads, importer reassignment, and local factory aliases. Both tests passed after intended before failures. On the independent main-based branch, both pass again in 4.92 seconds wrapper wall (3.66 seconds Vitest).
  • Real manifest entrypoint passed PR and scheduled-main inputs in indexed same-SHA and sparse-fetched different-SHA harness shapes. Source and ledger changes received clean P2 reviews, including the refreshed initial ledger.
  • Whole-tooling remains an explicitly accepted gap: B's tooling leases expired before execution. A's tooling shards 1/4 and 2/4 passed; 3/4 hit an unrelated SQLite child compiler-policy failure in unchanged runtime owners, and 4/4 never ran. The fallback fleet was at capacity. No whole-tooling pass is claimed. Earlier install-smoke failures were fixed on main by fix(release): preserve publication and source provenance contracts #164595 and its 16-case file passed on Linux.
  • Initial natural PR CI exposed an attributable memory failure in the new scanner: job 111336399393 exhausted its approximately 2 GiB Node heap while parsing all files together. The correction uses the existing parser's 32-file snapshot batches without changing fingerprints, diagnostics, or baseline entries. The full scan now passes under a 2 GiB limit on Linux in 21.14 seconds, with 979 MiB maximum resident memory; the same 10,852 identities also pass against the exact failed PR merge. The corrective P2 review is clean. Focused Linux check-changed and boundary lint passed; the proof lease stopped successfully.
  • The same first run also failed two unchanged transport-process-registration.test.ts cases in job 111336402567: PluginStateStoreError caused by a fresh Gateway owner in a different PID namespace. Test, registration, plugin-state, Gateway ownership, and runner source are identical to the tested main parent 4525e1d28e2a; no independent main replay is claimed. Main subsequently fixed that fixture in fix: restore Codex registration tests on Linux #164676 (b323c0441a35); the corrected PR run can consume that fix without rebasing.
  • On the memory-corrected run, the scanner completed in 24.64 seconds and correctly flagged stale initial-ledger identities after upstream CLI/Doctor changes. The failing sites were byte-identical to main. The approved initial snapshot was regenerated against main 19e87bf450a6; the checker and scanner code are unchanged from the passing Linux proof.
  • Final head 6bc1462742ac natural run 37169998836 passed checks-fast-baseline-ratchets (job 111341115073): 10,862 factories / 24.45 seconds. Eight observed failures are inherited from tested main 070b7479dc3f: production types (111341272744), test types (111341272737), core test-type groups 2–5 (111341272697, 111341272690, 111341272714, 111341272721), and core lint (111341272642) reject the unused normalizeProviderId import at src/agents/agent-model-discovery.ts:3; tooling job 111341117930 expects the deleted doctor-sandbox-legacy-registry.test.ts path from the unchanged database-worker inventory. Source/config/test/inventory blobs match the tested main parent; no independent main suite replay is claimed. Remaining checks and coordinator verification/pinned merge are pending.
  • No workflow dispatches or reruns.

@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@steipete
steipete enabled auto-merge (squash) October 4, 2026 01:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: XL labels Oct 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 10:21 PM ET / October 4, 2026, 02:21 UTC (Revision 4).

ClawSweeper review

What this changes

Adds a static check requiring new first-party test mock factories to preserve real module exports or explain their isolation, while grandfathering existing factories through an exact shrinking baseline.

Merge readiness

⛔ Blocked before merge - 3 items remain

This preventive guard remains useful and distinct from the merged test-selection fix. The previously reported implicit-fallthrough defect remains unresolved at the pinned head.

Priority: P2
Reviewed head: 6bc1462742ac04e38c9bbceb30dd4a3f946a458f

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused tooling with meaningful execution evidence, but the unresolved predicate defect prevents merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured evidence describes the real repository scanner recovering from its heap failure and processing the final 10,862-factory ledger through the actual CI ratchet entrypoint; GitHub confirms that exact-head job succeeded. Raw logs were inaccessible to this reviewer. This execution does not resolve the separate fallthrough finding, and no user stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured evidence describes the real repository scanner recovering from its heap failure and processing the final 10,862-factory ledger through the actual CI ratchet entrypoint; GitHub confirms that exact-head job succeeded. Raw logs were inaccessible to this reviewer. This execution does not resolve the separate fallthrough finding, and no user stored-data contract changes.
Evidence reviewed 8 items Introduced defect remains: Block factories are accepted when their collected explicit returns are complete. No check establishes that every normal completion path returns a value; a conditional return with no else therefore escapes the guard.
JavaScript enters the guard: The ratchet scans JavaScript as well as TypeScript and requests syntactic diagnostics only. The existing regression table covers an explicit bare return, but not an implicit fallthrough.
Re-review continuity: The supplied completed review identified the same fallthrough blocker at this exact head. Comparing that reviewed SHA with the checkout produces no scanner delta; this is an unresolved prior finding.
Findings 1 actionable finding [P2] [P2] Reject block factories that can fall through
Security None None.

How this fits together

OpenClaw's development checks scan test mock registrations before accepting changes. The new guard resolves first-party module targets, examines factories, and compares exceptions against the existing-debt baseline.

flowchart TD
  A[Test source and manifests] --> B[Resolve first-party modules]
  B --> C[Inspect mock factories]
  C --> D{Exports preserved or isolation explained}
  D -->|Yes| E[Accept factory]
  D -->|No| F[Compare exact baseline]
  F --> G[Pass or report violations]
Loading

Before merge

  • [P2] Reject block factories that can fall through (P2) - The prior blocker remains: vi.mock("./value.js", async original => { if (flag) return {...await original()}; }) supplies one complete explicit return, so this predicate accepts it. When flag is false, the factory resolves to undefined, and JavaScript files enter this guard without semantic return-path checking. Account for normal completion paths or conservatively reject unproven fallthrough, with a JavaScript regression through the ratchet entrypoint.
  • Resolve merge risk (P1) - The new CI guard can accept an unannotated factory that resolves to undefined on an implicit-fallthrough path.
  • Complete next step (P2) - Reject block factories with possible implicit fallthrough and add a JavaScript regression through the ratchet entrypoint.

Findings

  • [P2] [P2] Reject block factories that can fall through — scripts/lib/mock-factory-scan.mts:440-442
Agent review details

Security

None.

PR surface

Tests +302, Docs +32, Config +3, Other +11637. Total +11974 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 6 324 22 +302
Docs 1 32 0 +32
Config 2 4 1 +3
Generated 0 0 0 0
Other 6 11638 1 +11637
Total 15 11998 24 +11974

Review metrics

Metric Value Why it matters
Grandfathered mock debt 10,862 exact factory identities The large ledger preserves existing fixtures while the new policy applies to new or changed identities.

Merge-risk options

Maintainer options:

  1. Reject unproven normal completion (recommended)
    Repair block-factory analysis and add a JavaScript regression through the ratchet entrypoint before merging.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Reject block mock factories with possible implicit fallthrough, preserve valid complete-return and explicit isolation behavior, and add a failing-before, passing-after JavaScript regression through the existing ratchet main entrypoint without expanding the baseline.

Technical review

Best possible solution:

Keep the existing ratchet owner and exact baseline, but require block factories to prove complete normal returns or use the documented isolation annotation.

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

Yes, source establishes the introduced failure path: a JavaScript block factory with only a conditional complete return passes the scanner but resolves to undefined when the condition is false. No target code was executed during this read-only review.

Is this the best way to solve the issue?

Yes, extending the existing ratchet and resolver is a focused approach; its block-return predicate needs to account for implicit normal completion before the guard fulfills its contract.

Full review comments:

  • [P2] [P2] Reject block factories that can fall through — scripts/lib/mock-factory-scan.mts:440-442
    The prior blocker remains: vi.mock("./value.js", async original => { if (flag) return {...await original()}; }) supplies one complete explicit return, so this predicate accepts it. When flag is false, the factory resolves to undefined, and JavaScript files enter this guard without semantic return-path checking. Account for normal completion paths or conservatively reject unproven fallthrough, with a JavaScript regression through the ratchet entrypoint.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1836ae214644.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence describes the real repository scanner recovering from its heap failure and processing the final 10,862-factory ledger through the actual CI ratchet entrypoint; GitHub confirms that exact-head job succeeded. Raw logs were inaccessible to this reviewer. This execution does not resolve the separate fallthrough finding, and no user stored-data contract changes.

Label justifications:

  • P2: This is a bounded development-check reliability improvement with one unresolved scanner defect.
  • merge-risk: 🚨 automation: The introduced CI predicate can miss invalid factories despite the ratchet job passing.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The captured evidence describes the real repository scanner recovering from its heap failure and processing the final 10,862-factory ledger through the actual CI ratchet entrypoint; GitHub confirms that exact-head job succeeded. Raw logs were inaccessible to this reviewer. This execution does not resolve the separate fallthrough finding, and no user stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence describes the real repository scanner recovering from its heap failure and processing the final 10,862-factory ledger through the actual CI ratchet entrypoint; GitHub confirms that exact-head job succeeded. Raw logs were inaccessible to this reviewer. This execution does not resolve the separate fallthrough finding, and no user stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test test/scripts/check-test-mock-exports.test.ts --maxWorkers=1.
  • [P1] pnpm check:test-mock-exports --base 19e87bf.
  • [P1] node scripts/check-changed.mjs --base 19e87bf.
  • [P1] git diff --check.

What I checked:

  • Introduced defect remains: Block factories are accepted when their collected explicit returns are complete. No check establishes that every normal completion path returns a value; a conditional return with no else therefore escapes the guard. (scripts/lib/mock-factory-scan.mts:440, 6bc1462742ac)
  • JavaScript enters the guard: The ratchet scans JavaScript as well as TypeScript and requests syntactic diagnostics only. The existing regression table covers an explicit bare return, but not an implicit fallthrough. (scripts/check-test-mock-exports.mts:20, 6bc1462742ac)
  • Re-review continuity: The supplied completed review identified the same fallthrough blocker at this exact head. Comparing that reviewed SHA with the checkout produces no scanner delta; this is an unresolved prior finding. (scripts/lib/mock-factory-scan.mts:440, 6bc1462742ac)
  • Still necessary on main and release: Neither fetched main nor the supplied latest-release tree contains the new scanner or ratchet entrypoint. The merged fix(ci): select mock consumers when module exports change #164666 retains affected mock consumers in test selection; it does not impose this preventive factory policy. (scripts/test-projects.test-support.mts:4514, 1836ae214644)
  • Actual ratchet execution: GitHub verifies that checks-fast-baseline-ratchets job 111341115073 completed successfully for the pinned head, including its Run baseline ratchets step. The captured PR body reports the real repository scan processed 10,862 factories in 24.45 seconds and describes the earlier memory correction. The raw log download was blocked by the review environment; its contents were not independently inspected. (.github/workflows/ci.yml:2721, 6bc1462742ac)
  • Existing-debt contract: The baseline contains 10,862 exact identities. The owner rejects candidate-only bootstrap additions and subsequent baseline expansion; documentation explicitly permits reasoned isolation for stateful singleton fixtures. The captured body records approval of the initial bootstrap and discloses incomplete whole-tooling coverage. (scripts/check-test-mock-exports.mts:162, 6bc1462742ac)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Reject implicit fallthrough and demonstrate a failing-before, passing-after JavaScript regression through the ratchet entrypoint.

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 (3 earlier review cycles)
  • reviewed 2026-10-04T01:39:42.843Z sha bfff13777a4bd89f20ae139de60918fc02785805 :: needs changes before merge. :: [P2] [P2] Reject block factories that can fall through
  • reviewed 2026-10-04T01:58:23.010Z sha 5296e53d00ebdb9e2cc31b5dddc0b1afa27ec53c :: needs changes before merge. :: [P2] [P2] Reject block factories that can fall through
  • reviewed 2026-10-04T02:11:13.084Z sha 6bc1462 :: blocked before merge. :: [P2] [P2] Reject block factories that can fall through

Require real-module pass-through or an adjacent reasoned mock-isolation
annotation for new first-party vi.mock and vi.doMock factories. Reuse the
existing resolver and register the guard in existing check/CI ratchets.

Peter approved the initial exact shrink-only baseline on 2026-10-03.
Refreshing existing debt onto the publication base changes 10,843 entries
to 10,852 (11 existing identities added and two removed). Candidate-only
debt remains rejected, and published allowances can only shrink.

Document that importOriginal and vi.importActual may produce a separate
instance for stateful singletons; closed isolation mocks remain explicit.

Validation: Linux check-changed, full test-types, boundary lint, source
contracts, architecture, unit-fast, tooling-isolated, manifest smoke, and
focused guard regressions passed. Whole-tooling has the coordinator-accepted
unrelated SQLite compiler-policy failure/capacity gap; natural PR CI will
provide the remaining evidence.
Natural PR CI exhausted its 2 GiB Node heap when the new mock ratchet
parsed every candidate file into one syntax snapshot. Reload roots in
32-file batches through the existing parser owner, retaining fingerprints
and diagnostics while allowing previous syntax trees to be collected.

The full Linux scan passes under --max-old-space-size=2048 in 21.14s
with 979 MiB maximum RSS and exactly 10,852 baseline identities. The exact
failed PR merge also passes. Focused guard tests, Linux check-changed,
boundary lint, and P2 review pass. No heap, timeout, or runner increase.
Regenerate the approved unpublished bootstrap from main 19e87bf. All 17 added identities already exist in main; seven obsolete identities are removed. The owner rejects candidate-only debt, and the final initial ledger contains 10,862 exact factories.

Natural CI confirmed the bounded-memory scanner runs successfully. The stale-ledger failures came from unchanged upstream CLI and Doctor tests. Full scan under a 2 GiB heap and ledger-only P2 review passed; checker and scanner source remain unchanged from passing Linux proof.
@steipete
steipete force-pushed the fix/mock-export-ratchet-spd10 branch from 5296e53 to 6bc1462 Compare October 4, 2026 02:05
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 4, 2026
@steipete
steipete merged commit 07e2877 into main Oct 4, 2026
271 of 283 checks passed
@steipete
steipete deleted the fix/mock-export-ratchet-spd10 branch October 4, 2026 02:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…164673)

* fix(test): prevent new incomplete first-party module mocks

Require real-module pass-through or an adjacent reasoned mock-isolation
annotation for new first-party vi.mock and vi.doMock factories. Reuse the
existing resolver and register the guard in existing check/CI ratchets.

Peter approved the initial exact shrink-only baseline on 2026-10-03.
Refreshing existing debt onto the publication base changes 10,843 entries
to 10,852 (11 existing identities added and two removed). Candidate-only
debt remains rejected, and published allowances can only shrink.

Document that importOriginal and vi.importActual may produce a separate
instance for stateful singletons; closed isolation mocks remain explicit.

Validation: Linux check-changed, full test-types, boundary lint, source
contracts, architecture, unit-fast, tooling-isolated, manifest smoke, and
focused guard regressions passed. Whole-tooling has the coordinator-accepted
unrelated SQLite compiler-policy failure/capacity gap; natural PR CI will
provide the remaining evidence.

* fix(test): bound mock ratchet syntax tree batches

Natural PR CI exhausted its 2 GiB Node heap when the new mock ratchet
parsed every candidate file into one syntax snapshot. Reload roots in
32-file batches through the existing parser owner, retaining fingerprints
and diagnostics while allowing previous syntax trees to be collected.

The full Linux scan passes under --max-old-space-size=2048 in 21.14s
with 979 MiB maximum RSS and exactly 10,852 baseline identities. The exact
failed PR merge also passes. Focused guard tests, Linux check-changed,
boundary lint, and P2 review pass. No heap, timeout, or runner increase.

* test: refresh initial mock baseline after upstream refactors

Regenerate the approved unpublished bootstrap from main f4567d4. All 17 added identities already exist in main; seven obsolete identities are removed. The owner rejects candidate-only debt, and the final initial ledger contains 10,862 exact factories.

Natural CI confirmed the bounded-memory scanner runs successfully. The stale-ledger failures came from unchanged upstream CLI and Doctor tests. Full scan under a 2 GiB heap and ledger-only P2 review passed; checker and scanner source remain unchanged from passing Linux proof.
amittell added a commit to amittell/openclaw that referenced this pull request Oct 10, 2026
…atchet

Main's check:test-mock-exports (openclaw#164673) arrived with the merge and rejects
six mock factories this branch adds or changes. The two health-state mocks
now pass the real module through. The config, device-bootstrap,
setup-completion and health-owner mocks stay closed because isolating that
state is their purpose, and each says so in a mock-isolation line.

The baseline drops the four entries those edits retire.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant