/** * SMI-5358: QuarantineService Concurrency / Race Tests * * Existing coverage (QuarantineService.test.ts) only exercises single, strictly * sequential reviews. These tests model OVERLAPPING reviewer/writer operations * against the SAME quarantine entry and assert the concurrency invariants that * protect against lost updates and illegal state transitions: * * 1. Two reviewers racing to decide one SUSPICIOUS entry (approve vs reject) * -> exactly one wins, the loser is rejected as ALREADY_REVIEWED, and the * persisted DB state reflects the winner's decision (no lost update). * 2. A stale-snapshot ("optimistic version") writer whose read predates another * reviewer's decision -> the stale write is rejected, persisted state is * unchanged from the winner. * 3. MALICIOUS double-approval by the SAME reviewer -> the second is rejected, * only one approval row exists, and the entry does NOT illegally transition. * 4. MALICIOUS approval by two DISTINCT reviewers reaching the required count * -> the entry transitions to approved EXACTLY once with exactly two * approval rows (no double-count, no double-transition). * * HONESTY NOTE: better-sqlite3 is fully SYNCHRONOUS, so genuine OS-thread * interleaving is not achievable in-process. `Promise.all` / `Promise.allSettled` * here schedule each synchronous `service.review()` as a microtask; each call * therefore runs to completion atomically rather than truly interleaving. We are * NOT faking parallelism. What we test is the REAL concurrency invariant: the * read-then-act guard (`reviewStatus !== 'pending'`), the per-reviewer guard * (`hasReviewerApproved`), and the approval-count check are what prevent lost * updates / illegal transitions when overlapping operations target the same * entry. All assertions read the PERSISTED DB state after the race, never a mock * return value. Removing any of those guards makes the persisted state * inconsistent and fails these tests. */ export {}; //# sourceMappingURL=QuarantineService.concurrency.test.d.ts.map