@@ -414,39 +414,61 @@ describe('ingestPackagistItemsConcurrently', () => {
414414
415415// All-packages metadata scope: the env default drives due-selection's onlyCritical arg.
416416// Default is ALL packages (deps.dev has no Packagist data to fall back on); the env var
417- // narrows back to the critical slice.
417+ // narrows back to the critical slice. The due-cutoff is derived once from the run's
418+ // fixed cutoff minus the refresh window, not a live NOW() re-evaluated per batch.
418419describe ( 'getPackagistMetadataBatch scope' , ( ) => {
419420 const mockMetadataDue = vi . mocked ( getPackagistMetadataDuePurls )
421+ const RUN_CUTOFF = '2026-07-15T00:00:00.000Z'
422+ const DUE_CUTOFF = '2026-07-08T00:00:00.000Z' // RUN_CUTOFF minus the 7-day default
420423
421424 afterEach ( ( ) => {
422425 delete process . env . CROWD_PACKAGES_PACKAGIST_RUN_ONLY_FOR_CRITICAL
426+ delete process . env . CROWD_PACKAGES_PACKAGIST_METADATA_REFRESH_DAYS
427+ } )
428+
429+ it ( 'derives the due-cutoff from the fixed run cutoff, not a live clock' , async ( ) => {
430+ process . env . CROWD_PACKAGES_PACKAGIST_METADATA_REFRESH_DAYS = '3'
431+ mockMetadataDue . mockResolvedValue ( [ ] )
432+
433+ await getPackagistMetadataBatch ( RUN_CUTOFF , '' , 50 )
434+
435+ // 3 days before the run's own fixed cutoff — never "3 days before whenever this
436+ // particular batch happens to execute" — is what makes the keyset scan give every
437+ // purl exactly one refresh-eligibility check per drain.
438+ expect ( mockMetadataDue ) . toHaveBeenCalledWith (
439+ expect . anything ( ) ,
440+ '2026-07-12T00:00:00.000Z' ,
441+ '' ,
442+ 50 ,
443+ false ,
444+ )
423445 } )
424446
425447 it ( 'selects across ALL packagist packages by default' , async ( ) => {
426448 mockMetadataDue . mockResolvedValue ( [ ] )
427449
428- await getPackagistMetadataBatch ( '' , 50 )
450+ await getPackagistMetadataBatch ( RUN_CUTOFF , '' , 50 )
429451
430- expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , '' , 50 , 7 , false )
452+ expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , DUE_CUTOFF , '' , 50 , false )
431453 } )
432454
433455 it ( 'narrows to the critical slice when CROWD_PACKAGES_PACKAGIST_RUN_ONLY_FOR_CRITICAL=true' , async ( ) => {
434456 process . env . CROWD_PACKAGES_PACKAGIST_RUN_ONLY_FOR_CRITICAL = 'true'
435457 mockMetadataDue . mockResolvedValue ( [ ] )
436458
437- await getPackagistMetadataBatch ( '' , 50 )
459+ await getPackagistMetadataBatch ( RUN_CUTOFF , '' , 50 )
438460
439- expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , '' , 50 , 7 , true )
461+ expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , DUE_CUTOFF , '' , 50 , true )
440462 } )
441463
442464 it ( 'keeps the all-packages default when the env value is unrecognized' , async ( ) => {
443465 // a typo must not silently flip the sweep to critical-only
444466 process . env . CROWD_PACKAGES_PACKAGIST_RUN_ONLY_FOR_CRITICAL = 'ture'
445467 mockMetadataDue . mockResolvedValue ( [ ] )
446468
447- await getPackagistMetadataBatch ( '' , 50 )
469+ await getPackagistMetadataBatch ( RUN_CUTOFF , '' , 50 )
448470
449- expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , '' , 50 , 7 , false )
471+ expect ( mockMetadataDue ) . toHaveBeenCalledWith ( expect . anything ( ) , DUE_CUTOFF , '' , 50 , false )
450472 } )
451473} )
452474
0 commit comments