Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/development/review-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ And then note where the fix landed. Someone hit the audience gap, felt it, and b
39. **A test run's summary line is not its verdict — read the suite count before the colour, and never read a status through a pipe.** Two halves, and the second is the mechanism rather than a second symptom. **A status read through a pipe is the pipeline's status, not the command's**: `cmd | grep …` reports *grep's* exit, so a filter line that matches makes the visible outcome a success no matter what the command returned — `npx jest <file> 2>&1 | grep -E "Tests:|✕"` matched the `Tests:` line, so the shell saw 0 and the author read a pass jest had never given. Run the command unpiped, or print `$?` from the command itself. And read the **count** before the colour, because the count is the part a filter cannot flatter: `Tests: 0 total` is the shape of "nothing ran", and "nothing ran" is the one reading that is never a pass. Measured in a worktree with no `cli/node_modules`, from `cli/`: `npx --yes jest` and plain `npx jest </dev/null` both print `Test Suites: 49 failed, 49 total` / `Tests: 0 total` and exit **1**. Read together those lines are unmistakable. The control is a tree that *has* the modules — `1 passed, 15 passed`, exit 0 — because a zero-test run has to be distinguished from a run you did not execute. So quote all three lines, name the invocation, and never build a verdict on the absence of a complaint. *(Earned: 2026-09-26, TASK-069. A gate reported that `npx jest` in a module-less worktree "reports `Tests: 0 total` and exits 0"; the exit code had never been printed, only filtered away, and the correction came from that author with the invocation attached — along with the mechanism this rule now leads with, that a matched `grep` makes the visible outcome success regardless of what the command returned. The other half of the report is the half to keep: a zero-test pass is a failed instrument, the same false reassurance as a dry run that never decrypts. The exit-code *fact* was an inference and is corrected; the exit-code *habit* is the fix, and `&&` chains and CI do stop.)*

40. **A mutation's magnitude is machine-local, so report the sweep and a margin-chosen arm, not a single number.** "A 5 ms injected delay reddens this test" is a claim about the machine it was measured on, and a reviewer who cannot reproduce it has not found a contradiction — they have found a faster box. Report the threshold sweep, the arm chosen with margin above the slowest observed threshold, and both machines once both have been measured, because a single-point arm invites the next reader to diagnose a discrepancy that is a property of the hardware. The same holds for any arm whose effect is a race, a timeout or a scheduling cost: choose the magnitude from the sweep rather than from the smallest value that worked. *(Earned: 2026-09-26, TASK-129/#1914. The fix replaced a fixed turn count with a poll-until-ready helper; an injected delay in the mocked mount chain reddened the base test at 2 ms, 5 ms and 10–100 ms on one box but stayed green on the reviewer's box at 5 ms and red at 50 ms, with nothing between measured there, so the first published arm — "5 ms reddens it 3/3" — did not reproduce and read as a bad arm. Re-aimed by sweep (0–1 ms green, 2–5 ms 1 failed, 10–100 ms 3 failed) with **50 ms** chosen for margin, which then reproduced in both environments: base 3 failed of 9, head 9 passed of 9. The reviewer's own sharpening, adopted here: a diagnosis that predicts the next measurement is worth more than the original count.)*

## Clearing a field

41. **A `$set` that names a declared path can still write nothing — on a strict subdocument `undefined` is a NO-OP — so a clear has to be a VALUE, and WHICH value and which verb are decided by the reader, not by the writer.** Its own entry rather than a rider on rule 24, because every guard that rule sends you to check passes here — the path is declared, the spelling is right, the query matches, validators are irrelevant — and the write still does not happen, leaving the previous value on the row. Measured against `backend/models/Integration.ts`'s strict `config` on a real mongod: `$set {'config.providerSubject': undefined}` leaves the old subject in place, `$set {'config.providerSubject': null}` clears it, and a real string writes normally. The mock is not at fault and cannot be fixed: an assertion on the `$set` PAYLOAD reads `undefined` identically whether the store clears the field or does nothing, so this class is invisible to every suite that stops at the payload — the ordinary shape of a route test. Three checks, and they are three because the first two defeat each other if you stop there.

**An omitted update is not a clear.** `undefined` on a `$set` path writes nothing at all; where that is the code's intent — an optional field the caller simply did not send — the path must not be in the `$set` in the first place, and putting a sentinel there to "produce a value" silently overwrites a field nobody asked to change. Reach for a clear only where the code means the stored value must go away: a disconnect, a re-auth that invalidated the old credential, an account change. Say which of the two it is, because every line below differs between them.

**A clear is a value, and the verb is chosen by the READER.** `null` stores null; `$unset` removes the key. They are the same only to a reader testing `x == null` or `if (x)` — `'x' in doc`, `Object.keys` and `doc.toObject()` tell them apart, and `$unset` on a path a consumer enumerates changes the keys it sees. **A validator does not choose between them, and this is the one clause of this rule's first version that was wrong: neither clear satisfies `required`.** Measured on the locked mongoose 7.8.6 against a real mongod, four readings of a `required` path all come back `required` — an absent key, `null` on a fresh document, `null` on a hydrated one, and the key after `$unset` — with a real string the only `VALID` of the four. So a `required` path cannot be cleared at all, by either verb, and a `required` failure is evidence about the clear rather than about which verb was used. Validation is also opt-in per update: `updateOne` and `findOneAndUpdate` run no validators unless `runValidators: true`, and with it set both verbs fail `required` identically. Pick by what reads the field, and name it in the comment.

**Never convert with `||` where a legal value is falsy.** `x || null` turns a deliberate `false` into `null` and a limit of `0` into `null`, and this model is full of both: `config` declares Booleans at `models/Integration.ts:270,286,301,304,397,398` and Numbers at `:272,276,299,372`. `x ?? null` is the shape when only `undefined`/`null` should become the clear value; `||` is safe only where every legal value is truthy — the `credentialRef`, `refreshTokenRef` and `providerSubject` String paths the instances below come from — and even there it is a fact to check about that path, not a habit to carry to the next one.

Then keep one test per write path that drives the writer against a real in-memory Mongo and reads the row back, because the round-trip is the only instrument that can witness a no-op — and assert that the fields *beside* the cleared one are untouched, since a write that replaces the whole subdocument passes any assertion aimed at the single field. The failure itself is not a crash: it is a stale value nobody complains about, quiet for exactly as long as nothing compares it, and loud only where that comparison is a security decision. *(Earned: 2026-09-29, TASK-172 slice 3, three instances inside one slice — an unprefixed `$set` (rule 24's instance), a retired `refreshTokenRef` that survived a clear because `undefined` does not clear, and `providerSubject`: a token exchange that returned no ID token left the previous vendor account's subject on the row, so the next reconnect compared against a stale value, read "same account", and kept grants minted under whatever account held the row in between — the account-change rule that subject exists to enforce. The fix is a value in all three places, `|| null` there because all three are String paths whose legal values are all truthy — and precisely NOT the general prescription, since the same subdocument declares Booleans and Numbers where `||` would destroy a `false` or a `0`, which is the half Rhea's hold on the first version of this rule added. Her second hold removed a `required` distinction that does not exist — measured, either clear fails it, and an update validates neither verb unless `runValidators` is set — which is worth knowing about the rule itself: the first version coupled a real reader-visible distinction to a validator claim that was never run. The witness is a real-schema arm whose two assertions fail on the old code and pass on the new; that arm merges with the slice (TASK-172's stored-row callback suite, not on `main` when this rule was cut), which is why the rule is cut ahead of its code — a reviewer of the next connector write does not have to wait for it.)*
Loading