test(cli): cover onboard flow and start onboarding guidance

This commit is contained in:
William Valentin
2026-02-16 18:32:00 -08:00
parent 5b5fbb887c
commit 2e07ae44a3
4 changed files with 129 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
import { Command } from 'commander';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const { mockRunSetup } = vi.hoisted(() => ({
mockRunSetup: vi.fn(async () => undefined),
}));
const { mockGetConfigPath } = vi.hoisted(() => ({
mockGetConfigPath: vi.fn(() => '/tmp/default-config.yaml'),
}));
vi.mock('./setup.js', () => ({
runSetup: mockRunSetup,
}));
vi.mock('./shared.js', () => ({
getConfigPath: mockGetConfigPath,
}));
describe('onboard command', () => {
beforeEach(() => {
vi.clearAllMocks();
mockRunSetup.mockReset();
mockGetConfigPath.mockReset();
mockGetConfigPath.mockReturnValue('/tmp/default-config.yaml');
});
it('runs setup using default config path when --config is omitted', async () => {
const program = new Command();
const { registerOnboardCommand } = await import('./onboard.js');
registerOnboardCommand(program);
await program.parseAsync(['node', 'test', 'onboard']);
expect(mockGetConfigPath).toHaveBeenCalledOnce();
expect(mockRunSetup).toHaveBeenCalledWith('/tmp/default-config.yaml');
});
it('runs setup using explicit --config path when provided', async () => {
const program = new Command();
const { registerOnboardCommand } = await import('./onboard.js');
registerOnboardCommand(program);
await program.parseAsync(['node', 'test', 'onboard', '--config', '/tmp/custom.yaml']);
expect(mockGetConfigPath).not.toHaveBeenCalled();
expect(mockRunSetup).toHaveBeenCalledWith('/tmp/custom.yaml');
});
});
+65
View File
@@ -0,0 +1,65 @@
import { Command } from 'commander';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const { mockExistsSync } = vi.hoisted(() => ({
mockExistsSync: vi.fn(() => false),
}));
const { mockCreateInterface } = vi.hoisted(() => ({
mockCreateInterface: vi.fn(),
}));
const { mockCreatePrompter, mockConfirm } = vi.hoisted(() => ({
mockCreatePrompter: vi.fn(),
mockConfirm: vi.fn(async () => false),
}));
vi.mock('fs', () => ({
existsSync: mockExistsSync,
}));
vi.mock('readline/promises', () => ({
createInterface: mockCreateInterface,
}));
vi.mock('./setup/prompts.js', () => ({
createPrompter: mockCreatePrompter,
}));
describe('start command', () => {
beforeEach(() => {
vi.clearAllMocks();
mockExistsSync.mockReset();
mockExistsSync.mockReturnValue(false);
mockConfirm.mockReset();
mockConfirm.mockResolvedValue(false);
mockCreateInterface.mockReset();
mockCreateInterface.mockReturnValue({ close: vi.fn() });
mockCreatePrompter.mockReset();
mockCreatePrompter.mockReturnValue({
confirm: mockConfirm,
});
});
it('suggests onboard/setup guidance when config is missing and wizard is declined', async () => {
const program = new Command();
const { registerStartCommand } = await import('./start.js');
registerStartCommand(program);
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => {
throw new Error(`EXIT:${code ?? 0}`);
}) as never);
await expect(
program.parseAsync(['node', 'test', 'start', '--config', '/tmp/missing.yaml']),
).rejects.toThrow('EXIT:1');
expect(consoleError).toHaveBeenCalledWith(
'Run "flynn onboard" (or "flynn setup") to create one, or "flynn doctor" to diagnose.',
);
exitSpy.mockRestore();
consoleError.mockRestore();
});
});
+1 -1
View File
@@ -29,7 +29,7 @@ export function registerStartCommand(program: Command): void {
}
console.error(`Config file not found: ${configPath}`);
console.error('Run "flynn setup" to create one, or "flynn doctor" to diagnose.');
console.error('Run "flynn onboard" (or "flynn setup") to create one, or "flynn doctor" to diagnose.');
process.exit(1);
}