From 77ece406ac91fa56ac7e60956196406a958afc17 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 21 Nov 2026 23:45:03 +0800 Subject: [PATCH] fix: align release Node versions and wrap mobile editor controls Pin CI and production Node to 24.22.3 and validate dependencies against the manifest and lockfile. Retain explicit legacy runtime compatibility coverage. Wrap configuration and script editor toolbar controls on mobile. Validation: 11 runtime image/platform combinations, Node layer checks, full panel and CLI suites, plus a frontend build and 18 focused tests with the UI changes included. --- .github/workflows/build-docker-image.yml | 17 +- .github/workflows/cli-package.yml | 11 +- .github/workflows/release-readiness.yml | 11 +- .github/workflows/validate.yml | 2 +- .nvmrc | 2 +- docker/Dockerfile | 8 +- docker/Dockerfile.310 | 8 +- docker/Dockerfile.debian | 4 +- docker/Dockerfile.debian310 | 4 +- docker/install-node-debian.sh | 10 +- scripts/verify-runtime-dependencies.cjs | 35 +++++ src/layouts/index.less | 13 ++ src/pages/config/index.tsx | 2 +- src/pages/script/index.tsx | 2 +- test/back/release-runtime-alignment.test.cjs | 154 +++++++++++++++++++ 15 files changed, 251 insertions(+), 32 deletions(-) create mode 100644 scripts/verify-runtime-dependencies.cjs create mode 100644 test/back/release-runtime-alignment.test.cjs diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index f220b7ef..b7349be7 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -76,8 +76,13 @@ jobs: if: ${{ !inputs.static_sync_only }} needs: validate runs-on: ubuntu-latest + outputs: + node-version: ${{ steps.runtime.outputs.node-version }} steps: - uses: actions/checkout@v6 + - name: Read production Node version + id: runtime + run: echo "node-version=$(cat .nvmrc)" >> "$GITHUB_OUTPUT" - uses: pnpm/action-setup@v6 with: version: "8.3.1" @@ -251,7 +256,7 @@ jobs: version: "8.3.1" - uses: actions/setup-node@v6 with: - node-version: "24" + node-version-file: ".nvmrc" cache: "pnpm" cache-dependency-path: pnpm-lock.yaml @@ -340,7 +345,7 @@ jobs: version: "8.3.1" - uses: actions/setup-node@v6 with: - node-version: "24" + node-version-file: ".nvmrc" cache: "pnpm" cache-dependency-path: pnpm-lock.yaml @@ -441,7 +446,8 @@ jobs: fail-fast: false matrix: node: ['20.18.1', '24'] - container: node:${{ matrix.node }}-bookworm + # Keep Node 20 for legacy upgrade acceptance; the current runtime is pinned. + container: node:${{ matrix.node == '24' && needs.build-static.outputs.node-version || matrix.node }}-bookworm steps: - uses: actions/checkout@v6 - uses: actions/download-artifact@v6 @@ -481,10 +487,11 @@ jobs: contents: read id-token: write steps: + - uses: actions/checkout@v6 - name: Set up Node for trusted publishing uses: actions/setup-node@v6 with: - node-version: '24' + node-version-file: '.nvmrc' registry-url: https://registry.npmjs.org package-manager-cache: false @@ -593,7 +600,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: - node-version: '24' + node-version-file: '.nvmrc' - uses: pnpm/action-setup@v6 with: version: '8.3.1' diff --git a/.github/workflows/cli-package.yml b/.github/workflows/cli-package.yml index bd9ef75e..bb85092d 100644 --- a/.github/workflows/cli-package.yml +++ b/.github/workflows/cli-package.yml @@ -8,6 +8,7 @@ on: - 'back/api/**' - 'back/loaders/deps.ts' - 'package.json' + - '.nvmrc' - '.github/workflows/cli-package.yml' push: branches: [develop, master] @@ -17,6 +18,7 @@ on: - 'back/api/**' - 'back/loaders/deps.ts' - 'package.json' + - '.nvmrc' - '.github/workflows/cli-package.yml' workflow_dispatch: inputs: @@ -55,7 +57,9 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: - node-version: ${{ matrix.node }} + # Retain the minimum supported CLI runtime alongside production Node. + node-version: ${{ matrix.node == '22.12.0' && matrix.node || '' }} + node-version-file: '.nvmrc' cache: npm cache-dependency-path: cli/package-lock.json - name: Install test interpreters and tools @@ -104,7 +108,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: - node-version: '24' + node-version-file: '.nvmrc' cache: npm cache-dependency-path: cli/package-lock.json - run: npm ci --prefix cli --no-audit --no-fund @@ -126,9 +130,10 @@ jobs: contents: read id-token: write steps: + - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: - node-version: '24' + node-version-file: '.nvmrc' package-manager-cache: false registry-url: https://registry.npmjs.org - uses: actions/download-artifact@v7 diff --git a/.github/workflows/release-readiness.yml b/.github/workflows/release-readiness.yml index 9c120a37..fd533b36 100644 --- a/.github/workflows/release-readiness.yml +++ b/.github/workflows/release-readiness.yml @@ -4,13 +4,18 @@ on: pull_request: paths: - '.github/workflows/release-readiness.yml' + - '.github/workflows/validate.yml' + - '.nvmrc' - 'package.json' - 'pnpm-lock.yaml' - 'docker/Dockerfile*' + - 'docker/install-node-debian.sh' - 'shell/node-runtime-probe.cjs' - 'scripts/verify-panel-package.cjs' - 'scripts/verify-image-node-layers.py' + - 'scripts/verify-runtime-dependencies.cjs' - 'test/back/node-runtime-probe.test.cjs' + - 'test/back/release-runtime-alignment.test.cjs' workflow_dispatch: permissions: @@ -36,7 +41,7 @@ jobs: version: '8.3.1' - uses: actions/setup-node@v6 with: - node-version: '20' + node-version-file: '.nvmrc' cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm build:front && pnpm build:back && pnpm build:info @@ -122,9 +127,9 @@ jobs: sbom: false - name: Verify native production runtime without external networking run: | - docker run --rm --network none --entrypoint node \ + docker run --rm -i --network none --entrypoint node \ qinglong-readiness:${{ matrix.image }} \ - -e 'const assert=require("node:assert/strict"); const {createRequire}=require("node:module"); for(const [name,want] of Object.entries({"@grpc/grpc-js":"1.14.5",compression:"1.8.2",multer:"2.4.0",sequelize:"6.37.8"}))assert.equal(require(name+"/package.json").version,want); const expressRequire=createRequire(require.resolve("express")); assert.equal(expressRequire("proxy-addr/package.json").version,"2.0.8"); const sockRequire=createRequire(require.resolve("sockjs")); assert.equal(sockRequire("websocket-driver/package.json").version,"0.7.5"); require("sqlite3"); require("nodemailer"); require("undici"); console.log("Minimal production patches and runtime imports verified")' + < scripts/verify-runtime-dependencies.cjs - name: Load ARMv6 image for SQLite and Node regression checks if: startsWith(matrix.image, 'alpine') uses: docker/build-push-action@v7 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index e6cfeb9f..6ac1e200 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -18,7 +18,7 @@ jobs: version: '8.3.1' - uses: actions/setup-node@v6 with: - node-version: '20' + node-version-file: '.nvmrc' cache: pnpm - run: pnpm install --frozen-lockfile - run: cp .env.example .env diff --git a/.nvmrc b/.nvmrc index 2bd5a0a9..229b3ce8 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -22 +24.22.3 diff --git a/docker/Dockerfile b/docker/Dockerfile index bb6aac26..091212ea 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ # Run Node package installation natively on the builder. Node/npm can spin at # 100% CPU when Alpine s390x is emulated through QEMU. -FROM --platform=$BUILDPLATFORM node:24.18.1-alpine3.24 AS builder +FROM --platform=$BUILDPLATFORM node:24.22.3-alpine3.24 AS builder ARG TARGETARCH ARG TARGETVARIANT @@ -31,7 +31,7 @@ RUN set -x \ pnpm install --prod --frozen-lockfile --side-effects-cache=false # Pin amd64 to upstream's musl runtime after native URL parser crashes with APK Node. -FROM --platform=linux/amd64 node:24.18.1-alpine3.24@sha256:f70403e87646dc51b45295f4b8b70cdad0b63d2297c4c9899119b03f7af7a6b3 AS node-runtime-amd64 +FROM --platform=linux/amd64 node:24.22.3-alpine3.24@sha256:116b800c3754b440ee0aa3ed2f20f5bf3d99a554bfd9adeea09ea8017f6e85f5 AS node-runtime-amd64 FROM python:3.11-alpine3.24 @@ -70,7 +70,7 @@ RUN --mount=type=bind,from=node-runtime-amd64,source=/usr/local/bin/node,target= tzdata \ perl \ openssl \ - nodejs \ + nodejs=24.22.3-r0 \ jq \ openssh \ procps \ @@ -81,7 +81,7 @@ RUN --mount=type=bind,from=node-runtime-amd64,source=/usr/local/bin/node,target= cp /tmp/node-runtime-amd64 /usr/local/bin/node; \ ln -sf /usr/local/bin/node /usr/bin/node; \ fi \ - && node --version | grep -E '^v24\.' \ + && test "$(node --version)" = "v24.22.3" \ && rm -rf /var/cache/apk/* \ && apk update \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ diff --git a/docker/Dockerfile.310 b/docker/Dockerfile.310 index bbe87a97..aa162957 100644 --- a/docker/Dockerfile.310 +++ b/docker/Dockerfile.310 @@ -1,6 +1,6 @@ # Run Node package installation natively on the builder. Node/npm can spin at # 100% CPU when Alpine s390x is emulated through QEMU. -FROM --platform=$BUILDPLATFORM node:24.18.1-alpine3.24 AS builder +FROM --platform=$BUILDPLATFORM node:24.22.3-alpine3.24 AS builder ARG TARGETARCH ARG TARGETVARIANT @@ -31,7 +31,7 @@ RUN set -x \ pnpm install --prod --frozen-lockfile --side-effects-cache=false # Pin amd64 to upstream's musl runtime after native URL parser crashes with APK Node. -FROM --platform=linux/amd64 node:24.18.1-alpine3.24@sha256:f70403e87646dc51b45295f4b8b70cdad0b63d2297c4c9899119b03f7af7a6b3 AS node-runtime-amd64 +FROM --platform=linux/amd64 node:24.22.3-alpine3.24@sha256:116b800c3754b440ee0aa3ed2f20f5bf3d99a554bfd9adeea09ea8017f6e85f5 AS node-runtime-amd64 FROM python:3.10-alpine3.24 @@ -70,7 +70,7 @@ RUN --mount=type=bind,from=node-runtime-amd64,source=/usr/local/bin/node,target= tzdata \ perl \ openssl \ - nodejs \ + nodejs=24.22.3-r0 \ jq \ openssh \ procps \ @@ -81,7 +81,7 @@ RUN --mount=type=bind,from=node-runtime-amd64,source=/usr/local/bin/node,target= cp /tmp/node-runtime-amd64 /usr/local/bin/node; \ ln -sf /usr/local/bin/node /usr/bin/node; \ fi \ - && node --version | grep -E '^v24\.' \ + && test "$(node --version)" = "v24.22.3" \ && rm -rf /var/cache/apk/* \ && apk update \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ diff --git a/docker/Dockerfile.debian b/docker/Dockerfile.debian index 2b3a6499..6f7c5b8e 100644 --- a/docker/Dockerfile.debian +++ b/docker/Dockerfile.debian @@ -16,7 +16,7 @@ RUN set -x && \ apt-get update && \ apt-get install --no-install-recommends -y libatomic1 && \ npm i -g pnpm@8.3.1 && \ - test "$(node --version)" = "v24.18.1" && \ + test "$(node --version)" = "v24.22.3" && \ test "$(pnpm --version)" = "8.3.1" && \ cd /tmp/build && \ pnpm install --prod --frozen-lockfile @@ -77,7 +77,7 @@ RUN set -x && \ git config --global user.name "qinglong" && \ git config --global http.postBuffer 524288000 && \ npm install -g pnpm@8.3.1 pm2 ts-node typescript@5 && \ - test "$(node --version)" = "v24.18.1" && \ + test "$(node --version)" = "v24.22.3" && \ test "$(pnpm --version)" = "8.3.1" && \ npm cache clean --force && \ rm -rf /root/.cache && \ diff --git a/docker/Dockerfile.debian310 b/docker/Dockerfile.debian310 index b7e3b928..6247d4e5 100644 --- a/docker/Dockerfile.debian310 +++ b/docker/Dockerfile.debian310 @@ -18,7 +18,7 @@ RUN set -x && \ apt-get update && \ apt-get install --no-install-recommends -y libatomic1 && \ npm i -g pnpm@8.3.1 && \ - test "$(node --version)" = "v24.18.1" && \ + test "$(node --version)" = "v24.22.3" && \ cd /tmp/build && \ pnpm install --prod --frozen-lockfile @@ -77,7 +77,7 @@ RUN set -x && \ git config --global user.name "qinglong" && \ git config --global http.postBuffer 524288000 && \ npm install -g pnpm@8.3.1 pm2 ts-node typescript@5 && \ - test "$(node --version)" = "v24.18.1" && \ + test "$(node --version)" = "v24.22.3" && \ npm cache clean --force && \ rm -rf /root/.cache && \ rm -rf /root/.npm && \ diff --git a/docker/install-node-debian.sh b/docker/install-node-debian.sh index ca17eaa4..bc9b3021 100644 --- a/docker/install-node-debian.sh +++ b/docker/install-node-debian.sh @@ -3,12 +3,12 @@ set -eu # The official Node 24 Bookworm image does not cover s390x. Use the same # verified upstream release archive on every supported Debian architecture. -version=24.18.1 +version=24.22.3 case "${1:?Missing Docker TARGETARCH}" in - amd64) arch=x64; checksum=d6c664df3f3f61458e8c277585571328522d705166723a7c7823a9253a4d15a0 ;; - arm64) arch=arm64; checksum=7201e3a09dc825bac57867c81913e2b8f0ef87d04cb9082af4cda82f6ff3d88c ;; - ppc64le) arch=ppc64le; checksum=c47812c13862be7f6e71194c434c4d78a99096e72efb9c31a2627437e056d669 ;; - s390x) arch=s390x; checksum=acf57bd726f35afc2ba8475194e5a8bd532c00e1a3b2436295b2fbdde199d0e9 ;; + amd64) arch=x64; checksum=4f2b175a6d53a5c617a80dba2676238a0688cef28c6da4eba35c7d844e66fcfb ;; + arm64) arch=arm64; checksum=6e51a2ada00f0011cc266f65d98922b403d7ad88f809ca2aa615a5fe1ce6e86c ;; + ppc64le) arch=ppc64le; checksum=c4b446699171f64763304a0bc6fb972b0fb4acb1de5358e52b4c52a95883593a ;; + s390x) arch=s390x; checksum=b5dbeb563ffb81946478fd765ae92efc21117e410e4e9b7d966bf59b00cee55d ;; *) echo "Node ${version} has no supported Debian binary for TARGETARCH=$1" >&2; exit 1 ;; esac diff --git a/scripts/verify-runtime-dependencies.cjs b/scripts/verify-runtime-dependencies.cjs new file mode 100644 index 00000000..32353c14 --- /dev/null +++ b/scripts/verify-runtime-dependencies.cjs @@ -0,0 +1,35 @@ +// Run from the panel root, including via stdin inside an offline release image. +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const { createRequire } = require('node:module'); +const yaml = require('js-yaml'); + +assert.equal(process.versions.node, fs.readFileSync('.nvmrc', 'utf8').trim(), 'Node runtime differs from the production version'); + +const panelRequire = createRequire(path.resolve('package.json')); +const manifest = panelRequire('./package.json'); +const lock = yaml.load(fs.readFileSync('pnpm-lock.yaml', 'utf8')); + +function verifyDirect(name) { + const entry = lock.dependencies[name]; + assert.equal(entry?.specifier, manifest.dependencies[name], `${name}: manifest/lock mismatch`); + // pnpm appends peer resolution context, e.g. 6.37.8(@whyour/sqlite3@1.1.5). + assert.equal(panelRequire(`${name}/package.json`).version, entry.version.split('(')[0], `${name}: installed/lock mismatch`); + return entry.version; +} + +for (const name of ['@grpc/grpc-js', 'compression', 'multer', 'sequelize']) { + verifyDirect(name); +} + +for (const [parent, name] of [['express', 'proxy-addr'], ['sockjs', 'websocket-driver']]) { + const version = verifyDirect(parent); + const expected = lock.packages[`/${parent}@${version}`]?.dependencies?.[name]; + assert.ok(expected, `${parent} > ${name}: missing lock entry`); + const parentRequire = createRequire(panelRequire.resolve(parent)); + assert.equal(parentRequire(`${name}/package.json`).version, expected.split('(')[0], `${parent} > ${name}: installed/lock mismatch`); +} + +for (const name of ['sqlite3', 'nodemailer', 'undici']) panelRequire(name); +console.log('Production dependencies match the manifest and lockfile; runtime imports verified'); diff --git a/src/layouts/index.less b/src/layouts/index.less index fe2fd21a..40738d3f 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -185,6 +185,19 @@ body[data-mode='phone'] { .config-wrapper .config-select { width: min(38vw, 140px); } + + .editor-toolbar-wrapper .ant-page-header-heading-extra { + min-width: 0; + max-width: 100%; + justify-content: flex-start; + + // PageContainer wraps its extra controls in a non-wrapping Space. + > .ant-space { + max-width: 100%; + flex-wrap: wrap; + justify-content: flex-start; + } + } } .ant-tree { diff --git a/src/pages/config/index.tsx b/src/pages/config/index.tsx index 411e8113..0cc1a02f 100644 --- a/src/pages/config/index.tsx +++ b/src/pages/config/index.tsx @@ -96,7 +96,7 @@ const Config = () => { return ( { return ( {select} diff --git a/test/back/release-runtime-alignment.test.cjs b/test/back/release-runtime-alignment.test.cjs new file mode 100644 index 00000000..184ff938 --- /dev/null +++ b/test/back/release-runtime-alignment.test.cjs @@ -0,0 +1,154 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const vm = require('node:vm'); +const { spawnSync } = require('node:child_process'); +const yaml = require('js-yaml'); + +const root = path.resolve(__dirname, '../..'); +const read = (file) => fs.readFileSync(path.join(root, file), 'utf8'); +const productionNode = read('.nvmrc').trim(); +const workflow = (name) => yaml.load(read(`.github/workflows/${name}.yml`)); +const verifier = path.join(root, 'scripts/verify-runtime-dependencies.cjs'); + +test('CI uses the pinned production Node, retaining explicit compatibility coverage', () => { + assert.match(productionNode, /^24\.\d+\.\d+$/); + for (const file of ['docker/Dockerfile', 'docker/Dockerfile.310']) { + const versions = [...read(file).matchAll(/\bnode:(\d+\.\d+\.\d+)-alpine/g)]; + assert.ok(versions.length >= 2, file); + for (const [, version] of versions) assert.equal(version, productionNode, file); + const packageVersion = read(file).match(/\bnodejs=(\d+\.\d+\.\d+)-r\d+/); + assert.ok(packageVersion, `${file}: pin the Alpine Node package`); + assert.equal(packageVersion[1], productionNode, file); + assert.ok(read(file).includes(`test "$(node --version)" = "v${productionNode}"`), file); + } + assert.equal(read('docker/install-node-debian.sh').match(/^version=(.*)$/m)[1], productionNode); + for (const file of ['docker/Dockerfile.debian', 'docker/Dockerfile.debian310']) { + const versions = [...read(file).matchAll(/"v(\d+\.\d+\.\d+)"/g)]; + assert.ok(versions.length >= 2, file); + for (const [, version] of versions) assert.equal(version, productionNode, file); + } + for (const name of ['validate', 'release-readiness', 'build-docker-image', 'cli-package']) { + for (const [jobName, job] of Object.entries(workflow(name).jobs)) { + const steps = job.steps || []; + for (const [index, step] of steps.entries()) { + if (!step.uses?.startsWith('actions/setup-node@')) continue; + assert.equal(step.with['node-version-file'], '.nvmrc', `${name}/${jobName}`); + assert.ok(steps.slice(0, index).some((s) => s.uses?.startsWith('actions/checkout@')), `${name}/${jobName}: checkout before version file`); + const version = step.with['node-version']; + if (!version) continue; + assert.equal(name, 'cli-package'); + assert.equal(jobName, 'package'); + for (const node of job.strategy.matrix.node) { + const resolved = vm.runInNewContext(version.slice(3, -2), { matrix: { node } }); + assert.equal(resolved || productionNode, node === '22.12.0' ? node : productionNode); + } + } + } + } + const build = workflow('build-docker-image'); + const runtime = build.jobs['build-static'].steps.find((s) => s.id === 'runtime'); + assert.match(runtime.run, /cat \.nvmrc/); + assert.equal(build.jobs['build-static'].outputs['node-version'], '${{ steps.runtime.outputs.node-version }}'); + const verify = build.jobs['verify-npm-package']; + const expression = verify.container.match(/\$\{\{(.*?)\}\}/)[1] + .replace('needs.build-static.outputs.node-version', JSON.stringify(productionNode)); + for (const node of verify.strategy.matrix.node) { + const version = vm.runInNewContext(expression, { matrix: { node } }); + assert.equal(version, node === '20.18.1' ? node : productionNode); + } +}); + +test('release readiness runs the source verifier offline and watches its inputs', () => { + const readiness = workflow('release-readiness'); + for (const file of ['.nvmrc', '.github/workflows/validate.yml', 'docker/install-node-debian.sh', 'scripts/verify-runtime-dependencies.cjs', 'test/back/release-runtime-alignment.test.cjs']) { + assert.ok(readiness.on.pull_request.paths.includes(file), file); + } + const step = readiness.jobs.images.steps.find((s) => s.name === 'Verify native production runtime without external networking'); + assert.match(step.run, /docker run --rm -i --network none --entrypoint node/); + assert.match(step.run, /< scripts\/verify-runtime-dependencies\.cjs/); +}); + +function fixture(t) { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-release-deps-')); + t.after(() => fs.rmSync(directory, { recursive: true, force: true })); + const manifest = { dependencies: {} }; + const lock = { dependencies: {}, packages: {} }; + const write = (file, data) => { + const target = path.join(directory, file); + fs.mkdirSync(path.dirname(target), { recursive: true }); + fs.writeFileSync(target, typeof data === 'string' ? data : JSON.stringify(data)); + }; + const install = (name, version, parent) => { + const prefix = `node_modules/${parent ? `${parent}/node_modules/` : ''}${name}`; + write(`${prefix}/package.json`, { name, version, main: 'index.js' }); + write(`${prefix}/index.js`, 'module.exports = {};'); + }; + for (const name of ['@grpc/grpc-js', 'compression', 'multer', 'sequelize', 'express', 'sockjs']) { + manifest.dependencies[name] = '1.0.0'; + lock.dependencies[name] = { specifier: '1.0.0', version: '1.0.0' }; + install(name, '1.0.0'); + } + for (const [parent, name] of [['express', 'proxy-addr'], ['sockjs', 'websocket-driver']]) { + lock.packages[`/${parent}@1.0.0`] = { dependencies: { [name]: '1.0.0' } }; + install(name, '1.0.0', parent); + // A healthy root copy must not mask a stale copy resolved by the parent. + install(name, '1.0.0'); + } + for (const name of ['sqlite3', 'nodemailer', 'undici']) install(name, '1.0.0'); + write('.nvmrc', process.versions.node); + lock.dependencies.sequelize.version = '1.0.0(@whyour/sqlite3@1.1.5)'; + const run = (stdin = false) => { + write('package.json', manifest); + write('pnpm-lock.yaml', yaml.dump(lock)); + return spawnSync(process.execPath, stdin ? [] : [verifier], { + cwd: directory, encoding: 'utf8', timeout: 10000, + ...(stdin ? { input: fs.readFileSync(verifier, 'utf8'), env: { ...process.env, NODE_PATH: path.join(root, 'node_modules') } } : {}), + }); + }; + return { manifest, lock, install, run, write }; +} + +test('runtime verification follows dependency upgrades without a second version list, including stdin execution', (t) => { + const f = fixture(t); + f.manifest.dependencies.multer = '2.9.0'; + f.lock.dependencies.multer = { specifier: '2.9.0', version: '2.9.0' }; + f.install('multer', '2.9.0'); + f.lock.packages['/express@1.0.0'].dependencies['proxy-addr'] = '3.0.0'; + f.install('proxy-addr', '3.0.0', 'express'); + for (const stdin of [false, true]) { + const result = f.run(stdin); + assert.equal(result.status, 0, result.stderr); + } +}); + +for (const scenario of ['node-version', 'manifest', 'direct', 'transitive', 'missing-lock', 'missing-import']) { + test(`runtime verification rejects ${scenario} drift`, (t) => { + const f = fixture(t); + let expected; + if (scenario === 'node-version') { + f.write('.nvmrc', '0.0.0'); + expected = /Node runtime differs from the production version/; + } else if (scenario === 'manifest') { + f.manifest.dependencies.multer = '2.0.0'; + expected = /multer: manifest\/lock mismatch/; + } else if (scenario === 'direct') { + f.install('multer', '0.9.0'); + expected = /multer: installed\/lock mismatch/; + } else if (scenario === 'transitive') { + f.install('proxy-addr', '0.9.0', 'express'); + expected = /express > proxy-addr: installed\/lock mismatch/; + } else if (scenario === 'missing-lock') { + delete f.lock.packages['/sockjs@1.0.0']; + expected = /sockjs > websocket-driver: missing lock entry/; + } else { + f.write('node_modules/sqlite3/index.js', 'throw new Error("native binding unavailable")'); + expected = /native binding unavailable/; + } + const result = f.run(); + assert.notEqual(result.status, 0); + assert.match(result.stderr, expected); + }); +}