From 5490095e7e9fe45176e60fbc18fe331c25fa3f2b Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 09:02:17 -0500 Subject: [PATCH] test(release): the npx-install smoke packs the staged CLI, as a release does The smoke ran a bare pnpm pack, which bundles workspace links and never runs the staging step, so it tested a tarball nobody installs. It now stages the bundled runtime packages and packs with npm. The vendored range check no longer needs the semver package, which that job does not install. Co-Authored-By: RuFlo --- .../stage-internal-runtime-bundles.test.mjs | 10 ++++++++- scripts/smoke-cli-npx-install.mjs | 13 ++++++++++-- scripts/stage-internal-runtime-bundles.mjs | 21 +++++++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs index 7343b58712..aaf99f66c1 100644 --- a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs +++ b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs @@ -57,7 +57,15 @@ console.log('bundled runtime manifest is self-contained and preserves source met const { mkdtemp, mkdir, writeFile, readFile, rm, access } = await import('node:fs/promises'); const { tmpdir } = await import('node:os'); const { join } = await import('node:path'); - const { vendorDependency } = await import('../stage-internal-runtime-bundles.mjs'); + const { vendorDependency, satisfiesCaretOrExact } = await import('../stage-internal-runtime-bundles.mjs'); + assert.equal(satisfiesCaretOrExact('4.6.7', '^4.6.7'), true); + assert.equal(satisfiesCaretOrExact('4.7.0', '^4.6.7'), true); + assert.equal(satisfiesCaretOrExact('4.6.6', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('5.0.0', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('3.25.76', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('4.6.7', '4.6.7'), true); + assert.throws(() => satisfiesCaretOrExact('4.6.7', '>=4'), /Unsupported/); + assert.throws(() => satisfiesCaretOrExact('0.2.1', '^0.2.0'), /Unsupported/); const withVendored = createBundledRuntimeManifest( { name: '@claude-flow/example', version: '1.0.0', dependencies: { leaf: '^4.6.7', other: '^1.0.0' } }, diff --git a/scripts/smoke-cli-npx-install.mjs b/scripts/smoke-cli-npx-install.mjs index 626eac8e6e..7ab775b0d9 100644 --- a/scripts/smoke-cli-npx-install.mjs +++ b/scripts/smoke-cli-npx-install.mjs @@ -49,10 +49,19 @@ const packDest = mkdtempSync(join(tmpdir(), 'cli-pack-')); let tarball; { console.log(`[1/5] packing CLI to ${packDest}`); - const pnpm = run('pnpm', ['pack', '--pack-destination', packDest], { cwd: CLI_DIR }); - if (pnpm.code === 0) { + // #4940: pack what a release packs. A release stages the bundled runtime + // packages (and their vendored dependencies) and then runs npm pack; a bare + // `pnpm pack` bundles the workspace links, which is not the published shape. + let pnpm = { code: 1, stderr: 'skipped: staged bundles are packed with npm' }; + try { + const { stageInternalRuntimeBundles } = await import('./stage-internal-runtime-bundles.mjs'); + await stageInternalRuntimeBundles(CLI_DIR, { build: false }); + const staged = run('npm', ['pack', '--ignore-scripts', '--pack-destination', packDest], { cwd: CLI_DIR }); + if (staged.code !== 0) fail(`npm pack of the staged CLI failed:\n${staged.stderr}`); const tgz = readdirSync(packDest).find((f) => f.endsWith('.tgz')); if (tgz) tarball = join(packDest, tgz); + } catch (error) { + fail(`staging the bundled runtime packages failed: ${error?.stack ?? error}`); } if (!tarball) { // Fallback to npm pack — works when run with pnpm-resolved workspace already installed diff --git a/scripts/stage-internal-runtime-bundles.mjs b/scripts/stage-internal-runtime-bundles.mjs index 05b1da6b69..d55d32200c 100644 --- a/scripts/stage-internal-runtime-bundles.mjs +++ b/scripts/stage-internal-runtime-bundles.mjs @@ -169,6 +169,24 @@ export function createBundledRuntimeManifest(packageJson, vendoredDependencies = return bundledManifest; } +/** + * Range check for a vendored dependency, without a semver package: this script + * also runs in CI jobs that install only the v3 workspace. Accepts an exact + * version or a caret range on a major >= 1; anything else is refused so an + * unusual range is looked at, not guessed. + */ +export function satisfiesCaretOrExact(version, range) { + const parse = (value) => /^(\d+)\.(\d+)\.(\d+)$/.exec(value)?.slice(1).map(Number); + const got = parse(version); + const caret = range.startsWith('^'); + const want = parse(caret ? range.slice(1) : range); + if (!got || !want) throw new Error(`Unsupported vendored version or range: ${version} vs ${range}`); + if (!caret) return got.join('.') === want.join('.'); + if (want[0] === 0) throw new Error(`Unsupported vendored range (0.x caret): ${range}`); + if (got[0] !== want[0]) return false; + return got[1] !== want[1] ? got[1] > want[1] : got[2] >= want[2]; +} + /** * Copy one dependency of a bundled package into that package's node_modules, * from the copy the workspace build resolved. Only leaf packages qualify: a @@ -191,8 +209,7 @@ export async function vendorDependency(sourceRoot, stagedRoot, packageJson, name if (parent === directory) throw new Error(`Cannot find the package root of ${name}`); directory = parent; } - const { default: semver } = await import('semver'); - if (!semver.satisfies(manifest.version, range)) { + if (!satisfiesCaretOrExact(manifest.version, range)) { throw new Error( `${packageJson.name} needs ${name}@${range}, but the workspace resolved ${manifest.version}`, );