@@ -7,6 +7,7 @@ import { VcsProcessSpawnError } from "@t3tools/contracts";
77import * as Effect from "effect/Effect" ;
88import * as FileSystem from "effect/FileSystem" ;
99import * as Layer from "effect/Layer" ;
10+ import * as TestClock from "effect/testing/TestClock" ;
1011import { HttpServerResponse } from "effect/http" ;
1112import * as AzureDevOpsMedia from "./AzureDevOpsMedia.ts" ;
1213import { assetFileResponse } from "../http.ts" ;
@@ -186,22 +187,54 @@ it.effect("shares renewed capabilities and reuses range downloads under cache pr
186187 expect ( yield * fs . readFileString ( first . path ) ) . toBe ( "GIF89a" ) ;
187188 }
188189 expect ( calls ) . toBe ( 20 ) ;
190+ let overflowPath = "" ;
189191 yield * Effect . scoped (
190192 Effect . gen ( function * ( ) {
191193 for ( let index = 0 ; index < 15 ; index ++ ) {
192194 yield * media . get ( { cwd : "/repo" , url : `${ base } -active-${ index } .mp4` } ) ;
193195 }
194- const transient = yield * Effect . scoped (
196+ const beforeOverflow = calls ;
197+ const overflow = yield * Effect . scoped (
195198 Effect . gen ( function * ( ) {
196199 const file = yield * media . get ( { cwd : "/repo" , url : `${ base } -overflow.mp4` } ) ;
197200 expect ( yield * fs . readFileString ( file . path ) ) . toBe ( "GIF89a" ) ;
198201 return file ;
199202 } ) ,
200203 ) ;
201- expect ( yield * fs . exists ( transient . path ) ) . toBe ( false ) ;
204+ overflowPath = overflow . path ;
205+ expect ( yield * fs . exists ( overflow . path ) ) . toBe ( true ) ;
206+ yield * Effect . scoped (
207+ Effect . gen ( function * ( ) {
208+ const repeated = yield * media . get ( { cwd : "/repo" , url : `${ base } -overflow.mp4` } ) ;
209+ expect ( repeated . path ) . toBe ( overflow . path ) ;
210+ const ranged = HttpServerResponse . toWeb (
211+ yield * assetFileResponse ( repeated , "bytes=1-3" ) ,
212+ ) ;
213+ expect ( ranged . status ) . toBe ( 206 ) ;
214+ expect ( yield * Effect . promise ( ( ) => ranged . text ( ) ) ) . toBe ( "IF8" ) ;
215+ expect ( calls ) . toBe ( beforeOverflow + 1 ) ;
216+ for ( let index = 0 ; index < 15 ; index ++ ) {
217+ yield * media . get ( { cwd : "/repo" , url : `${ base } -overflow-active-${ index } .mp4` } ) ;
218+ }
219+ const transient = yield * Effect . scoped (
220+ media . get ( { cwd : "/repo" , url : `${ base } -uncached.mp4` } ) ,
221+ ) ;
222+ expect ( yield * fs . exists ( transient . path ) ) . toBe ( false ) ;
223+ expect ( yield * fs . readFileString ( overflow . path ) ) . toBe ( "GIF89a" ) ;
224+ const retained = yield * Effect . forEach ( paths , ( path ) => fs . exists ( path ) ) ;
225+ expect ( retained . filter ( Boolean ) ) . toHaveLength ( 32 ) ;
226+ } ) ,
227+ ) ;
202228 expect ( yield * fs . readFileString ( first . path ) ) . toBe ( "GIF89a" ) ;
203229 } ) ,
204230 ) ;
231+ const beforeReuse = calls ;
232+ const reused = yield * Effect . scoped ( media . get ( { cwd : "/repo" , url : `${ base } -overflow.mp4` } ) ) ;
233+ expect ( reused . path ) . toBe ( overflowPath ) ;
234+ expect ( calls ) . toBe ( beforeReuse ) ;
235+ yield * TestClock . adjust ( "1 minute" ) ;
236+ expect ( yield * fs . exists ( overflowPath ) ) . toBe ( false ) ;
237+ expect ( yield * fs . readFileString ( first . path ) ) . toBe ( "GIF89a" ) ;
205238 } ) . pipe ( Effect . scoped , Effect . provide ( AzureDevOpsMedia . layer . pipe ( Layer . provide ( cli ) ) ) ) ;
206239 for ( const path of paths ) expect ( yield * fs . exists ( path ) ) . toBe ( false ) ;
207240 } ) . pipe ( Effect . provide ( Layer . merge ( NodeServices . layer , NodeHttpPlatform . layer ) ) ) ,
0 commit comments