Skip to content

impl(027): increment 7, the platform packages - #140

Merged
bartekus merged 1 commit into
mainfrom
impl/027-inc7-packages
Oct 21, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/027-inc7-packages

Conversation

@bartekus

@bartekus bartekus commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Spec 027 increment 7, first change: the native package's platform packages (3.13.1, 3.13.2).

  • integrations/rustev-node/npm/<platform>/package.json for the seven platforms the main package's optionalDependencies name (linux-x64-gnu, linux-x64-musl, linux-arm64-gnu, linux-arm64-musl, darwin-arm64, darwin-x64, win32-x64-msvc): @statecrafting/rustev-<platform> at the main package's version, license and engines; os, cpu and, on Linux, libc as the name says; main and files the addon rustev.<platform>.node alone; no scripts; private until spec 031's release.
  • tools/rustev-conformance/js/platform-packages.mjs:
    • check: every optional dependency has its package and they agree as above; no stray platform directory; no script in a platform package and no install-time script (preinstall, install, postinstall, prepare) in the main package;
    • stage <target>: copies this host's release addon into its platform package;
    • fresh <dir>: npm packs the main package and this host's platform package and installs both into a fresh project from the tarballs (--omit=optional --ignore-scripts), so nothing is fetched for another platform, and fails if the main package's tarball carries an addon.
  • copy-addon.mjs exports the addon naming it already had (addonName, builtAddon) for that reuse; its command line is unchanged.
  • make bindings runs check, stage, fresh, then the native conformance suite on the fresh install, so the suite exercises the loader's platform-package path (3.13.2), not only the local build.
  • Spec 027: implementation record.

Building and smoke-testing each of the seven targets in CI is a later change of this increment (the bindings job).

Local verification (macOS arm64, clean build of the changed crates): make bindings passes end to end (npm audit signatures, WebAssembly conformance 23/23, 27 native tests, native conformance 34/34 on the local build and 34/34 on the fresh install); make gate; bash scripts/check-authored-content.sh.

Review round 1 (3 findings, fixed):

  1. check refused any scripts on the main package. 3.13.2 forbids install-time code, so it now refuses only npm's install lifecycle scripts there (preinstall, install, postinstall, prepare); a platform package still has no script at all. Seeded locally: a build script on the main package passes, a postinstall fails naming it.
  2. stage and fresh let addonName()'s throw on an unsupported platform escape as a stack trace; both now go through hostPlatform(), which exits with the message.
  3. npm ran with shell: true on Windows, so cmd.exe parsed the paths. npm now runs without a shell everywhere: on Windows its entry point (node_modules/npm/bin/npm-cli.js beside node.exe) runs under the current Node, and a missing one fails by name.

Review round 2 (2 findings, fixed):

  1. fresh deleted its target directory unconditionally. It now writes a marker (.rustev-fresh) into the directory it makes and replaces only a directory carrying it; any other existing path is refused by name and left alone (seeded locally: a scratch directory holding a file was refused and kept). In make bindings the path is under the cargo target directory, which the target already refuses to be empty.
  2. pack joined npm's reported file name unchecked. A response that is not JSON, or a name that is not one plain .tgz file name, or a tarball that is not there, now fails with a message naming the package.

Review round 3 (1 finding, answered in the diff, no behavior change): addonName() skips excludeNetwork when process.report has no such own property. That is deliberate and unchanged from #135's loader: only a Node that supports leaving the network section out exposes the property, and assigning it elsewhere would add a plain property the report never reads. The comment at the call now says so; the report then runs whole, slower but correct.

Rebased onto main after #138 and #139 merged. Local make bindings on the rebased branch, after cargo clean -p of every crate #139 changed: WebAssembly conformance 23/23, 27 native tests, native conformance 34/34; its fresh step refused a native-fresh directory left by a run from before the round-2 marker existed (the guard working as intended). With that directory removed, the fresh install's suite passed 34/34.

Review round 4 (2 findings, fixed):

  1. builtAddon() produced a path ending in .undefined on an unsupported platform; it now throws naming the platform, and stage reports it cleanly.
  2. check counted any entry under npm/ as a platform directory, so macOS's .DS_Store failed it; only non-hidden directories count now (seeded locally with a .DS_Store: check passes).

@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, the main changes are: seven new platform package.json files, a refactored copy-addon.mjs (now exports two functions), and a new platform-packages.mjs script with check, stage, and fresh subcommands.

Finding 1 — check() tests the main package for scripts, not just platform packages

platform-packages.mjs:51:

if (main.scripts) failures.push(`${main.name}: has scripts (3.13.2 allows none)`);

