Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/agent-bundle/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { promisify } from 'node:util';
import { expect, it } from '@rstest/core';

import { runCli as runSourceCli } from '../src/cli.ts';
import { cachedNpmInstallArguments } from './support/shared-pack.ts';

const execFile = promisify(executeFile);
const workspaceRoot = process.cwd();
Expand Down Expand Up @@ -128,7 +129,7 @@ const createPackedConsumer = async (): Promise<{ readonly cli: string; readonly
const [packed] = JSON.parse(stdout) as Array<{ readonly filename: string }>;
await writeFile(join(root, 'package.json'), '{"type":"module"}\n');
await execFile(
'npm', ['install', '--ignore-scripts', '--no-audit', '--no-fund', join(root, packed.filename)],
'npm', ['install', ...cachedNpmInstallArguments, join(root, packed.filename)],
{ cwd: root },
);
return { cli: join(root, 'node_modules', '.bin', 'agent-bundle'), root };
Expand Down
6 changes: 3 additions & 3 deletions packages/agent-bundle/tests/dev-workbench-packaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { promisify } from 'node:util';

import { describe, expect, it } from '@rstest/core';

import { installedEnvironment, npmInstallArguments, sharedPackedTarball } from './support/shared-pack.ts';
import { cachedNpmInstallArguments, installedEnvironment, sharedPackedTarball } from './support/shared-pack.ts';

const execFile = promisify(executeFile);
const workspaceRoot = process.cwd();
Expand Down Expand Up @@ -83,7 +83,7 @@ it('serves prebuilt workbench assets from an installed tarball without the repos
expect(listing.stdout).not.toMatch(/package\/dist\/workbench\/.*-[a-f0-9]{8,}/iu);

await writeFile(join(consumer, 'package.json'), '{"type":"module"}\n');
await execFile('npm', ['install', ...npmInstallArguments, tarball], { cwd: consumer });
await execFile('npm', ['install', ...cachedNpmInstallArguments, tarball], { cwd: consumer });
await mkdir(join(project, 'skills', 'review'), { recursive: true });
await Promise.all([
writeFile(join(project, 'package.json'), '{"type":"module"}\n'),
Expand Down Expand Up @@ -115,7 +115,7 @@ it('runs the Agent API from an omit-dev installed tarball with its runtime MCP d
const project = join(consumer, 'project');
try {
await writeFile(join(consumer, 'package.json'), '{"type":"module"}\n');
await execFile('npm', ['install', '--omit=dev', ...npmInstallArguments, tarball], { cwd: consumer });
await execFile('npm', ['install', '--omit=dev', ...cachedNpmInstallArguments, tarball], { cwd: consumer });
await mkdir(join(project, 'skills', 'review'), { recursive: true });
await Promise.all([
writeFile(join(project, 'package.json'), '{"type":"module"}\n'),
Expand Down
6 changes: 3 additions & 3 deletions packages/agent-bundle/tests/packed-consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { promisify } from 'node:util';
import { expect, it } from '@rstest/core';

import { sha256Hex } from '../src/core/digest.ts';
import { installedEnvironment, npmInstallArguments } from './support/shared-pack.ts';
import { cachedNpmInstallArguments, installedEnvironment } from './support/shared-pack.ts';

const execFile = promisify(executeFile);
const workspaceRoot = process.cwd();
Expand Down Expand Up @@ -110,7 +110,7 @@ it('uses only an installed tarball after source deletion', async () => {
// The two consumers are disjoint directories; npm's cache handles the
// concurrent installs (the scaffolder e2e relies on the same property).
await Promise.all([projectRoot, scriptProjectRoot].map(async (consumer) =>
execFile('npm', ['install', ...npmInstallArguments, tarball], {
execFile('npm', ['install', ...cachedNpmInstallArguments, tarball], {
cwd: consumer,
env: installedEnvironment(),
})));
Expand Down Expand Up @@ -331,7 +331,7 @@ it('uses only an installed tarball after source deletion', async () => {
'',
].join('\n')),
]);
await execFile('npm', ['install', ...npmInstallArguments, tarball], {
await execFile('npm', ['install', ...cachedNpmInstallArguments, tarball], {
cwd: frameworkRoot,
env: installedEnvironment(),
});
Expand Down
8 changes: 4 additions & 4 deletions packages/agent-bundle/tests/public-api-packed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { promisify } from 'node:util';
import { expect, it } from '@rstest/core';

import { writeFixtureManifest } from './support/manifest.ts';
import { npmInstallArguments, sharedPackedTarball } from './support/shared-pack.ts';
import { cachedNpmInstallArguments, sharedPackedTarball } from './support/shared-pack.ts';

interface PackageManifest {
bin: {
Expand Down Expand Up @@ -58,7 +58,7 @@ it('writes the package version as the producer of a packed CLI manifest', async
try {
await writeFile(join(consumerRoot, 'package.json'), '{"type":"module"}\n');
await execFile(
'npm', ['install', ...npmInstallArguments, tarball],
'npm', ['install', ...cachedNpmInstallArguments, tarball],
{ cwd: consumerRoot },
);

Expand Down Expand Up @@ -90,7 +90,7 @@ it('imports the externalized config entry from a packed npm consumer', async ()
await writeFile(join(consumerRoot, 'package.json'), '{"type":"module"}\n');
await execFile(
'npm',
['install', ...npmInstallArguments, tarball],
['install', ...cachedNpmInstallArguments, tarball],
{ cwd: consumerRoot },
);

Expand Down Expand Up @@ -198,7 +198,7 @@ it('invokes a prebuilt MCP server from a clean packed consumer', async () => {
await writeFile(join(consumerRoot, 'package.json'), '{"type":"module"}\n');
await execFile(
'npm',
['install', ...npmInstallArguments, tarball],
['install', ...cachedNpmInstallArguments, tarball],
{ cwd: consumerRoot },
);
const { stdout } = await execFile(process.execPath, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from 'node:util';

import { describe, expect, it } from '@rstest/core';

import { npmInstallArguments, sharedPackedTarball } from './support/shared-pack.ts';
import { cachedNpmInstallArguments, sharedPackedTarball } from './support/shared-pack.ts';

const execFile = promisify(executeFile);
const workspaceRoot = process.cwd();
Expand Down Expand Up @@ -45,7 +45,7 @@ describe.sequential('optional RSC runtime package boundary', () => {
const tarListing = (await execFile('tar', ['-tf', tarball])).stdout;
expect(tarListing).not.toMatch(/examples\/rsc-agent-runtime|react-server-dom-rspack|rsbuild-plugin-rsc/u);

await execFile('npm', ['install', ...npmInstallArguments, tarball], { cwd: consumer });
await execFile('npm', ['install', ...cachedNpmInstallArguments, tarball], { cwd: consumer });
const dependencyTree = JSON.parse((await execFile('npm', ['ls', '--all', '--json'], { cwd: consumer })).stdout) as InstalledDependencyTree;
const installedNames = installedDependencyNames(dependencyTree);
for (const name of ['react', 'react-dom', 'react-server-dom-rspack', 'rsbuild-plugin-rsc']) {
Expand Down
8 changes: 5 additions & 3 deletions packages/agent-bundle/tests/support/packed-native-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { homedir, tmpdir } from 'node:os';
import { join } from 'node:path';
import { promisify } from 'node:util';

// The native smoke installs the production closure a real consumer would get,
// so it stays on npm's default metadata staleness checks.
import { npmInstallArguments } from './shared-pack.ts';

const execFile = promisify(executeFile);
const workspaceRoot = process.cwd();
const packageRoot = join(workspaceRoot, 'packages', 'agent-bundle');
Expand Down Expand Up @@ -236,9 +240,7 @@ export const runPackedNativeSmoke = async (options: {
const installed = await runNodeEntrypoint(npmEntrypoint, [
'install',
'--omit=dev',
'--ignore-scripts',
'--no-audit',
'--no-fund',
...npmInstallArguments,
join(tarballs, listing[0].filename),
], { cwd: consumer, environment });
if (installed.exitCode !== 0) throw new Error('Packed native smoke could not install the release tarball.');
Expand Down
21 changes: 20 additions & 1 deletion packages/agent-bundle/tests/support/shared-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,28 @@ export const installedEnvironment = (): NodeJS.ProcessEnv => {
return environment;
};

/** Canonical flags for installing a packed tarball into a consumer fixture. */
/**
* Canonical flags for installing a packed tarball into a consumer fixture.
* They keep npm's default metadata staleness checks, so the install resolves
* the tree a consumer would get today. That is the point of the proofs that
* stand in for a real consumer — release-audit's production entrypoint walk,
* the scaffolder template matrix, the native host smoke — and exact direct
* pins do not make it free: transitive ranges still move underneath them, and
* scripts/audit-packed-release.mjs audits the installed tree without ever
* exercising it.
*/
export const npmInstallArguments = ['--ignore-scripts', '--no-audit', '--no-fund'] as const;

/**
* The same flags for suites that only prove the packed tarball resolves,
* imports, and runs, where the dependency tree is a means rather than the
* subject. `--prefer-offline` serves cached registry metadata without
* revalidating it: the tarball under test is always read from disk and
* uncached dependencies are still fetched, so only the staleness round-trips
* are skipped.
*/
export const cachedNpmInstallArguments = [...npmInstallArguments, '--prefer-offline'] as const;

const packs = new Map<SharedPackPackage, Promise<SharedPack>>();
let fallbackBuild: Promise<void> | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from 'node:util';

import { expect } from '@rstest/core';

import { installedEnvironment, npmInstallArguments, sharedPackedTarball } from '../../../agent-bundle/tests/support/shared-pack.ts';
import { cachedNpmInstallArguments, installedEnvironment, sharedPackedTarball } from '../../../agent-bundle/tests/support/shared-pack.ts';

const execFile = promisify(executeFile);

Expand Down Expand Up @@ -36,7 +36,7 @@ const packFixture = async (): Promise<PackedFixture> => {
const runnerRoot = join(root, 'runner');
await mkdir(runnerRoot, { recursive: true });
await writeFile(join(runnerRoot, 'package.json'), '{"name":"scaffold-runner","type":"module","private":true}\n');
await execFile('npm', ['install', ...npmInstallArguments, scaffolderTarball], {
await execFile('npm', ['install', ...cachedNpmInstallArguments, scaffolderTarball], {
cwd: runnerRoot,
env: installedEnvironment(),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/workbench/tests/packed-release.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
validateOutageLedger,
type ConsoleErrorRecord,
} from './support/packed-outage-ledger.ts';
import { npmInstallArguments, sharedPackedTarball } from '../../agent-bundle/tests/support/shared-pack.ts';
import { cachedNpmInstallArguments, sharedPackedTarball } from '../../agent-bundle/tests/support/shared-pack.ts';
import { timeScale } from '../../agent-bundle/tests/support/time-scale.ts';
import {
availablePort,
Expand Down Expand Up @@ -83,7 +83,7 @@ e2e('runs every Agent API tool from the installed tarball', { timeout: 360_000 *
let primaryFailure: Error | undefined;
try {
await writeFile(join(consumer, 'package.json'), '{"type":"module"}\n');
await execFile('npm', ['install', '--omit=dev', ...npmInstallArguments, tarball], {
await execFile('npm', ['install', '--omit=dev', ...cachedNpmInstallArguments, tarball], {
cwd: consumer,
env: installedEnvironment(),
});
Expand Down
5 changes: 5 additions & 0 deletions scripts/audit-packed-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ const auditPackedRelease = async () => {
'--pack-destination', tarballs,
], { cwd: packageRoot, env: productionEnvironment })).stdout);
const tarball = join(tarballs, asString(filename, 'npm pack did not produce a tarball filename'));
// No `--prefer-offline` here (unlike the packed pool's
// cachedNpmInstallArguments): the tree this install produces is what
// `npm audit`, `npm audit signatures`, and `npm sbom` below report on, so
// it has to resolve against live registry metadata rather than whatever
// the cache last saw.
await execNpm([
'install',
'--omit=dev',
Expand Down
Loading