@@ -19,6 +19,7 @@ import * as Redacted from "effect/Redacted";
1919import * as Path from "effect/Path" ;
2020import * as PlatformError from "effect/PlatformError" ;
2121import * as Schema from "effect/Schema" ;
22+ import * as TestClock from "effect/testing/TestClock" ;
2223import { HttpClient , HttpClientResponse , HttpServerResponse } from "effect/http" ;
2324import { vi } from "vite-plus/test" ;
2425
@@ -602,6 +603,43 @@ describe("AssetAccess", () => {
602603 } ) . pipe ( Effect . provide ( layerTest ) ) ,
603604 ) ;
604605
606+ it . effect ( "versions media by file changes rather than by re-signing" , ( ) =>
607+ Effect . gen ( function * ( ) {
608+ const fs = yield * FileSystem . FileSystem ;
609+ const path = yield * Path . Path ;
610+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-media-revision-" } ) ;
611+ const filePath = path . join ( root , "recording.mp4" ) ;
612+ yield * fs . writeFileString ( filePath , "original" ) ;
613+ yield * Effect . promise ( ( ) => NodeFSP . utimes ( filePath , 1_000 , 1_000 ) ) ;
614+ const input = {
615+ resource : {
616+ _tag : "media-file" as const ,
617+ threadId : ThreadId . make ( "thread-1" ) ,
618+ path : filePath ,
619+ } ,
620+ } ;
621+ const original = yield * issueAssetUrl ( input ) ;
622+ expect ( original . fileRevision ) . toEqual ( expect . any ( String ) ) ;
623+
624+ yield * TestClock . adjust ( "1 minute" ) ;
625+ const renewed = yield * issueAssetUrl ( input ) ;
626+ expect ( renewed . relativeUrl ) . not . toBe ( original . relativeUrl ) ;
627+ expect ( renewed . fileRevision ) . toBe ( original . fileRevision ) ;
628+
629+ yield * fs . writeFileString ( filePath , "modified" ) ;
630+ yield * Effect . promise ( ( ) => NodeFSP . utimes ( filePath , 2_000 , 2_000 ) ) ;
631+ const edited = yield * issueAssetUrl ( input ) ;
632+ expect ( edited . fileRevision ) . not . toBe ( original . fileRevision ) ;
633+
634+ const replacement = path . join ( root , "replacement.mp4" ) ;
635+ yield * fs . writeFileString ( replacement , "modified" ) ;
636+ yield * Effect . promise ( ( ) => NodeFSP . utimes ( replacement , 2_000 , 2_000 ) ) ;
637+ yield * fs . rename ( replacement , filePath ) ;
638+ const replaced = yield * issueAssetUrl ( input ) ;
639+ expect ( replaced . fileRevision ) . not . toBe ( edited . fileRevision ) ;
640+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
641+ ) ;
642+
605643 it . effect ( "keeps in-place edits readable but requires a new URL after atomic replacement" , ( ) =>
606644 Effect . gen ( function * ( ) {
607645 const fs = yield * FileSystem . FileSystem ;
0 commit comments