Skip to content

Commit db0d877

Browse files
build: add test artifact bootstrap
* docs: design test artifact bootstrap * docs: plan test artifact bootstrap * build: add test artifact bootstrap
1 parent a307917 commit db0d877

6 files changed

Lines changed: 247 additions & 22 deletions

File tree

.github/scripts/workflow-policy.test.mjs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const CI_WORKFLOW_URL = new URL("ci.yml", WORKFLOWS_URL);
99
const COVERAGE_WORKFLOW_URL = new URL("coverage.yml", WORKFLOWS_URL);
1010
const RELEASE_WORKFLOW_URL = new URL("release.yml", WORKFLOWS_URL);
1111
const FALLOW_CONFIG_URL = new URL(".fallowrc.json", ROOT_URL);
12+
const PACKAGE_JSON_URL = new URL("package.json", ROOT_URL);
1213
const WASM_PACK_INSTALL_ACTION = "taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853";
1314
const WASM_PACK_WORKFLOWS = new Map([
1415
["bench.yml", " if: matrix.kind == 'node'\n"],
@@ -95,6 +96,30 @@ describe("Generated artifact policy", () => {
9596

9697
assert.ok(config.ignoreUnresolvedImports.includes("**/srcmap_*_wasm_bg.wasm"));
9798
});
99+
100+
it("uses one safe bootstrap command for JavaScript test artifacts", async () => {
101+
const packageJson = JSON.parse(await readFile(PACKAGE_JSON_URL, "utf8"));
102+
assert.equal(
103+
packageJson.scripts["build:test-artifacts"],
104+
"pnpm run build:test-artifacts:napi && pnpm run build:test-artifacts:wasm",
105+
);
106+
assert.equal(
107+
packageJson.scripts["build:test-artifacts:napi"],
108+
"pnpm --filter @srcmap/codec exec napi build --release --platform --no-js --dts ../../target/napi-codec.d.ts && pnpm --filter @srcmap/sourcemap exec napi build --release --platform --no-js --dts ../../target/napi-sourcemap.d.ts",
109+
);
110+
assert.equal(
111+
packageJson.scripts["build:test-artifacts:wasm"],
112+
"pnpm --filter @srcmap/sourcemap-wasm build:all && pnpm --filter @srcmap/generator-wasm build:all && pnpm --filter @srcmap/remapping-wasm build:all && pnpm --filter @srcmap/symbolicate-wasm build:all",
113+
);
114+
115+
const workflow = await readFile(CI_WORKFLOW_URL, "utf8");
116+
const job = workflowJob(workflow, "js-runtime");
117+
assert.match(
118+
job,
119+
/ - name: Build JavaScript test artifacts\n run: corepack pnpm run build:test-artifacts/,
120+
);
121+
assert.doesNotMatch(job, /corepack pnpm --filter @srcmap\/.+ build/);
122+
});
98123
});
99124

