Skip to content

Commit be66a2d

Browse files
committed
smoke(8al-node): load the Pi extension with the modules the Pi host provides
The 8al-node probe imports the generated Pi extension in bare Node with an empty node_modules. That was a sound stand-in for the Pi host only while the extension imported nothing but node: builtins; the first package import (`typebox`, Pi's schema library for tool parameters — a real Pi dependency, verified against pi-coding-agent 0.84.4 on DeusData#1809) can never resolve there, so the probe fails on a correct extension and would pass a wrong one just as readily. Give the probe what the host gives the extension: a Proxy-backed `typebox` stub in the probe's node_modules (any Type.X(...) returns a descriptor, so the probe never tracks which helpers the emitter uses — it only exercises the tool lifecycle), plus an explicit allowlist: every import specifier in the generated file must be a node: builtin or a package on PI_HOST_PACKAGES, otherwise the probe fails naming the specifier. That turns the guarantee the empty node_modules gave by accident (no surprise dependency) into an asserted contract. Verified locally by running only the 8al-node block against extensions generated by two binaries: main@5802ccdd extension, old probe: OK; new probe: OK DeusData#1809 extension, old probe: ERR_MODULE_NOT_FOUND typebox (the CI red) DeusData#1809 extension, new probe: OK DeusData#1809 extension + an injected 'lodash' import, new probe: FAIL 8al-node: ... packages the Pi host does not provide: lodash Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 5802ccd commit be66a2d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎scripts/smoke-test.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,35 @@ if command -v node >/dev/null 2>&1; then
23392339
PI_NODE=$(command -v node)
23402340
PI_PROBE_DIR="$TMPDIR/pi-node-probe"
23412341
mkdir -p "$PI_PROBE_DIR"
2342+
# The extension is loaded by the Pi host, not by bare Node, so the probe
2343+
# provides what that host provides: Node's builtins plus the packages Pi
2344+
# ships to extensions (`typebox` — Pi's schema library for tool
2345+
# parameters). Every import the generated file makes must come from that
2346+
# set, otherwise it loads in this probe and fails in a real install with
2347+
# ERR_MODULE_NOT_FOUND. The typebox stub is a Proxy: any Type.X(...) call
2348+
# returns a descriptor, so the probe never depends on which helpers the
2349+
# emitter uses; it only exercises the tool lifecycle.
2350+
PI_HOST_PACKAGES="typebox"
2351+
mkdir -p "$PI_PROBE_DIR/node_modules/typebox"
2352+
cat >"$PI_PROBE_DIR/node_modules/typebox/package.json" <<'PITYPEBOXPKG'
2353+
{ "name": "typebox", "version": "0.0.0-smoke-stub", "type": "module", "exports": "./index.mjs" }
2354+
PITYPEBOXPKG
2355+
cat >"$PI_PROBE_DIR/node_modules/typebox/index.mjs" <<'PITYPEBOXSTUB'
2356+
export const Type = new Proxy({}, {
2357+
get: (_target, helper) => (...args) => ({ smokeStubHelper: String(helper), args }),
2358+
});
2359+
export default { Type };
2360+
PITYPEBOXSTUB
2361+
PI_FOREIGN_IMPORTS=$(grep -oE "^import .* from '[^']+'" "$PI_EXTENSION" |
2362+
sed -E "s/.* from '([^']+)'/\1/" | grep -vE '^node:' |
2363+
grep -vxF -f <(
2364+
# shellcheck disable=SC2086
2365+
printf '%s\n' $PI_HOST_PACKAGES
2366+
) || true)
2367+
if [ -n "$PI_FOREIGN_IMPORTS" ]; then
2368+
echo "FAIL 8al-node: generated Pi extension imports packages the Pi host does not provide: $(echo "$PI_FOREIGN_IMPORTS" | tr '\n' ' ')"
2369+
exit 1
2370+
fi
23422371
python3 - "$PI_EXTENSION" "$PI_PROBE_DIR/cbmem.mjs" <<'PYPIADAPTER'
23432372
import pathlib
23442373
import sys

0 commit comments

Comments
 (0)