From 31c8149c7c5a4264e0a1e003d1e4290e2cfdb33e Mon Sep 17 00:00:00 2001 From: awork Date: Sun, 18 Oct 2026 02:45:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ci:=20thin-install=20smoke=20lane=20?= =?UTF-8?q?=E2=80=94=20run=20the=20packed=20tarball=20from=20a=20bare=20in?= =?UTF-8?q?stall=20(#3617-C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New scripts/check-dist-thin-install.mjs, wired into the static-gates job after > billion-context@0.1.199 build > npm --prefix kernel run build && npm --prefix pi-subagents run build && tsup && node scripts/write-build-info.mjs && node scripts/check-dist-import-annotations.mjs && node scripts/check-dist-external-zod.mjs > acp-kernel@0.0.130 build > npm run clean && tsup && tsc --emitDeclarationOnly > acp-kernel@0.0.130 clean > node -e "require('fs').rmSync('dist',{recursive:true,force:true})" CLI Building entry: src/index.ts, src/panel/index.ts, src/persist/index.ts, src/wire/index.ts CLI Using tsconfig: tsconfig.json CLI tsup v8.5.1 CLI Using tsup config: /var/lib/ework-daemon/share/opencode-workdir/ranxianglei--billion-context/3617/ework-daemon/kernel/tsup.config.ts CLI Target: es2022 ESM Build start ESM dist/persist/index.js 19.83 KB ESM dist/wire/index.js 58.33 KB ESM dist/index.js 314.09 KB ESM dist/chunk-KJXO6XX7.js 29.34 KB ESM dist/chunk-6ECDTFU5.js 2.02 KB ESM dist/panel/index.js 6.96 KB ESM dist/persist/index.js.map 46.16 KB ESM dist/wire/index.js.map 154.06 KB ESM dist/chunk-KJXO6XX7.js.map 53.58 KB ESM dist/chunk-6ECDTFU5.js.map 4.38 KB ESM dist/panel/index.js.map 17.58 KB ESM dist/index.js.map 752.42 KB ESM ⚡️ Build success in 92ms > billion-context-pi-subagents@0.2.0 build > tsup && tsc --emitDeclarationOnly CLI Building entry: src/index.ts CLI Using tsconfig: tsconfig.json CLI tsup v8.5.1 CLI Using tsup config: /var/lib/ework-daemon/share/opencode-workdir/ranxianglei--billion-context/3617/ework-daemon/pi-subagents/tsup.config.ts CLI Target: es2022 CLI Cleaning output folder ESM Build start ESM dist/index.js 464.23 KB ESM dist/index.js.map 1.31 MB ESM ⚡️ Build success in 266ms CLI Building entry: {"agent/dsh-native-client":"src/agent/dsh-native-client.ts"} CLI Using tsconfig: tsconfig.json CLI tsup v8.5.1 CLI Using tsup config: /var/lib/ework-daemon/share/opencode-workdir/ranxianglei--billion-context/3617/ework-daemon/tsup.config.ts CLI Building entry: src/claude-native-bootstrap.ts, src/index.ts, src/mcp.ts, src/agent/dsh-acp.ts, src/agent/dsh-native.ts, src/agent/omp-native.ts, src/agent/omp.ts, src/agent/opencode-native.ts, src/agent/opencode.ts, src/agent/pi-native.ts, src/agent/pi.ts, src/kimi/bootstrap-hook.ts, src/kimi/native-mcp.ts, src/zcode/bootstrap-hook.ts, src/zcode/mcp-entry.ts CLI Using tsconfig: tsconfig.json CLI tsup v8.5.1 CLI Using tsup config: /var/lib/ework-daemon/share/opencode-workdir/ranxianglei--billion-context/3617/ework-daemon/tsup.config.ts CLI Target: es2020 CJS Build start CLI Target: node20 CLI Cleaning output folder ESM Build start CJS dist/agent/dsh-native-client.js 14.08 KB CJS ⚡️ Build success in 36ms ESM dist/agent/dsh-acp.js 5.77 KB ESM dist/mcp.js 731.30 KB ESM dist/agent/omp.js 1.27 MB ESM dist/agent/pi.js 1.27 MB ESM dist/claude-native-bootstrap.js 2.13 MB ESM dist/agent/opencode-native.js 2.30 MB ESM dist/agent/opencode.js 2.27 MB ESM dist/kimi/bootstrap-hook.js 2.10 MB ESM dist/kimi/native-mcp.js 2.14 MB ESM dist/zcode/bootstrap-hook.js 2.11 MB ESM dist/zcode/mcp-entry.js 2.16 MB ESM dist/agent/dsh-native.js 2.22 MB ESM dist/agent/dsh-acp.js.map 49.41 KB ESM dist/agent/omp-native.js 2.60 MB ESM dist/index.js 4.64 MB ESM dist/agent/pi-native.js 4.69 MB ESM dist/mcp.js.map 2.05 MB ESM dist/agent/omp.js.map 5.32 MB ESM dist/agent/pi.js.map 5.32 MB ESM dist/claude-native-bootstrap.js.map 6.92 MB ESM dist/kimi/native-mcp.js.map 6.94 MB ESM dist/zcode/mcp-entry.js.map 6.95 MB ESM dist/agent/opencode.js.map 8.07 MB ESM dist/agent/opencode-native.js.map 8.16 MB ESM dist/zcode/bootstrap-hook.js.map 6.91 MB ESM dist/agent/dsh-native.js.map 7.50 MB ESM dist/kimi/bootstrap-hook.js.map 6.91 MB ESM dist/agent/omp-native.js.map 8.85 MB ESM dist/index.js.map 13.03 MB ESM dist/agent/pi-native.js.map 14.22 MB ESM ⚡️ Build success in 3342ms build-info: commit=fd3232fae-dirty dist-import-annotations: OK dist-external-zod: OK (additive step; no matrix/leg-name changes, branch protection untouched). It packs the current tree, installs ONLY the tarball into a scratch dir with no repo node_modules, then proves the artifact runs: 0.1.199 (fd3232fae-dirty) exits 0, and every Node-consumed dist/agent/*.js entry imports in its own process. dsh-native-client.js is a browser bundle by design (tsup platform:browser, window.__ModuleLoader__ format) — parse-checked instead of imported.\n\nWhy: #3511 (zod statically in dist while undeclared) shipped because PR CI never installed the tarball into a bare dir — #3519's check-dist-external-zod gate is static analysis for ONE known offender and CI ran it only inside the build chain. This smoke catches ANY undeclared runtime dependency at import time, in the same shape a real consumer hits it. Verified negative: injecting a fake undeclared import into a built bundle fails the script with ERR_MODULE_NOT_FOUND.\n\nDeliberately NOT added to the local build chain or the prepare gate: it needs registry access for declared deps and must not slow consumer installs. Also exposed as > billion-context@0.1.199 check:dist-thin > node scripts/check-dist-thin-install.mjs dist-thin-install: OK — cli 0.1.199; imported 8 agent bundle(s) [dsh-acp.js, dsh-native.js, omp-native.js, omp.js, opencode-native.js, opencode.js, pi-native.js, pi.js]; parse-checked browser bundle(s) [dsh-native-client.js] for manual use. No behavior change to the product. --- .github/workflows/ci.yml | 5 ++ package.json | 1 + scripts/check-dist-thin-install.mjs | 83 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 scripts/check-dist-thin-install.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 781c6eac2b..e3eacf7c76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -238,6 +238,11 @@ jobs: # pi-lane component — its own unit suite against its TS source. - run: npm --prefix pi-subagents test - run: npm run build + # #3617-C: thin-install smoke — install ONLY the packed tarball into a + # scratch dir (no repo node_modules) and run it: catches ANY undeclared + # runtime dependency in the bundles at import time (the #3511 zod class; + # generalizes #3519's static-only check). + - run: node scripts/check-dist-thin-install.mjs version-guard: runs-on: ubuntu-latest diff --git a/package.json b/package.json index 52a8ecd432..0636c3ce3e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "typecheck": "tsc --noEmit --project tsconfig.json", "check:unused-exports": "node scripts/check-unused-exports.mjs", "check:test-import-graph": "node scripts/check-test-import-graph.mjs", + "check:dist-thin": "node scripts/check-dist-thin-install.mjs", "pretest": "node scripts/test-suite-lock.mjs gate && npm --prefix kernel run build && npm --prefix pi-subagents run build", "test": "node scripts/test-suite-lock.mjs run", "start": "node dist/index.js", diff --git a/scripts/check-dist-thin-install.mjs b/scripts/check-dist-thin-install.mjs new file mode 100644 index 0000000000..aff0973e25 --- /dev/null +++ b/scripts/check-dist-thin-install.mjs @@ -0,0 +1,83 @@ +// Thin-install smoke (#3617-C, generalizes the #3511 zod class): pack the +// current tree, install ONLY the tarball into a scratch dir with no repo +// node_modules, then prove the artifact actually runs: +// 1. `node dist/index.js --version` exits 0 (the CLI entry loads); +// 2. every Node-consumed dist/agent/*.js entry IMPORTS in its own process +// without throwing — an undeclared runtime dependency fails here at +// import time, exactly where it would fail in a real consumer's process +// (static analysis like check-dist-external-zod can only see one known +// offender; this catches any future one). +// Run after `npm run build` in CI (static-gates). Deliberately NOT part of +// the local build chain or the prepare gate: it needs registry access for +// the package's declared deps and must never slow a consumer install. + +import { execFileSync, spawnSync } from "node:child_process"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import process from "node:process"; +import { fileURLToPath, pathToFileURL } from "node:url"; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"; + +function fail(msg) { + console.error(`dist-thin-install: FAIL — ${msg}`); + process.exit(1); +} + +if (!existsSync(path.join(root, "dist", "index.js"))) { + fail("dist/index.js missing — run `npm run build` first"); +} +const repoVersion = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")).version; + +const scratch = mkdtempSync(path.join(os.tmpdir(), "bili-thin-install-")); +try { + // 1. Pack + install the tarball alone (declared deps come from the + // registry; nothing from this checkout). + execFileSync(npmCmd, ["pack", "--pack-destination", scratch, "--loglevel=error"], { cwd: root, stdio: "pipe" }); + const tarball = readdirSync(scratch).find((f) => f.startsWith("billion-context-") && f.endsWith(".tgz")); + if (!tarball) fail("npm pack produced no tarball"); + const installDir = path.join(scratch, "install"); + mkdirSync(installDir, { recursive: true }); + writeFileSync(path.join(installDir, "package.json"), JSON.stringify({ name: "bili-thin-smoke", version: "0.0.0", private: true }, null, 2)); + execFileSync(npmCmd, ["install", path.join(scratch, tarball), "--no-audit", "--no-fund", "--loglevel=error"], { cwd: installDir, stdio: "pipe" }); + const pkgDir = path.join(installDir, "node_modules", "billion-context"); + if (!existsSync(path.join(pkgDir, "dist", "index.js"))) fail("installed tarball has no dist/index.js"); + const installedVersion = JSON.parse(readFileSync(path.join(pkgDir, "package.json"), "utf8")).version; + if (installedVersion !== repoVersion) fail(`installed version ${installedVersion} != repo version ${repoVersion}`); + + // 2. CLI entry runs and reports its version. + const cli = spawnSync(process.execPath, [path.join(pkgDir, "dist", "index.js"), "--version"], { encoding: "utf8" }); + if (cli.status !== 0 || !/\d+\.\d+\.\d+/.test(cli.stdout ?? "")) { + fail(`dist/index.js --version exited ${cli.status}: ${(cli.stderr ?? "").slice(0, 400)}`); + } + + // 3. Every agent entry imports standalone (own process each: a real host + // loads exactly one bundle, so cross-bundle interference is not a signal). + const agentDir = path.join(pkgDir, "dist", "agent"); + const entries = readdirSync(agentDir).filter((f) => f.endsWith(".js") && !f.endsWith(".map")).sort(); + if (entries.length === 0) fail("no dist/agent/*.js entries found in the tarball"); + const imported = []; + const parsed = []; + for (const name of entries) { + const file = path.join(agentDir, name); + if (name === "dsh-native-client.js") { + // Browser bundle by design (tsup platform:"browser", cjs, + // window.__ModuleLoader__ format, react external): it cannot be + // imported in Node. Parse-check it instead — a broken build still + // fails here, and it has no Node-visible externals to miss. + const chk = spawnSync(process.execPath, ["--check", file], { encoding: "utf8" }); + if (chk.status !== 0) fail(`parse check failed for ${name}: ${(chk.stderr ?? "").slice(0, 400)}`); + parsed.push(name); + continue; + } + const probe = `await import(${JSON.stringify(pathToFileURL(file).href)});`; + const r = spawnSync(process.execPath, ["--input-type=module", "-e", probe], { encoding: "utf8" }); + if (r.status !== 0) fail(`import failed for ${name}: ${(r.stderr ?? "").slice(0, 400)}`); + imported.push(name); + } + console.log(`dist-thin-install: OK — cli ${installedVersion}; imported ${imported.length} agent bundle(s) [${imported.join(", ")}]; parse-checked browser bundle(s) [${parsed.join(", ")}]`); +} finally { + rmSync(scratch, { recursive: true, force: true }); +} From 479832b12178034636ae3c890abff3a0d3a38d3f Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sun, 18 Oct 2026 13:19:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(win):=20spawn=20npm.cmd=20through=20a?= =?UTF-8?q?=20shell=20in=20thin-install=20smoke=20=E2=80=94=20Node=20>=3D2?= =?UTF-8?q?2=20EINVAL=20without=20it=20(#3617-C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows static-gates failed with EINVAL spawnSync npm.cmd: spawning a .cmd requires shell:true since the CVE-2024-27980 hardening in Node 18.20/20.12/22. The npmCmd line was copied from run-ci-tests.mjs but the matching shell option was missed. Add it at both call sites (pack, install); Linux behavior unchanged (shell:false). --- scripts/check-dist-thin-install.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/check-dist-thin-install.mjs b/scripts/check-dist-thin-install.mjs index aff0973e25..f202fe870d 100644 --- a/scripts/check-dist-thin-install.mjs +++ b/scripts/check-dist-thin-install.mjs @@ -19,6 +19,9 @@ import process from "node:process"; import { fileURLToPath, pathToFileURL } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +// NOTE: spawning npm.cmd on Windows requires shell:true (Node >= 18.20/22 +// hardening, CVE-2024-27980) — EINVAL otherwise. Same pattern as +// scripts/run-ci-tests.mjs:141. const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"; function fail(msg) { @@ -35,13 +38,13 @@ const scratch = mkdtempSync(path.join(os.tmpdir(), "bili-thin-install-")); try { // 1. Pack + install the tarball alone (declared deps come from the // registry; nothing from this checkout). - execFileSync(npmCmd, ["pack", "--pack-destination", scratch, "--loglevel=error"], { cwd: root, stdio: "pipe" }); + execFileSync(npmCmd, ["pack", "--pack-destination", scratch, "--loglevel=error"], { cwd: root, stdio: "pipe", shell: process.platform === "win32" }); const tarball = readdirSync(scratch).find((f) => f.startsWith("billion-context-") && f.endsWith(".tgz")); if (!tarball) fail("npm pack produced no tarball"); const installDir = path.join(scratch, "install"); mkdirSync(installDir, { recursive: true }); writeFileSync(path.join(installDir, "package.json"), JSON.stringify({ name: "bili-thin-smoke", version: "0.0.0", private: true }, null, 2)); - execFileSync(npmCmd, ["install", path.join(scratch, tarball), "--no-audit", "--no-fund", "--loglevel=error"], { cwd: installDir, stdio: "pipe" }); + execFileSync(npmCmd, ["install", path.join(scratch, tarball), "--no-audit", "--no-fund", "--loglevel=error"], { cwd: installDir, stdio: "pipe", shell: process.platform === "win32" }); const pkgDir = path.join(installDir, "node_modules", "billion-context"); if (!existsSync(path.join(pkgDir, "dist", "index.js"))) fail("installed tarball has no dist/index.js"); const installedVersion = JSON.parse(readFileSync(path.join(pkgDir, "package.json"), "utf8")).version;