Skip to content
Draft
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
4 changes: 2 additions & 2 deletions integ-tests/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('status command', () => {

it('emits failure telemetry for invalid --type', async () => {
const result = await runCLI(['status', '--type', 'bogus'], projectDir, { env: telemetry.env });
expect(result.exitCode).toBe(0);
expect(result.exitCode).toBe(1);
telemetry.assertMetricEmitted({
command: 'status',
exit_reason: 'failure',
Expand All @@ -80,7 +80,7 @@ describe('status command', () => {

it('emits failure telemetry for invalid --state', async () => {
const result = await runCLI(['status', '--state', 'bogus'], projectDir, { env: telemetry.env });
expect(result.exitCode).toBe(0);
expect(result.exitCode).toBe(1);
telemetry.assertMetricEmitted({
command: 'status',
exit_reason: 'failure',
Expand Down
77 changes: 77 additions & 0 deletions src/cli/commands/status/__tests__/command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { handleProjectStatus, loadStatusConfig } from '../action.js';
import { registerStatus } from '../command.js';
import { Command } from '@commander-js/extra-typings';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

const { mockRender } = vi.hoisted(() => ({
mockRender: vi.fn(),
}));

vi.mock('../../../tui/guards', () => ({
requireProject: vi.fn(),
}));

vi.mock('../../../telemetry/cli-command-run.js', () => ({
withCommandRunTelemetry: vi.fn((_command, _attrs, run) => run()),
}));

vi.mock('../../../operations/dataset', () => ({
getDatasetStatus: vi.fn(),
}));

vi.mock('../action.js', () => ({
handleProjectStatus: vi.fn(),
handleRuntimeLookup: vi.fn(),
loadStatusConfig: vi.fn(),
}));

vi.mock('../../../feature-flags', () => ({
isPreviewEnabled: () => false,
}));

vi.mock('ink', () => ({
Box: ({ children }: { children?: unknown }) => children,
Text: ({ children }: { children?: unknown }) => children,
render: mockRender,
}));

describe('status command validation', () => {
let program: Command;
let originalExitCode: typeof process.exitCode;

beforeEach(() => {
originalExitCode = process.exitCode;
process.exitCode = undefined;
program = new Command();
program.exitOverride();
registerStatus(program);
});

afterEach(() => {
process.exitCode = originalExitCode;
vi.clearAllMocks();
});

it('sets a non-zero exit code for invalid resource type', async () => {
await program.parseAsync(['status', '--type', 'bogus'], { from: 'user' });

expect(process.exitCode).toBe(1);
expect(mockRender).toHaveBeenCalled();
});

it('sets a non-zero exit code for invalid state', async () => {
await program.parseAsync(['status', '--state', 'bogus'], { from: 'user' });

expect(process.exitCode).toBe(1);
expect(mockRender).toHaveBeenCalled();
});

it('leaves exit code unset for a valid filter', async () => {
vi.mocked(loadStatusConfig).mockResolvedValue({} as never);
vi.mocked(handleProjectStatus).mockResolvedValue({ success: true, resources: [] } as never);

await program.parseAsync(['status', '--type', 'agent'], { from: 'user' });

expect(process.exitCode).toBeUndefined();
});
});
2 changes: 2 additions & 0 deletions src/cli/commands/status/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
error: new ValidationError(msg),
}));
render(<Text color="red">{msg}</Text>);
process.exitCode = 1;
return;
}

Expand All @@ -107,6 +108,7 @@
error: new ValidationError(msg),
}));
render(<Text color="red">{msg}</Text>);
process.exitCode = 1;
return;
}

Expand Down Expand Up @@ -417,7 +419,7 @@
});
};

function ResourceEntry({ entry, showRuntime }: { entry: ResourceStatusEntry; showRuntime?: boolean }) {

Check warning on line 422 in src/cli/commands/status/command.tsx

View workflow job for this annotation

GitHub Actions / lint

Fast refresh only works when a file only exports components. Move your component(s) to a separate file. If all exports are HOCs, add them to the `extraHOCs` option
return (
<Text>
{' '}
Expand Down
Loading