Skip to content

Commit c5d65f2

Browse files
Reduce remaining structural and duplicated tests after #159 (#167)
2 parents 6bccb13 + 3a4cd6d commit c5d65f2

3 files changed

Lines changed: 62 additions & 95 deletions

File tree

test/cli/run.test.ts

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import assert from 'node:assert/strict';
22

3-
import { describe, test } from 'vitest';
3+
import { test } from 'vitest';
44

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

10-
const COMMAND_GROUPS = listCommandGroups();
11-
const ALL_COMMANDS = listCommandNames();
12-
139
test('runCli renders root help', async () => {
1410
const stdout = new MemoryStream();
1511
const stderr = new MemoryStream();
@@ -101,52 +97,6 @@ test('runCli does not support -v as a root-level alias for --version', async ()
10197
assert.match(stderr.output, /See: orfe --help/);
10298
});
10399

104-
describe('runCli renders help for each command group', () => {
105-
for (const group of COMMAND_GROUPS) {
106-
test(`group ${group}`, async () => {
107-
const stdout = new MemoryStream();
108-
const stderr = new MemoryStream();
109-
110-
const exitCode = await runCli([group, '--help'], { stdout, stderr });
111-
112-
assert.equal(exitCode, 0);
113-
assert.equal(stderr.output, '');
114-
assert.match(stdout.output, new RegExp(`orfe ${group}`));
115-
assert.match(stdout.output, /Usage:/);
116-
assert.match(stdout.output, /Commands:/);
117-
118-
for (const definition of getGroupDefinitions(group)) {
119-
assert.match(stdout.output, new RegExp(`${definition.leaf} - ${escapeForRegExp(definition.purpose)}`));
120-
}
121-
});
122-
}
123-
});
124-
125-
describe('runCli renders leaf help for every agreed V1 command', () => {
126-
for (const commandName of ALL_COMMANDS) {
127-
test(commandName, async () => {
128-
const stdout = new MemoryStream();
129-
const stderr = new MemoryStream();
130-
const definition = getCommandDefinition(commandName);
131-
const args = definition.topLevel ? [commandName, '--help'] : [definition.group, definition.leaf, '--help'];
132-
133-
const exitCode = await runCli(args, { stdout, stderr });
134-
135-
assert.equal(exitCode, 0);
136-
assert.equal(stderr.output, '');
137-
assert.match(stdout.output, new RegExp(`^${escapeForRegExp(commandName)}`, 'm'));
138-
assert.match(stdout.output, new RegExp(`Purpose: ${escapeForRegExp(definition.purpose)}`));
139-
assert.match(stdout.output, new RegExp(`Usage: ${escapeForRegExp(definition.usage)}`));
140-
assert.match(stdout.output, /Required options:/);
141-
assert.match(stdout.output, /Optional options:/);
142-
assert.match(stdout.output, new RegExp(`Success: ${escapeForRegExp(definition.successSummary)}`));
143-
assert.match(stdout.output, /Examples:/);
144-
assert.match(stdout.output, /JSON success shape example:/);
145-
assert.match(stdout.output, new RegExp(escapeForRegExp(JSON.stringify(definition.successDataExample))));
146-
});
147-
}
148-
});
149-
150100
test('runCli reports invalid usage for unknown commands', async () => {
151101
const stdout = new MemoryStream();
152102
const stderr = new MemoryStream();
@@ -232,7 +182,3 @@ test('runCli reports malformed repo overrides as usage errors', async () => {
232182
assert.match(stderr.output, /Repository must be in "owner\/name" format\./);
233183
assert.match(stderr.output, /See: orfe issue get --help/);
234184
});
235-
236-
function escapeForRegExp(value: string): string {
237-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
238-
}

test/core/command-registry.test.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

test/core/core-run.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'vitest';
3+
4+
import { runOrfeCore } from '../../src/core/run.js';
5+
import { OrfeError } from '../../src/runtime/errors.js';
6+
import { readPackageVersion } from '../support/cli-test.js';
7+
8+
test('runOrfeCore executes runtime-only commands without caller, config, auth, or GitHub access', async () => {
9+
const packageVersion = await readPackageVersion();
10+
11+
const result = await runOrfeCore(
12+
{
13+
callerName: '',
14+
command: 'runtime info',
15+
input: {},
16+
},
17+
{
18+
loadRepoConfigImpl: async () => {
19+
throw new Error('loadRepoConfigImpl should not run');
20+
},
21+
loadAuthConfigImpl: async () => {
22+
throw new Error('loadAuthConfigImpl should not run');
23+
},
24+
},
25+
);
26+
27+
assert.deepEqual(result, {
28+
ok: true,
29+
command: 'runtime info',
30+
data: {
31+
orfe_version: packageVersion,
32+
entrypoint: 'cli',
33+
},
34+
});
35+
});
36+
37+
test('runOrfeCore rejects unknown commands before loading config or auth', async () => {
38+
await assert.rejects(
39+
runOrfeCore(
40+
{
41+
callerName: 'Greg',
42+
command: 'issue unknown',
43+
input: {},
44+
},
45+
{
46+
loadRepoConfigImpl: async () => {
47+
throw new Error('loadRepoConfigImpl should not run');
48+
},
49+
loadAuthConfigImpl: async () => {
50+
throw new Error('loadAuthConfigImpl should not run');
51+
},
52+
},
53+
),
54+
(error: unknown) => {
55+
assert(error instanceof OrfeError);
56+
assert.equal(error.code, 'invalid_usage');
57+
assert.match(error.message, /Unknown command "issue unknown"\./);
58+
return true;
59+
},
60+
);
61+
});

0 commit comments

Comments
 (0)