Skip to content

fix(typescript): read a toMatchObject const argument bound in the test body (RIPR-SPEC-0250) - #8134

Merged
EffortlessSteven merged 2 commits into
mainfrom
claude/project-thread-pwvs2k
Oct 15, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
claude/project-thread-pwvs2k

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • Before: const grown = { name: "bo", adult: true }; expect(buildProfile("bo", 18)).toMatchObject(grown); read weakly_exposed, a false gap. The test pins adult exactly as the inline-literal form does.
  • After: toMatchObject(<name>) reads the flat literal of a test-body const that the body names only in its binding and that argument, so the RIPR-SPEC-0250 field pin credits it (exposed, exact_value / strong).
  • These keep the weak reading:
    • a let binding;
    • any other mention (alias, field write, helper call, second assertion);
    • a binding outside the test body;
    • a call in a nested block;
    • a nested or spread literal;
    • .not, .resolves or .rejects chains;
    • a body with eval, with or a \u escape.
  • How: match_object_guard.rs gains match_object_consts / match_object_const_argument. oracle.rs attaches the literal to the assertion as expected_object_const, and ts_match_object_facts reads it like an inline literal. A read argument no longer also lists typescript_dynamic_assertion_unresolved.
  • Also mirrors the instance-class wrapped-member and nested-wrap call shapes in the match-object identity test (an optional finding on fix(typescript): read a pin through a test-local identity helper (RIPR-SPEC-0249, RIPR-SPEC-0250) #8092).

Swarm / Source Boundary

  • 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-0250 (example 5 amended 2026-10-15)
ADR: n/a
Plan item: n/a
Governing issue or accepted claim: #6654
Acceptance delta (one sentence): corpus row jest-spec0250-ex05-non-literal-expected moves gap → credited, and no other row moves.

Candidate Relationships

Candidate branch: claude/project-thread-pwvs2k
Stack parent or prerequisite PR: #8092 (merged)
Proposed replacement of PR: none

Scope

  • One analyzer reading, plus its spec amendment, tests, traceability and corpus re-bless.

Scope Classification

  • One production behavior

Production delta:

  • toMatchObject(<const>) on a direct expect(...) statement reads the bound flat literal.

Evidence/support delta:

  • Spec 0250: the Matcher reading paragraph, example 5, Required Evidence, and the Test and Implementation Mappings.
  • The corpus case reasoning and row.

Single acceptance criterion:

  • The amended example 5 is exposed, and every refusal listed above stays not exposed.

Non-goals:

  • Nested listed objects, asymmetric matchers, bindings outside the test body, and await expect(...). These are missed credits, not false credits.

Support-tier Impact

  • none

Claim/proof notes:

  • TypeScript stays Preview.

Policy Impact

  • doc artifacts (spec amendment, traceability)

Proof

cargo test -p ripr --lib typescript          # 1130 passed
cargo test -p ripr --lib match_object        # 10 passed
cargo xtask verdict-corpus bless --language typescript   # only ex05 moved
cargo xtask precommit                        # exit 0 on c26734366

Results:

  • TypeScript corpus false verdicts go from 7/169 to 6/169. False exposed stays at 0.
  • Mutation checks: removing the nested-block emptying of the consts in AssertionContext::nested() fails call-in-block. Removing the expected_object_const.is_none() guard in static_limit.rs fails the positive test's limitation assertion.
  • One untested defensive branch remains: the declared_end <= call.span.start check. Use before the declaration would throw a TDZ error at runtime, so no passing test can reach it.

Claim Boundary

May claim: a test-body const flat-literal toMatchObject argument is read when the body names it nowhere else.

Must not claim: any data-flow reading of expected objects beyond that.

Rollback

Revert the squash commit and re-bless the TypeScript corpus.

Spec-Test-Code Traceability

  • Spec: RIPR-SPEC-0250
  • Tests: match_object_tests.rs::match_object_pin_reads_a_test_body_object_const
  • Code: match_object_guard.rs, oracle.rs, static_limit.rs, types.rs
  • Golden outputs: fixtures/typescript-verdict-corpus (one row)
  • Metrics: typescript_match_object_pin_mismatch

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.

Gates

  • cargo fmt --check (via precommit)

Found in review and filed separately: #8133 (an older __proto__: key hole in the match-object pin).

🤖 Generated with Claude Code

https://claude.ai/code/session_013ajVbPgh9yZDQgaAHkZE8V


Generated by Claude Code

…t body (RIPR-SPEC-0250)

`toMatchObject(expected)` now reads the flat object literal of a
test-body `const expected = {...}` that the body names only in its
binding and that one argument, so the field pin credits the listed
returned field. Any other mention, a `let` binding, a binding outside the
test body, nested or spread literals, and bodies with `eval`, `with` or a
`\u` escape keep the weak reading.

Spec 0250 example 5 is amended; corpus row
jest-spec0250-ex05-non-literal-expected moves from gap to credited and no
other row moves. Also mirrors the instance-class wrapped-member and
nested-wrap call shapes in the match-object identity test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ajVbPgh9yZDQgaAHkZE8V
A read const argument no longer also reports
typescript_dynamic_assertion_unresolved. Adds call-in-block and
resolves-chain refusal cases, states the direct-statement, top-level and
declared-before-call conditions in spec 0250, and records the ex04/ex05
row moves under Required Evidence.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013ajVbPgh9yZDQgaAHkZE8V
@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!

Copy link
Copy Markdown
Member Author

Review of record — head c267343

Two independent reviewer agents read the exact candidate, each from a different angle.

1. Correctness / false-credit (adversarial). No hole introduced by this change. The reviewer checked each of these and refuted every one:

  • nested or callback bindings and shadowing;
  • the name appearing in strings, comments or templates (that only overcounts, which withholds);
  • destructuring and multi-declarator forms;
  • hoisting and TDZ;
  • x!, as and parentheses;
  • object keys and shorthand;
  • multi-assertion bodies;
  • .not, .resolves, .rejects and await (fail closed);
  • getters, methods, computed keys and spreads (rejected by safe_mock_expected_object);
  • test.each row substitution;
  • export const.

It also found one older hole that this PR does not cause: a __proto__: key read as a field. That is filed as #8133.

2. Tests / spec / contract. Nothing blocking. It raised five optional findings, all fixed in c267343:

  • the nested-block case did not exercise AssertionContext::nested(), so I added call-in-block;
  • there was no test for a .resolves chain, so I added resolves-chain (a .not chain yields no assertion at all, so there is nothing to test);
  • the spec over-claimed .resolves and left out the top-level and declared-before-call conditions, so the Matcher reading paragraph is reworded;
  • an exposed finding still listed typescript_dynamic_assertion_unresolved, so that is now suppressed for a read const, with an assertion in the positive test;
  • Required Evidence was stale, so it now records the ex04 and ex05 row moves.

Mutation checks:

  • Reverting the nested() consts emptying fails call-in-block.
  • Reverting the static_limit.rs guard fails the positive test.
  • The declared_end check is still untested. It is defensive: use before the declaration throws a TDZ error at runtime.

Evidence:

  • cargo test -p ripr --lib typescript: 1130 passed.
  • cargo xtask precommit: exit 0 on this head.
  • Corpus re-bless: only jest-spec0250-ex05-non-literal-expected moves (gap → credited, outcome ideal).
  • TypeScript false verdicts: 7 → 6 of 169; false exposed stays at 0.

Disposition: nothing blocking. Marking Ready.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 15, 2026 13:36
@EffortlessSteven
EffortlessSteven enabled auto-merge (squash) October 15, 2026 13:36
@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 15, 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: Advanced
  • Run ID: baa9ab0a-2614-4816-95f2-fd78236ef83d
📥 Commits

Reviewing files that changed from the base of the PR and between 0d8bae7 and c267343.

📒 Files selected for processing: 11
  • .ripr/traceability.toml
  • changelog.d/typescript-match-object-const-argument.md
  • crates/ripr/src/analysis/language/typescript/match_object_guard.rs
  • crates/ripr/src/analysis/language/typescript/oracle.rs
  • crates/ripr/src/analysis/language/typescript/static_limit.rs
  • crates/ripr/src/analysis/language/typescript/tests.rs
  • crates/ripr/src/analysis/language/typescript/tests/match_object_tests.rs
  • crates/ripr/src/analysis/language/typescript/types.rs
  • docs/specs/RIPR-SPEC-0250-typescript-match-object-field-pin.md
  • fixtures/typescript-verdict-corpus/cases/jest-spec0250-ex05-non-literal-expected.json
  • fixtures/typescript-verdict-corpus/expected/rows/jest-spec0250-ex05-non-literal-expected.json
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Summary by CodeRabbit

  • New Features
    • TypeScript toMatchObject assertions can now recognize a flat object literal stored in a test-body const, allowing its fields to count toward field-pin analysis when the binding is used only for that matcher argument.
    • The analysis continues to treat mutable bindings, aliases, additional uses, unsupported object shapes, and bindings outside the test body as unqualified. Resolved object arguments are no longer reported as unresolved dynamic assertions.

Walkthrough

The TypeScript analyzer now recognizes qualifying test-body const object literals passed to toMatchObject. It uses the resolved object for field-pinning analysis and avoids the unresolved-dynamic limitation for that argument. Tests, the specification, changelog, traceability manifest, and corpus verdict were updated.

Changes

TypeScript Match Object Field Pinning

Layer / File(s) Summary
Assertion metadata and collection
crates/ripr/src/analysis/language/typescript/types.rs, crates/ripr/src/analysis/language/typescript/oracle.rs, crates/ripr/src/analysis/language/typescript/tests.rs
Assertions now carry optional object-constant metadata. Assertion collection records eligible constants for the relevant test-body contexts.
Resolve constants and apply pinning
crates/ripr/src/analysis/language/typescript/match_object_guard.rs, crates/ripr/src/analysis/language/typescript/static_limit.rs
The analyzer resolves eligible direct toMatchObject identifier arguments and checks their object text for pinned fields. Resolved arguments do not receive the unresolved-dynamic-assertion limitation.
Tests, specification, and corpus results
crates/ripr/src/analysis/language/typescript/tests/match_object_tests.rs, docs/specs/RIPR-SPEC-0250-typescript-match-object-field-pin.md, changelog.d/*, .ripr/traceability.toml, fixtures/typescript-verdict-corpus/*
Tests cover eligible bindings and refusal conditions. The specification and changelog describe the conditions. The corpus case and expected row now report a credited, exposed result.

Priority: ⬇️ Low

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant TestCallback
  participant AssertionCollector
  participant ObjectConstantGuard
  participant TypeScriptAssertion
  participant FieldPinAnalysis
  TestCallback->>AssertionCollector: collect assertions and test-body constants
  AssertionCollector->>ObjectConstantGuard: resolve direct toMatchObject identifier
  ObjectConstantGuard->>TypeScriptAssertion: attach expected_object_const
  TypeScriptAssertion->>FieldPinAnalysis: provide resolved object text
Loading
Merge Risk: ⚪ Minimal · up to c2673

The documented recognition rule and corpus outcome present no identified issue that needs correction before merge.

Security architecture risk: 🔵 Low · up to c2673

Strong test-coverage credit now accepts a restricted class of local constants. The inspected paths preserve conservative eligibility checks and reveal no concrete new security exposure. Full before-and-after verification was limited.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect is confined to derived TypeScript pin credit and limitation reporting. The inspected producer-consumer path does not establish expanded tenant access, credentials, execution privileges, or deployment authority.

Trust Boundaries and Controls

  • observed — Source-controlled names are promoted to literal-backed evidence only after eligibility checks. Exactly two whole-word occurrences are required, so ordinary additional mentions such as aliases, writes, helper arguments, or repeated assertions withhold resolution. Failed resolution leaves the new metadata absent and does not activate its limitation-suppression exception.
Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 94.74% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 5 files. (6 skipped: 5 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the TypeScript behavior being fixed and references the relevant specification. It is specific and concise enough for repository history.
Description check Passed The description follows the repository template and documents the scope, source boundary, acceptance criterion, behavior, non-goals, proof, traceability, rollback, and claim boundary. Some template ch…
✨ Finishing Touches
📝 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 the matcher’s call,
And finds a const behind it all.
Flat little fields now come to light,
While let and aliases stay out of sight.
Tests mark the paths the rules allow,
Then nibble carrots, pleased somehow.

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs one verification check before upstream.

Verification questions

  • Confirm diff also breaks one prior weakly_exposed reading for spec example 5; corpus row re-bless and one stat move (weakly_exposed → exposed). Reviewer should confirm the single-row move is intentional and that no other verdict row changed.

Refuted

  • The 'declared_end <= call.span.start' TDZ guard is untestable and could bit-rot; an OOO call like const expected={...}; if (foo(expected)) expect(x).toMatchObject(expected); might falsely credit because the const is reachable via a hoisted binding.; refuted because: only matches[2] of (ExactValue,Strong) is asserted. False-premise: TDZ in JS throws before the assertion; no passing test can reach out-of-order use. PR body acknowledges this as one untested defensive branch.
  • A 'toMatchObject(expected)' argument whose const literal has a getter or computed key could be mis-credited as flat-keyed and trip the field-pin 'lists_key' check via safe_mock_expected_object rejection path.; refuted because: safe_mock_expected_object (existing helper) rejects getters/methods/computed keys/spreads; the test 'spread' refusal case covers spread; the helper is unchanged and pre-existing. Refuted.

Parked follow-ups

  • declare check (declared_end <= call.span.start) has no passing test reaching the misuse path; reaching it would be a TDZ ReferenceError at runtime, so defense is sufficient.
  • Pre-existing ci/precommit script gap (npx --no-install highlight or similar) from #8134 review thread is unrelated to red/green; tests pass as-is.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

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.

2 participants