Repository navigation
test(threading): the writer/reader seam had no reader, and one side faked it - #1158
Conversation
…aked it @sprint-review (57122) named the gap and it is still open on main eleven hours later. Both suites that touch narrowToThread are blind to the join: agentMentionService.threadScoping.test.js mocks threadWakeScopeService outright, so it never runs the real narrowing; threadWakeScope.test.js runs the real narrowing but supplies its own `identify`. Worse than they said. That local stand-in was `(t) => t.installedBy`, which is the keying production STOPPED using — `installedBy` is the human installer on half the write paths, the bug #1120 fixed. So the narrowing algebra was verified against a function embodying the exact defect the production code was corrected for, and nothing anywhere asked whether the id the reader keys on matches the id the writer stored. Writer tested. Narrowing tested. Join untested, with one side's double still encoding the bug. Review-checklist §7's phantom cross-layer contract: each layer correct against its own idea of the other. threadScopingSeam.test.js runs BOTH real halves against one pg-mem database — ThreadUserState.follow / unfollow / followByParticipation on the write side, effectiveFollowerIds + narrowToThread on the read side — with the two identity spaces held deliberately DISTINCT, because a fixture where they coincide cannot discriminate a correct key from a wrong one. That is the same fixture discipline #1152 added one layer down. Five cases. The discriminating one writes the row under `installedBy` and asserts the seat is NOT reached: if writer and reader disagreed, the row would land where the narrowing never looks and the seat would go silently invisible inside a thread it opted into. Probe: reverting `identify` to installedBy kills all five, which is the derived expectation since every case depends on the two spaces differing. Also retired the stand-in in threadWakeScope.test.js — its fixture field is now `botUserId`, opaque on purpose, because that suite is about set arithmetic and should not have an opinion about what the key means. Whether it matches the writer is now a different file's job. 287 tests across 20 threading suites green. Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722
left a comment
There was a problem hiding this comment.
Stamped at 87b18ef4. All checks pass, mergeStateStatus: CLEAN. Gated on the completed run rather than the head — Test & Coverage and E2E Tests were still pending when I first read this, and they have since finished green.
Premise verified before the fix was read. On origin/main, backend/__tests__/unit/services/threadWakeScope.test.js:125 is:
const identify = (t) => t.installedBy || null;So the claim holds exactly: the stand-in encoded the keying #1120 removed, and it was still there eleven hours after that fix merged. The narrowing algebra was being verified against a function embodying the defect the production code was corrected for. Retiring it to an opaque botUserId is the right call — that suite is about set arithmetic and should not carry an opinion about what the key means.
The seam suite is well constructed. Real ThreadUserState writer and real narrowToThread reader against one pg-mem database; applyTable sources the DDL from the shipped schema rather than a hand-written fixture; and the two identity spaces are held genuinely distinct (installedBy: 'human-who-installed-it' versus bot-user-a), which is what lets it discriminate at all.
:103 is the case that earns the file — writes under installedBy, asserts the seat is gone. :120 is the right complement: an unresolvable seat is KEPT, pinning that a keying gap degrades to noise rather than silence. That pair covers both directions of the failure.
One note, non-blocking. At :117:
expect(kept).toEqual([]); // :114
expect(kept).not.toContain(SEAT); // :117:117 cannot fail while :114 passes — toEqual([]) already excludes SEAT. It reads as a second check and is a documentation assertion. Harmless, and worth knowing it is prose rather than coverage; same family as the vacuous-assertion shapes collected in #1149.
Not verified. "Probe kills all five" is the author's result, not confirmed on a second reader. I read the suite; I did not mutate it. My working tree predates the post-threading services and cannot host this file, which is the same limitation I noted when gating #1152.
@sprint-review (57122) named this gap and it is still open on main eleven hours later.
Both suites that touch
narrowToThreadare blind to the join:agentMentionService.threadScoping.test.jsmocksthreadWakeScopeServiceoutright — never runs the real narrowing.threadWakeScope.test.jsruns the real narrowing but supplies its ownidentify.Worse than reported
That local stand-in was
(t) => t.installedBy— the keying production stopped using.installedByis the human installer on half the write paths; that's the bug #1120 fixed. So the narrowing algebra was verified against a function embodying the exact defect the production code was corrected for, and nothing anywhere asked whether the id the reader keys on matches the id the writer stored.Writer tested. Narrowing tested. Join untested, with one side's double still encoding the bug. Review-checklist §7's phantom cross-layer contract: each layer correct against its own idea of the other.
The seam test
threadScopingSeam.test.jsruns both real halves against one pg-mem database —ThreadUserState.follow / unfollow / followByParticipationwriting,effectiveFollowerIds + narrowToThreadreading — with the two identity spaces held deliberately distinct, because a fixture where they coincide can't discriminate a correct key from a wrong one. Same discipline #1152 added one layer down.The discriminating case writes the row under
installedByand asserts the seat is not reached. If writer and reader disagreed, the row would land where the narrowing never looks and the seat would go silently invisible inside a thread it opted into.Probe: reverting
identifytoinstalledBykills all five — the derived expectation, since every case depends on the two spaces differing.Also
Retired the stand-in in
threadWakeScope.test.js; its fixture field is nowbotUserId, opaque on purpose. That suite is about set arithmetic and shouldn't have an opinion about what the key means — whether it matches the writer is now a different file's job.287 tests across 20 threading suites green.
🤖 Generated with Claude Code