@@ -306,6 +306,97 @@ describe("file/time", () => {
306306 } )
307307 } )
308308
309+ describe ( "path normalization" , ( ) => {
310+ test ( "read with forward slashes, assert with backslashes" , async ( ) => {
311+ await using tmp = await tmpdir ( )
312+ const filepath = path . join ( tmp . path , "file.txt" )
313+ await fs . writeFile ( filepath , "content" , "utf-8" )
314+ await touch ( filepath , 1_000 )
315+
316+ const forwardSlash = filepath . replaceAll ( "\\" , "/" )
317+
318+ await Instance . provide ( {
319+ directory : tmp . path ,
320+ fn : async ( ) => {
321+ await FileTime . read ( sessionID , forwardSlash )
322+ // assert with the native backslash path should still work
323+ await FileTime . assert ( sessionID , filepath )
324+ } ,
325+ } )
326+ } )
327+
328+ test ( "read with backslashes, assert with forward slashes" , async ( ) => {
329+ await using tmp = await tmpdir ( )
330+ const filepath = path . join ( tmp . path , "file.txt" )
331+ await fs . writeFile ( filepath , "content" , "utf-8" )
332+ await touch ( filepath , 1_000 )
333+
334+ const forwardSlash = filepath . replaceAll ( "\\" , "/" )
335+
336+ await Instance . provide ( {
337+ directory : tmp . path ,
338+ fn : async ( ) => {
339+ await FileTime . read ( sessionID , filepath )
340+ // assert with forward slashes should still work
341+ await FileTime . assert ( sessionID , forwardSlash )
342+ } ,
343+ } )
344+ } )
345+
346+ test ( "get returns timestamp regardless of slash direction" , async ( ) => {
347+ await using tmp = await tmpdir ( )
348+ const filepath = path . join ( tmp . path , "file.txt" )
349+ await fs . writeFile ( filepath , "content" , "utf-8" )
350+
351+ const forwardSlash = filepath . replaceAll ( "\\" , "/" )
352+
353+ await Instance . provide ( {
354+ directory : tmp . path ,
355+ fn : async ( ) => {
356+ await FileTime . read ( sessionID , forwardSlash )
357+ const result = await FileTime . get ( sessionID , filepath )
358+ expect ( result ) . toBeInstanceOf ( Date )
359+ } ,
360+ } )
361+ } )
362+
363+ test ( "withLock serializes regardless of slash direction" , async ( ) => {
364+ await using tmp = await tmpdir ( )
365+ const filepath = path . join ( tmp . path , "file.txt" )
366+
367+ const forwardSlash = filepath . replaceAll ( "\\" , "/" )
368+
369+ await Instance . provide ( {
370+ directory : tmp . path ,
371+ fn : async ( ) => {
372+ const order : number [ ] = [ ]
373+ const hold = gate ( )
374+ const ready = gate ( )
375+
376+ const op1 = FileTime . withLock ( filepath , async ( ) => {
377+ order . push ( 1 )
378+ ready . open ( )
379+ await hold . wait
380+ order . push ( 2 )
381+ } )
382+
383+ await ready . wait
384+
385+ // Use forward-slash variant -- should still serialize against op1
386+ const op2 = FileTime . withLock ( forwardSlash , async ( ) => {
387+ order . push ( 3 )
388+ order . push ( 4 )
389+ } )
390+
391+ hold . open ( )
392+
393+ await Promise . all ( [ op1 , op2 ] )
394+ expect ( order ) . toEqual ( [ 1 , 2 , 3 , 4 ] )
395+ } ,
396+ } )
397+ } )
398+ } )
399+
309400 describe ( "stat() Filesystem.stat pattern" , ( ) => {
310401 test ( "reads file modification time via Filesystem.stat()" , async ( ) => {
311402 await using tmp = await tmpdir ( )
0 commit comments