Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Exercise the warm pnpm store path in cli-e2e on every run (#5544)

Nick Gomez4686d6f76df8
diff --git a/packages/cli/tests/e2e/cli-linux-e2e.ts b/packages/cli/tests/e2e/cli-linux-e2e.ts
index efb697813..7d978a48e 100644
--- a/packages/cli/tests/e2e/cli-linux-e2e.ts
+++ b/packages/cli/tests/e2e/cli-linux-e2e.ts
@@ -14,14 +14,19 @@ const CLI_PKG_DIR = resolve(HERE, '..', '..');
const WORKSPACE_DIST_CLI = join(CLI_PKG_DIR, 'dist', 'cli.mjs');
const NODE = process.execPath.includes('bun') ? 'node' : process.execPath;
const SUT_MODE = process.env.OK_E2E_SUT === 'workspace' ? 'workspace' : 'packed';
+const LOCKED_PACKED_INSTALL =
+ SUT_MODE === 'packed' && (process.env.OK_CLI_E2E_INSTALL_MODE ?? 'locked') === 'locked';
const HERMETIC_ENV = { OK_BUNDLE_PROXY: '0' } as const;
const START_PORT = Number(process.env.OK_E2E_PORT ?? 13581);
+type Acquisition = Awaited<ReturnType<typeof installPackedCli>>['acquisition'];
+
interface Harness {
cliPath: string;
binShim: string | null;
installPrefix: string | null;
packDest: string | null;
+ acquisition: Acquisition;
contentDir: string;
lockPath: string;
server: ChildProcess | null;
@@ -32,11 +37,16 @@ const H: Harness = {
binShim: null,
installPrefix: null,
packDest: null,
+ acquisition: null,
contentDir: '',
lockPath: '',
server: null,
};
+function progressOf(acquisition: Acquisition, status: string) {
+ return acquisition?.progress.get(status) ?? new Set<string>();
+}
+
function runOk(
args: string[],
opts: { cwd?: string; timeoutMs?: number; env?: NodeJS.ProcessEnv } = {},
@@ -102,7 +112,7 @@ function readLockPort(): number | null {
beforeAll(async () => {
if (!existsSync(WORKSPACE_DIST_CLI)) {
throw new Error(
- `Missing ${WORKSPACE_DIST_CLI}. Run \`bun run build --filter=@inkeep/open-knowledge\` before this smoke.`,
+ `Missing ${WORKSPACE_DIST_CLI}. Run \`pnpm exec turbo run build --filter=@inkeep/open-knowledge\` before this smoke.`,
);
}
@@ -117,6 +127,7 @@ beforeAll(async () => {
});
H.cliPath = installed.cliPath;
H.binShim = installed.binShim;
+ H.acquisition = installed.acquisition;
} else {
H.cliPath = WORKSPACE_DIST_CLI;
}
@@ -151,6 +162,43 @@ describe(`CLI Linux e2e (${SUT_MODE} SUT)`, () => {
}
});
+ test.skipIf(!LOCKED_PACKED_INSTALL)(
+ '1b. a second install of the same packed CLI takes the warm-store path and its bin runs',
+ async () => {
+ const installPrefix = mkdtempSync(join(tmpdir(), 'ok-e2e-warm-install-'));
+ try {
+ const installation = installPackedCli({
+ packageDir: CLI_PKG_DIR,
+ packDest: H.packDest as string,
+ installPrefix,
+ });
+ await expect(installation).resolves.toMatchObject({ binShim: expect.any(String) });
+ const { binShim, acquisition } = await installation;
+
+ const version = spawnSync(binShim, ['--version'], {
+ cwd: installPrefix,
+ timeout: 30_000,
+ encoding: 'utf8',
+ env: { ...process.env, ...HERMETIC_ENV },
+ });
+ expect(version.status, version.stderr).toBe(0);
+ expect(version.stdout.split('\n')[0]).toMatch(/^\d+\.\d+\.\d+\S*$/);
+
+ const acquired = new Set([
+ ...progressOf(H.acquisition, 'fetched'),
+ ...progressOf(H.acquisition, 'found_in_store'),
+ ]);
+ expect(progressOf(acquisition, 'found_in_store')).toContain('file:cli.tgz');
+ expect(progressOf(acquisition, 'found_in_store')).toEqual(acquired);
+ expect(acquisition?.fetchStarts).toEqual(new Set());
+ expect(progressOf(acquisition, 'fetched')).toEqual(new Set());
+ } finally {
+ rmSync(installPrefix, { recursive: true, force: true });
+ }
+ },
+ 240_000,
+ );
+
test('2. ok init scaffolds .ok/ in the content dir', () => {
const r = runOk(['init', '--no-mcp'], { timeoutMs: 60_000 });
expect(r.status).toBe(0);
diff --git a/packages/cli/tests/e2e/packed-install.test-helper.ts b/packages/cli/tests/e2e/packed-install.test-helper.ts
index d0eadf2b0..bff1d3560 100644
--- a/packages/cli/tests/e2e/packed-install.test-helper.ts
+++ b/packages/cli/tests/e2e/packed-install.test-helper.ts
@@ -176,6 +176,19 @@ function pnpmIncompleteFetches(output: string) {
return [...started];
}
+function pnpmAcquisition(output: string) {
+ const events = ndjsonEvents(output);
+ const progress = new Map<string, Set<string>>();
+ for (const event of events)
+ if (
+ event.name === 'pnpm:progress' &&
+ typeof event.status === 'string' &&
+ typeof event.packageId === 'string'
+ )
+ progress.set(event.status, (progress.get(event.status) ?? new Set()).add(event.packageId));
+ return { fetchStarts: pnpmStartedFetches(events), progress };
+}
+
function pnpmReportedErrors(output: string) {
return ndjsonEvents(output).flatMap((event) => {
const parsed = pnpmErrorSchema.safeParse(event);
@@ -345,6 +358,7 @@ export async function installPackedCli(
const deadline = now() + INSTALL_TIMEOUT_MS;
let unavailable: CliInstallUnavailableError | undefined;
let outputBytes = 0;
+ let acceptedOutput = '';
for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt++) {
const timeout = deadline - now();
if (timeout <= 0)
@@ -441,7 +455,10 @@ export async function installPackedCli(
}
const unobserved =
mode === 'locked' && !failed && !pnpmRecordedAcquisition(`${stdout}\n${stderr}`);
- if (!failed && !failures.length && !unobserved) break;
+ if (!failed && !failures.length && !unobserved) {
+ acceptedOutput = `${stdout}\n${stderr}`;
+ break;
+ }
process.stderr.write(stdout + stderr);
const retryable =
failures.length > 0 &&
@@ -482,5 +499,6 @@ export async function installPackedCli(
return {
cliPath: join(installed, 'dist', 'cli.mjs'),
binShim,
+ acquisition: mode === 'locked' ? pnpmAcquisition(acceptedOutput) : null,
};
}
diff --git a/packages/cli/tests/e2e/packed-install.test.ts b/packages/cli/tests/e2e/packed-install.test.ts
index 2855d4f64..0578c26eb 100644
--- a/packages/cli/tests/e2e/packed-install.test.ts
+++ b/packages/cli/tests/e2e/packed-install.test.ts
@@ -204,6 +204,12 @@ test('retries an optional dependency whose tarball fails once and then downloads
fixture.oneShotResponses.set(`/${LEAF}/-/${LEAF}-1.0.0.tgz`, [503]);
const installed = await installPackedCli(fixture, { now: Date.now, ...installer });
expect(installer.attempts).toBe(2);
+ const retried = new Set([`${LEAF}@1.0.0`]);
+ expect(installed.acquisition?.fetchStarts).toEqual(retried);
+ expect(installed.acquisition?.progress.get('fetched')).toEqual(retried);
+ expect(installed.acquisition?.progress.get('found_in_store')).toEqual(
+ new Set(['file:cli.tgz', ...[PARENT, PEER].map((name) => `${name}@1.0.0`)]),
+ );
const result = await promisify(execFile)(process.execPath, [installed.cliPath]);
expect(JSON.parse(result.stdout)).toEqual({ leaf: '1.0.0', peer: '1.0.0' });
} finally {
@@ -554,10 +560,16 @@ test.each([
const fixture = await createInstallFixture();
try {
const coldStart = fixture.requests.length;
- await installPackedCli(fixture);
+ const cold = await installPackedCli(fixture);
expect(new Set(tarballRequestsSince(fixture, coldStart))).toEqual(
new Set([LEAF, PARENT, PEER].map((name) => `/${name}/-/${name}-1.0.0.tgz`)),
);
+ const coldFetches = new Set([
+ 'file:cli.tgz',
+ ...[LEAF, PARENT, PEER].map((name) => `${name}@1.0.0`),
+ ]);
+ expect(cold.acquisition?.fetchStarts).toEqual(coldFetches);
+ expect(cold.acquisition?.progress.get('fetched')).toEqual(coldFetches);
const firstPack = readPackedCli(fixture.packDest);
if (rebuild) {
const cli = join(fixture.packageDir, 'dist/cli.mjs');
@@ -570,7 +582,13 @@ test.each([
expect(readPackedCli(fixture.packDest).equals(firstPack)).toBe(!rebuild);
expect(tarballRequestsSince(fixture, warmStart)).toEqual([]);
await expect(installation).resolves.toMatchObject({ cliPath: expect.any(String) });
- const { cliPath } = await installation;
+ const { cliPath, acquisition } = await installation;
+ const warmFetches = new Set(rebuild ? ['file:cli.tgz'] : []);
+ expect(acquisition?.progress.get('found_in_store')).toEqual(
+ new Set([...coldFetches].filter((id) => !warmFetches.has(id))),
+ );
+ expect(acquisition?.fetchStarts).toEqual(warmFetches);
+ expect(acquisition?.progress.get('fetched') ?? new Set()).toEqual(warmFetches);
const result = await promisify(execFile)(process.execPath, [cliPath]);
expect(JSON.parse(result.stdout)).toEqual({ leaf: '1.0.0', peer: '1.0.0' });
} finally {