Files
callstack__agent-device/test/integration/smoke-cli.test.ts
Michał Pierzchała 4f5a87b6b3 refactor(command-registry): move CLI flag grammar, text and command aliases down (#2561)
Move the vocabulary that both the CLI and commands read but no command's runtime
depends on into the package below both: flag types, registry, groups and the four
flag-definitions files, command-text, and cli-command-aliases. These are pure moves;
only their import specifiers change.

No compat re-export at the old paths — every consumer switches to the owning
subpath. The per-command defaults stay where they are for now (the daemon's edge into
the facet resolver is the harder cut and belongs with the daemon-closure work).

Part of #2545 / #2543.
2026-09-14 11:27:22 +02:00

56 lines
2.0 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { runCmdSync } from '@agent-device/host-kit/command';
import { cliAliasesForCommand } from '@agent-device/command-registry/cli-command-aliases';
import { listCliCommandNames } from '@agent-device/command-registry/catalog';
function runCli(args: string[]): { status: number; stdout: string; stderr: string } {
const result = runCmdSync(
process.execPath,
['--experimental-strip-types', 'src/bin.ts', ...args],
{ allowFailure: true },
);
return { status: result.exitCode, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
}
test('cli --help returns usage', () => {
const result = runCli(['--help']);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /agent-device/i);
assert.match(result.stdout, /agent-device help commands/i);
const commands = runCli(['help', 'commands']);
assert.equal(commands.status, 0, commands.stderr);
assert.match(commands.stdout, /reinstall <app> <path>/i);
});
test('cli --version prints semver and exits 0', () => {
const result = runCli(['--version']);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /^\d+\.\d+\.\d+/i);
});
test('cli -V prints semver and exits 0', () => {
const result = runCli(['-V']);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /^\d+\.\d+\.\d+/i);
});
test('cli without command prints usage and exits 1', () => {
const result = runCli([]);
assert.equal(result.status, 1, result.stderr);
assert.match(result.stdout, /agent-device <command>/i);
});
test('alias --help matches the canonical command help', () => {
const aliases = listCliCommandNames().flatMap((command) =>
cliAliasesForCommand(command).map((entry) => [entry.alias, command] as const),
);
assert.ok(aliases.length > 0);
for (const [alias, canonical] of aliases) {
const result = runCli([alias, '--help']);
assert.equal(result.status, 0, result.stderr);
assert.equal(result.stdout, runCli([canonical, '--help']).stdout, alias);
}
});