Skip to content

feat(core,web): review parity rules, vectors and writers - #56

Merged
PastaPastaPasta merged 1 commit into
masterfrom
feat/review-parity-rules
Sep 27, 2026
Merged

PastaPastaPasta merged 1 commit into
masterfrom
feat/review-parity-rules

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

PR 2 of the GitHub-parity review plan (docs/design/review-parity-spec.md §7). It adds the rules, vectors, writers and readers on top of the contract revision in #48 (forge-collab BMfPmaEiMqDp64NDa4Am79VoRpZ9MPVNnCUy6i3UiyWi). Spec §3.12 lists every function signature for the web and CLI PRs 3–7.

Rules (Rust forge_core::rules::review, TS lib/rules/review.ts)

80 new shared vectors run in both harnesses: fold_review_v2__*, policy__*, anchor__*, review_group__*, suggestion__*, linked_issues__*, fold_pr_v2__*, and approvals__dismiss*.

  • fold_pr_review_v2 computes the review state:
    • the head: the newest headUpdate (only a 40- or 64-hex oid counts), else patch.headOid;
    • requested reviewers: the newest request or remove per identity;
    • resolved threads: only thread roots the PR actually has;
    • dismissals: the first one per review stands;
    • the milestone.
  • fold_pr_state_v2 starts from patch.draft, and the author's authorEvents now apply: draft, ready, resolve, request and head update. An author event of any other kind is inert.
  • count_approvals skips dismissed reviews. A dismissed review neither counts nor clears an earlier verdict.
  • Negative vectors cover each refused case:
    • an authorEvent merge (even with a reachable oid), label or dismissal is inert;
    • a stranger's head update or resolve is inert;
    • resolving an unknown root is inert;
    • a malformed head oid is inert;
    • a dismissed review is not counted.
  • Also added: meets_policy, anchor_of, group_review_comments, parse_suggestions, apply_suggestion and linked_issues.
    • The suggestion parser treats only ASCII space, tab and CR as fence whitespace, because Rust and JS disagree on U+0085 and U+FEFF. It also normalises a lone CR and strips the opening fence's indentation from content lines.

Writers and readers

forge-core

  • Collab::post_target_event(repo, target, kind, EventPayload { value, oid, ref_id }) picks member event versus author authorEvent through kind_route, and refuses events missing their payload.
  • New writer arguments: review(.., comment_count), and comment with start_line / review_id.
  • New methods: set_policy / policy, and patches_from_branch, which uses the sourceRef index.
  • PatchView now carries head (the folded head), review and log. The folded head is what dg pr view, review, merge, checkout and diff now use. Merge reachability is still checked against base tips.

forge-web

  • lib/repo/review-writes.ts:
    • postTargetEvent and postComment (anchors, reviewId).
    • A resumable pending review: ReviewDraft in the IndexedDB journal, submitted with submitReviewDraft. The review is written first with commentCount, then each comment with reviewId. A resumed draft is first reconciled with the chain, so a write that landed without its local save is adopted rather than posted twice.
    • setPolicy, updateTarget and updateComment.
  • New replaceDocumentIdempotent in lib/sdk/write.ts:
    • It checks the owner before signing, and signs nothing when the document already holds the edit.
    • It reads back to settle a write whose wait timed out, and re-reads after a 40106 revision refusal.
  • readPull folds the head and the draft state. Approvals skip dismissed reviews. toEvent maps kinds 11–18 and refId.
  • The timeline labels the new kinds.

forge-relay follows headUpdate, ordered by ($createdAt, $id) across both streams. It uses the new head for webhook head.sha and the check-run watch, and sends a synchronize action when the head moves.

Private repos (follow-up)

These writers write plaintext. In a private repo, writes of an issue, PR, comment or review, and every edit, are refused before signing (refusePlaintextInPrivate, which also covers the existing createComment). The sealed versions still need to be wired:

A private PR edit must re-seal under the patch's own epoch (private-repos.md §4.5, §8.2).

Tests

  • cargo test --workspace passes and clippy -D warnings is clean.
  • pnpm test: 1,031 tests pass.
  • Live on moutai (FORGE_LIVE=1 … vitest run lib/repo/review-parity.live.test.ts), entirely through the web's writers:
    • CONTRIB opens a draft PR, marks it ready and moves its head; OWNER requests a reviewer.
    • COLLAB submits a pending review: one review plus single-line, range and file-level comments.
    • CONTRIB replies and resolves the thread; OWNER dismisses the review and sets a policy.
    • CONTRIB edits the PR title and a comment. An identical second edit signs nothing.
    • COLLAB deletes the review, then edits the orphaned comment: keeping the dead reviewId is refused at consensus (40120); dropping it succeeds.
    • Every step is read back through the folds.
  • lib/repo/v2.live.test.ts (the fixture) also passes.

