mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-09-14 20:16:53 +08:00
80 lines
2.3 KiB
TypeScript
80 lines
2.3 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('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'
|
|
]);
|
|
});
|
|
});
|
|
|