smoke-tarball.mjs72 lines · main
1#!/usr/bin/env node
2// Builds, packs, and consumes the resulting tarball from a clean scratch dir.
3// Catches the class of bug where source-tree dev works (tsx fallback in
4// bin/briven.js) but a real install is broken — exact case that motivated this.
5import { execSync } from 'node:child_process';
6import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
7import { tmpdir } from 'node:os';
8import { join, resolve } from 'node:path';
9import { fileURLToPath } from 'node:url';
10
11const here = fileURLToPath(new URL('.', import.meta.url));
12const cliDir = resolve(here, '..');
13const distPack = resolve(cliDir, '../../dist-pack');
14
15const log = (m) => process.stdout.write(`[smoke] ${m}\n`);
16const die = (m) => {
17 process.stderr.write(`[smoke] FAIL: ${m}\n`);
18 process.exit(1);
19};
20
21log('building + packing');
22execSync('pnpm pack:tarball', { cwd: cliDir, stdio: 'inherit' });
23
24const tarballs = readdirSync(distPack)
25 .filter((f) => f.startsWith('briven-cli-') && f.endsWith('.tgz'))
26 .sort();
27if (tarballs.length === 0) die(`no tarball found in ${distPack}`);
28const tarball = join(distPack, tarballs[tarballs.length - 1]);
29log(`tarball: ${tarball}`);
30
31const scratch = mkdtempSync(join(tmpdir(), 'briven-cli-smoke-'));
32log(`scratch: ${scratch}`);
33
34const cleanup = () => rmSync(scratch, { recursive: true, force: true });
35process.on('exit', cleanup);
36
37writeFileSync(join(scratch, 'package.json'), JSON.stringify({ private: true, type: 'module' }));
38execSync(`npm install --silent --no-audit --no-fund "${tarball}"`, { cwd: scratch, stdio: 'inherit' });
39
40log('checking briven --help');
41const helpOut = execSync('./node_modules/.bin/briven --help', { cwd: scratch, encoding: 'utf8' });
42if (!/briven/i.test(helpOut)) die(`--help output unexpected:\n${helpOut}`);
43
44log('checking briven --version');
45execSync('./node_modules/.bin/briven --version', { cwd: scratch, stdio: 'inherit' });
46
47log('checking briven on unknown command exits 1');
48let unknownExit = 0;
49try {
50 execSync('./node_modules/.bin/briven definitely-not-a-command', { cwd: scratch, stdio: 'pipe' });
51} catch (e) {
52 unknownExit = e.status ?? 0;
53}
54if (unknownExit !== 1) die(`unknown command exited ${unknownExit}, expected 1`);
55
56log('checking sub-exports import cleanly');
57writeFileSync(
58 join(scratch, 'check.mjs'),
59 [
60 `import * as cli from '@briven/cli';`,
61 `import * as schema from '@briven/cli/schema';`,
62 `import * as server from '@briven/cli/server';`,
63 `if (typeof cli.run !== 'function') { console.error('cli.run not exported'); process.exit(1); }`,
64 `if (Object.keys(schema).length === 0) { console.error('schema export is empty'); process.exit(1); }`,
65 `if (Object.keys(server).length === 0) { console.error('server export is empty'); process.exit(1); }`,
66 `console.log('[smoke] sub-exports ok');`,
67 ``,
68 ].join('\n')
69);
70execSync('node check.mjs', { cwd: scratch, stdio: 'inherit' });
71
72log('PASS');