|
| 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. |
0 commit comments