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
56 changes: 1 addition & 55 deletions test/cli/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import assert from 'node:assert/strict';

import { describe, test } from 'vitest';
import { test } from 'vitest';

import { getCommandDefinition, getGroupDefinitions, listCommandGroups, listCommandNames } from '../../src/commands/registry/index.js';
import { parseInvocationForCli } from '../../src/cli/parse.js';
import { runCli } from '../../src/cli/run.js';
import { MemoryStream, createRuntimeDependencies, readPackageVersion } from '../support/cli-test.js';

const COMMAND_GROUPS = listCommandGroups();
const ALL_COMMANDS = listCommandNames();

test('runCli renders root help', async () => {
const stdout = new MemoryStream();
const stderr = new MemoryStream();
Expand Down Expand Up @@ -101,52 +97,6 @@ test('runCli does not support -v as a root-level alias for --version', async ()
assert.match(stderr.output, /See: orfe --help/);
});

describe('runCli renders help for each command group', () => {
for (const group of COMMAND_GROUPS) {
test(`group ${group}`, async () => {
const stdout = new MemoryStream();
const stderr = new MemoryStream();

const exitCode = await runCli([group, '--help'], { stdout, stderr });

assert.equal(exitCode, 0);
assert.equal(stderr.output, '');
assert.match(stdout.output, new RegExp(`orfe ${group}`));
assert.match(stdout.output, /Usage:/);
assert.match(stdout.output, /Commands:/);

for (const definition of getGroupDefinitions(group)) {
assert.match(stdout.output, new RegExp(`${definition.leaf} - ${escapeForRegExp(definition.purpose)}`));
}
});
}
});

describe('runCli renders leaf help for every agreed V1 command', () => {
for (const commandName of ALL_COMMANDS) {
test(commandName, async () => {
const stdout = new MemoryStream();
const stderr = new MemoryStream();
const definition = getCommandDefinition(commandName);
const args = definition.topLevel ? [commandName, '--help'] : [definition.group, definition.leaf, '--help'];

const exitCode = await runCli(args, { stdout, stderr });

assert.equal(exitCode, 0);
assert.equal(stderr.output, '');
assert.match(stdout.output, new RegExp(`^${escapeForRegExp(commandName)}`, 'm'));
assert.match(stdout.output, new RegExp(`Purpose: ${escapeForRegExp(definition.purpose)}`));
assert.match(stdout.output, new RegExp(`Usage: ${escapeForRegExp(definition.usage)}`));
assert.match(stdout.output, /Required options:/);
assert.match(stdout.output, /Optional options:/);
assert.match(stdout.output, new RegExp(`Success: ${escapeForRegExp(definition.successSummary)}`));
assert.match(stdout.output, /Examples:/);
assert.match(stdout.output, /JSON success shape example:/);
assert.match(stdout.output, new RegExp(escapeForRegExp(JSON.stringify(definition.successDataExample))));
});
}
});

test('runCli reports invalid usage for unknown commands', async () => {
const stdout = new MemoryStream();
const stderr = new MemoryStream();
Expand Down Expand Up @@ -232,7 +182,3 @@ test('runCli reports malformed repo overrides as usage errors', async () => {
assert.match(stderr.output, /Repository must be in "owner\/name" format\./);
assert.match(stderr.output, /See: orfe issue get --help/);
});

function escapeForRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
40 changes: 0 additions & 40 deletions test/core/command-registry.test.ts

This file was deleted.

61 changes: 61 additions & 0 deletions test/core/core-run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';

import { runOrfeCore } from '../../src/core/run.js';
import { OrfeError } from '../../src/runtime/errors.js';
import { readPackageVersion } from '../support/cli-test.js';

test('runOrfeCore executes runtime-only commands without caller, config, auth, or GitHub access', async () => {
const packageVersion = await readPackageVersion();

const result = await runOrfeCore(
{
callerName: '',
command: 'runtime info',
input: {},
},
{
loadRepoConfigImpl: async () => {
throw new Error('loadRepoConfigImpl should not run');
},
loadAuthConfigImpl: async () => {
throw new Error('loadAuthConfigImpl should not run');
},
},
);

assert.deepEqual(result, {
ok: true,
command: 'runtime info',
data: {
orfe_version: packageVersion,
entrypoint: 'cli',
},
});
});

test('runOrfeCore rejects unknown commands before loading config or auth', async () => {
await assert.rejects(
runOrfeCore(
{
callerName: 'Greg',
command: 'issue unknown',
input: {},
},
{
loadRepoConfigImpl: async () => {
throw new Error('loadRepoConfigImpl should not run');
},
loadAuthConfigImpl: async () => {
throw new Error('loadAuthConfigImpl should not run');
},
},
),
(error: unknown) => {
assert(error instanceof OrfeError);
assert.equal(error.code, 'invalid_usage');
assert.match(error.message, /Unknown command "issue unknown"\./);
return true;
},
);
});