Files
headroom/e2e/wrap/tools/dependency-regression.test.cjs
Parideboy f6fbac3a49 fix(deps): move the wrap E2E harness to npm 12.2.2 and drop the fixed audit exceptions (#4778)
## Description

`e2e/wrap/tools/npm-audit-exceptions.json` excepted 8 advisories in npm
12.2.1's bundled copies and gave "no newer npm release is available" as
part of the reason. npm 12.2.2 is published and bundles cleanness for 6
of those 8: undici 6.29.0 → 6.29.1 and ip-address 10.7.2 → 10.7.5.
Moving the harness pin drops those exceptions; glob 13.0.6 and minimatch
10.2.5 are unchanged, so their two exceptions stay and the file's expiry
moves off the 2026-11-15 cliff, where the security job would otherwise
fail every PR.

Closes #4774

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- `e2e/wrap/tools/package.json` and `e2e/wrap/Dockerfile`: pin npm
12.2.2 instead of 12.2.1, in both the dependency override and the
image's global install.
- `e2e/wrap/tools/package-lock.json`: regenerated by installing the lock
with npm 12.2.2 itself. `npm install --package-lock-only` does **not**
refresh the `inBundle` child entries, so it left undici at 6.29.0; a
real `npm install --ignore-scripts` updated them. Only the bundled
copies npm 12.2.2 changed moved — `@npmcli/promise-spawn` 10.0.1,
`bin-links` 7.0.1, `ip-address` 10.7.5, `libnpmexec` 11.0.5, `pacote`
22.0.1, `semver` 7.8.6, `undici` 6.29.1 — with no unrelated transitive
drift and the npm entry itself at 12.2.2 with the registry's
`dist.integrity`.
- `e2e/wrap/tools/npm-audit-exceptions.json`: removed the 5 undici and 1
ip-address entries, corrected the reason (they are fixed in what 12.2.2
bundles), and moved `expires` to 2026-12-15 so the two glob/minimatch
exceptions left are not a four-day fuse.
- `e2e/wrap/tools/README.md`: the pin references, the paragraph
describing which bundled copies the audit still reports, and a separate
procedure for bumping the `npm` override, since `npm install
--package-lock-only` does not refresh npm's `inBundle` children.
- `e2e/wrap/tools/dependency-regression.test.cjs` and
`e2e/wrap/Dockerfile`: a regression test that reads npm's bundled undici
and ip-address versions, fails if either is below its fixed floor
(6.29.1, 10.7.5) or still has an entry in `npm-audit-exceptions.json`,
and runs in the image too.

## Testing

- [ ] Unit tests pass (`pytest`)
- [ ] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
# npm 12.2.2 tarball, from registry.npmjs.org (sha512 matches dist.integrity)
$ tar -xzf npm-12.2.2.tgz
undici 6.29.1
ip-address 10.7.5
glob 13.0.6
minimatch 10.2.5
12.2.2

# every bundled copy the registry tarball ships, vs npm 12.2.1
changed: 7
@npmcli/promise-spawn: 10.0.0 -> 10.0.1
bin-links: 7.0.0 -> 7.0.1
ip-address: 10.7.2 -> 10.7.5
libnpmexec: 11.0.4 -> 11.0.5
pacote: 22.0.0 -> 22.0.1
semver: 7.8.5 -> 7.8.6
undici: 6.29.0 -> 6.29.1

# CI's audit step from .github/workflows/security.yml, run locally on the new lock
$ cd e2e/wrap/tools && npm audit --package-lock-only --json > audit.json && python3 ci_audit_check.py audit.json
Only excepted bundled advisories remain (2), until 2026-12-15.

# same script, same lock, with the runner's npm 11 instead of 12.2.2
Only excepted bundled advisories remain (2), until 2026-12-15.

# raw audit totals, before -> after
{"moderate":33,"high":1,"total":34}   # undici high + ip-address moderate
{"moderate":33,"high":0,"total":33}   # glob + minimatch only; the rest inherit from them

# clean install of the new lock with npm 12.2.2, in a scratch prefix like /opt/wrap-tools
$ npm ci --prefix <dir> --no-fund --no-audit --strict-allow-scripts
added 363 packages in 28s
$ npm test                      # this branch
1..4
# tests 4
# pass 4
# fail 0

# the same test file against base (npm 12.2.1 + its 8 exceptions), installed from the old lock
$ node node_modules/npm/bin/npm-cli.js test
not ok 1 - npm bundles the fixed undici and ip-address instead of excepting them
  error: 'npm bundles undici 6.29.0, below the fixed 6.29.1'
# pass 3
# fail 1

# and against npm 12.2.2 while the old exceptions file is still in place
not ok 1 - npm bundles the fixed undici and ip-address instead of excepting them
# (fails on the leftover exception entries, as intended)
```

## Real Behavior Proof

- Environment: Windows 11, Node 26.10.0, npm 12.2.2 taken from the
downloaded registry tarball; no Docker engine on this machine.
- Exact command / steps: (1) unpack `npm-12.2.2.tgz` and read the
bundled `package.json` versions, comparing all 132 entries against
12.2.1. (2) `npm install --ignore-scripts` into a copy of
`e2e/wrap/tools` so the lock's `inBundle` entries regenerate. (3) `npm
audit --package-lock-only` on that lock, then the Python exception check
copied verbatim from `.github/workflows/security.yml`. (4) `npm ci
--prefix <dir> --no-fund --no-audit --strict-allow-scripts`, then `npm
test`, `openclaw --version`, `codex --version` in that prefix. (5)
Cross-check every one of the 147 `node_modules/npm/node_modules/*` lock
entries against the tree npm 12.2.2 actually installed. (6) Run the new
test file against base's lock installed with npm 12.2.1, and against the
same tree with base's exceptions file restored.
- Observed result: the lock resolves npm 12.2.2 and its 7 new bundled
copies. The CI check prints `Only excepted bundled advisories remain
(2), until 2026-12-15.` with exit 0, for both the bundled npm 12.2.2 and
the runner's npm 11. The high-severity undici finding is gone, and no
`STALE EXCEPTION` line appears because the removed entries and their
advisories are gone together. The prefix install is byte-consistent with
the lock: 147/147 bundled entries match, 0 mismatches. `npm test` is 4/4
on this branch; the new check fails on base with `npm bundles undici
6.29.0, below the fixed 6.29.1`, and also fails on 12.2.2 if the old
exception entries are put back. `openclaw --version` → `OpenClaw
2026.10.10 (7dc3350)`, `codex --version` → `codex-cli 0.166.0`.
- Not tested: the Docker image build and the wrap E2E run itself —
neither can run here without Docker. `docker-native-e2e` and Wrap E2E
cover that in this PR, since their path filters include `e2e/**`. The
installed CLIs were exercised only via `--version`, not a full
Codex/OpenClaw session.

## Runtime Rollout Safety

- Rollout-managed feature(s): none
- Minimum rollout channel: n/a, dependency pins for the E2E harness only
- Stable/default behavior changed: no. The wheel, SDK and plugins are
untouched; this only changes the npm the E2E image installs with and the
lock the harness installs from.
- Kill switch / disable path: none needed
- Unsafe override required: no
- Qualification impact: none; no shipped artifact embeds npm or these
bundled copies
- Rollback path: revert this commit

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` - it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Screenshots (if applicable)

N/A

## Additional Notes

**Dependency justification** (CONTRIBUTING, "Dependencies & supply
chain"):

| Package | Why this version | Maintainer, activity | Install surface |
|---|---|---|---|
| `npm` 12.2.1 → 12.2.2 | Security patch in the bundled copies: 12.2.2
ships undici 6.29.1 and ip-address 10.7.5, which clear 5 undici
advisories (GHSA-4qv8-2p9j-2685, GHSA-xjj6-f33q-929c,
GHSA-2m5v-pch6-74hx, GHSA-qrxm-fqhp-jwvm, GHSA-9fm3-97px-rjf6) and
GHSA-rxp7-6hxx-x8q5 that 12.2.1's undici 6.29.0 and ip-address 10.7.2
carried. It is also `latest` and the only release that closes them. |
npm, Inc., maintained at [npm/cli](https://github.com/npm/cli) under the
same release process as every other npm; monthly minors, patch releases
within days of a bundled-dependency fix. | Same as the 12.2.1 pin it
replaces: a global CLI install in the E2E image only. No new package, no
new install script, no native code. Registry tarball carries
`dist.integrity`, which the lock now pins. |

The six bundled copies also move (`@npmcli/promise-spawn`, `bin-links`,
`libnpmexec`, `pacote`, `semver` patch bumps — they are npm's own
release, not a resolution I chose). None is reachable from the wheel or
SDK; the whole tree lives in `/opt/wrap-tools` inside the E2E image.

Why the expiry moves rather than disappearing: glob GHSA-3g3m-2fjr-6pw4
(fixed only in glob 14.0.2) and minimatch GHSA-g3hv-75wg-m249 (fixed
only in 11.0.1) still apply, because npm 12.2.2 bundles glob 13.0.6 and
minimatch 10.2.5 — both majors npm does not bundle. Deleting the file
would fail the security job on those two; keeping 2026-11-15 would fail
it in four days regardless of this change. 2026-12-15 is one month,
matching the cadence the file had.

N/A items: `pytest`, `ruff`, `mypy` — no Python changed. The new test is
the one CONTRIBUTING asks for on a bug fix: it fails on base (`npm
bundles undici 6.29.0, below the fixed 6.29.1`) and passes here, and it
keeps holding the invariant for the next npm bump rather than only
pinning this one. The remaining glob/minimatch exceptions are still
verified by the security job's own check, which rejects stale entries.

Answering the two review comments: both are addressed — the regression
test is the new `dependency-regression.test.cjs` case, and the README
now documents the npm override bump as its own procedure with the reason
`--package-lock-only` is not enough.
2026-11-11 09:49:01 -06:00

139 lines
6.6 KiB
JavaScript

'use strict';
// From e2e/wrap/tools after installing its locked dependencies:
// node --test --test-concurrency=1 --test-reporter=tap dependency-regression.test.cjs
const path = require('node:path');
const { createRequire } = require('node:module');
const fromTools = createRequire(path.join(process.cwd(), 'package.json'));
if (process.argv[2] === '--serve') {
const express = fromTools('express');
const app = express();
app.get('/health', (_req, res) => res.json({ ok: true }));
app.post('/text', express.text({ verify() {} }), (req, res) => res.json(req.body));
app.use((error, _req, res, _next) => res.status(error.status || 500).json({ type: error.type }));
const server = app.listen(0, '127.0.0.1', () => process.send({ port: server.address().port }));
process.on('message', (message) => {
if (message === 'stop') { server.close(() => process.exit(0)); server.closeAllConnections(); }
});
} else {
const fs = require('node:fs');
const test = require('node:test');
const assert = require('node:assert/strict');
const http = require('node:http');
const { fork } = require('node:child_process');
// Bundled copies npm does not let overrides reach, so the npm pin itself has
// to carry the fix. 12.2.2 is the first release that does.
const BUNDLED_FIXES = { undici: '6.29.1', 'ip-address': '10.7.5' };
const bundlePath = (name) => `node_modules/npm/node_modules/${name}`;
const parse = (version) => version.split('.').map(Number);
const atLeast = (version, floor) => {
const [a, b] = [parse(version), parse(floor)];
for (let i = 0; i < Math.max(a.length, b.length); i++) {
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
}
return true;
};
test('npm bundles the fixed undici and ip-address instead of excepting them', () => {
const exceptions = JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'npm-audit-exceptions.json'), 'utf8'),
);
for (const [name, fixed] of Object.entries(BUNDLED_FIXES)) {
const manifest = path.join(process.cwd(), 'node_modules', 'npm', 'node_modules', name, 'package.json');
const { version } = JSON.parse(fs.readFileSync(manifest, 'utf8'));
assert.ok(atLeast(version, fixed), `npm bundles ${name} ${version}, below the fixed ${fixed}`);
const excepted = Object.keys(exceptions.advisories).filter(
(advisory) => bundlePath(name) in exceptions.advisories[advisory],
);
assert.deepEqual(excepted, [], `${bundlePath(name)} ${version} carries a fix: drop its exceptions`);
}
});
test('Ajv rejects a percent-encoded scheme instead of aliasing an HTTPS schema', () => {
const Ajv = fromTools('ajv');
const ajv = new Ajv();
ajv.addSchema({ $id: 'https://example.invalid/defs.json', type: 'integer' });
const valid = ajv.compile({ $ref: 'https://example.invalid/defs.json' });
assert.equal(valid(42), true);
assert.equal(valid('42'), false);
assert.throws(
() => ajv.compile({ $ref: '%68ttps://example.invalid/defs.json' }),
{ message: 'URI scheme is malformed.' },
);
});
test('minimatch bounds the **/.. expansion instead of comparing every pair (GHSA-g3hv-75wg-m249)', () => {
// The copy OpenClaw resolves, which the openclaw override pins.
const fromOpenclaw = createRequire(
path.join(process.cwd(), 'node_modules', 'openclaw', 'package.json'),
);
const { Minimatch } = fromOpenclaw('minimatch');
const { partsMatch } = Minimatch.prototype;
assert.equal(typeof partsMatch, 'function', 'minimatch internals changed: rewrite this check');
let calls = 0;
Minimatch.prototype.partsMatch = function countedPartsMatch(...args) {
calls++;
return partsMatch.apply(this, args);
};
try {
// Each `**/../x/y` doubles the expanded pattern parts: 4096 here.
const mm = new Minimatch('**/../x/y/'.repeat(12) + 'z', { optimizationLevel: 2 });
assert.equal(mm.match('x/y/'.repeat(12) + 'z'), true);
} finally {
Minimatch.prototype.partsMatch = partsMatch;
}
// minimatch 10.2.6 compares every pair of parts: 8,386,560 calls.
assert.ok(calls < 100000, `${calls} pairwise part comparisons`);
});
test('unsupported charset with invalid gzip leaves the Express process healthy', async (t) => {
const child = fork(__filename, ['--serve'], {
cwd: process.cwd(), env: process.env, execArgv: [], silent: true,
});
let stderr = '';
child.stdout.resume();
child.stderr.on('data', (chunk) => { stderr += chunk; });
t.after(async () => {
t.diagnostic(JSON.stringify({ exitCode: child.exitCode, signal: child.signalCode, stderr }));
if (child.exitCode !== null || child.signalCode !== null) return;
await new Promise((resolve) => {
const timer = setTimeout(() => { child.kill(); resolve(); }, 1000);
child.once('exit', () => { clearTimeout(timer); resolve(); });
if (child.connected) child.send('stop'); else child.kill();
});
});
const port = await new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error('server startup timeout')), 3000);
child.once('message', (msg) => { clearTimeout(timer); resolve(msg.port); });
child.once('error', (err) => { clearTimeout(timer); reject(err); });
child.once('exit', (code) => { clearTimeout(timer); reject(new Error('server exited: ' + code + stderr)); });
});
function request(route, body, headers = {}, method = 'POST') {
return new Promise((resolve, reject) => {
const req = http.request({ hostname: '127.0.0.1', port, path: route, method, agent: false,
headers: { ...headers, 'Content-Length': Buffer.byteLength(body) } }, (res) => {
const chunks = [];
res.on('data', (chunk) => chunks.push(chunk));
res.on('error', reject);
res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks).toString() }));
});
req.setTimeout(2000, () => req.destroy(new Error('localhost request timeout')));
req.on('error', reject);
req.end(body);
});
}
const response = await request('/text', 'not-gzip', {
'Content-Type': 'text/plain; charset=not-a-real-charset', 'Content-Encoding': 'gzip',
});
assert.equal(response.status, 415);
assert.equal(JSON.parse(response.body).type, 'charset.unsupported');
// Let a pending zlib error surface before checking the child's health.
await new Promise((resolve) => setTimeout(resolve, 80));
assert.equal(child.exitCode, null, stderr);
const health = await request('/health', '', {}, 'GET');
assert.equal(health.status, 200);
assert.deepEqual(JSON.parse(health.body), { ok: true });
});
}