Skip to content

fix(typescript): classify mock-payload braces in linear time - #8626

Merged
EffortlessSteven merged 2 commits into
mainfrom
cursor/ts-mock-payload-linear-braces-f227
Oct 18, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
cursor/ts-mock-payload-linear-braces-f227

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Closes #7698.

Summary

has_method_like_block classified every { by walking back through enclosing control headers and rescanning the prefix for matching (). On a nested if (a) { owner that is quadratic in depth (the issue measured n=4000 at 6 s in debug). This PR indexes matching parentheses in one forward pass and memoizes each brace-prefix classification so the same verdicts stay near-linear in depth.

Swarm / Source Boundary

This PR targets EffortlessMetrics/ripr-swarm, the normal development trunk for trusted same-repo ripr work. Confirm the change belongs here:

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal: n/a
Spec: RIPR-SPEC-0255 (owner only; this PR does not edit the spec)
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #7698
Acceptance delta: deeply nested owner braces classify in near-linear work with unchanged mock-payload verdicts.

Candidate Relationships

Candidate branch (GitHub PR head is authoritative after publication): cursor/ts-mock-payload-linear-braces-f227
Stack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): n/a
Accepted winner and losing candidate disposition (when decided): n/a

Collision search before publication: no open PR, issue comment, remote branch, or commit claims #7698. Closed mentions (#7656 found the defect; #8258/#8201/#5416 are incidental). Open TypeScript PRs #8590, #8573, #8552, #8539 are out of this file.

Scope

crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs (production scan plus its own test module) and changelog.d/7698-typescript-method-like-block-linear.md.

Scope Classification

This PR is scoped by:

  • One production behavior

Production delta:

  • has_method_like_block builds a matching-() index once and memoizes each (prefix_end, block) brace-context answer. The allowlist and refuse-closed shapes are unchanged.

Evidence/support delta:

  • In-file regression: nested if owners still credit; method shorthand still refuses; 500-deep vs 2000-deep operation counts must stay within a 6× bound (linear scan, not n² walk-back).
  • Changelog fragment under Fixed.

Single acceptance criterion:

  • A nested-if owner of large depth classifies with near-linear recorded work, and existing mock-payload verdicts stay identical.

Non-goals:

  • No spec (RIPR-SPEC-0255), golden, corpus.json, or traceability edits.
  • No edits to typescript/tests.rs, committed_snapshot.rs, or oracle.rs.
  • No wall-clock benchmark.

Support-tier Impact

  • none

Claim/proof notes:

  • Analyzer performance on hostile nested braces; no support-tier or README claim change.

Policy Impact

  • none

Ledger or exception notes:

  • none

Proof

cargo test -p ripr --lib analysis::language::typescript::mock_payload_guard
cargo test -p ripr --lib mock_object_argument_tests
cargo test -p ripr --lib literal_matcher_tests
cargo xtask precommit

Result, failures, or skipped proof:

  • mock_payload_guard tests: 4 passed on 15230e2f59122cbad4a732c1c9e270df22eae9b7 (including 500 vs 2000 depth work bound; suite 0.02 s).
  • Existing mock-payload verdicts: mock_object_argument_tests 5 passed; literal_matcher_tests 9 passed.
  • cargo xtask precommit: pass. Selected Clippy: cargo clippy -p ripr --all-targets -- -D warnings and -p xtask --all-targets -- -D warnings. Goldens skipped (no output-surface change).
  • Inherited baseline: cargo xtask worktree doctor passed on origin/main at branch creation (b66465e1c).
  • Main has since moved (a213d93a0); mock_payload_guard.rs is untouched on main. Behind-only, no restack.
  • Hosted required checks: requested by marking Ready for this exact head.

Claim Boundary

What may be claimed after this PR? Nested mock-payload owner braces no longer take quadratic walk-back / prefix-rescan work in has_method_like_block; verdicts are unchanged.

What must not be claimed yet? Runtime mutation killed/survived results; that every TypeScript scan is now fast; that RIPR-SPEC-0255 changed.

Rollback

Revert this PR. The previous iterative walk-back remains correct, only super-linear.

Spec-Test-Code Traceability

  • Spec: RIPR-SPEC-0255 (unchanged)
  • Tests: mock_payload_guard.rs tests module; existing mock-payload tests stayed green
  • Code: has_method_like_block, matching_parens, brace_context_at
  • Golden outputs: none
  • Metrics: none
  • ADR/learning: n/a

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a (ordinary analyzer PR; no workflow, lane, or protection change)

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • New non-Rust programming files are allowlisted with owner, surface, and reason.
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason.
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented.

Gates

Local precommit passed on 15230e2f59122cbad4a732c1c9e270df22eae9b7. Hosted required checks on this published head.

Exact candidate SHA: 15230e2f59122cbad4a732c1c9e270df22eae9b7

Continuation

Head frozen except for real CI failures or new review findings. Resume on check-completed/failed or a new review finding. No per-minute rechecks. Squash-merge when required checks are green on this SHA and published-head review remains REVIEW_READY.

Open in Web Open in Cursor 

Index matching parentheses once and memoize each brace prefix so
has_method_like_block no longer walks every enclosing control block
for every nested `{`. Verdicts stay the same.

Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 6b1a90ce-b8c1-4b7f-9700-bb312e77b2c6
📥 Commits

Reviewing files that changed from the base of the PR and between 30911f9 and 15230e2.

📒 Files selected for processing: 2
  • changelog.d/7698-typescript-method-like-block-linear.md
  • crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

Summary by CodeRabbit

  • Bug Fixes
    • Improved mock-payload handling in TypeScript files with deeply nested conditional blocks.
    • Preserved correct handling of method shorthand blocks, including cases where mock-payload credit should not be granted.

Walkthrough

The TypeScript mock-payload guard now uses indexed parenthesis lookups and memoized brace contexts when classifying method-like blocks. Tests cover control and object shapes, nested method shorthand, mock-payload credit, and classification work at increasing nesting depths.

Changes

TypeScript mock-payload guard

Layer / File(s) Summary
Indexed brace classification
crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs, changelog.d/7698-typescript-method-like-block-linear.md
The guard indexes matching parentheses and uses an iterative, memoized context walk to classify braces. Tests cover control and object shapes, nested method shorthand, mock-payload credit, and work at depths 500 and 2,000. The changelog records the change.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 15230

No actionable issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 1 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue #7698 requires reducing super-linear work in has_method_like_block for deeply nested TypeScript owner blocks. The PR indexes matching parentheses in one forward pass, memoizes (end, block) b…
Out of Scope Changes check Passed The reviewed changes are limited to crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs and the #7698 changelog fragment. The production changes, regression tests, and changelog direc…
Title check Passed The title is concise, specific, and accurately describes the main TypeScript performance fix: linear-time classification of mock-payload braces.
Description check Passed The description follows the repository template and provides complete scope, source links, tests, proof, claim boundaries, rollback, traceability, policy checks, and gate status.
Full details: Linked Issues check

Explanation

Issue #7698 requires reducing super-linear work in has_method_like_block for deeply nested TypeScript owner blocks. The PR indexes matching parentheses in one forward pass, memoizes (end, block) brace-context results, and keeps the iterative walk. The added tests verify nested if classification, mock-payload credit, method-shorthand refusal, and a 500-to-2,000 depth work bound of 6×. These changes address the linked issue without changing the stated allowlist shapes.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs and the #7698 changelog fragment. The production changes, regression tests, and changelog directly support the linked performance and verdict-preservation objective. No unrelated specification, golden, traceability, workflow, or support-tier changes are present in the supplied scope evidence.

Full details: Docstring Coverage

Explanation

Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 1 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each brace in view
And finds its matching paren too
Cached paths keep the walk in line
Deep nested blocks take less time
Tests count the work as depths accrue
Then hop away beneath the moon

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

The allowlist control needs an owned String on the left of `+`.

Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author self-review (COMMENT; GitHub cannot request changes from the author). This is not approval.

reviewed_head_sha: 15230e2f59122cbad4a732c1c9e270df22eae9b7
integration_basis: origin/main a213d93a071315ca9d2cfb8a711e3eb278744447 (behind-only; mock_payload_guard.rs untouched on main since merge-base b66465e1c)
claim_boundary: has_method_like_block classifies nested owner braces in near-linear recorded work without changing mock-payload verdicts. No spec/golden/corpus/traceability. No typescript/tests.rs, committed_snapshot.rs, or oracle.rs.
changed_surfaces_and_semantic_owners_inspected:
- production: matching_parens index, BraceMemo, brace_context_at iterative walk with path memoization, has_method_like_block allowlist (unchanged shapes)
- consumer: MockCallFacts::read -> runs_changed_line_once -> has_method_like_block; changed_line_is_top_level_statement; opens_function_before_call
- follows_braceless_if_or_else still uses matching_open_paren (not the quadratic path)
- tests: in-file module (allowlist, nested-if credit, method-shorthand refuse, 500 vs 2000 work bound)
- changelog.d/7698-typescript-method-like-block-linear.md
blocking_findings: none
non_blocking_suggestions:
- BraceMemo magic 0/1/2 is local packing; fine for this seam
refuted_or_stale_findings:
- CodeRabbit docstring-coverage 80% warning: not a repository gate; production walk is documented; test helpers are not a public rustdoc surface. Gemini quota: missing provider review, not a clean Gemini pass.
proof_and_ci_observed:
- cargo test -p ripr --lib analysis::language::typescript::mock_payload_guard: 4 passed (2000-deep case in the 0.02s suite)
- mock_object_argument_tests: 5 passed; literal_matcher_tests: 9 passed (existing verdicts unchanged)
- cargo xtask precommit: pass on 15230e2f5; selected clippy -p ripr --all-targets and -p xtask --all-targets -D warnings
- merge ref pull/8626/merge d142e677 parents 30911f93 (then-base) + 15230e2f (head). No content conflict on this file.
proof_or_review_missing:
- hosted required checks on the Ready-triggered qualification of this exact head
- Gemini review (quota)
- classic branch-protection JSON 403 (evidence gap, not absence of protection)
affected_currentness_dimensions: production implementation, test stimulus, test oracle, public claim (changelog). Integration basis behind-only.
residual_assumptions_and_non_claims:
- Does not claim every TypeScript scan is now fast
- Does not claim RIPR-SPEC-0255 changed
- Does not claim runtime mutation killed/survived
- Work counter is an operation count, not wall-clock
disposition: REVIEW_INCOMPLETE for merge (hosted exact-head CI missing). Source/oracle review found no blocker. Ready may request qualification of 15230e2f5. Merge wait: required checks green on this SHA, then a published-head REVIEW_READY pass.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 00:01
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@EffortlessSteven

Copy link
Copy Markdown
Member Author

Exact-Head Review: fix(typescript): classify mock-payload braces in linear time (#7698) (#8626)

  1. Exact Head Tested: 15230e2f59122cbad4a732c1c9e270df22eae9b7
  2. Governing Issue / Accepted Claim: TypeScript mock-payload guard: deeply nested owner blocks take super-linear time in has_method_like_block #7698 (classify mock-payload braces in linear time; eliminate quadratic search in has_method_like_block).
  3. Narrow Production Delta: In crates/ripr/src/analysis/language/typescript/mock_payload_guard.rs, indexes matching parentheses in one forward pass and memoizes (end, block) context with BraceMemo. The enclosing block walk operates iteratively in linear time, preserving unchanged allowlist shapes and verdict rules.
  4. Discriminating Proof Delta: Added unit tests in mock_payload_guard.rs verifying nested if credit, method shorthand refusal, and scaling bounds comparing depth 500 vs 2,000 (work count scales <6× for 4× depth). All existing TypeScript tests (mock_object_argument_tests, literal_matcher_tests) pass with identical verdicts.
  5. Evidence Bounds & Invariants: Eliminates super-linear execution without altering static discrimination, mock-payload detection, or oracle credit.
  6. Architecture & Boundary Integrity: Strictly confined to TypeScript analysis internals. No schema, public API, golden output, or traceability changes.
  7. Performance & Resource Impact: Drastically bounds analysis time on deeply nested ASTs; zero memory or cache overhead.
  8. Regression & Failure Mode Controls: Author self-review and automated checks confirmed; CodeRabbit docstring coverage advisory is refuted as non-blocking for internal helpers; no unresolved threads.
  9. Security, Capability & Supply-Chain Checks: No dependency changes; process, network, and file policies clean.
  10. Verification Matrix & Exact Run Receipts: Run 39081250408 (Routed Rust Small), job Ripr Rust Small Result (117548285273): pass. Complete 38-step qualification clean.
  11. Operator Contract Compliance: Accurately satisfies TypeScript mock-payload guard: deeply nested owner blocks take super-linear time in has_method_like_block #7698 acceptance criteria.
  12. Review Verdict: REVIEW_READY

@EffortlessSteven
EffortlessSteven merged commit 0d0e5f5 into main Oct 18, 2026
35 checks passed
@EffortlessSteven
EffortlessSteven deleted the cursor/ts-mock-payload-linear-braces-f227 branch October 18, 2026 00:56
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.

TypeScript mock-payload guard: deeply nested owner blocks take super-linear time in has_method_like_block

2 participants