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
134 lines
5.7 KiB
TypeScript
134 lines
5.7 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
import { runCLI } from '../helpers/run-cli.js';
|
|
|
|
describe('top-level validate command', () => {
|
|
const projectRoot = process.cwd();
|
|
const testDir = path.join(projectRoot, 'test-validate-command-tmp');
|
|
const changesDir = path.join(testDir, 'openspec', 'changes');
|
|
const specsDir = path.join(testDir, 'openspec', 'specs');
|
|
|
|
beforeEach(async () => {
|
|
await fs.mkdir(changesDir, { recursive: true });
|
|
await fs.mkdir(specsDir, { recursive: true });
|
|
|
|
// Create a valid spec
|
|
const specContent = [
|
|
'## Purpose',
|
|
'This spec ensures the validation harness exercises a deterministic alpha module for automated tests.',
|
|
'',
|
|
'## Requirements',
|
|
'',
|
|
'### Requirement: Alpha module SHALL produce deterministic output',
|
|
'The alpha module SHALL produce a deterministic response for validation.',
|
|
'',
|
|
'#### Scenario: Deterministic alpha run',
|
|
'- **GIVEN** a configured alpha module',
|
|
'- **WHEN** the module runs the default flow',
|
|
'- **THEN** the output matches the expected fixture result',
|
|
].join('\n');
|
|
await fs.mkdir(path.join(specsDir, 'alpha'), { recursive: true });
|
|
await fs.writeFile(path.join(specsDir, 'alpha', 'spec.md'), specContent, 'utf-8');
|
|
|
|
// Create a simple change with bullets (parser supports this)
|
|
const changeContent = `# Test Change\n\n## Why\nBecause reasons that are sufficiently long for validation.\n\n## What Changes\n- **alpha:** Add something`;
|
|
await fs.mkdir(path.join(changesDir, 'c1'), { recursive: true });
|
|
await fs.writeFile(path.join(changesDir, 'c1', 'proposal.md'), changeContent, 'utf-8');
|
|
const deltaContent = [
|
|
'## ADDED Requirements',
|
|
'### Requirement: Validator SHALL support alpha change deltas',
|
|
'The validator SHALL accept deltas provided by the test harness.',
|
|
'',
|
|
'#### Scenario: Apply alpha delta',
|
|
'- **GIVEN** the test change delta',
|
|
'- **WHEN** openspec validate runs',
|
|
'- **THEN** the validator reports the change as valid',
|
|
].join('\n');
|
|
const c1DeltaDir = path.join(changesDir, 'c1', 'specs', 'alpha');
|
|
await fs.mkdir(c1DeltaDir, { recursive: true });
|
|
await fs.writeFile(path.join(c1DeltaDir, 'spec.md'), deltaContent, 'utf-8');
|
|
|
|
// Duplicate name for ambiguity test
|
|
await fs.mkdir(path.join(changesDir, 'dup'), { recursive: true });
|
|
await fs.writeFile(path.join(changesDir, 'dup', 'proposal.md'), changeContent, 'utf-8');
|
|
const dupDeltaDir = path.join(changesDir, 'dup', 'specs', 'dup');
|
|
await fs.mkdir(dupDeltaDir, { recursive: true });
|
|
await fs.writeFile(path.join(dupDeltaDir, 'spec.md'), deltaContent, 'utf-8');
|
|
await fs.mkdir(path.join(specsDir, 'dup'), { recursive: true });
|
|
await fs.writeFile(path.join(specsDir, 'dup', 'spec.md'), specContent, 'utf-8');
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await fs.rm(testDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('prints a helpful hint when no args in non-interactive mode', async () => {
|
|
const result = await runCLI(['validate'], { cwd: testDir });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.stderr).toContain('Nothing to validate. Try one of:');
|
|
});
|
|
|
|
it('validates all with --all and outputs JSON summary', async () => {
|
|
const result = await runCLI(['validate', '--all', '--json'], { cwd: testDir });
|
|
expect(result.exitCode).toBe(0);
|
|
const output = result.stdout.trim();
|
|
expect(output).not.toBe('');
|
|
const json = JSON.parse(output);
|
|
expect(Array.isArray(json.items)).toBe(true);
|
|
expect(json.summary?.totals?.items).toBeDefined();
|
|
expect(json.version).toBe('1.0');
|
|
});
|
|
|
|
it('validates only specs with --specs and respects --concurrency', async () => {
|
|
const result = await runCLI(['validate', '--specs', '--json', '--concurrency', '1'], { cwd: testDir });
|
|
expect(result.exitCode).toBe(0);
|
|
const output = result.stdout.trim();
|
|
expect(output).not.toBe('');
|
|
const json = JSON.parse(output);
|
|
expect(json.items.every((i: any) => i.type === 'spec')).toBe(true);
|
|
});
|
|
|
|
it('errors on ambiguous item names and suggests type override', async () => {
|
|
const result = await runCLI(['validate', 'dup'], { cwd: testDir });
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.stderr).toContain('Ambiguous item');
|
|
});
|
|
|
|
it('accepts change proposals saved with CRLF line endings', async () => {
|
|
const changeId = 'crlf-change';
|
|
const toCrlf = (segments: string[]) => segments.join('\n').replace(/\n/g, '\r\n');
|
|
|
|
const crlfContent = toCrlf([
|
|
'# CRLF Proposal',
|
|
'',
|
|
'## Why',
|
|
'This change verifies validation works with Windows line endings.',
|
|
'',
|
|
'## What Changes',
|
|
'- **alpha:** Ensure validation passes on CRLF files',
|
|
]);
|
|
|
|
await fs.mkdir(path.join(changesDir, changeId), { recursive: true });
|
|
await fs.writeFile(path.join(changesDir, changeId, 'proposal.md'), crlfContent, 'utf-8');
|
|
|
|
const deltaContent = toCrlf([
|
|
'## ADDED Requirements',
|
|
'### Requirement: Parser SHALL accept CRLF change proposals',
|
|
'The parser SHALL accept CRLF change proposals without manual edits.',
|
|
'',
|
|
'#### Scenario: Validate CRLF change',
|
|
'- **GIVEN** a change proposal saved with CRLF line endings',
|
|
'- **WHEN** a developer runs openspec validate on the proposal',
|
|
'- **THEN** validation succeeds without section errors',
|
|
]);
|
|
|
|
const deltaDir = path.join(changesDir, changeId, 'specs', 'alpha');
|
|
await fs.mkdir(deltaDir, { recursive: true });
|
|
await fs.writeFile(path.join(deltaDir, 'spec.md'), deltaContent, 'utf-8');
|
|
|
|
const result = await runCLI(['validate', changeId], { cwd: testDir });
|
|
expect(result.exitCode).toBe(0);
|
|
});
|
|
});
|