Skip to content

Commit 7cf00de

Browse files
authored
Make nine CrossDialectJoinTests row assertions order-independent (#337)
1 parent b03e246 commit 7cf00de

2 files changed

Lines changed: 136 additions & 100 deletions

File tree

llm-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Rules of thumb when adding or converting a test:
132132
- **The key must be a total order over the rows the query actually returns.** A join that yields the same user twice ties on `UserName`; use the primary key, or a composite tuple key: `.SortedByAsync(r => (r.ProductName, r.UserName))`.
133133
- **Do not sort a query that already has a top-level `ORDER BY`.** Re-sorting in C# would mask a regression that drops the `ORDER BY` — which is the very thing those tests pin. An `ORDER BY` inside a window `OVER (...)`, a subquery, or a CTE body does *not* order the outer result set and does not count.
134134
- **Sorting cannot fix nondeterministic row *selection*.** `LIMIT`/`OFFSET` with no `ORDER BY` returns an arbitrary subset, and `ExecuteFetchFirstAsync` over a multi-row predicate returns an arbitrary row. Those need a query-side `.OrderBy(...)` — note it goes *after* `Select` and takes the source-entity lambda: `Select(u => (u.UserId, u.UserName)).OrderBy(u => u.UserId)`. Ordering on a literal column adds no parameter, so existing parameter indices are unaffected.
135-
- **Never reorder or rewrite assertions to fit a key.** If no ascending key reproduces the asserted sequence, the order is encoded in a column the projection does not carry — that is a query-side or assertion-side fix, not a sort. `CrossDialectJoinTests` has nine such tests, tracked in #332; its `<remarks>` block explains why a plausible-looking composite key silently reorders them.
135+
- **Never reorder or rewrite assertions to fit a key.** If no ascending key reproduces the asserted sequence, the order is encoded in a column the projection does not carry — that is a query-side or assertion-side fix, not a sort. `CrossDialectJoinTests` had nine such tests; #332 resolved them assertion-side with `Is.EquivalentTo` (order-independent, every value still asserted, pinned SQL untouched) rather than with a sort. Its `<remarks>` block explains why a plausible-looking composite key silently reorders them — reach for `Is.EquivalentTo` in the same situation, not a key that merely compiles.
136136
- Order-independent assertions (`Is.EquivalentTo`, `Does.Contain`, `.First(predicate)`, `.All(...)`, count-only) need no sort at all — much of the suite is already written this way.
137137

138138
### Per-dialect entity types

0 commit comments

Comments
 (0)