Review

  • The code-review-validator required changes; all are fixed with failing-first tests:
    • M1: suggestion parsing diverged between Rust and TS on Unicode whitespace.
    • M2: a resumed submit could post the review or comments twice.
    • M3: a plaintext edit in a private repo was not refused.
  • It also flagged relay head ordering. A short re-review of M1–M3 then led to fixes for a reconcile false-adoption risk (reconcile now runs only for a draft with a recorded attempt, and matches verdict and body), relay ordering, and the head oid lengths writers accept.
  • Simplifier suggestions are applied, plus a Rust/TS parity fix for leading zeros in linked issues. One larger write-engine refactor is logged in the QA backlog.

🤖 Generated with Claude Code

The review-parity client rules of docs/design/review-parity-spec.md section 5 in Rust (forge_core::rules::review) and TypeScript (lib/rules/review.ts), held in parity by 80 new shared vectors: fold_pr_review_v2 (folded head from headUpdate, requested reviewers, resolved threads, dismissals, milestone), author kinds in the state fold (draft/ready from the patch and the author), dismissed reviews skipped by count_approvals, meets_policy, anchor_of, group_review_comments, parse_suggestions/apply_suggestion (ASCII fence whitespace, lone CR, indented fences) and linked_issues.

Writers and readers: forge-core Collab post_target_event (kind_route), review comment_count, comment start_line/review_id, set_policy/policy, patches_from_branch, PatchView.head used by dg pr view/review/merge/checkout; forge-web review-writes (postTargetEvent, postComment, a resumable and chain-reconciled pending review submit, setPolicy, updateTarget/updateComment) over a new replaceDocumentIdempotent, readPull folding the head and draft; plaintext writes into private repos are refused until the sealed writers land. forge-relay follows headUpdate for head.sha, check-run watching and synchronize; the timeline labels the new kinds. Live on moutai through the web writers.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 108 files, which is 8 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Check out review usage here.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5824a64a-430a-4758-b35a-25c0d280f2dd

📥 Commits

Reviewing files that changed from the base of the PR and between e546f82 and b125088.