The spec's "no script" constraint is stated for platform packages. This line rejects any scripts key on the main integrations/rustev-node/package.json, including ordinary dev/build entries (build, test, etc.). If the main package has any scripts field, check always fails. The per-platform check at line 82 already enforces no-scripts on each platform package. The main-package guard should be removed or restricted to lifecycle-install scripts (e.g., install, preinstall, postinstall).

Finding 2 — addonName() is uncaught in stage() and fresh()

platform-packages.mjs:100 (stage) and platform-packages.mjs:119 (fresh) call addonName() directly. addonName() throws on an unsupported platform (e.g., FreeBSD). copy-addon.mjs's own main block wraps the same call in try/catch and exits with a clean message; the two callers here do not, producing a raw stack trace instead.

Finding 3 — shell: true on Windows passes unescaped paths to cmd.exe

platform-packages.mjs:107–111 (pack):

execFileSync('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', into, dir], {
  encoding: 'utf8',
  shell: process.platform === 'win32',
});

dir and into are derived from resolve(arg) where arg is process.argv[2] (user-supplied). With shell: true, cmd.exe parses the command line, so paths containing &, ^, (, ) or spaces without proper quoting can cause misinterpretation or injection. The same pattern is used in execFileSync in fresh(). Since execFileSync with an array of arguments already handles spaces correctly on Unix, the shell option is only needed on Windows for npm (a .cmd shim), but the path arguments themselves should be quoted or the call should wrap only the executable name in the shell invocation rather than passing raw user-derived paths as unquoted shell tokens.

