@@ -17,7 +17,11 @@ const runActor = async (input = {}, options = {}) => {
1717 return await client . run ( runId ) . get ( ) ;
1818} ;
1919
20- test ( 'aliased storages work locally with alias as name' , async ( ) => {
20+ test ( 'aliased storages work locally with purge-on-first-open across restarts' , async ( ) => {
21+ // The actor runs two lifecycle processes in sequence, sharing the same filesystem.
22+ // Each lifecycle creates a fresh Actor instance (resetting purgedStorageAliases),
23+ // opens the aliased dataset (triggering purge on first open), writes data, and
24+ // pushes a summary to the platform default dataset.
2125 const run = await runActor ( ) ;
2226
2327 assert . strictEqual ( run . status , 'SUCCEEDED' ) ;
@@ -29,53 +33,31 @@ test('aliased storages work locally with alias as name', async () => {
2933
3034 assert . strictEqual (
3135 data . count ,
32- 1 ,
33- 'There must be exactly one summary item in the dataset ' ,
36+ 2 ,
37+ 'There must be exactly two summary items (one per lifecycle) ' ,
3438 ) ;
3539
36- const summary = data . items [ 0 ] ;
37-
38- // The dataset should have 3 items total (2 from first open + 1 from second open),
39- // proving that the second open did NOT purge the data
40+ // First lifecycle: fresh local storage, writes 3 items total (2 + 1 from second open)
41+ const firstSummary = data . items [ 0 ] ;
4042 assert . strictEqual (
41- summary . datasetItemCount ,
43+ firstSummary . datasetItemCount ,
4244 3 ,
43- 'Aliased dataset should have 3 items (purge only happened on first open)' ,
44- ) ;
45-
46- // Verify the actual items
47- assert . strictEqual ( summary . datasetItems [ 0 ] . url , 'https://example.com' ) ;
48- assert . strictEqual ( summary . datasetItems [ 0 ] . title , 'Example' ) ;
49- assert . strictEqual ( summary . datasetItems [ 1 ] . url , 'https://example.org' ) ;
50- assert . strictEqual ( summary . datasetItems [ 1 ] . title , 'Example Org' ) ;
51- assert . strictEqual ( summary . datasetItems [ 2 ] . url , 'https://example.net' ) ;
52- assert . strictEqual ( summary . datasetItems [ 2 ] . title , 'Example Net' ) ;
53- } ) ;
54-
55- test ( 'purge-on-first-open works across runs' , async ( ) => {
56- // Run the actor a second time — the aliased storages should be purged again
57- // at the start of this new run (since purgedStorageAliases resets per Actor instance)
58- const run = await runActor ( ) ;
59-
60- assert . strictEqual ( run . status , 'SUCCEEDED' ) ;
61-
62- const dataset = await Dataset . open ( run . defaultDatasetId , {
63- storageClient : client ,
64- } ) ;
65- const data = await dataset . getData ( ) ;
66-
67- assert . strictEqual (
68- data . count ,
69- 1 ,
70- 'There must be exactly one summary item in the dataset' ,
45+ 'First lifecycle: aliased dataset should have 3 items (purge only happened on first open)' ,
7146 ) ;
72-
73- const summary = data . items [ 0 ] ;
74-
75- // Should again be 3 items, not 6 — because the first open purged the stale data from the previous run
47+ assert . strictEqual ( firstSummary . datasetItems [ 0 ] . url , 'https://example.com' ) ;
48+ assert . strictEqual ( firstSummary . datasetItems [ 0 ] . title , 'Example' ) ;
49+ assert . strictEqual ( firstSummary . datasetItems [ 1 ] . url , 'https://example.org' ) ;
50+ assert . strictEqual ( firstSummary . datasetItems [ 1 ] . title , 'Example Org' ) ;
51+ assert . strictEqual ( firstSummary . datasetItems [ 2 ] . url , 'https://example.net' ) ;
52+ assert . strictEqual ( firstSummary . datasetItems [ 2 ] . title , 'Example Net' ) ;
53+
54+ // Second lifecycle: the aliased dataset from the first lifecycle is still on disk.
55+ // The second lifecycle's first openDataset({ alias: 'results' }) should purge it,
56+ // then write 3 fresh items. If purge didn't work, there would be 6 items.
57+ const secondSummary = data . items [ 1 ] ;
7658 assert . strictEqual (
77- summary . datasetItemCount ,
59+ secondSummary . datasetItemCount ,
7860 3 ,
79- 'Aliased dataset should have 3 items (previous run data was purged)' ,
61+ 'Second lifecycle: aliased dataset should have 3 items (stale data from first lifecycle was purged)' ,
8062 ) ;
8163} ) ;
0 commit comments