mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-09-14 20:16:53 +08:00
fb7ff527a6
* proposal: add artifact workflow CLI commands (Slice 4) Add CLI commands for artifact workflow operations: - `openspec status --change <id>` - Show artifact completion state - `openspec next --change <id>` - Show ready artifacts - `openspec instructions <artifact> --change <id>` - Get enriched template - `openspec templates --change <id>` - Show template paths - `openspec new change <name>` - Create new change Commands are top-level for fluid UX and implemented in isolation for easy removal (experimental feature). * fix: remove --change from templates command Templates are schema-level, not change-level. The command now uses --schema instead of --change for consistency with how templates are actually resolved. * rename: cli-workflow -> cli-artifact-workflow More specific capability name that clarifies which workflow the CLI commands are for. * feat: implement artifact workflow CLI commands (Slice 4) Add experimental CLI commands for artifact-based workflow management: - `openspec status --change <id>` - display artifact completion status - `openspec next --change <id>` - show artifacts ready to create - `openspec instructions <artifact> --change <id>` - output enriched template - `openspec templates [--schema <name>]` - show resolved template paths - `openspec new change <name>` - create new change directory Features: - JSON output support (--json flag) for all commands - Color-coded status indicators (green/yellow/red) - Progress spinners during loading - --no-color and NO_COLOR env support - --schema option for custom schema selection - Comprehensive error handling with helpful messages All commands are isolated in src/commands/artifact-workflow.ts for easy removal if the feature doesn't work out. Help text marks them as experimental. * fix: update specs glob to match nested directory structure The schema used specs/*.md but specs are stored as specs/<capability>/spec.md. Updated to specs/**/*.md so openspec status/next correctly detect spec completion. * test: update test to match new specs glob pattern * chore: archive add-artifact-workflow-cli change - Move change to archive/2025-12-28-add-artifact-workflow-cli - Create cli-artifact-workflow spec * feat: unify change state model for scaffolded changes - Update artifact workflow commands to work with scaffolded changes - Add draft changes section to dashboard view - Fix completed changes to require tasks.total > 0 - Archive unify-change-state-model change * fix: validate change name format to prevent path traversal Add validation in validateChangeExists() to ensure --change parameter is a valid kebab-case ID before constructing file paths. This prevents path traversal attacks like --change "../foo" or --change "/etc/passwd". - Reuses existing validateChangeName() from change-utils.ts - Adds 3 tests for path traversal, absolute paths, and slashes
130 lines
4.5 KiB
TypeScript
130 lines
4.5 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
import os from 'os';
|
|
import { ViewCommand } from '../../src/core/view.js';
|
|
|
|
const stripAnsi = (input: string): string => input.replace(/\u001b\[[0-9;]*m/g, '');
|
|
|
|
describe('ViewCommand', () => {
|
|
let tempDir: string;
|
|
let originalLog: typeof console.log;
|
|
let logOutput: string[] = [];
|
|
|
|
beforeEach(async () => {
|
|
tempDir = path.join(os.tmpdir(), `openspec-view-test-${Date.now()}`);
|
|
await fs.mkdir(tempDir, { recursive: true });
|
|
|
|
originalLog = console.log;
|
|
console.log = (...args: any[]) => {
|
|
logOutput.push(args.join(' '));
|
|
};
|
|
|
|
logOutput = [];
|
|
});
|
|
|
|
afterEach(async () => {
|
|
console.log = originalLog;
|
|
await fs.rm(tempDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('shows changes with no tasks in Draft section, not Completed', async () => {
|
|
const changesDir = path.join(tempDir, 'openspec', 'changes');
|
|
await fs.mkdir(changesDir, { recursive: true });
|
|
|
|
// Empty change (no tasks.md) - should show in Draft
|
|
await fs.mkdir(path.join(changesDir, 'empty-change'), { recursive: true });
|
|
|
|
// Change with tasks.md but no tasks - should show in Draft
|
|
await fs.mkdir(path.join(changesDir, 'no-tasks-change'), { recursive: true });
|
|
await fs.writeFile(path.join(changesDir, 'no-tasks-change', 'tasks.md'), '# Tasks\n\nNo tasks yet.');
|
|
|
|
// Change with all tasks complete - should show in Completed
|
|
await fs.mkdir(path.join(changesDir, 'completed-change'), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(changesDir, 'completed-change', 'tasks.md'),
|
|
'- [x] Done task\n'
|
|
);
|
|
|
|
const viewCommand = new ViewCommand();
|
|
await viewCommand.execute(tempDir);
|
|
|
|
const output = logOutput.map(stripAnsi).join('\n');
|
|
|
|
// Draft section should contain empty and no-tasks changes
|
|
expect(output).toContain('Draft Changes');
|
|
expect(output).toContain('empty-change');
|
|
expect(output).toContain('no-tasks-change');
|
|
|
|
// Completed section should only contain changes with all tasks done
|
|
expect(output).toContain('Completed Changes');
|
|
expect(output).toContain('completed-change');
|
|
|
|
// Verify empty-change and no-tasks-change are in Draft section (marked with ○)
|
|
const draftLines = logOutput
|
|
.map(stripAnsi)
|
|
.filter((line) => line.includes('○'));
|
|
const draftNames = draftLines.map((line) => line.trim().replace('○ ', ''));
|
|
expect(draftNames).toContain('empty-change');
|
|
expect(draftNames).toContain('no-tasks-change');
|
|
|
|
// Verify completed-change is in Completed section (marked with ✓)
|
|
const completedLines = logOutput
|
|
.map(stripAnsi)
|
|
.filter((line) => line.includes('✓'));
|
|
const completedNames = completedLines.map((line) => line.trim().replace('✓ ', ''));
|
|
expect(completedNames).toContain('completed-change');
|
|
expect(completedNames).not.toContain('empty-change');
|
|
expect(completedNames).not.toContain('no-tasks-change');
|
|
});
|
|
|
|
it('sorts active changes by completion percentage ascending with deterministic tie-breakers', async () => {
|
|
const changesDir = path.join(tempDir, 'openspec', 'changes');
|
|
await fs.mkdir(changesDir, { recursive: true });
|
|
|
|
await fs.mkdir(path.join(changesDir, 'gamma-change'), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(changesDir, 'gamma-change', 'tasks.md'),
|
|
'- [x] Done\n- [x] Also done\n- [ ] Not done\n'
|
|
);
|
|
|
|
await fs.mkdir(path.join(changesDir, 'beta-change'), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(changesDir, 'beta-change', 'tasks.md'),
|
|
'- [x] Task 1\n- [ ] Task 2\n'
|
|
);
|
|
|
|
await fs.mkdir(path.join(changesDir, 'delta-change'), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(changesDir, 'delta-change', 'tasks.md'),
|
|
'- [x] Task 1\n- [ ] Task 2\n'
|
|
);
|
|
|
|
await fs.mkdir(path.join(changesDir, 'alpha-change'), { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(changesDir, 'alpha-change', 'tasks.md'),
|
|
'- [ ] Task 1\n- [ ] Task 2\n'
|
|
);
|
|
|
|
const viewCommand = new ViewCommand();
|
|
await viewCommand.execute(tempDir);
|
|
|
|
const activeLines = logOutput
|
|
.map(stripAnsi)
|
|
.filter(line => line.includes('◉'));
|
|
|
|
const activeOrder = activeLines.map(line => {
|
|
const afterBullet = line.split('◉')[1] ?? '';
|
|
return afterBullet.split('[')[0]?.trim();
|
|
});
|
|
|
|
expect(activeOrder).toEqual([
|
|
'alpha-change',
|
|
'beta-change',
|
|
'delta-change',
|
|
'gamma-change'
|
|
]);
|
|
});
|
|
});
|
|
|