Skip to content

fix(server): the score-band filter read query names the BFF never sent - #273

Merged
athvin merged 1 commit into
mainfrom
fix/band-filter-params
Oct 22, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/band-filter-params

Conversation

@athvin

@athvin athvin commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

The bug

match_scores_list read min/max; the BFF forwards band_low/band_high (frontend/src/app/api/orgs/[org]/match-scores/route.ts:5). The bounds were dropped on every request, so the endpoint returned the first page of all active pairs and the "By score" tab on the duplicates screen has never filtered against a real backend. Pre-existing on main.

Why three layers of tests all stayed green

Each agreed with one side of the mismatch, and nothing compared them:

  • the Playwright mock honours band_low/band_high (frontend/tests/mock-erserver/server.mjs:1533-1534) and the functional tier asserts against the mock — so that tier only ever confirmed the frontend's own belief;
  • pg_golden_read.rs:418 did cover the band, and its >= 0.95 assertion was sound — but it requested ?min=0.95, the name the handler read rather than the one the product sends. It passed legitimately while testing a parameter no caller used;
  • mock_contract.rs compares route + method only, so a query-param rename is outside what it can see at all.

One assertion was also unfalsifiable

assert!(hi.len() <= pairs.len(), "band narrows the set") — an ignored band returns the full set, which satisfies <=. Replaced with a distribution-independent backstop: take the maximum observed probability, request a band above it, require an empty page. That holds regardless of how a fixture's scores cluster. Also adds the first coverage of band_high (both bounds inclusive — >= $min_prob / <= $max_prob in entities/match_score/read/active_page.sql).

Verification

  • make check green locally — fmt, clippy --workspace --all-targets -D warnings, er-entity verify, skills-check, cargo test --workspace.
  • make check does NOT exercise the band assertions. pg_golden_read.rs is gated on both ER_TEST_PG_DSN and DEDUPE_E2E_DUCKLAKE=1; on a miss it prints to stderr and returns, reporting test golden_records_read_over_ducklake ... ok having run nothing (0.00s). Noting it because that line is actively misleading.
  • Ran for real against a throwaway Postgres with both vars set: 1 passed, 8.58s.
  • Observed failing without the fix. Reverting the handler to min/max while keeping the new test: FAILED. 0 passed; 1 failed, panicking at pg_golden_read.rs:432. So the test now genuinely locks the contract rather than restating the handler's own spelling.
  • CI's DuckLake + extensions e2e job (rust.yml:486-498) sets all three vars and runs on this PR, so the assertions are covered in the PR tier.

Scope

The other min/max site (lib.rs:3398, the review queue) is deliberately untouched: its BFF route forwards neither name and it defaults to the full range, so it is unused rather than wrong.

No OpenAPI regeneration — match-scores is not in the document.

Follow-up, not in this PR

Extending mock_contract.rs to compare query-param names between each BFF PASSTHROUGH list and its handler's params.get calls would catch this class in the fast tier. Left out deliberately: a new static analysis over delicate parsing — that file already documents a regex that silently dropped every route — and worth its own review.

🤖 Generated with Claude Code

`match_scores_list` read `min`/`max`, while the BFF forwards
`band_low`/`band_high` (`src/app/api/orgs/[org]/match-scores/route.ts:5`). The
bounds were dropped on every request and the endpoint returned the first page of
*all* active pairs, so the "By score" tab on the duplicates screen has never
filtered against a real backend.

Three layers each agreed with one side, and nothing compared them:

- the Playwright mock honours `band_low`/`band_high`
  (`frontend/tests/mock-erserver/server.mjs`) and the functional tier asserts
  against the mock — so the frontend tier only confirmed the frontend's belief;
- `pg_golden_read.rs` *did* cover the band, but requested `?min=0.95` — the
  server's own spelling rather than the contract the product speaks. A real
  test, green, asserting the wrong half;
- `mock_contract.rs` compares route and method only, so a query-param rename is
  outside what it can detect at all.

Rename both reads and move the test onto the forwarded names. That test's
`hi.len() <= pairs.len()` assertion was itself unfalsifiable — an ignored band
returns the full set, which satisfies `<=` — so it is replaced with a
distribution-independent check: a band above every observed score must return an
empty page. Adds the first coverage of `band_high`.

The other `min`/`max` site (the review queue, `lib.rs:3398`) is deliberately
untouched: its BFF route forwards neither name and it defaults to the full
range, so it is unused rather than wrong. Changing it would be an unrequested
behaviour change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 2df985e into main Oct 22, 2026
17 checks passed
@athvin
athvin deleted the fix/band-filter-params branch October 22, 2026 19:59
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