fix(690,758): assert page IDENTITIES in the MediaCards tests, not just counts
Build ErsatzTV Image / CI toolchain image resolves (pull_request) Successful in 12s
PR Gates / decisions lifecycle (pull_request) Successful in 24s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 15s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 30s
PR Gates / Docs update reminder (pull_request) Successful in 31s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 17s
Review verdict / Set review-verdict status (pull_request_target) Successful in 31s
PR Gates / Script lint and tests (ruff + pytest) (pull_request) Successful in 5m21s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m59s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m30s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Skipped
review-verdict/h10 Review-verdict: MERGEABLE @ f392879 (base: main)
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m37s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 8s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 6s
Build ErsatzTV Image / CI toolchain image resolves (pull_request) Successful in 12s
PR Gates / decisions lifecycle (pull_request) Successful in 24s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 15s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 30s
PR Gates / Docs update reminder (pull_request) Successful in 31s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 17s
Review verdict / Set review-verdict status (pull_request_target) Successful in 31s
PR Gates / Script lint and tests (ruff + pytest) (pull_request) Successful in 5m21s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m59s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m30s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Skipped
review-verdict/h10 Review-verdict: MERGEABLE @ f392879 (base: main)
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m37s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 8s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 6s
A bounded cold review of the docs-only commits (which no reviewer had seen) found the same failure a third time — the previous commit fixed the body wording and left `mechanics:` asserting the superseded version — and one finding that was not prose at all. `mechanics:` claimed both fixtures "assert LITERAL expected counts and expected page contents". False for MediaCardsCountMatchesPageTests: all four cases asserted only `count.ShouldBe(n)` and `page.Count.ShouldBe(n)`. A count and a page can agree on the WRONG SET and stay green, so the fixture pinned agreement without pinning correctness. The honest repair is the test, not the sentence: each case now pins the identities on the page (season ids, episode ids, music video titles). Mutation proving those assertions are load-bearing rather than decorative: changing GetPagedSeasons' predicate to `s.Id != 11` pages a SAME-SIZE wrong set (5 rows, [12,13,14,15,19] instead of [11..15]). Both count assertions still pass; the identity assertion fails. Executed, witnessed red, reverted. Remaining prose corrections from the same review, each checked against the tree: - `mechanics:` "one test per filtering paged handler" -> "at least one" (7 cases over 6 handlers since the second-page test landed) — the exact residual the previous commit set out to remove, one field over. - "Each seeds five rows of which exactly two match Alpha" was untrue of the handlers carrying a non-search clause, which seed a sixth row that clause must exclude from both sides. Stated as such. - The corruption-only scoping enumerated Season.ShowId and MusicVideo.ArtistId but not Episode.SeasonId, the first inner join in the episode chain. - The title described only enforcement mode 1, so a retrieval hit on the title alone under-described the record. - api-conventions.md said "beside a filtered page query", which reads as permission to count the DbSet while no filter exists yet — the opposite of corollary (2).
This commit is contained in:
@@ -60,6 +60,10 @@ public class MediaCardsCountMatchesPageTests
|
||||
count.ShouldBe(5);
|
||||
page.Count.ShouldBe(5);
|
||||
count.ShouldBe(page.Count);
|
||||
|
||||
// pin WHICH rows, not just how many — a count and a page can agree on the wrong set
|
||||
page.Select(s => s.Id).OrderBy(id => id).ShouldBe([11, 12, 13, 14, 15]);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -118,6 +122,9 @@ public class MediaCardsCountMatchesPageTests
|
||||
count.ShouldBe(2);
|
||||
page.Count.ShouldBe(2);
|
||||
count.ShouldBe(page.Count);
|
||||
|
||||
// the two episodes WITH metadata, and not the other season's
|
||||
page.Select(em => em.EpisodeId).OrderBy(id => id).ShouldBe([21, 22]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -152,5 +159,8 @@ public class MediaCardsCountMatchesPageTests
|
||||
count.ShouldBe(2);
|
||||
page.Count.ShouldBe(2);
|
||||
count.ShouldBe(page.Count);
|
||||
|
||||
// this artist's two videos with metadata, and not the other artist's
|
||||
page.Select(m => m.Title).OrderBy(x => x).ShouldBe(["A", "B"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,9 @@ Exemplars:
|
||||
descriptions. See `api.paging-zero-based`.
|
||||
**The handler behind it must compute its total from the SAME query it pages.** Build one
|
||||
`IQueryable`, apply every filter to it, then take both `CountAsync` and the page from that object —
|
||||
never `dbContext.<Set>.CountAsync(ct)` beside a filtered page query, and never a second
|
||||
`CountAsync(pred, ct)` restating the predicate. The drifted state is silent and shaped like working
|
||||
never `dbContext.<Set>.CountAsync(ct)` beside a separate page query, and never a second
|
||||
`CountAsync(pred, ct)` restating the predicate. Take the shape even before the first filter exists —
|
||||
a handler with no filter today is where the drift is introduced tomorrow. The drifted state is silent and shaped like working
|
||||
software: the page is right, the total is wrong, and the client believes the total, so the SPA
|
||||
paginates to pages that can never fill and an MCP caller pages toward a completeness target it
|
||||
cannot reach. Eager-loading `.Include(...)` belongs on the page chain only, appended after the
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
key: api.paged-count-matches-page-query
|
||||
title: '2026-08-26 — A paged handler computes TotalCount from the SAME IQueryable it pages, never from the DbSet (#690, #758)'
|
||||
title: '2026-08-26 — A paged total is computed from the SAME query it pages — one IQueryable in a handler, a test-pinned pair where the count and page are separate methods (#690, #758)'
|
||||
status: active
|
||||
since: '2026-08-26'
|
||||
supersedes: none
|
||||
superseded-by: none
|
||||
rule: 'A handler that returns a page plus a total count builds ONE `IQueryable`, applies every filter to it, and then derives BOTH the count and the page from that single object — `int count = await query.CountAsync(ct)` followed by `query.Include(...).OrderBy(...).Skip(...).Take(...)`. Counting the `DbSet` directly, or re-stating the predicate in a second `CountAsync(pred, ct)`, is the defect: the two expressions are then free to drift and nothing reports it. This is not a style preference — the drifted state is SILENT and shaped like working software. The page is correct, the count is wrong, and the client trusts the count: the SPA paginates on `TotalCount`, so 40 rows with 3 matching a search renders 4 pages of which 3 are permanently empty (#690), and an MCP agent paging to a completeness target reads a `totalCount` its own page can never reach (#758). Scope that harm honestly — of the six, only `GetPagedRerunCollections`, `GetPagedMultiCollections` and `GetPagedPlayouts` reach a controller today; `GetPagedCollections`, `GetPagedSmartCollections` and `GetPagedProgramSchedules` have no production caller (their REST routes use unpaged `GetAll*` queries), so they were latent, not live. Both named issues were ONE mechanism at six sites, of which the issues named two: `GetPagedCollections`, `GetPagedMultiCollections`, `GetPagedRerunCollections`, `GetPagedSmartCollections`, `GetPagedPlayouts`, `GetPagedProgramSchedules`. THE FILTER IS NOT ONLY THE SEARCH STRING — `GetPagedPlayouts` also applies `Filter(p => p.Channel != null)` to the page, and counting the DbSet missed that too; that clause is DEFENSIVE rather than a live defect, because `Playout.ChannelId` is non-nullable with `DeleteBehavior.Cascade` and both production connection strings set `foreign keys=true`, so the orphan state is unreachable while the FK holds. Three corollaries. (1) INCLUDES BELONG TO THE PAGE CHAIN, not to the shared filtered query: a COUNT does not materialize the graph, so `.Include(...)`/`IncludeSelectionDetails()` are appended after the count is taken, which keeps `api.selection-projection-include-chain` intact while leaving one predicate source. (2) A HANDLER WITH NO FILTER STILL TAKES THE SHAPE — `GetPagedFillerPresets` and `GetPagedTraktLists` take no `Query` parameter, so their `DbSet` counts were not WRONG, but leaving them counting one expression while paging another preserves exactly the drift this record is about for whoever adds the first filter. They derive both from one query too. (3) THE POPULATION IS DERIVED FROM THE SHAPE, NOT FROM THE `GetPaged*` NAME — three further count+page producers in `ErsatzTV.Application/MediaCards` (`GetTelevisionSeasonCards`, `GetTelevisionEpisodeCards`, `GetMusicVideoCards`) carry the same drift across a REPOSITORY boundary, where the count and the page are two interface methods rather than two expressions, so the structural fix cannot apply and they are pinned by a test instead (`MediaCardsCountMatchesPageTests`). `GetSeasonCount` now expands to the same Title+Year show set `GetPagedSeasons` pages; `GetEpisodeCount` and `GetMusicVideoCount` now count the METADATA table their pages are taken from, so a media item whose metadata row is missing no longer inflates the total. Their 1-based `pageNumber` is a separate defect against `api.paging-zero-based` and stays open in #832.'
|
||||
signals: 'TotalCount ignores the search query · filtered page reports the unfiltered total · SPA renders empty pages after a search · agent pages to a completeness target it can never reach · count the same query you page · one predicate applied to both so they cannot drift · CountAsync on the DbSet · Channel != null missing from the count · includes belong to the page chain not the counted query · an unfiltered paged handler takes the shape too · a repository count and its page are two methods that must be pinned by a test · paths: `ErsatzTV.Application/MediaCollections/Queries/GetPagedCollectionsHandler.cs`, `ErsatzTV.Application/MediaCollections/Queries/GetPagedMultiCollectionsHandler.cs`, `ErsatzTV.Application/MediaCollections/Queries/GetPagedRerunCollectionsHandler.cs`, `ErsatzTV.Application/MediaCollections/Queries/GetPagedSmartCollectionsHandler.cs`, `ErsatzTV.Application/Playouts/Queries/GetPagedPlayoutsHandler.cs`, `ErsatzTV.Application/ProgramSchedules/Queries/GetPagedProgramSchedulesHandler.cs`, `ErsatzTV.Application/Filler/Queries/GetPagedFillerPresetsHandler.cs`, `ErsatzTV.Application/MediaCollections/Queries/GetPagedTraktListsHandler.cs`, `ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs`, `ErsatzTV.Infrastructure/Data/Repositories/MusicVideoRepository.cs`, `ErsatzTV.Tests/Application/Paging/PagedQueryTotalCountTests.cs`, `ErsatzTV.Tests/Application/Paging/MediaCardsCountMatchesPageTests.cs` · issues: #758, #690, #671, #757'
|
||||
mechanics: 'TWO enforcement modes, because the rule has two shapes. Where the count and the page are expressions in one handler, the STRUCTURE carries it (one `IQueryable`) and `PagedQueryTotalCountTests` pins one test per filtering paged handler. Where they are separate repository methods (`MediaCards`), nothing structural is available and `MediaCardsCountMatchesPageTests` pins their agreement instead. Both assert LITERAL expected counts and expected page contents. No repo-wide detector is proposed — see the record body for why the obvious one is not reliable.'
|
||||
mechanics: 'TWO enforcement modes, because the rule has two shapes. Where the count and the page are expressions in one handler, the STRUCTURE carries it (one `IQueryable`) and `PagedQueryTotalCountTests` pins at least one test per filtering paged handler. Where they are separate repository methods (`MediaCards`), nothing structural is available and `MediaCardsCountMatchesPageTests` pins their agreement instead. Every case asserts LITERAL expected counts AND the literal identities on the page — counts alone would let a count and a page agree on the WRONG SET and stay green. No repo-wide detector is proposed — see the record body for why the obvious one is not reliable.'
|
||||
---
|
||||
|
||||
**The two issues were filed as separate bugs on separate entities, and they are one mechanism.**
|
||||
@@ -46,8 +46,8 @@ the count, in ALL THREE pairs rather than the one it was first noticed in: a REQ
|
||||
each return nothing when the principal row is absent, while the corrected count still counts. A
|
||||
COLLECTION `Include` such as `Show.ShowMetadata` is a LEFT JOIN and drops nothing — the distinction
|
||||
is the whole mechanism, so do not read "an include filters" as a blanket claim. Scope the consequence
|
||||
honestly, the same way the `Channel != null` clause above is scoped: `Season.ShowId` and
|
||||
`MusicVideo.ArtistId` are non-nullable with `DeleteBehavior.Cascade` and production enforces the FK,
|
||||
honestly, the same way the `Channel != null` clause above is scoped: `Episode.SeasonId`, `Season.ShowId` and
|
||||
`MusicVideo.ArtistId` are all non-nullable with `DeleteBehavior.Cascade` and production enforces the FK,
|
||||
so count-N / page-0 is a corruption-only state no user can reach. It is stated because it makes
|
||||
"count the table the page reads" necessary and NOT sufficient as a general rule, not because a live
|
||||
defect is being left open; #832 carries it.
|
||||
@@ -72,9 +72,10 @@ distinction is not pedantic: the name-derived population is eight handlers and m
|
||||
by shape. That is the failure this record's own first paragraph names, committed once inside the fix
|
||||
for it. (#832 carries what is deliberately left there: 1-based paging and delete-or-keep.)
|
||||
|
||||
**The tests assert pinned literals, not filter-derived expectations.** Each seeds five rows of which
|
||||
exactly two match `"Alpha"`, then asserts `TotalCount.ShouldBe(2)` and the page's names against the
|
||||
literal pair. Recomputing the expectation by re-applying the handler's own predicate would pass
|
||||
**The tests assert pinned literals, not filter-derived expectations.** Each seeds five matchable rows
|
||||
of which exactly two contain `"Alpha"` — plus, where the handler carries a non-search clause, one row
|
||||
that clause must exclude from BOTH sides (a channel-owned collection, an orphaned playout) — then
|
||||
asserts `TotalCount.ShouldBe(2)` and the page's names against the literal pair. Recomputing the expectation by re-applying the handler's own predicate would pass
|
||||
whatever the handler does. The mutation proof is recorded in the PR, in both modes: restoring the
|
||||
pre-fix `CountAsync` clause at all six handler sites turns the six per-handler
|
||||
`PagedQueryTotalCountTests` cases red, and each of those constructs exactly one handler, so every
|
||||
|
||||
Reference in New Issue
Block a user