@@ -4,6 +4,7 @@ import os from "node:os";
44import path from "node:path" ;
55import { afterEach , describe , expect , it } from "vitest" ;
66import {
7+ decodeSessionArchiveBytes ,
78 encodeSessionArchiveContent ,
89 materializeSessionArchiveForRead ,
910 readSessionArchiveContentSync ,
@@ -30,6 +31,31 @@ function makeTempDir(): string {
3031}
3132
3233describe ( "archive compression" , ( ) => {
34+ it ( "decodes both plain bytes and runtime-supported compressed archive bytes" , ( ) => {
35+ const content = `${ JSON . stringify ( { type : "message" , body : "archive round trip" } ) } \n` ;
36+ const encoded = encodeSessionArchiveContent ( content ) ;
37+
38+ expect ( decodeSessionArchiveBytes ( Buffer . from ( content , "utf8" ) , false ) ) . toBe ( content ) ;
39+ expect ( decodeSessionArchiveBytes ( encoded . bytes , encoded . suffix !== "" ) ) . toBe ( content ) ;
40+ } ) ;
41+
42+ it ( "invalidates a materialized cache when its source archive is removed" , ( ) => {
43+ const encoded = encodeSessionArchiveContent ( "cached archive contents\n" ) ;
44+ if ( encoded . suffix !== SESSION_ARCHIVE_ZSTD_SUFFIX ) {
45+ return ;
46+ }
47+ const dir = makeTempDir ( ) ;
48+ const archivePath = path . join ( dir , `removed.jsonl.deleted.2026-07-11${ encoded . suffix } ` ) ;
49+ fs . writeFileSync ( archivePath , encoded . bytes ) ;
50+ const cachePath = materializeSessionArchiveForRead ( archivePath ) ;
51+ expect ( fs . existsSync ( cachePath ) ) . toBe ( true ) ;
52+
53+ fs . rmSync ( archivePath ) ;
54+
55+ expect ( ( ) => materializeSessionArchiveForRead ( archivePath ) ) . toThrow ( ) ;
56+ expect ( fs . existsSync ( cachePath ) ) . toBe ( false ) ;
57+ } ) ;
58+
3359 it ( "round-trips archived transcript content through encode and read" , ( ) => {
3460 const content = `${ JSON . stringify ( { type : "message" , body : "hello" } ) } \n` . repeat ( 200 ) ;
3561 const encoded = encodeSessionArchiveContent ( content ) ;
0 commit comments