|
| 1 | +# Brief: S1-D3 — M:N include integration tests (operator standard) |
| 2 | + |
| 3 | +## Task |
| 4 | + |
| 5 | +Prove the M:N include works end-to-end against the database, following the project's **integration-test standard**. The fixture (S1-D1) defines `User.tags` (→ `Tag` via `UserTag`); the read path (S1-D2) compiles the correlated junction subquery. Add integration tests under `test/integration/test/sql-orm-client/` (alongside `include.test.ts` / `nested-includes.test.ts`), using the existing harness (`withCollectionRuntime`, PGlite). Seed users, tags, and `user_tags` junction rows, then assert `db.orm.User.include('tags')` returns the expected shape. |
| 6 | + |
| 7 | +**The standard (all three apply):** |
| 8 | +1. **Whole-row assertions** — `toEqual` (or snapshot) on the complete returned rows; never cherry-pick individual fields. |
| 9 | +2. **Explicit `.select(...)` in most tests** — project the fields each test asserts (user-level and nested `tags`-level), so adding a field to `User`/`Tag` later doesn't churn these assertions. Assert the whole *selected* shape. |
| 10 | +3. **≥1 implicit/default-selection test** — at least one test does `include('tags')` with **no** `.select`, asserting the full default row shape (all `User` fields + `tags: Tag[]` with all `Tag` fields) comes back. |
| 11 | + |
| 12 | +Plus: |
| 13 | +- **Single execution** — assert the M:N include runs in **one** SQL execution (the harness's query-count/exec hook if available; otherwise assert no `LATERAL` in the emitted SQL). Mirror how `include.test.ts` / `nested-includes-strategy.test.ts` verify execution count if they do. |
| 14 | +- **Depth-2** — a test that nests another include under the M:N read (or M:N nested under a 1:N), to prove the junction walk composes with deeper includes. |
| 15 | +- Edge: a user with **no** tags returns `tags: []`; a tag connected to multiple users still resolves correctly. |
| 16 | + |
| 17 | +## Scope |
| 18 | + |
| 19 | +**In:** new integration test file(s) under `test/integration/test/sql-orm-client/`; any seed/helper needed there. |
| 20 | + |
| 21 | +**Out:** filter (slice 2); write (slice 3); production code changes (D2 owns the read path — if a test reveals a read **bug**, surface it, don't fix production here without flagging). Do not modify the fixture (D1 owns it). |
| 22 | + |
| 23 | +## Completed when |
| 24 | + |
| 25 | +- [ ] M:N `include('tags')` integration tests pass on PGlite: whole-row `toEqual`; **most** use explicit `.select`; **≥1** uses implicit/default selection; depth-2 covered; empty-tags and shared-tag cases covered. |
| 26 | +- [ ] A single-execution assertion (no `LATERAL`, one query) for the M:N include. |
| 27 | +- [ ] Gate: the new tests run green — `cd test/integration && pnpm test test/sql-orm-client/<your-file>` (this is how the sql-orm-client integration suite runs in-sandbox; the CLI-journey e2e tests are the ones with the known env limitation, not these). |
| 28 | + |
| 29 | +## Standing instruction |
| 30 | + |
| 31 | +Match the existing integration corpus's style (whole-row `toEqual`); add the explicit-select-dominant + implicit-select cases the standard requires. If a test surfaces a real read-path bug, **surface it to me** with the failing assertion — that would be a `must-fix` against D2, not something to patch here. |
| 32 | + |
| 33 | +## References |
| 34 | + |
| 35 | +- Existing corpus: `test/integration/test/sql-orm-client/include.test.ts`, `nested-includes.test.ts`, `nested-includes-strategy.test.ts` (assertion + execution-count patterns to mirror). |
| 36 | +- Slice spec: `projects/sql-orm-many-to-many/slices/01-correlated-read-through-junction/spec.md` (§ done conditions — the standard). |
| 37 | +- Fixture: `User.tags` M:N via `UserTag` (commit `fcecac5b3`). |
| 38 | + |
| 39 | +## Operational metadata |
| 40 | + |
| 41 | +- **Model tier:** sonnet. |
| 42 | +- **Branch:** `tml-2785-slice-1-correlated-read`. Explicit staging + `-s` sign-off. **Do not push.** |
| 43 | +- **Time-box:** ~75 min — write the core whole-row + implicit-select tests first, get them green, then add depth-2/edge cases; don't over-explore. |
| 44 | +- **Halt + surface to me:** if the sql-orm-client integration harness genuinely cannot run in-sandbox (PGlite spin-up failure unrelated to your tests), describe the failure — don't claim green without running. If `include('tags')` returns a wrong shape (read-path bug in D2), surface it. |
0 commit comments