@@ -25,6 +25,7 @@ import {
2525 selectOldestPercent ,
2626 type ExecuteCleanupOptions ,
2727} from "../src/storage/cleanup" ;
28+ import { STORE_BUDGET_MS } from "./helpers/test-budget" ;
2829
2930const OLD = new Date ( "2026-01-01T00:00:00Z" ) ;
3031const MID = new Date ( "2026-02-01T00:00:00Z" ) ;
@@ -418,7 +419,7 @@ describe("executeArchivedCleanup", () => {
418419 try { logsRead ?. close ( ) ; } catch { /* */ }
419420 try { memoriesRead ?. close ( ) ; } catch { /* */ }
420421 }
421- } , { timeout : 20_000 } ) ;
422+ } , { timeout : STORE_BUDGET_MS } ) ;
422423
423424 test ( "rolls back staged renames when a later rename fails" , ( ) => {
424425 home = buildHome ( ) ;
@@ -639,7 +640,7 @@ describe("executeArchivedCleanup", () => {
639640 const ids = state . query < { id : string } , [ ] > ( "SELECT id FROM threads" ) . all ( ) . map ( r => r . id ) ;
640641 state . close ( ) ;
641642 expect ( ids ) . toEqual ( [ "active" ] ) ;
642- } , { timeout : 20_000 } ) ;
643+ } , { timeout : STORE_BUDGET_MS } ) ;
643644
644645 test ( "threads read failure leaves every file and database unchanged" , ( ) => {
645646 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -666,7 +667,7 @@ describe("executeArchivedCleanup", () => {
666667 expect ( Buffer . compare ( beforeGoals , readFileSync ( join ( home , "goals_1.sqlite" ) ) ) ) . toBe ( 0 ) ;
667668 expect ( Buffer . compare ( beforeMemories , readFileSync ( join ( home , "memories_1.sqlite" ) ) ) ) . toBe ( 0 ) ;
668669 expect ( Buffer . compare ( beforeState , readFileSync ( join ( home , "state_5.sqlite" ) ) ) ) . toBe ( 0 ) ;
669- } , { timeout : 20_000 } ) ;
670+ } , { timeout : STORE_BUDGET_MS } ) ;
670671
671672 // Windows CI: injected satellite rollback paths (especially goals) can measure 6–13s
672673 // there and trip bun's default 5s harness timeout.
@@ -723,7 +724,7 @@ describe("executeArchivedCleanup", () => {
723724 expect ( stateAfter . query ( "SELECT id, rollout_path, archived FROM threads ORDER BY id" ) . all ( ) ) . toEqual ( threads ) ;
724725 stateAfter . close ( ) ;
725726 } ,
726- { timeout : 30_000 } ,
727+ { timeout : STORE_BUDGET_MS } ,
727728 ) ;
728729
729730 test ( "satellite restore failure keeps recovery trashDir and manifest" , ( ) => {
@@ -922,7 +923,7 @@ describe("executeArchivedCleanup", () => {
922923 job_key : ( expected as { job_key : string } ) . job_key ,
923924 } ) ;
924925 }
925- } , { timeout : 30_000 } ) ;
926+ } , { timeout : STORE_BUDGET_MS } ) ;
926927
927928 test ( "permanent cleanup works with logs-only satellite store" , ( ) => {
928929 home = buildHome ( { satellites : "logs" } ) ;
@@ -1012,7 +1013,7 @@ describe("executeArchivedCleanup", () => {
10121013 "active" , "tmid" , "tnew" , "told" ,
10131014 ] ) ;
10141015 state . close ( ) ;
1015- } , { timeout : 30_000 } ) ;
1016+ } , { timeout : STORE_BUDGET_MS } ) ;
10161017
10171018 // Windows CI: same multi-satellite restore profile as above (timed out at 5s on PR #558).
10181019 test ( "concurrent consolidate enqueue watermark change is preserved on restore" , ( ) => {
@@ -1050,7 +1051,7 @@ describe("executeArchivedCleanup", () => {
10501051 "active" , "tmid" , "tnew" , "told" ,
10511052 ] ) ;
10521053 state . close ( ) ;
1053- } , { timeout : 30_000 } ) ;
1054+ } , { timeout : STORE_BUDGET_MS } ) ;
10541055} ) ;
10551056
10561057describe ( "listTrashEntries + restoreTrashEntry" , ( ) => {
@@ -1441,7 +1442,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
14411442 has_user_event : 1 ,
14421443 archived : 1 ,
14431444 } ) ;
1444- } , { timeout : 20_000 } ) ;
1445+ } , { timeout : STORE_BUDGET_MS } ) ;
14451446
14461447 test . each ( [
14471448 [ "failAfterStateCommit" , { failAfterStateCommit : true } , "db_reconcile_failed" ] ,
@@ -1498,7 +1499,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
14981499 expect ( logsAfter . query ( "SELECT COUNT(*) AS n FROM logs WHERE thread_id='told'" ) . get ( ) ) . toEqual ( { n : 1 } ) ;
14991500 logsAfter . close ( ) ;
15001501 } ,
1501- { timeout : 20_000 } ,
1502+ { timeout : STORE_BUDGET_MS } ,
15021503 ) ;
15031504
15041505 test ( "late failure after logs commit keeps metadata, persists pending sections, and resume preserves pre-existing rows" , ( ) => {
@@ -1602,7 +1603,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
16021603 goals . query ( "SELECT COUNT(*) AS n FROM thread_goals WHERE thread_id IN ('told','tmid','tnew')" ) . get ( ) ,
16031604 ) . toEqual ( { n : 2 } ) ; // fixture seeds told+tmid only
16041605 goals . close ( ) ;
1605- } , { timeout : 20_000 } ) ;
1606+ } , { timeout : STORE_BUDGET_MS } ) ;
16061607
16071608 test ( "leftover-stage failure never restages files and retry accepts destinations" , ( ) => {
16081609 // Regression for reverse-move failure after metadata compensation: restage
@@ -1660,7 +1661,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
16601661 logsAfter . query ( "SELECT ts, target FROM logs WHERE id=1" ) . get ( ) ,
16611662 ) . toEqual ( { ts : 42 , target : "pre" } ) ;
16621663 logsAfter . close ( ) ;
1663- } , { timeout : 20_000 } ) ;
1664+ } , { timeout : STORE_BUDGET_MS } ) ;
16641665
16651666 test ( "initial restore-pending write failure moves no files" , ( ) => {
16661667 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1684,7 +1685,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
16841685 expect ( retried . ok ) . toBe ( true ) ;
16851686 expect ( retried . count ) . toBe ( 3 ) ;
16861687 expect ( existsSync ( stage ) ) . toBe ( false ) ;
1687- } , { timeout : 20_000 } ) ;
1688+ } , { timeout : STORE_BUDGET_MS } ) ;
16881689
16891690 test ( "interrupted pending update preserves the previous valid marker" , ( ) => {
16901691 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1721,7 +1722,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
17211722 expect ( retried . ok ) . toBe ( true ) ;
17221723 expect ( retried . error ) . toBeUndefined ( ) ;
17231724 expect ( existsSync ( stage ) ) . toBe ( false ) ;
1724- } , { timeout : 20_000 } ) ;
1725+ } , { timeout : STORE_BUDGET_MS } ) ;
17251726
17261727 test ( "crash after file move retries without dest_exists or fs_failed" , ( ) => {
17271728 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1747,7 +1748,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
17471748 expect ( retried . error ) . not . toBe ( "fs_failed" ) ;
17481749 expect ( retried . count ) . toBe ( 3 ) ;
17491750 expect ( existsSync ( stage ) ) . toBe ( false ) ;
1750- } , { timeout : 20_000 } ) ;
1751+ } , { timeout : STORE_BUDGET_MS } ) ;
17511752
17521753 test ( "mid-move failure keeps placed dest, marker, and resumes without dest_exists" , ( ) => {
17531754 // First rename succeeds, second throws. Do not reverse the first file or drop
@@ -1801,7 +1802,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
18011802 expect ( existsSync ( join ( home , "archived_sessions" , "rollout-old.jsonl" ) ) ) . toBe ( true ) ;
18021803 expect ( existsSync ( join ( home , "archived_sessions" , "rollout-mid.jsonl" ) ) ) . toBe ( true ) ;
18031804 expect ( existsSync ( join ( home , "archived_sessions" , "rollout-new.jsonl" ) ) ) . toBe ( true ) ;
1804- } , { timeout : 20_000 } ) ;
1805+ } , { timeout : STORE_BUDGET_MS } ) ;
18051806
18061807 test ( "malformed restore-pending.json is not treated as a fresh restore" , ( ) => {
18071808 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1819,7 +1820,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
18191820 expect ( existsSync ( join ( stage , "rollout-old.jsonl" ) ) ) . toBe ( true ) ;
18201821 expect ( existsSync ( join ( home , "archived_sessions" , "rollout-old.jsonl" ) ) ) . toBe ( false ) ;
18211822 expect ( readFileSync ( join ( stage , "restore-pending.json" ) , "utf8" ) ) . toBe ( "{not-valid-json" ) ;
1822- } , { timeout : 20_000 } ) ;
1823+ } , { timeout : STORE_BUDGET_MS } ) ;
18231824
18241825 test ( "resume with owed satellite sections and missing backup fails closed" , ( ) => {
18251826 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1850,7 +1851,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
18501851 expect ( failed . error ) . toBe ( "db_reconcile_failed" ) ;
18511852 expect ( existsSync ( stage ) ) . toBe ( true ) ;
18521853 expect ( existsSync ( join ( stage , "manifest.json" ) ) ) . toBe ( true ) ;
1853- } , { timeout : 20_000 } ) ;
1854+ } , { timeout : STORE_BUDGET_MS } ) ;
18541855
18551856 test ( "resume with owed logs section but missing logs in backup fails closed" , ( ) => {
18561857 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1881,7 +1882,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
18811882 expect ( existsSync ( stage ) ) . toBe ( true ) ;
18821883 expect ( existsSync ( join ( stage , "manifest.json" ) ) ) . toBe ( true ) ;
18831884 expect ( existsSync ( join ( stage , "restore-pending.json" ) ) ) . toBe ( true ) ;
1884- } , { timeout : 20_000 } ) ;
1885+ } , { timeout : STORE_BUDGET_MS } ) ;
18851886
18861887 test ( "failed tombstone rename keeps stage recoverable and listed" , ( ) => {
18871888 home = buildHome ( ) ;
@@ -1905,7 +1906,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
19051906 expect ( retried . ok ) . toBe ( true ) ;
19061907 expect ( existsSync ( stage ) ) . toBe ( false ) ;
19071908 expect ( listTrashEntries ( home ) ) . toEqual ( [ ] ) ;
1908- } , { timeout : 20_000 } ) ;
1909+ } , { timeout : STORE_BUDGET_MS } ) ;
19091910
19101911 test ( "tombstone delete failure reports success without phantom trash entry" , ( ) => {
19111912 home = buildHome ( ) ;
@@ -1925,7 +1926,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
19251926 const trashRoot = join ( home , ".trash" ) ;
19261927 const tombstones = readdirSync ( trashRoot ) . filter ( n => n . startsWith ( ".tombstone-" ) ) ;
19271928 expect ( tombstones . length ) . toBe ( 1 ) ;
1928- } , { timeout : 20_000 } ) ;
1929+ } , { timeout : STORE_BUDGET_MS } ) ;
19291930
19301931 test ( "cleanup rejects overlap with accepted restore-pending destinations after state-commit failure" , ( ) => {
19311932 home = buildHome ( { withSatelliteStores : true } ) ;
@@ -1961,7 +1962,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
19611962 const retry = restoreTrashEntry ( trashId , { codexHome : home } ) ;
19621963 expect ( retry . ok ) . toBe ( true ) ;
19631964 expect ( existsSync ( join ( home , restoredRel ) ) ) . toBe ( true ) ;
1964- } , { timeout : 20_000 } ) ;
1965+ } , { timeout : STORE_BUDGET_MS } ) ;
19651966
19661967 test ( "cleanup rejects overlap with accepted restore-pending destinations after file-move failure" , ( ) => {
19671968 home = buildHome ( ) ;
@@ -1996,7 +1997,7 @@ describe("listTrashEntries + restoreTrashEntry", () => {
19961997
19971998 const retry = restoreTrashEntry ( trashId , { codexHome : home } ) ;
19981999 expect ( retry . ok ) . toBe ( true ) ;
1999- } , { timeout : 20_000 } ) ;
2000+ } , { timeout : STORE_BUDGET_MS } ) ;
20002001
20012002 test ( "percent preview backfills past pending oldest archive for manual cleanup" , ( ) => {
20022003 home = buildHome ( ) ;
0 commit comments