{"head": "768a872aa1c2a2b3f5be33978c64c7a353be926e", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 51, "summary": "check() tests main.scripts for absence of scripts, but the spec's no-script constraint applies only to platform packages; any dev/build script entry on the main package.json causes check to always fail."}, {"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 100, "summary": "addonName() is called without try/catch in stage() and fresh(), producing a raw stack trace on unsupported platforms instead of the clean error message copy-addon.mjs's own main block produces."}, {"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 108, "summary": "shell: true on Windows passes unescaped user-supplied path arguments (dir, into) through cmd.exe, making paths with shell-special characters (& ^ () spaces) subject to misinterpretation or injection."}]}

Subject: cbd5bfb...768a872, diff digest 6435177c2d52a9ed781b80e0184462cbe371cf22a175080d220bad1274c1828a, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security issues, and inconsistencies.

copy-addon.mjs refactoring -- The module-guard pattern (resolve(process.argv[1]) === fileURLToPath(import.meta.url)) is standard; the save/restore of process.report.excludeNetwork is unchanged from the original. No regression.

platform-packages.mjs check() -- The bidirectional directory/optionalDependencies check is sound. The expected() regex and libc-triple mapping are correct. JSON.stringify comparison handles undefined for non-Linux libc correctly.

platform-packages.mjs fresh()

Line ~133: rmSync(into, { recursive: true, force: true }) is called immediately on the resolved argument with no bounds check. In the Makefile invocation, into is resolve("$(BINDINGS_OUT)/native-fresh"); if BINDINGS_OUT is unset the shell expands "$(BINDINGS_OUT)/native-fresh" to "/native-fresh" (empty-string prefix), and rmSync('/native-fresh', {recursive:true, force:true}) runs silently. Not catastrophic but imprecise for a CI tool.

Lines ~119-122 (pack()): JSON.parse(out)[0].filename is used to form the tarball path. execFileSync throws on non-zero exit, but if npm exits 0 with empty or unexpected output the caller gets a bare SyntaxError / TypeError rather than an actionable message. Additionally, filename is joined directly without sanitization; a path-traversal value (e.g. ../../outside.tgz) would produce a path outside tarballs. npm is trusted here so real risk is low, but there is no guard.

Platform package.json files -- All seven packages are consistent: correct os/cpu/libc triples, matching main and files, private: true, no scripts. The version fields all read 0.1.0, matching what check() will validate against main.version.

Makefile -- The $$(cat ...) double-dollar escaping is correct Make/shell idiom; the captured stdout of platform-packages.mjs fresh feeds run.mjs via the path file as intended.

{"head": "1eaaab3dab916bfbd84424c60f12dd0e595f64f3", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 133, "summary": "rmSync with recursive+force is called on the raw user-supplied path with no bounds check; if BINDINGS_OUT is unset the Makefile expands to /native-fresh and the deletion proceeds silently against an absolute system path."}, {"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 122, "summary": "pack() joins the filename from npm's JSON output directly without sanitisation; a path-traversal value in npm's response would resolve the tarball outside the intended tarballs directory, and a malformed response produces an opaque SyntaxError rather than a clear diagnostic."}]}

Subject: cbd5bfb...1eaaab3, diff digest 919667dd6b760f28752e83865cda45a198ad98e1f30d5d1b922ca5c763468505, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 21, 2026 07:17 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/027-inc7-packages branch from 1eaaab3 to 02297d2 Compare October 21, 2026 07:19
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the seven new platform package.json files, the refactored copy-addon.mjs, the new platform-packages.mjs, the Makefile additions, and the spec update.

Platform package files (darwin-arm64, darwin-x64, linux-*, win32-x64-msvc): structure, os/cpu/libc fields, main, files, private, engines, and license all look correct and consistent with the spec.

copy-addon.mjs refactor: Logic is correctly extracted into addonName() and builtAddon(). The __main__-style guard (resolve(process.argv[1]) === fileURLToPath(import.meta.url)) is the right pattern for dual import/exec use.

addonName() — excludeNetwork logic bug (copy-addon.mjs, inside the if (platform === 'linux') block):

const had = Object.hasOwn(process.report, 'excludeNetwork')
  ? process.report.excludeNetwork
  : undefined;
if (had !== undefined) process.report.excludeNetwork = true;   // ← never fires when property is absent
glibc = process.report.getReport().header?.glibcVersionRuntime;
if (had !== undefined) process.report.excludeNetwork = had;

When process.report.excludeNetwork is not an own property (older Node.js), had is undefined, both guards are skipped, and getReport() runs with the full network section — the costly path the comment explicitly says to avoid. The property should be set unconditionally (and deleted rather than restored if it was absent). This produces a correct result but defeats the stated performance intent on older runtimes.

platform-packages.mjs check() — version comparison (~line 110): version !== main.version compares the raw string from optionalDependencies against main.version. If anyone ever writes "^0.1.0" in the optional dep map the check spuriously fails. The design intent (exact versions only) is sound, but the check has no guard or comment about this assumption.

pack() tarball-name validation: The basename(filename) !== filename / filename === '..' / .endsWith('.tgz') chain is correct and not bypassable from npm's JSON output.

fresh() marker guard and the rmSync call are safe: deletion is gated on the .rustev-fresh sentinel file.

Makefile shell expansion: "$$(cat "$(BINDINGS_OUT)/native-fresh.path")" correctly strips the trailing newline via command substitution and double-quotes the result.

{"head": "02297d21e740b21ba89a180e7273f79b4e5226ff", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/js/copy-addon.mjs", "line": null, "summary": "In addonName(), the excludeNetwork optimisation is never applied when the property is absent from process.report (had === undefined causes both guards to skip), so getReport() runs the expensive network section on any Node.js version that does not already expose that property."}]}

Subject: cbd5bfb...02297d2, diff digest 593e335086faa87df96c96732aca0e3fbc3e37e658b1eb9395da04784fc0c7ba, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 21, 2026 07:23 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/027-inc7-packages branch from 02297d2 to 7251222 Compare October 21, 2026 07:47
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for bugs, security problems, and inconsistencies.

copy-addon.mjs refactor — The conversion from a standalone script to an ESM module with exported functions is clean. The import.meta.url guard for direct execution is idiomatic. The addonName() and builtAddon() extraction preserves the original logic faithfully, including the excludeNetwork save/restore pattern.

platform-packages.mjs — npm() helper — Uses execFileSync with an argument array (not a shell string), which avoids shell injection. The Windows path locates npm by walking up from process.execPath; this is a reasonable assumption for bundled Node installs and the existsSync guard gives a clear error if it breaks.

pack() — tarball filename validation — The chain typeof filename !== 'string' || basename(filename) !== filename || filename === '..' || !filename.endsWith('.tgz') correctly rejects path traversal (foo/bar.tgz fails basename check; .. is caught explicitly and also by the .tgz check). The resulting join(into, filename) is then safe.

fresh() — directory safety — The MARKER file guard prevents accidental deletion of directories the tool didn't create. The stdio: ['ignore', 2, 2] routing is intentional: npm output goes to stderr, while only the installed path goes to stdout (consumed by the Makefile redirect).

check() — version comparison — version !== main.version compares the optionalDependencies value string directly to main.version. This works when exact versions are pinned (which the spec requires), but would always fail if a semver range like ^0.1.0 were used. The main package.json is not in the diff, so this can't be fully verified, but the spec intent is exact pinning.

check() — readdirSync returns all npmDir entries — Both files and directories are included. A stray file (e.g. a future README in npm/) would be falsely flagged as an orphaned platform package with no matching optional dependency. This is a minor robustness issue, though unlikely to trigger with the current layout.

check() — same() is order-sensitive — JSON.stringify comparison for engines would produce a false failure if key order differed between packages. Given all packages have the trivial {"node": ">=20"}, this is theoretical.

Makefile — $$(cat "$(BINDINGS_OUT)/native-fresh.path") correctly double-escapes the $ for Make so the shell sees $(cat ...). Shell command substitution strips the trailing newline from console.log. The "$(CARGO_TARGET)" quoting is correct.

Platform package.json files — All seven are consistent with the spec: private: true, "node": ">=20" engine, correct os/cpu/libc fields for their platforms, and only the .node addon in files. Version is 0.1.0 across all.

No critical bugs or security issues found.

{"head": "725122205fd332cd614708f9c4370410ea9443ca", "verdict": "no-findings", "findings": []}

Subject: cbd5bfb...7251222, diff digest 6a43ca85104a80c1e2386f7af149c2226e5903d587aa77a264f0d8c852d40df6, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/027-inc7-packages branch from 7251222 to f5d267b Compare October 21, 2026 14:02
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff: new platform package manifests, a new platform-packages.mjs script, and a refactoring of copy-addon.mjs into an importable module.

tools/rustev-conformance/js/copy-addon.mjs — builtAddon missing platform guard

addonName() throws on unsupported platforms (line ~13), but the exported builtAddon() (line ~43) does not. If process.platform is unrecognised, ext resolves to undefined and the function silently returns a path like .../librustev_node.undefined. Every current caller protects against this by invoking addonName() first, but the exported function can be imported elsewhere without that guard. A single if (!ext) throw new Error(...) after line ~45 would close it.

tools/rustev-conformance/js/platform-packages.mjs — readdirSync in check() doesn't filter for directories (line ~89)

const dirs = existsSync(npmDir) ? readdirSync(npmDir).sort() : [];

readdirSync returns files and directories alike. On a macOS workstation .DS_Store (or any other stray file) inside integrations/rustev-node/npm/ would be compared against named and produce a spurious npm/.DS_Store: no optional dependency of the main package names it failure, breaking make bindings locally. Filtering with { withFileTypes: true } and keeping only entries where d.isDirectory() would fix it.

Everything else looks correct: the TOCTOU guard on the fresh directory uses a marker file appropriately; the pack result is validated against path-traversal (basename(filename) !== filename); the Windows npm path falls back safely; stdio: ['ignore', 2, 2] is intentional and the comment explains it; and the platform-package manifests are internally consistent.

{"head": "f5d267b2d1ec403395d8fe41918c8c69b38cbde0", "verdict": "findings", "findings": [{"path": "tools/rustev-conformance/js/copy-addon.mjs", "line": 43, "summary": "builtAddon() does not validate the platform, returning a path ending in '.undefined' if called on an unsupported platform without a prior addonName() guard."}, {"path": "tools/rustev-conformance/js/platform-packages.mjs", "line": 89, "summary": "readdirSync without a directory filter causes check() to flag any stray file (e.g. .DS_Store) in npm/ as a missing optional dependency, producing false failures on macOS."}]}

Subject: b2c5c6d...f5d267b, diff digest 6a43ca85104a80c1e2386f7af149c2226e5903d587aa77a264f0d8c852d40df6, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 21, 2026 14:06 — with GitHub Actions Error
The seven platform packages of 3.13.1 in napi-rs's optional-dependency layout, a check that they agree with the main package, staging of this host's addon, and a fresh install from the tarballs alone that the native conformance suite runs on.
@bartekus
bartekus force-pushed the impl/027-inc7-packages branch from f5d267b to 92d4d9a Compare October 21, 2026 14:24
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff carefully: seven new platform package.json manifests, a refactoring of copy-addon.mjs to export addonName and builtAddon, a new platform-packages.mjs implementing check/stage/fresh, and corresponding Makefile additions.

copy-addon.mjs refactoring -- The ESM entry-point guard (resolve(process.argv[1]) === fileURLToPath(import.meta.url)) is the correct idiom. The addonName glibc-detection logic is faithfully preserved.

platform-packages.mjs pack() filename validation -- basename(filename) !== filename catches path separators; filename === '..' is technically redundant (basename('..') is '..' so the prior check passes it, but !filename.endsWith('.tgz') would catch '..' anyway). Redundant but harmless.

fresh() stdio redirect -- stdio: ['ignore', 2, 2] passes numeric fd 2 for the child's stdout and stderr. Node.js supports numeric fds 0-2 on Windows in execFileSync, so this is portable.

check() version comparison -- version !== main.version compares the string from optionalDependencies to main.version. If the main package uses a semver range (e.g. "^0.1.0") instead of an exact pin, this would produce a false failure. However, the napi-rs convention for platform packages is exact pinning, and the existing platform package.json files all use "0.1.0". This is by design rather than a bug.

fresh() marker safety -- The .rustev-fresh marker guard before rmSync is correctly scoped: it only removes directories this command created.

npm on Windows -- The fallback to npm-cli.js under dirname(process.execPath) avoids shell injection from cmd.exe. Paths come from process.execPath (trusted). Arguments are passed as an array to execFileSync, never through a shell.

Platform package.json files -- All seven are internally consistent: os, cpu, and (where applicable) libc match the directory name; main and files name only the expected .node addon; private: true; no scripts.

No bugs or security issues found.

{"head": "92d4d9a5a0f1f8f6ad5b5916300e9a151e6db93c", "verdict": "no-findings", "findings": []}

Subject: b2c5c6d...92d4d9a, diff digest cc2816232d17af02064917ff5799bf54d2058d3d1be16caf422d55abf869ce99, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus merged commit 3556d24 into main Oct 21, 2026
7 checks passed
@bartekus
bartekus deleted the impl/027-inc7-packages branch October 21, 2026 14:46
bartekus added a commit that referenced this pull request Oct 21, 2026
Spec 027 increment 7, second change: the WebAssembly package in headless
Chromium (3.10.5, 3.11.3, 3.13.3).

- `tools/rustev-conformance/js/package.json`: `playwright-core`
exact-pinned at 1.63.0 (no dependencies; `npm audit signatures` covers
it), which fixes the Chromium build; `make bindings` installs that
version's headless shell.
- `tools/rustev-conformance/js/chromium.mjs time <pkg> <out>`: cold
instantiation as 3.10.5 defines it (module bytes in memory to the first
successful `version()`), 3 discarded warm-up runs then 21 measured, each
in a fresh browser process, the page served from a loopback server
holding only the package directory (paths outside it refused). Writes
browser version, samples, median and p95; prints the median.
- `wasm-check.mjs`: `--chromium-record <file>` records those in the
measurement document (`chromium`, `chromium_instantiation_ms` with
samples and p95); its median must equal the gated `--chromium-ms`.
- `run.mjs`: the WebAssembly adapter now turns each case into one plain
call (`wasmCall`, bytes as base64) run by one self-contained executor
(`executeWasm`), so identical code runs in Node and in a Chromium page.
`run.mjs chromium <pkg>` runs every WebAssembly case in Chromium. A
replay's synchronous resolver answers from the case's store items,
exactly as before.
- `Makefile` (`bindings`): installs the headless shell, measures
Chromium, passes the median and record to `wasm-check.mjs`, and runs the
conformance cases in Chromium after Node.
- Spec 027: implementation record.

#140 has merged; this PR is rebased onto `main`.

Local verification (macOS arm64): `make bindings` passes end to end:
WebAssembly conformance 23/23 in Node and 23/23 in Chromium
153.0.8010.12 (headless shell), Chromium instantiation median 3.1 ms and
p95 3.3 ms (budget 100 ms), Node median 3.7 ms, sizes raw 2,216,152 /
gzip 763,059 / Brotli 543,437, 27 native tests, native conformance 34/34
on the local build and on the fresh install. That run preceded the
rebase onto #140's review fixes, which touch only
`platform-packages.mjs` and were verified there. `make gate`; `bash
scripts/check-authored-content.sh`.

Review round 1 (3 findings, fixed):
1. An absent optional argument crossed into the page as `undefined`
(which a page receives as `null`) and stayed `undefined` in Node. Both
cases already read as `None` (wasm-bindgen's `isLikeNone` tests both),
which is why all 23 cases passed in Chromium, but `wasmCall` now writes
`null` itself for `--execution` and `--host-cap-ms`, so Node and the
page receive the same value, with a comment saying why.
2. A request whose URL does not parse or whose path does not decode
threw out of the server's handler; it is now answered 400 (checked
locally with a raw request for `/%E0%A4%A`).
3. The timing run launched a 25th browser only to read its version; each
sample now returns its browser's version, and the record takes the first
measured one.

Rebased onto #140's review rounds 2 and 3. After the fixes: `run.mjs
wasm` 23/23 and `run.mjs chromium` 23/23, `chromium.mjs time` median 3
ms with version 153.0.8010.12 recorded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant