Skip to content

Commit f501453

Browse files
claude[bot]claude
andauthored
test: pin the call count where a repeat would be a defect (#15607) (#15782)
A census of `toHaveBeenCalledWith` across `packages/**`, `examples/**` and `apps/**` found 811 assertions, 763 of them standalone — no sibling `toHaveBeenCalledTimes` / `toHaveBeenCalledOnce` / `mock.calls.length` on the same spy in the same test. Most of those genuinely do not care about arity and are left alone on purpose. Nine do care, and all nine sit on a path where a doubled call is a defect the assertion cannot see: irreversible byte deletes in a reap sweep, a retry backoff, and seed application — the class the card was filed from. Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk Co-authored-by: Claude <noreply@anthropic.com>
1 parent 044403e commit f501453

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

packages/runtime/src/seed-loader.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ describe('SeedLoaderService', () => {
11191119

11201120
expect(result.success).toBe(true);
11211121
expect(result.summary.totalErrored).toBe(0);
1122+
// One record ⇒ one write; a repeat here would be a double seed (#15607).
1123+
expect(engine.insert).toHaveBeenCalledTimes(1);
11221124
expect(engine.insert).toHaveBeenCalledWith(
11231125
'note',
11241126
expect.objectContaining({ name: 'N1', author: 'usr_system' }),
@@ -1152,6 +1154,8 @@ describe('SeedLoaderService', () => {
11521154

11531155
expect(result.success).toBe(true);
11541156
expect(result.summary.totalErrored).toBe(0);
1157+
// One record ⇒ one write; a repeat here would be a double seed (#15607).
1158+
expect(engine.insert).toHaveBeenCalledTimes(1);
11551159
expect(engine.insert).toHaveBeenCalledWith(
11561160
'note',
11571161
expect.objectContaining({ name: 'N1', author: null }),
@@ -1180,6 +1184,10 @@ describe('SeedLoaderService', () => {
11801184
});
11811185

11821186
expect(result.success).toBe(true);
1187+
// One record, mode 'insert' ⇒ exactly ONE engine write. Seed application is
1188+
// the very path where a doubled collect writes twice and stays green under
1189+
// `toHaveBeenCalledWith` (#15607).
1190+
expect(engine.insert).toHaveBeenCalledTimes(1);
11831191
expect(engine.insert).toHaveBeenCalledWith(
11841192
'note',
11851193
expect.objectContaining({ org_label: 'org_123' }),

packages/services/service-storage/src/attachment-lifecycle.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ describe('createSysFileReapGuard', () => {
418418
{ id: 'f1', key: 'attachments/f1.bin', status: 'deleted', scope: 'attachments' },
419419
]);
420420

421+
// ONE tombstoned row in ⇒ exactly ONE irreversible byte delete: the count IS
422+
// the contract for a sweep that re-runs, and `toHaveBeenCalledWith` alone is
423+
// satisfied by a repeat just as well as by a single call (#15607).
424+
expect(s.delete).toHaveBeenCalledTimes(1);
421425
expect(s.delete).toHaveBeenCalledWith('attachments/f1.bin');
422426
expect(confirmed).toEqual(['f1']);
423427
});
@@ -467,6 +471,9 @@ describe('createSysFileReapGuard', () => {
467471
{ id: 'f1', key: 'user/f1.png', status: 'deleted', scope: 'user', ref_object: null, ref_id: null },
468472
]);
469473

474+
// One released field file, one open gate ⇒ exactly one byte delete; a second
475+
// call would be a re-reap of a key already gone (#15607).
476+
expect(s.delete).toHaveBeenCalledTimes(1);
470477
expect(s.delete).toHaveBeenCalledWith('user/f1.png');
471478
expect(confirmed).toEqual(['f1']);
472479
});
@@ -566,6 +573,8 @@ describe('createSysFileReapGuard', () => {
566573
{ id: 'p1', key: 'user/p1.bin', status: 'pending' },
567574
]);
568575

576+
// Best-effort cleanup of ONE abandoned upload — exactly one delete (#15607).
577+
expect(s.delete).toHaveBeenCalledTimes(1);
569578
expect(s.delete).toHaveBeenCalledWith('user/p1.bin');
570579
expect(confirmed).toEqual(['p1']);
571580
});

packages/services/service-storage/src/lax-deviation-reclamation-gate.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ describe('the reclamation gate refuses to delete bytes while a deviation stands
182182
});
183183

184184
expect(await guard('sys_file', [{ ...RELEASED_FIELD_FILE }])).toEqual(['f1']);
185+
// The guard ran TWICE in this test: withheld first, authorised second. So the
186+
// count is the whole point — 1 proves the withheld pass deleted nothing, and
187+
// `toHaveBeenCalledWith` alone would pass just the same if it had (#15607).
188+
expect(s.delete).toHaveBeenCalledTimes(1);
185189
expect(s.delete).toHaveBeenCalledWith('user/f1.png');
186190
});
187191

@@ -201,6 +205,8 @@ describe('the reclamation gate refuses to delete bytes while a deviation stands
201205
// reach a lifecycle that never gated on the flag would be the borrowed-
202206
// evidence error in the other direction.
203207
expect(confirmed).toEqual(['a1']);
208+
// One attachment-scope tombstone ⇒ exactly one byte delete (#15607).
209+
expect(s.delete).toHaveBeenCalledTimes(1);
204210
expect(s.delete).toHaveBeenCalledWith('attachments/a1.bin');
205211
});
206212
});

packages/spec/src/shared/resilient-fetch.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ describe('resilientFetch', () => {
6464
const fetchImpl = scripted([[429, { 'retry-after': '2' }], 200]);
6565
const sleep = vi.fn(noSleep);
6666
await resilientFetch('http://x', {}, { fetchImpl, sleep, retries: 3 });
67+
// One 429 ⇒ exactly ONE backoff. This is a retry path, where a doubled sleep
68+
// is a real defect and `toHaveBeenCalledWith(2000)` cannot see it (#15607).
69+
expect(sleep).toHaveBeenCalledTimes(1);
6770
expect(sleep).toHaveBeenCalledWith(2000);
6871
});
6972

0 commit comments

Comments
 (0)