@@ -20,6 +20,7 @@ import { createHash } from "node:crypto";
2020import { existsSync , mkdirSync , mkdtempSync , readFileSync , rmSync , writeFileSync } from "node:fs" ;
2121import { tmpdir } from "node:os" ;
2222import { dirname , join } from "node:path" ;
23+ import { S3Client } from "@aws-sdk/client-s3" ;
2324import {
2425 CURRENT_PLAN_PROTOCOL ,
2526 PlanVideosMetadataError ,
@@ -28,6 +29,7 @@ import {
2829 type PlanResult ,
2930 type PlanV2ArtifactPublisher ,
3031 type PlanV2Manifest ,
32+ type PlanV2WithPublisherOptions ,
3133 publishPlanV2FromExecutionPlan ,
3234} from "@hyperframes/producer/distributed" ;
3335import { recomputePlanHashFromPlanDir } from "../../producer/src/services/render/stages/freezePlan.js" ;
@@ -744,6 +746,16 @@ describe("handler dispatch", () => {
744746 } ) ;
745747} ) ;
746748
749+ /** A real client (so it can pre-sign offline) whose requests go to the fake. */
750+ function presigningClient ( fake : FakeS3Client ) : import ( "@aws-sdk/client-s3" ) . S3Client {
751+ const client = new S3Client ( {
752+ region : "us-east-2" ,
753+ credentials : { accessKeyId : "AKIDTEST" , secretAccessKey : "test-secret" } ,
754+ } ) ;
755+ client . send = fake . send . bind ( fake ) as S3Client [ "send" ] ;
756+ return client ;
757+ }
758+
747759describe ( "handler — plan from a deployed site" , ( ) => {
748760 function storeSiteFile ( s3 : FakeS3Client , bytes : string ) : string {
749761 const sha256 = createHash ( "sha256" ) . update ( bytes ) . digest ( "hex" ) ;
@@ -762,7 +774,7 @@ describe("handler — plan from a deployed site", () => {
762774 } ;
763775 }
764776
765- it ( "rebuilds the project from the content store and reuses its media without uploading it " , async ( ) => {
777+ it ( "plans a site's video in place: never downloads, never uploads its bytes " , async ( ) => {
766778 const s3 = new FakeS3Client ( ) ;
767779 const html = storeSiteFile ( s3 , "<html></html>" ) ;
768780 const media = storeSiteFile ( s3 , "VIDEO-BYTES" ) ;
@@ -778,10 +790,19 @@ describe("handler — plan from a deployed site", () => {
778790 ) ,
779791 ) ;
780792 const planV2WithPublisher = mock (
781- async ( projectDir : string , _config : unknown , publisher : PlanV2ArtifactPublisher ) => {
793+ async (
794+ projectDir : string ,
795+ _config : unknown ,
796+ publisher : PlanV2ArtifactPublisher ,
797+ options : PlanV2WithPublisherOptions ,
798+ ) => {
782799 expect ( readFileSync ( join ( projectDir , "index.html" ) , "utf-8" ) ) . toBe ( "<html></html>" ) ;
783- const mediaPath = join ( projectDir , "assets" , "bg.mp4" ) ;
784- await publisher . putBlob ( { sourcePath : mediaPath , sha256 : media , sizeBytes : 11 } ) ;
800+ expect ( existsSync ( join ( projectDir , "assets" , "bg.mp4" ) ) ) . toBe ( false ) ;
801+ const remote = options . remoteFiles ?. [ "assets/bg.mp4" ] ;
802+ expect ( remote ) . toMatchObject ( { sha256 : media , sizeBytes : 11 } ) ;
803+ expect ( remote ?. url ) . toContain ( `/cas/sha256/${ media . slice ( 0 , 2 ) } /${ media } ?` ) ;
804+ expect ( remote ?. url ) . toContain ( "X-Amz-Signature=" ) ;
805+ await publisher . referenceStoredBlob ! ( { sha256 : media , sizeBytes : 11 } ) ;
785806 const manifest = {
786807 planHash : "c" . repeat ( 64 ) ,
787808 chunkCount : 1 ,
@@ -800,7 +821,7 @@ describe("handler — plan from a deployed site", () => {
800821 ) ;
801822
802823 const result = await handler ( planEvent ( ) , {
803- s3 : s3 as unknown as import ( "@aws-sdk/client-s3" ) . S3Client ,
824+ s3 : presigningClient ( s3 ) ,
804825 primitives : {
805826 plan : mock ( ) as unknown as typeof import ( "@hyperframes/producer/distributed" ) . plan ,
806827 planV2WithPublisher :
@@ -819,6 +840,8 @@ describe("handler — plan from a deployed site", () => {
819840 "s3://bucket/renders/r1/v2/manifest.json" ,
820841 ] ) ;
821842 expect ( s3 . ops . some ( ( op ) => op . uri . endsWith ( ".tar.gz" ) ) ) . toBe ( false ) ;
843+ const mediaKey = `s3://bucket/cas/sha256/${ media . slice ( 0 , 2 ) } /${ media } ` ;
844+ expect ( s3 . ops . filter ( ( op ) => op . uri === mediaKey && op . kind === "download" ) ) . toEqual ( [ ] ) ;
822845 } ) ;
823846
824847 it ( "refuses a site manifest path that escapes the project" , async ( ) => {
0 commit comments