@@ -5,11 +5,15 @@ import { describe, it } from "node:test";
55
66const ROOT_URL = new URL ( "../../" , import . meta. url ) ;
77const WORKFLOWS_URL = new URL ( "workflows/" , new URL ( "../" , import . meta. url ) ) ;
8+ const BENCH_WORKFLOW_URL = new URL ( "bench.yml" , WORKFLOWS_URL ) ;
89const CI_WORKFLOW_URL = new URL ( "ci.yml" , WORKFLOWS_URL ) ;
910const COVERAGE_WORKFLOW_URL = new URL ( "coverage.yml" , WORKFLOWS_URL ) ;
1011const RELEASE_WORKFLOW_URL = new URL ( "release.yml" , WORKFLOWS_URL ) ;
12+ const CONTRIBUTING_URL = new URL ( "CONTRIBUTING.md" , ROOT_URL ) ;
13+ const DEPENDABOT_CONFIG_URL = new URL ( ".github/dependabot.yml" , ROOT_URL ) ;
1114const FALLOW_CONFIG_URL = new URL ( ".fallowrc.json" , ROOT_URL ) ;
1215const PACKAGE_JSON_URL = new URL ( "package.json" , ROOT_URL ) ;
16+ const README_URL = new URL ( "README.md" , ROOT_URL ) ;
1317const WASM_PACK_INSTALL_ACTION = "taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853" ;
1418const WASM_PACK_WORKFLOWS = new Map ( [
1519 [ "bench.yml" , " if: matrix.kind == 'node'\n" ] ,
@@ -70,6 +74,19 @@ const workflowJob = (workflow, jobName) => {
7074 return nextJob === - 1 ? remaining : remaining . slice ( 0 , nextJob ) ;
7175} ;
7276
77+ const assertSafeNapiConsumer = ( name , contents ) => {
78+ const unsafeBuilds = [
79+ / \b n a p i b u i l d \b / ,
80+ / \b p n p m \b [ ^ \n ] * - - f i l t e r @ s r c m a p \/ (?: c o d e c | s o u r c e m a p ) (? = \s ) [ ^ \n ] * \b b u i l d \b / ,
81+ / \b (?: c d | w o r k i n g - d i r e c t o r y : ) \s + p a c k a g e s \/ (?: c o d e c | s o u r c e m a p ) (? = \s | $ ) / m,
82+ / \b p n p m \b [ ^ \n ] * - - d i r \s + p a c k a g e s \/ (?: c o d e c | s o u r c e m a p ) (? = \s ) [ ^ \n ] * \b b u i l d \b / ,
83+ ] ;
84+
85+ for ( const unsafeBuild of unsafeBuilds ) {
86+ assert . doesNotMatch ( contents , unsafeBuild , `${ name } : use the no-js bootstrap` ) ;
87+ }
88+ } ;
89+
7390describe ( "JavaScript dependency policy" , ( ) => {
7491 it ( "keeps pnpm-lock.yaml as the only tracked JavaScript lockfile" , async ( ) => {
7592 assert . deepEqual ( await trackedPackageLocks ( ) , [ ] ) ;
@@ -120,6 +137,50 @@ describe("Generated artifact policy", () => {
120137 ) ;
121138 assert . doesNotMatch ( job , / c o r e p a c k p n p m - - f i l t e r @ s r c m a p \/ .+ b u i l d / ) ;
122139 } ) ;
140+
141+ it ( "keeps every non-release NAPI consumer on the no-js bootstrap" , async ( ) => {
142+ const ci = await readFile ( CI_WORKFLOW_URL , "utf8" ) ;
143+ const coverage = await readFile ( COVERAGE_WORKFLOW_URL , "utf8" ) ;
144+ const bench = await readFile ( BENCH_WORKFLOW_URL , "utf8" ) ;
145+ const contributing = await readFile ( CONTRIBUTING_URL , "utf8" ) ;
146+ const readme = await readFile ( README_URL , "utf8" ) ;
147+ assert . match ( workflowJob ( ci , "js-runtime" ) , / c o r e p a c k p n p m r u n b u i l d : t e s t - a r t i f a c t s / ) ;
148+ assert . match ( workflowJob ( coverage , "coverage" ) , / c o r e p a c k p n p m r u n b u i l d : t e s t - a r t i f a c t s : n a p i / ) ;
149+ assert . match ( bench , / c o r e p a c k p n p m r u n b u i l d : t e s t - a r t i f a c t s : n a p i / ) ;
150+ assert . match ( contributing , / c o r e p a c k p n p m r u n b u i l d : t e s t - a r t i f a c t s : n a p i / ) ;
151+ assert . match ( readme , / c o r e p a c k p n p m r u n b u i l d : t e s t - a r t i f a c t s : n a p i / ) ;
152+
153+ for ( const [ name , contents ] of [
154+ [ "ci.yml" , ci ] ,
155+ [ "coverage.yml" , coverage ] ,
156+ [ "bench.yml" , bench ] ,
157+ [ "CONTRIBUTING.md" , contributing ] ,
158+ [ "README.md" , readme ] ,
159+ ] ) {
160+ assertSafeNapiConsumer ( name , contents ) ;
161+ }
162+ } ) ;
163+
164+ it ( "rejects direct and package-local NAPI build variants" , ( ) => {
165+ for ( const unsafeBuild of [
166+ "corepack pnpm exec napi build --release" ,
167+ "run: corepack pnpm run build\nworking-directory: packages/codec" ,
168+ "corepack pnpm --dir packages/sourcemap run build" ,
169+ ] ) {
170+ assert . throws ( ( ) => assertSafeNapiConsumer ( "fixture" , unsafeBuild ) ) ;
171+ }
172+ } ) ;
173+ } ) ;
174+
175+ describe ( "Dependabot policy" , ( ) => {
176+ it ( "holds only memchr 2.8.3 after its failed performance gate" , async ( ) => {
177+ const config = await readFile ( DEPENDABOT_CONFIG_URL , "utf8" ) ;
178+
179+ assert . match (
180+ config ,
181+ / # m e m c h r 2 \. 8 \. 3 r e g r e s s e d t h e p e r f o r m a n c e g a t e ; r e t r y w i t h t h e n e x t r e l e a s e \. \n \s + - d e p e n d e n c y - n a m e : m e m c h r \n \s + v e r s i o n s : \[ " 2 \. 8 \. 3 " \] / ,
182+ ) ;
183+ } ) ;
123184} ) ;
124185
125186describe ( "Checkout credential policy" , ( ) => {
0 commit comments