Skip to content

test(action-ledger): replace source-text ledger tests with behavior tests - #1803

Merged
obviyus merged 5 commits into
mainfrom
cleanup-r7-action-ledger-tests
Oct 9, 2026
Merged

obviyus merged 5 commits into
mainfrom
cleanup-r7-action-ledger-tests

Conversation

@obviyus

@obviyus obviyus commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Row 7 cleanup for test/clawsweeper-action-ledger.test.ts. The 11 tests that read src/** or raw .github/** text and checked it with regex, indexOf and slice order are gone. New tests drive the real code:

  • the exported factories createApplyActionLedger and createReviewActionLedger, writing to a private spool that the test then reads back
  • the built CLI (dist/clawsweeper.js apply-decisions and retry-failed-reviews) with a fake gh, run from a private copy of dist so its ledger spool stays inside the fixture
  • YAML-parsed workflow steps where a workflow guard is real and no other test covers it

The applyPhaseSequenceForTest and apply business-identity *ForTest exports were only there for these tests. They are now removed. The internal helpers lose the ForTest suffix, and their behavior is still checked through real events.

Old test Class Now
lane instrumentation uses stable slots with explicit parent and phase ordering a apply ledger starts items lazily and chains every receipt in phase order + review ledger starts items lazily and closes every started item (dense phase_seq, parent chain, idempotency key does not change with status, batch order or checkpoint, but does change with source revision)
review candidates start lazily and deferred items cannot remain active a (ledger part) / c (order-of-calls slices in review-command-workflow: materialization, model admission and lease-release order) review ledger starts items lazily and closes every started item
apply receipts start per item and persist mutation observation before finalization a apply-decisions records per-request receipts before it finalizes the item (CLI). The yield-handler slice is covered by apply-live-state.test.ts › "comment-only sync defers the remaining batch when GitHub is rate limited"
apply mutation receipts … (source-text half) a / c Label "already exists" no-op is now asserted through the CLI (mutation_rejected, mutation:false). Lease identity strings and the posted-result object shape were plumbing (c). The seam-driven half is kept.
GitHub throttles abort apply lease checks … (source-text half) a Same test, through the CLI: a throttled issue edit never deletes the lease, and a throttled lease delete surfaces as skipped_runtime_budget
blocked exact close publication discards staged labels before writing the report b Guard in test/apply-label-sync.test.ts › "a blocked exact close discards staged labels before it writes the report". A CLI fixture would need a PR close-coverage block plus staged labels.
apply failure finalization survives report publication errors a CLI: --report-path under a regular file. The ledger still records item failure → batch failed → publication skipped/not_found
apply report publication uses digest evidence without a durable record path a Covered by the CLI receipts test: subject {repository, kind: publication} and an apply_report sha256 equal to the report bytes
retry and review publication lanes finalize unexpected failures a (retry) / c (apply-artifacts catch slice, onMutation: wiring regexes) failed-review-retry finalizes its ledger when the command fails (CLI). The CLI receipts test covers mutation observation (item and batch mutation:true).
sweep publishes complete immutable shards … (raw sweep.yml) a (parsed steps) / c sweep finalizes open ledger attempts and publishes shards through the signed queue. Parts that sweep-workflow.test.ts already covers are dropped: "apply workflow finalization retries only target status…", "apply workflow isolates proof Codex…", "failed-review retry cleanup restores…"
comment router publishes immutable command receipts … (raw yml) a (parsed steps) / c comment router publishes command receipts per invocation through the signed queue. Commit-step webhook wiring stays in repair/comment-router-action-ledger.test.ts. The requeue publisher stays in repair/command-ops-action-ledger.test.ts.
apply and retry business idempotency … (apply half, ForTest seam) c Replaced by the real-event identity assertions above. The retry half is kept.

Three (b) guards were added to the domain test files. Each has a one-line reason. The PR does not touch test/structural-invariants.test.ts:

  • apply-label-sync.test.ts: a blocked exact close discards staged labels before it writes the report
  • apply-label-sync.test.ts: labels_synced_at is recorded only after a confirmed label mutation (this came from the old "blocked exact close" test)
  • work-plan-artifacts.test.ts: apply-artifacts records an interrupted publication before it rethrows

Why

These tests broke on any rename or extraction even when behavior did not change. Several of them also only checked text, never what the code does.

Proof

  • Focused: node --test test/structural-invariants.test.ts test/clawsweeper-action-ledger.test.ts test/apply-label-sync.test.ts test/work-plan-artifacts.test.ts passes. pnpm run lint:scripts and the oxfmt check pass.
  • pnpm run check (run on the previous head): static, build, lint and coverage-changed all pass. The full suite gave 6962 pass, 0 fail. It exited 1 only because of the known coverage file is empty flake.
  • Counts from the shared counter (source-text tests / asserts / reads):
    • test/clawsweeper-action-ledger.test.ts: before 11 / 179 / 32 → after 0 / 0 / 0
    • the three (b) guards (2 in test/apply-label-sync.test.ts, 1 in test/work-plan-artifacts.test.ts): 3 / 3 / 3
    • total: 11 / 179 / 32 → 3 / 3 / 3
  • File lines 1132 → 1209. Whole PR: +647 / −587. grep -c ForTest over src: 401 → 383.

Mutation proofs. Each was a temporary src change, then rebuild, then run the test and see it fail, then revert:

Mutation Test that failed
apply mutation-attempt parentEventId: state.startEventId apply ledger lazily/chains (parent indexes)
applyItemBusinessIdempotencyIdentity ignores sourceRevision apply ledger lazily/chains (revision-41b key equal)
finishReviewActionLedger skips started items review ledger lazily/closes (item terminal + log publication missing)
drop knownNoMutation: labelAlreadyExistsError in label-mutations CLI receipts (mutation_outcome_unknown,true instead of mutation_rejected,false)
finishApply catch rethrows instead of saving publicationError apply failure finalization (no failure/batch-terminal events)
drop activeApplyMutationLease = null on rate limit throttle test (lease delete called)
drop rate-limit rethrow in releaseActiveApplyMutationLease throttle test (kept_open instead of skipped_runtime_budget)
drop failure: commandError in failed-review retry retry failure (completed instead of failed)
delete discardIssueLabelBatch() in the blocked close guard (apply-label-sync): blocked exact close discards staged labels
make rememberPublishedLabelSync() unconditional guard (apply-label-sync): labels_synced_at only after a confirmed mutation
skip recordPublication in the apply-artifacts catch guard (work-plan-artifacts): apply-artifacts records an interrupted publication

Coverage check for the (c) claims. With these mutations, apply-*.test.ts, clawsweeper.test.ts, failed-review-retry, reconcile, work-plan-artifacts, manual-publication-authority and decision-packets all still passed:

  • dropping discardIssueLabelBatch() in the blocked close
  • recording the apply-artifacts interrupted publication on failure
  • making rememberPublishedLabelSync unconditional

That is why these three properties now have structural guards. Each guard failed under its mutation and passed after the revert.

Codex dispositions

codex review --base origin/main ran once on head 738e9bc. Build and all 27 focused tests passed. One finding:

  • [P2] test/clawsweeper-action-ledger.test.ts:425: the fixture's repoRelativePath used relative(root, filePath). On Windows that returns records\41.md, and the ledger rejects backslashes in subject.recordPath. Fixed: the fixture now normalizes separators to /, the same way the production repoRelativePath in src/clawsweeper-runtime.ts does.

Merge Danger

Test-only, except for removing unused ForTest exports and renaming two internal apply-ledger helpers. Runtime behavior does not change.

The three order-of-calls properties that no behavior test covers are now kept by minimal guards in test/apply-label-sync.test.ts and test/work-plan-artifacts.test.ts.

The CLI tests copy dist once per file, so this file takes about 25–45 s under load.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces source-text checks with tests of action receipts, the records of review and apply operations, and removes three unused test exports.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, mechanically sound test maintenance with confidence limited to reported fixture-based executions.
Proof confidence 🦐 gold shrimp (3/6) GitHub confirms maintainer authorship, so the external proof gate does not apply. Reported executions exercise the built apply/retry commands with fake GitHub responses and the real ledger factories with private receipt files; they support the test rewrite without establishing live GitHub behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes
User problem: Maintainers get test failures after harmless ledger refactors without a runtime regression.
Reason: Receipt and command assertions reduce failures from harmless extractions while checking meaningful safety outcomes. The small production cleanup preserves runtime semantics.

Merge readiness

✅ Ready for maintainer review

This PR remains a useful, distinct maintenance contribution that current main has not incorporated. No actionable correctness defect was found in the pinned patch.

Priority: P3
Reviewed head: 77ad3d6963aea322825f637183caa3a519e7c0cd

Before merge

None.

Findings

None.

Agent review details

How this fits together

ClawSweeper’s action ledger records review and apply requests, mutation outcomes, and completion as immutable receipts. These tests inspect receipts produced by the existing ledger factories and built commands.

flowchart TD
  A[Review or apply command] --> B[Action ledger]
  B --> C[Request outcome receipts]
  B --> D[Completion and publication receipts]
  C --> E[Isolated receipt files]
  D --> E
  E --> F[Behavior assertions]
Loading

Technical review

Best possible solution:

Keep receipt assertions at the existing ledger and command boundaries, with narrowly justified structural safety guards.

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

Not applicable: this is test maintenance, and the base tests visibly depend on production source names and slices. Tests were not executed during this read-only review.

Is this the best way to solve the issue?

Yes: assertions on emitted receipts exercise the existing production owners, and the retained safety guards have specific reported mutation-check evidence.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • test/clawsweeper-action-ledger.test.ts receipt and completion coverage keeps the original intent (9c3545a: The recorded commit establishes review/apply receipt coverage; subsequent commits explicitly strengthen crash safety and retry/recovery invariants. Older patch inspection was limited by unavailable blobs.)
  • test/clawsweeper-action-ledger.test.ts review preparation ordering checks changes intended behavior with a stated reason (fix(review): verify checkout access before publication #1170: Verify access to the exact checkout before starting or publishing a review.)
  • test/clawsweeper-action-ledger.test.ts blocked-close and label-sync checks keeps the original intent (fix(apply): batch exact publication labels #1085: Restore unpublished staged labels before durable writes and advance label-sync timestamps only after confirmed publication.)
  • test/clawsweeper-action-ledger.test.ts command workflow publication checks keeps the original intent (8c9d8d4: Publish command action receipts, subsequently strengthened with canonical-root publication and no-op finalization requirements.)
  • src/clawsweeper-apply-ledger.ts test-only helper exports changes intended behavior with a stated reason (refactor: decompose ClawSweeper orchestration into focused workflows #998: Extract immutable receipts, mutation observation, and business idempotency behind typed workflow boundaries while preserving command behavior and exports.)
  • src/clawsweeper-command-operations.ts and src/clawsweeper-runtime.ts test-export forwarding changes intended behavior with a stated reason (refactor: shrink ClawSweeper entrypoint by 77% with focused subsystems #1005: Separate focused subsystems while retaining public/test exports and preserving mutation ownership and ledger causality.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Repository policy: Read the complete root policy and applied its guidance on narrow test placement, changelog ownership, proof, and conservative cleanup. No nested AGENTS.md files or maintainer-notes directory were found. (AGENTS.md:1, 77ad3d6963ae)
  • Production behavior preserved: The production delta removes three test-only exports and renames internal identity helpers without changing their bodies or production semantics. Searches found no remaining consumers of the removed exports. Receipt formats, authorization, stored settings, and OpenClaw Bay contracts are unchanged. (src/clawsweeper-apply-ledger.ts:140, 77ad3d6963ae)
  • Receipt and command coverage: The replacement scenarios inspect lazy item starts, causal receipt chains, stable retry identities, source-revision changes, known no-op mutations, throttled lease handling, and terminal receipts after publication failure. Built-command fixtures explicitly substitute a fake gh executable. (test/clawsweeper-action-ledger.test.ts:419, 77ad3d6963ae)
  • Re-review continuity: The previous review listed no findings. The targeted comparison with its head shows no further changes to the action-ledger test file; the current commit places three narrow source guards in the matching label-sync and artifact test files. Their reported mutation checks explain why these safety properties remain guarded structurally. (test/apply-label-sync.test.ts:4735, 77ad3d6963ae)
  • Original safety contract: fix(apply): batch exact publication labels #1085 explicitly requires restoring staged labels before blocked-close report writes and advancing labels_synced_at only after confirmed publication. The retained guards preserve those requirements. (src/clawsweeper-apply-decision-workflow.ts:601, 77ad3d6963ae)
  • Current-main necessity: Current main remains at the pinned base and retains the source-text action-ledger tests replaced here. The merged cleanup at test(review): drive review and apply rules through behavior instead of source text #1807 covers separate review/apply tests and does not incorporate this rewrite. (test/clawsweeper-action-ledger.test.ts:421, b17e94d1e7ed)

Review metrics

Metric Value Why it matters
Production versus test LOC Production +5/−22; tests +665/−565 Production shrinks by 17 lines; test growth supports receipt-chain and command-failure scenarios.
Test-only exports 3 removed Repository searches found no remaining consumers of these exports.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This improves test maintainability while preserving user-facing runtime behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-09T09:12:01.137Z sha 4fed7fe :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T10:26:53.364Z sha 662d035 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T10:40:41.162Z sha 83760ae :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T10:53:40.170Z sha 9c120b0 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 7:11 AM ET / 11:11 UTC (Revision 5).

@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@obviyus
obviyus force-pushed the cleanup-r7-action-ledger-tests branch from 8f4b7da to 662d035 Compare October 9, 2026 10:23
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 9, 2026
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@obviyus
obviyus force-pushed the cleanup-r7-action-ledger-tests branch from 662d035 to 83760ae Compare October 9, 2026 10:37
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 9, 2026
@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@obviyus
obviyus force-pushed the cleanup-r7-action-ledger-tests branch from 83760ae to 9c120b0 Compare October 9, 2026 10:50
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 9066ba1 into main Oct 9, 2026
13 of 16 checks passed
@obviyus
obviyus deleted the cleanup-r7-action-ledger-tests branch October 9, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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