mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-09-14 20:16:53 +08:00
4867bfade5
* feat: implement Phase 1 E2E testing with cross-platform CI matrix - Add shared runCLI helper in test/helpers/run-cli.ts for spawn testing - Create test/cli-e2e/basic.test.ts covering help, version, validate flows - Migrate existing CLI exec tests to use runCLI helper - Extend CI matrix to bash (Linux/macOS) and pwsh (Windows) - Update Phase 1 tasks and proposal with implementation status * fix: correct YAML syntax in CI workflow diagnostics command * fix: use multiline YAML for diagnostics command * fix ci * fix: ci * fix: update core validation and json converter * chore(ci): split pr and main workflows * refactor: simplify CI workflow with unified matrix strategy - Consolidate test_pr and test_matrix into single test job - Add proper shell configuration with defaults - Add timeout protection (15 minutes) - Simplify required-checks to single job - Maintain cross-platform testing (bash on Linux/macOS, pwsh on Windows) * fix: restore lean PR workflow with async main branch matrix - PRs run only essential tests on ubuntu-latest (fast feedback) - Main branch runs full cross-platform matrix asynchronously - Separate required-checks for each workflow type - Different timeouts: 10min for PR, 15min for matrix
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { afterAll, describe, it, expect } from 'vitest';
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
import { tmpdir } from 'os';
|
|
import { runCLI, cliProjectRoot } from '../helpers/run-cli.js';
|
|
|
|
const tempRoots: string[] = [];
|
|
|
|
async function prepareFixture(fixtureName: string): Promise<string> {
|
|
const base = await fs.mkdtemp(path.join(tmpdir(), 'openspec-cli-e2e-'));
|
|
tempRoots.push(base);
|
|
const projectDir = path.join(base, 'project');
|
|
await fs.mkdir(projectDir, { recursive: true });
|
|
const fixtureDir = path.join(cliProjectRoot, 'test', 'fixtures', fixtureName);
|
|
await fs.cp(fixtureDir, projectDir, { recursive: true });
|
|
return projectDir;
|
|
}
|
|
|
|
afterAll(async () => {
|
|
await Promise.all(tempRoots.map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe('openspec CLI e2e basics', () => {
|
|
it('shows help output', async () => {
|
|
const result = await runCLI(['--help']);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain('Usage: openspec');
|
|
expect(result.stderr).toBe('');
|
|
});
|
|
|
|
it('reports the package version', async () => {
|
|
const pkgRaw = await fs.readFile(path.join(cliProjectRoot, 'package.json'), 'utf-8');
|
|
const pkg = JSON.parse(pkgRaw);
|
|
const result = await runCLI(['--version']);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout.trim()).toBe(pkg.version);
|
|
});
|
|
|
|
it('validates the tmp-init fixture with --all --json', async () => {
|
|
const projectDir = await prepareFixture('tmp-init');
|
|
const result = await runCLI(['validate', '--all', '--json'], { cwd: projectDir });
|
|
expect(result.exitCode).toBe(0);
|
|
const output = result.stdout.trim();
|
|
expect(output).not.toBe('');
|
|
const json = JSON.parse(output);
|
|
expect(json.summary?.totals?.failed).toBe(0);
|
|
expect(json.items.some((item: any) => item.id === 'c1' && item.type === 'change')).toBe(true);
|
|
});
|
|
|
|
it('returns an error for unknown items in the fixture', async () => {
|
|
const projectDir = await prepareFixture('tmp-init');
|
|
const result = await runCLI(['validate', 'does-not-exist'], { cwd: projectDir });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.stderr).toContain("Unknown item 'does-not-exist'");
|
|
});
|
|
});
|