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
6 changes: 1 addition & 5 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env node

import { realpathSync } from 'node:fs';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { runCommandLine } from './runtime.js';

const executable = (path: string) => { try { return realpathSync(path); } catch { return resolve(path); } };
if (executable(process.argv[1] ?? '') === executable(fileURLToPath(import.meta.url))) process.exitCode = await runCommandLine(process.argv.slice(2));
process.exitCode = await runCommandLine(process.argv.slice(2));
11 changes: 10 additions & 1 deletion tests/contract/package/installed-assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { execFile } from 'node:child_process';
import { createHash } from 'node:crypto';
import { existsSync, lstatSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { existsSync, lstatSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { resolve } from 'node:path';
import test from 'node:test';
Expand Down Expand Up @@ -61,6 +61,15 @@ test('native production CLI archive retains exact observation assets and execute
const env: NodeJS.ProcessEnv = { ...process.env, TREESEED_CONFIG_HOME: resolve(root, 'config') }; delete env.NODE_OPTIONS; delete env.NODE_TEST_CONTEXT;
const result = await promisify(execFile)(process.execPath, [binary, '--help'], { cwd: root, env, encoding: 'utf8' });
assert.equal(result.stderr, ''); assert.match(result.stdout, /trsd/u); assert.deepEqual(readFileSync(binary), bytes);
const alias = resolve(root, 'trsd'), replacement = resolve(root, 'replacement.ts'), preload = resolve(root, 'switch-entrypoint.mts');
symlinkSync(binary, alias); writeFileSync(replacement, bytes);
writeFileSync(preload, `import{registerHooks}from'node:module';import{unlinkSync,symlinkSync,writeFileSync}from'node:fs';import{pathToFileURL}from'node:url';
registerHooks({resolve(specifier,context,next){if(context.parentURL===pathToFileURL(${JSON.stringify(binary)}).href&&specifier==='./runtime.js'){
unlinkSync(${JSON.stringify(alias)});symlinkSync(${JSON.stringify(replacement)},${JSON.stringify(alias)});writeFileSync(${JSON.stringify(resolve(root,'switched'))},'observed');}return next(specifier,context);}});`);
const switched = await promisify(execFile)(process.execPath, ['--import', preload, alias, '--help'], { cwd: root, env, encoding: 'utf8' });
assert.equal(readFileSync(resolve(root, 'switched'), 'utf8'), 'observed');
assert.equal(switched.stderr, ''); assert.match(switched.stdout, /trsd/u, 'The loaded public binary must finish even when its invocation symlink moves');
assert.deepEqual(readFileSync(binary), bytes);
const inventory = async () => (JSON.parse(await execute('npm', ['pack', '--dry-run', '--ignore-scripts', '--json'], installed)) as Packed[])[0]!;
const before = await inventory();
for (const path of ['dist/.treeseed-build-complete.json', 'dist/.treeseed-build-complete.json.new'])
Expand Down
9 changes: 9 additions & 0 deletions tests/contract/package/thin-package.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import test from 'node:test';
import { parse } from 'yaml';
Expand Down Expand Up @@ -47,6 +48,14 @@ test('the executable drains complete output before exiting', () => {
const main = readFileSync('src/cli/main.ts', 'utf8');
assert.equal(main.includes('process.exit('), false);
assert.equal(main.includes('process.exitCode = await runCommandLine'), true);
const invoke = (args: string[]) => spawnSync(process.execPath, ['dist/cli/main.js', ...args],
{ encoding: 'utf8', timeout: 5_000, maxBuffer: 1024 * 1024 });
const help = invoke(['--help']);
assert.equal(help.error, undefined); assert.equal(help.signal, null); assert.equal(help.status, 0);
assert.equal(help.stderr, ''); assert.match(help.stdout, /trsd/u);
const denied = invoke(['definitely-invalid-command', '--json']);
assert.equal(denied.error, undefined); assert.equal(denied.signal, null); assert.equal(denied.status, 1);
assert.equal(denied.stdout, ''); assert.equal(JSON.parse(denied.stderr).error.code, 'unknown_command');
});

test('candidate promotion uses staging while stable publication uses production', () => {
Expand Down
Loading