Apply the AGENTS.md comments guideline to every .ts under tests/: remove what the code already expresses, keep only what it cannot. Removed: spec-header coverage inventories the describe/test tree already names; comments restating the next line's assertion or its message; helper JSDoc whose body already says it; within-file duplicates; five stale claims (trendChart's "six aggregated turns" against agg.length === 8, agentGraph's "six categories" against CATS' seven, fold-timing's "cheapest call LAST" against a loop that feeds it first, fold-surface's unreachable plain-JSON note, contextView's "two turns" for a one-turn fixture). Kept and condensed: the projection-freeze class, strict wire/state-schema hazards, retention and pricing windows, pairing rules, hostile-input rationale, fixture and expectation-array ground truth, jsdom mechanics, and issue-numbered regressions. Comment lines 2604 -> 2014 (-22%); 85 module headers kept, 30 coverage inventories dropped; every surviving comment line is within the 140-column limit, with 36 wrapped lines joined onto fuller ones. No logic, string, identifier, import or directive changed: a comment-strip gate proves each file's comment-free code is byte-identical to HEAD, and a line-level proof pairs all 845 changed lines with an unchanged code part. pnpm run lint && pnpm run test (106 files / 2061 tests, per-file 100% coverage) && pnpm run build all pass.
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
// Per-session modal stores (src/client/modalStore.ts): identity, observable set semantics, and the deferred
|
|
// token-consume guards. Session ids are unique per test so the module-level Maps never leak between cases.
|
|
|
|
import assert from 'node:assert/strict'
|
|
import { describe, test } from 'vitest'
|
|
import { modalStoreOf, setPendingConsume, takePendingConsume, type ConsumeGuard } from '../../src/client/modalStore'
|
|
|
|
describe('modalStoreOf', () => {
|
|
test('returns the same store per session id and distinct stores across ids', () => {
|
|
assert.equal(modalStoreOf('modal-same-a'), modalStoreOf('modal-same-a'))
|
|
assert.notEqual(modalStoreOf('modal-same-a'), modalStoreOf('modal-same-b'))
|
|
})
|
|
|
|
test('starts closed and reports state through getSnapshot', () => {
|
|
const store = modalStoreOf('modal-initial')
|
|
assert.equal(store.getSnapshot(), false)
|
|
})
|
|
|
|
test('set with the same value does not notify', () => {
|
|
const store = modalStoreOf('modal-noop')
|
|
let calls = 0
|
|
store.subscribe(() => { calls++ })
|
|
store.set(false)
|
|
assert.equal(calls, 0)
|
|
})
|
|
|
|
test('set with a flipped value notifies once per change', () => {
|
|
const store = modalStoreOf('modal-flip')
|
|
let calls = 0
|
|
store.subscribe(() => { calls++ })
|
|
store.set(true)
|
|
assert.equal(calls, 1)
|
|
assert.equal(store.getSnapshot(), true)
|
|
store.set(true)
|
|
assert.equal(calls, 1)
|
|
store.set(false)
|
|
assert.equal(calls, 2)
|
|
assert.equal(store.getSnapshot(), false)
|
|
})
|
|
|
|
test('unsubscribe stops notifications', () => {
|
|
const store = modalStoreOf('modal-unsub')
|
|
let calls = 0
|
|
const unsubscribe = store.subscribe(() => { calls++ })
|
|
store.set(true)
|
|
assert.equal(calls, 1)
|
|
unsubscribe()
|
|
store.set(false)
|
|
assert.equal(calls, 1)
|
|
})
|
|
})
|
|
|
|
describe('pending consume guards', () => {
|
|
test('take returns the guard once, then undefined', () => {
|
|
const guard: ConsumeGuard = { kind: 'bare-token', token: '/context' }
|
|
setPendingConsume('consume-once', guard)
|
|
assert.equal(takePendingConsume('consume-once'), guard)
|
|
assert.equal(takePendingConsume('consume-once'), undefined)
|
|
})
|
|
|
|
test('take on an absent guard returns undefined', () => {
|
|
assert.equal(takePendingConsume('consume-absent'), undefined)
|
|
})
|
|
|
|
test('guards are isolated per session', () => {
|
|
const guard: ConsumeGuard = { kind: 'span', span: { start: 0, end: 8, draftRev: 1 } }
|
|
setPendingConsume('consume-iso-a', guard)
|
|
assert.equal(takePendingConsume('consume-iso-b'), undefined)
|
|
assert.equal(takePendingConsume('consume-iso-a'), guard)
|
|
})
|
|
})
|