100125
describe("Checkout credential policy", () => {
@@ -284,7 +309,7 @@ describe("NAPI declaration coverage", () => {
284309
it("checks generated declarations after the NAPI build and before JavaScript tests", async () => {
285310
const workflow = await readFile(CI_WORKFLOW_URL, "utf8");
286311
const job = workflowJob(workflow, "js-runtime");
287-
const build = "corepack pnpm --filter @srcmap/sourcemap build";
312+
const build = "corepack pnpm run build:test-artifacts";
288313
const declarationStep =
289314
" - name: Check N-API declarations\n run: node .github/scripts/check-napi-declarations.mjs";
290315
const check = "node .github/scripts/check-napi-declarations.mjs";
@@ -300,7 +325,7 @@ describe("WASM package coverage", () => {
300325
it("builds symbolicate WASM targets before JavaScript tests", async () => {
301326
const workflow = await readFile(CI_WORKFLOW_URL, "utf8");
302327
const job = workflowJob(workflow, "js-runtime");
303-
const build = "corepack pnpm --filter @srcmap/symbolicate-wasm build:all";
328+
const build = "corepack pnpm run build:test-artifacts";
304329
const test = "corepack pnpm run test:js";
305330

306331
assert.ok(job.includes(build), "missing symbolicate WASM build");

.github/workflows/ci.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,10 @@ jobs:
225225
uses: taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853 # v2.83.2
226226
with:
227227
tool: wasm-pack@0.13.1
228-
- name: Build N-API packages
229-
run: |
230-
corepack pnpm --filter @srcmap/codec build
231-
corepack pnpm --filter @srcmap/sourcemap build
228+
- name: Build JavaScript test artifacts
229+
run: corepack pnpm run build:test-artifacts
232230
- name: Check N-API declarations
233231
run: node .github/scripts/check-napi-declarations.mjs
234-
- name: Build WASM packages
235-
run: |
236-
corepack pnpm --filter @srcmap/sourcemap-wasm build:all
237-
corepack pnpm --filter @srcmap/generator-wasm build:all
238-
corepack pnpm --filter @srcmap/remapping-wasm build:all
239-
corepack pnpm --filter @srcmap/symbolicate-wasm build:all
240232
- name: Run JS tests
241233
run: corepack pnpm run test:js
242234

CONTRIBUTING.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@ corepack pnpm install --frozen-lockfile
2222
# Build the Rust workspace
2323
cargo build --workspace
2424

25-
# Build the NAPI packages used by the JavaScript tests
26-
corepack pnpm --filter @srcmap/codec build
27-
corepack pnpm --filter @srcmap/sourcemap build
28-
29-
# Build the Node.js and browser WASM packages used by the JavaScript tests
30-
corepack pnpm --filter @srcmap/sourcemap-wasm build:all
31-
corepack pnpm --filter @srcmap/generator-wasm build:all
32-
corepack pnpm --filter @srcmap/remapping-wasm build:all
33-
corepack pnpm --filter @srcmap/symbolicate-wasm build:all
25+
# Build all generated NAPI and WASM artifacts used by the JavaScript tests
26+
corepack pnpm run build:test-artifacts
3427

3528
# Run all repository checks
3629
corepack pnpm run check
@@ -90,7 +83,7 @@ corepack pnpm --filter @srcmap/sourcemap-wasm build:all
9083
```bash
9184
cargo test # All Rust tests
9285
cargo test -p srcmap-sourcemap # Single crate
93-
corepack pnpm run test:js # JS/WASM tests (run the binding builds above first)
86+
corepack pnpm run test:js # JS/WASM tests (run build:test-artifacts first)
9487
```
9588

9689
### Benchmarks
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Test Artifact Bootstrap Implementation Plan
2+
3+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4+
5+
**Goal:** Add one root command that safely builds every generated NAPI and WASM artifact required by JavaScript tests in a clean checkout or worktree.
6+
7+
**Architecture:** Define the build contract in root package scripts, use `--no-js` for NAPI builds to preserve tracked loaders, and reuse the command in the JavaScript runtime CI job. Lock the contract with the existing workflow policy test and document it in the contributor quick start.
8+
9+
**Tech Stack:** pnpm 10, Node.js test runner, NAPI-RS CLI, wasm-pack, GitHub Actions.
10+
11+
## Global Constraints
12+
13+
- Add no dependencies.
14+
- Preserve tracked NAPI JavaScript loaders.
15+
- Do not make `pnpm test` rebuild artifacts automatically.
16+
- Keep the existing focused package build commands available.
17+
- Use signed conventional commits without attribution.
18+
19+
---
20+
21+
### Task 1: Define the bootstrap contract test-first
22+
23+
**Files:**
24+
- Modify: `.github/scripts/workflow-policy.test.mjs`
25+
- Modify: `package.json`
26+
- Modify: `.github/workflows/ci.yml`
27+
28+
**Interfaces:**
29+
- Consumes: root `package.json` scripts and the `js-runtime` workflow job.
30+
- Produces: `build:test-artifacts`, `build:test-artifacts:napi`, and `build:test-artifacts:wasm` package scripts used by contributors and CI.
31+
32+
- [ ] **Step 1: Write the failing policy test**
33+
34+
Add `PACKAGE_JSON_URL` and extend `Generated artifact policy` with a test that checks the exact root scripts and CI step:
35+
36+
```js
37+
const PACKAGE_JSON_URL = new URL("package.json", ROOT_URL);
38+
39+
it("uses one safe bootstrap command for JavaScript test artifacts", async () => {
40+
const packageJson = JSON.parse(await readFile(PACKAGE_JSON_URL, "utf8"));
41+
assert.equal(
42+
packageJson.scripts["build:test-artifacts"],
43+
"pnpm run build:test-artifacts:napi && pnpm run build:test-artifacts:wasm",
44+
);
45+
assert.equal(
46+
packageJson.scripts["build:test-artifacts:napi"],
47+
"pnpm --filter @srcmap/codec exec napi build --release --platform --no-js --dts ../../target/napi-codec.d.ts && pnpm --filter @srcmap/sourcemap exec napi build --release --platform --no-js --dts ../../target/napi-sourcemap.d.ts",
48+
);
49+
assert.equal(
50+
packageJson.scripts["build:test-artifacts:wasm"],
51+
"pnpm --filter @srcmap/sourcemap-wasm build:all && pnpm --filter @srcmap/generator-wasm build:all && pnpm --filter @srcmap/remapping-wasm build:all && pnpm --filter @srcmap/symbolicate-wasm build:all",
52+
);
53+
54+
const workflow = await readFile(CI_WORKFLOW_URL, "utf8");
55+
const job = workflowJob(workflow, "js-runtime");
56+
assert.match(
57+
job,
58+
/ - name: Build JavaScript test artifacts\n run: corepack pnpm run build:test-artifacts/,
59+
);
60+
assert.doesNotMatch(job, /corepack pnpm --filter @srcmap\/.+ build/);
61+
});
62+
```
63+
64+
- [ ] **Step 2: Run the policy test and verify red**
65+
66+
Run:
67+
68+
```bash
69+
node --test .github/scripts/workflow-policy.test.mjs
70+
```
71+
72+
Expected: FAIL because `build:test-artifacts` is not defined.
73+
74+
- [ ] **Step 3: Add the root package scripts**
75+
76+
Add these scripts before `check:napi-declarations` in `package.json`:
77+
78+
```json
79+
"build:test-artifacts": "pnpm run build:test-artifacts:napi && pnpm run build:test-artifacts:wasm",
80+
"build:test-artifacts:napi": "pnpm --filter @srcmap/codec exec napi build --release --platform --no-js --dts ../../target/napi-codec.d.ts && pnpm --filter @srcmap/sourcemap exec napi build --release --platform --no-js --dts ../../target/napi-sourcemap.d.ts",
81+
"build:test-artifacts:wasm": "pnpm --filter @srcmap/sourcemap-wasm build:all && pnpm --filter @srcmap/generator-wasm build:all && pnpm --filter @srcmap/remapping-wasm build:all && pnpm --filter @srcmap/symbolicate-wasm build:all"
82+
```
83+
84+
- [ ] **Step 4: Make CI use the root command**
85+
86+
Replace the `Build N-API packages` and `Build WASM packages` steps in the `js-runtime` job with:
87+
88+
```yaml
89+
- name: Build JavaScript test artifacts
90+
run: corepack pnpm run build:test-artifacts
91+
- name: Check N-API declarations
92+
run: node .github/scripts/check-napi-declarations.mjs
93+
```
94+
95+
- [ ] **Step 5: Run the policy test and verify green**
96+
97+
Run:
98+
99+
```bash
100+
node --test .github/scripts/workflow-policy.test.mjs
101+
```
102+
103+
Expected: PASS.
104+
105+
### Task 2: Document and prove clean-worktree setup
106+
107+
**Files:**
108+
- Modify: `CONTRIBUTING.md:15-38,77-96`
109+
110+
**Interfaces:**
111+
- Consumes: `pnpm build:test-artifacts` from Task 1.
112+
- Produces: one contributor-facing setup command and explicit JavaScript test prerequisite.
113+
114+
- [ ] **Step 1: Replace duplicated quick-start build commands**
115+
116+
Keep the Rust workspace build, then replace the package-specific NAPI and WASM command block with:
117+
118+
```bash
119+
# Build all generated NAPI and WASM artifacts used by the JavaScript tests
120+
corepack pnpm run build:test-artifacts
121+
```
122+
123+
- [ ] **Step 2: Update the JavaScript testing note**
124+
125+
Use:
126+
127+
```bash
128+
corepack pnpm run test:js # JS/WASM tests (run build:test-artifacts first)
129+
```
130+
131+
- [ ] **Step 3: Install clean-worktree dependencies**
132+
133+
Run:
134+
135+
```bash
136+
corepack pnpm install --ignore-scripts --frozen-lockfile
137+
```
138+
139+
Expected: the lockfile is unchanged and no generated binding artifacts exist before bootstrap.
140+
141+
- [ ] **Step 4: Execute the bootstrap command**
142+
143+
Run with bounded output:
144+
145+
```bash
146+
corepack pnpm run build:test-artifacts > /tmp/srcmap-test-artifacts-build.log 2>&1
147+
```
148+
149+
Expected: the command exits successfully, both platform NAPI binaries exist, and every listed WASM package has Node and browser outputs.
150+
151+
- [ ] **Step 5: Verify tracked loader hygiene**
152+
153+
Run:
154+
155+
```bash
156+
git status --short
157+
git diff -- packages/codec/index.js packages/sourcemap/index.js
158+
```
159+
160+
Expected: only the intended policy, package, workflow, and contributor documentation files are modified; tracked loader files are unchanged.
161+
162+
- [ ] **Step 6: Run full verification**
163+
164+
Run with bounded logs:
165+
166+
```bash
167+
pnpm check > /tmp/srcmap-test-artifacts-check.log 2>&1
168+
pnpm test > /tmp/srcmap-test-artifacts-test.log 2>&1
169+
git diff --check
170+
```
171+
172+
Expected: all commands exit successfully.
173+
174+
- [ ] **Step 7: Review and commit**
175+
176+
Review `git status --short`, the complete diff, and staged scope. Commit with:
177+
178+
```bash
179+
git commit -S -m "build: add test artifact bootstrap"
180+
```
181+
182+
- [ ] **Step 8: Publish and verify**
183+
184+
Push `codex/test-artifact-bootstrap`, create a ready pull request targeting `main`, require all checks, squash merge with a conventional subject, and verify CI, coverage, benchmarks, and Release Drafter on the exact merge commit.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Test Artifact Bootstrap Design
2+
3+
## Goal
4+
5+
Provide one repository command that prepares every generated NAPI and WASM artifact required by the JavaScript test suite in a clean checkout or isolated worktree.
6+
7+
## Command contract
8+
9+
Add `pnpm build:test-artifacts` at the workspace root. It runs two internal scripts in sequence:
10+
11+
- `build:test-artifacts:napi` builds the codec and sourcemap NAPI binaries with `--no-js`, preserving the tracked JavaScript loaders while still generating the platform binary and declaration outputs.
12+
- `build:test-artifacts:wasm` runs the existing `build:all` scripts for sourcemap, generator, remapping, and symbolicate WASM packages.
13+
14+
The command requires the existing project prerequisites, including `wasm-pack`. It stops on the first failed build and does not install dependencies or run tests implicitly.
15+
16+
## CI ownership
17+
18+
Replace the duplicated NAPI and WASM build commands in the JavaScript runtime workflow with `corepack pnpm run build:test-artifacts`. CI then validates the same public command contributors use locally. Keep the declaration check after the bootstrap command and before the JavaScript tests.
19+
20+
Extend the workflow policy test to require this root command in the JavaScript runtime job and reject reintroduced package-specific build commands in that job.
21+
22+
## Documentation
23+
24+
Update `CONTRIBUTING.md` so quick start uses the single bootstrap command. Keep the existing focused package build examples for contributors working on one binding package. Update the JavaScript testing note to name the bootstrap command explicitly.
25+
26+
## Verification
27+
28+
Use a clean isolated worktree with dependencies installed but no ignored binding artifacts. Run `pnpm build:test-artifacts`, confirm all required NAPI and WASM outputs exist, and confirm tracked loaders remain unchanged. Then run the workflow policy test, JavaScript tests, the full quality gate, and the full repository test suite.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"analyze:js": "pnpm run analyze:js:dupes && pnpm run analyze:js:health",
1818
"analyze:js:dupes": "fallow dupes --format json --quiet",
1919
"analyze:js:health": "fallow health --format json --quiet --top 20",
20+
"build:test-artifacts": "pnpm run build:test-artifacts:napi && pnpm run build:test-artifacts:wasm",
21+
"build:test-artifacts:napi": "pnpm --filter @srcmap/codec exec napi build --release --platform --no-js --dts ../../target/napi-codec.d.ts && pnpm --filter @srcmap/sourcemap exec napi build --release --platform --no-js --dts ../../target/napi-sourcemap.d.ts",
22+
"build:test-artifacts:wasm": "pnpm --filter @srcmap/sourcemap-wasm build:all && pnpm --filter @srcmap/generator-wasm build:all && pnpm --filter @srcmap/remapping-wasm build:all && pnpm --filter @srcmap/symbolicate-wasm build:all",
2023
"check:napi-declarations": "pnpm --filter @srcmap/sourcemap exec napi build --release --platform --no-js --dts ../../target/napi-sourcemap.d.ts && node .github/scripts/check-napi-declarations.mjs",
2124
"check": "pnpm run fmt:check && pnpm run lint:rust && pnpm run lint:js && pnpm run typos && pnpm run deny",
2225
"fmt:check": "cargo fmt --all --check && pnpm run fmt:js:check",

0 commit comments

Comments
 (0)