@@ -81,11 +81,12 @@ describe("production supply-chain policy", () => {
8181 expect ( violations ) . toEqual ( [ ] ) ;
8282 } ) ;
8383
84- it ( "stages the patch directory in every image that installs from the lockfile " , ( ) => {
84+ it ( "stages patches exactly when an image's workspace lockfile requires them " , ( ) => {
8585 // `patchedDependencies` makes the lockfile reference each patch by file
8686 // hash, so a `pnpm install --frozen-lockfile` that cannot read the patch
87- // fails outright. Every image that installs must therefore copy the
88- // patches its own workspace root declares.
87+ // fails outright. Conversely, Docker rejects a COPY when that workspace's
88+ // patch directory no longer exists. Keep each install stage in exact sync
89+ // with the patches its own workspace root declares.
8990 for ( const [ workspaceRoot , dockerfiles ] of [
9091 [
9192 "." ,
@@ -102,12 +103,14 @@ describe("production supply-chain policy", () => {
102103 const workspace = read (
103104 `${ workspaceRoot === "." ? "" : `${ workspaceRoot } /` } pnpm-workspace.yaml` ,
104105 ) ;
105- if ( ! workspace . includes ( "patchedDependencies:" ) ) continue ;
106+ const hasPatchedDependencies = workspace . includes ( "patchedDependencies:" ) ;
106107 for ( const dockerfile of dockerfiles ) {
107108 const contents = read ( dockerfile ) ;
108109 const installs = contents . match ( / p n p m i n s t a l l - - f r o z e n - l o c k f i l e / g) ?. length ?? 0 ;
109110 expect ( installs , dockerfile ) . toBeGreaterThan ( 0 ) ;
110- expect ( contents . match ( / C O P Y p a t c h e s \/ p a t c h e s \/ / g) ?. length ?? 0 , dockerfile ) . toBe ( installs ) ;
111+ expect ( contents . match ( / C O P Y p a t c h e s \/ p a t c h e s \/ / g) ?. length ?? 0 , dockerfile ) . toBe (
112+ hasPatchedDependencies ? installs : 0 ,
113+ ) ;
111114 }
112115 }
113116 } ) ;
0 commit comments