📒 Files selected for processing (108)
  • crates/dg/src/pr.rs
  • crates/forge-core/src/collab/mod.rs
  • crates/forge-core/src/collab/v2.rs
  • crates/forge-core/src/rules.rs
  • crates/forge-core/src/rules/review.rs
  • crates/forge-core/src/rules/v2.rs
  • crates/forge-import/examples/show_mirror.rs
  • crates/forge-import/src/sink.rs
  • crates/forge-import/src/source_github.rs
  • crates/forge-relay/src/daemon.rs
  • crates/forge-relay/src/ingest.rs
  • docs/contracts/forge-v2.md
  • docs/design/review-parity-spec.md
  • forge-contracts/vectors/anchor__bad_commit_malformed.json
  • forge-contracts/vectors/anchor__bad_side_malformed.json
  • forge-contracts/vectors/anchor__file_level.json
  • forge-contracts/vectors/anchor__line.json
  • forge-contracts/vectors/anchor__line_without_side_malformed.json
  • forge-contracts/vectors/anchor__no_path_general.json
  • forge-contracts/vectors/anchor__range_ok.json
  • forge-contracts/vectors/anchor__side_without_line_malformed.json
  • forge-contracts/vectors/anchor__start_after_end_malformed.json
  • forge-contracts/vectors/anchor__start_without_line_malformed.json
  • forge-contracts/vectors/approvals__dismissal_of_unknown_review_is_noop.json
  • forge-contracts/vectors/approvals__dismissed_request_changes_unblocks.json
  • forge-contracts/vectors/approvals__dismissed_review_does_not_clear_earlier_verdict.json
  • forge-contracts/vectors/approvals__dismissed_review_does_not_count.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_draft_inert.json
  • forge-contracts/vectors/fold_pr_v2__author_cannot_label.json
  • forge-contracts/vectors/fold_pr_v2__author_cannot_merge_even_if_reachable.json
  • forge-contracts/vectors/fold_pr_v2__author_marks_draft.json
  • forge-contracts/vectors/fold_pr_v2__author_marks_ready.json
  • forge-contracts/vectors/fold_pr_v2__draft_from_document.json
  • forge-contracts/vectors/fold_pr_v2__member_draft_after_author_ready_wins_by_time.json
  • forge-contracts/vectors/fold_pr_v2__pr_author_event_draft_retarget_label_inert.json
  • forge-contracts/vectors/fold_pr_v2__review_kinds_leave_state_alone.json
  • forge-contracts/vectors/fold_pr_v2__stranger_ready_inert.json
  • forge-contracts/vectors/fold_review_v2__author_milestone_inert.json
  • forge-contracts/vectors/fold_review_v2__dismiss_by_author_inert.json
  • forge-contracts/vectors/fold_review_v2__dismiss_records_reason.json
  • forge-contracts/vectors/fold_review_v2__first_dismissal_stands.json
  • forge-contracts/vectors/fold_review_v2__head_update_bad_length_inert.json
  • forge-contracts/vectors/fold_review_v2__head_update_by_stranger_ignored.json
  • forge-contracts/vectors/fold_review_v2__head_update_newest_wins.json
  • forge-contracts/vectors/fold_review_v2__head_update_tie_breaks_by_id.json
  • forge-contracts/vectors/fold_review_v2__head_update_without_oid_inert.json
  • forge-contracts/vectors/fold_review_v2__member_head_update_counts.json
  • forge-contracts/vectors/fold_review_v2__milestone_set_clear.json
  • forge-contracts/vectors/fold_review_v2__no_events_initial_head.json
  • forge-contracts/vectors/fold_review_v2__request_by_author.json
  • forge-contracts/vectors/fold_review_v2__request_remove_request.json
  • forge-contracts/vectors/fold_review_v2__request_without_ref_inert.json
  • forge-contracts/vectors/fold_review_v2__resolve_by_author.json
  • forge-contracts/vectors/fold_review_v2__resolve_by_stranger_inert.json
  • forge-contracts/vectors/fold_review_v2__resolve_then_unresolve.json
  • forge-contracts/vectors/fold_review_v2__resolve_unknown_root_inert.json
  • forge-contracts/vectors/linked_issues__leading_zeros.json
  • forge-contracts/vectors/linked_issues__leading_zeros_u32_edge.json
  • forge-contracts/vectors/linked_issues__non_ascii_adjacent.json
  • forge-contracts/vectors/linked_issues__none.json
  • forge-contracts/vectors/linked_issues__verbs_and_case.json
  • forge-contracts/vectors/linked_issues__word_boundaries.json
  • forge-contracts/vectors/linked_issues__zero_and_overflow_ignored.json
  • forge-contracts/vectors/policy__any_member_counts_writer.json
  • forge-contracts/vectors/policy__dismissed_approval_not_counted.json
  • forge-contracts/vectors/policy__maintainers_only_excludes_writer.json
  • forge-contracts/vectors/policy__stale_approval_not_counted.json
  • forge-contracts/vectors/policy__writer_promoted_to_maintainer_counts.json
  • forge-contracts/vectors/policy__zero_required_always_met.json
  • forge-contracts/vectors/review_group__count_progress.json
  • forge-contracts/vectors/review_group__no_comment_count.json
  • forge-contracts/vectors/review_group__other_owner_excluded.json
  • forge-contracts/vectors/suggestion__apply_bad_range_error.json
  • forge-contracts/vectors/suggestion__apply_crlf.json
  • forge-contracts/vectors/suggestion__apply_delete_lines.json
  • forge-contracts/vectors/suggestion__apply_empty_file_error.json
  • forge-contracts/vectors/suggestion__apply_file_only_newline.json
  • forge-contracts/vectors/suggestion__apply_last_line_keeps_trailing_newline.json
  • forge-contracts/vectors/suggestion__apply_middle.json
  • forge-contracts/vectors/suggestion__apply_no_trailing_newline_kept.json
  • forge-contracts/vectors/suggestion__apply_out_of_range_error.json
  • forge-contracts/vectors/suggestion__parse_close_with_trailing_text.json
  • forge-contracts/vectors/suggestion__parse_cr_only_body.json
  • forge-contracts/vectors/suggestion__parse_crlf_and_empty.json
  • forge-contracts/vectors/suggestion__parse_indented_fence.json
  • forge-contracts/vectors/suggestion__parse_info_word_only.json
  • forge-contracts/vectors/suggestion__parse_single.json
  • forge-contracts/vectors/suggestion__parse_two_blocks_ignores_code_fence.json
  • forge-contracts/vectors/suggestion__parse_unclosed_runs_to_end.json
  • forge-contracts/vectors/suggestion__parse_unicode_whitespace.json
  • forge-web/components/repo/timeline.tsx
  • forge-web/lib/repo/contract.ts
  • forge-web/lib/repo/index.ts
  • forge-web/lib/repo/issues.ts
  • forge-web/lib/repo/review-parity.live.test.ts
  • forge-web/lib/repo/review-writes.test.ts
  • forge-web/lib/repo/review-writes.ts
  • forge-web/lib/repo/v2.live.test.ts
  • forge-web/lib/repo/writes.ts
  • forge-web/lib/rules/conformance.test.ts
  • forge-web/lib/rules/fold.ts
  • forge-web/lib/rules/review.ts
  • forge-web/lib/rules/types.ts
  • forge-web/lib/rules/v2.ts
  • forge-web/lib/sdk/cost.ts
  • forge-web/lib/sdk/index.ts
  • forge-web/lib/sdk/write.ts
  • forge-web/lib/view/issues-view.ts

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@PastaPastaPasta
PastaPastaPasta merged commit 13c0f66 into master Sep 27, 2026
22 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
… comments

The review-parity contract (#56) stores anchors in comment fields only: the forge-anchor body block and the readAnchor adapter are gone. Comments are read with anchorOf (ranges placed under their last line, file-level anchors listed as File comments), posted with postComment, and a review's own comments nest under it in the timeline (groupReviewComments). Dismissed reviews drop out of the review summary as they do from the fold.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant