@@ -33,7 +33,36 @@ afterEach(() => {
3333 }
3434} ) ;
3535
36- effectIt . layer ( NodeServices . layer ) ( "asynchronous rotating file sink" , ( it ) => {
36+ effectIt . layer ( NodeServices . layer ) ( "rotating file sinks" , ( it ) => {
37+ it . effect . each ( [ "synchronous" , "asynchronous" ] as const ) (
38+ "%s startup prunes only canonical rotation suffixes" ,
39+ ( mode ) =>
40+ Effect . gen ( function * ( ) {
41+ const directory = makeTempDirectory ( ) ;
42+ const filePath = NodePath . join ( directory , "debug.log" ) ;
43+ const retained = [ "1" , "3" , "04" , "4.0" , "4e0" , "0x4" , "+4" , "notes" ] ;
44+ for ( const suffix of [ ...retained , "4" , "50" ] ) {
45+ NodeFS . writeFileSync ( `${ filePath } .${ suffix } ` , suffix ) ;
46+ }
47+ const options = { filePath, maxBytes : 100 , maxFiles : 3 } ;
48+
49+ const sink =
50+ mode === "synchronous"
51+ ? new RotatingFileSink ( options )
52+ : yield * makeAsyncRotatingFileSink ( options ) ;
53+ if ( sink instanceof RotatingFileSink ) sink . write ( "current" ) ;
54+ else yield * sink . write ( "current" ) ;
55+
56+ expect ( NodeFS . readdirSync ( directory ) . sort ( ) ) . toEqual (
57+ [ "debug.log" , ...retained . map ( ( suffix ) => `debug.log.${ suffix } ` ) ] . sort ( ) ,
58+ ) ;
59+ expect ( NodeFS . readFileSync ( filePath , "utf8" ) ) . toBe ( "current" ) ;
60+ for ( const suffix of retained ) {
61+ expect ( NodeFS . readFileSync ( `${ filePath } .${ suffix } ` , "utf8" ) ) . toBe ( suffix ) ;
62+ }
63+ } ) ,
64+ ) ;
65+
3766 it . effect ( "serializes concurrent appends across rotation and resumes an existing file" , ( ) =>
3867 Effect . gen ( function * ( ) {
3968 const directory = makeTempDirectory ( ) ;
0 commit comments