mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-10-21 06:29:34 +08:00
* docs(openspec): propose resolution/validation parity bug bundle (#1182, #1202, #1156) Planning artifacts only (proposal/design/spec deltas/tasks) for a focused bug-fix bundle. Three read/validate paths silently diverge from the canonical logic a sibling command already gets right: - #1182 validate ignores workspace planning homes that status/instructions resolve - #1202 view counts only changes/<name>/tasks.md, ignoring the schema tasks glob - #1156 the SHALL/MUST body-keyword hint fires for deltas but not main specs Fix converges each divergent path onto the canonical one; parity is asserted by test. No new surface, no behavior change to the already-correct paths. Validates --strict. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(openspec): bulletproof the parity bundle after adversarial source review Hardened all three bugs after tracing each path to source with parallel verification agents. Material corrections: - #1182: reframed from "workspace planning home resolution" (planning homes are repo-only; the feature is now 'stores', and validate already accepts --store) to the real, reproducible-at-HEAD mechanism: validate's proposal.md membership gate (getActiveChangeIds) vs status/instructions' directory-existence rule (validateChangeExists). Pulled nested specs/<area>/<cap> delta discovery and bulk --all into scope; noted show.ts sibling. - #1202: widened from view-only to the shared helper's real blast radius — also the archive incomplete-task gate (silently archives unfinished glob-tasks changes: data safety) and a 2nd hardcoded copy in change.ts. Pinned apply.tracks as the source, change-dir scope containment, and the no-schema fallback. Added cli-archive delta for the gate. - #1156: the main-spec parser discards the requirement header before Zod runs, so the hint can't be "lifted" — fix needs header recovery (reuse requirement-blocks) + Zod de-dup, and the main-spec message can't be byte-identical to the delta's (no ADDED prefix). Pinned the actionable sentence + single-emission + regression scenarios across all main-spec surfaces. 4 deltas (cli-validate x2, cli-view, cli-archive). Validates --strict. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(openspec): deep-harden the parity bundle with empirical reproduction Round 2 of bulletproofing: 3 parallel agents reproduced every bug against the built (pre-fix) CLI and traced fix sites. This pass corrected two substantive errors in my own prior spec and closed several gaps. #1202 (two corrections to the prior draft): - apply.tracks is a FILENAME that selects the tracked artifact, NOT a glob; the glob is that artifact's `generates`. status resolves via resolveArtifactOutputs(changeDir, artifact.generates). Fixed all wording. - "view/archive counts equal status" is FALSE: status checks file EXISTENCE, not checkboxes (proven: status calls a 3/5 change isComplete:true). Deleted the two count-parity scenarios; reframed as resolution-mechanism parity (same files). - Added schema-resolution-failure fallback (resolveSchema throws; helper must catch or view/list/archive crash). Added projectRoot param + 6-site wiring. - Empirically PROVEN data-safety bug: archive moved a 3/5 unfinished change into changes/archive/. #1182: - Found a THIRD getActiveChangeIds site (interactive selector, validate.ts:97). - Proven: --all with a lone proposal-less change exits 0 silently. Added exit-code scenarios. Trimmed over-scope: getSpecIds spec-side is NOT a bug; no store-specific scenario needed; noun-form scoped out. #1156: - Refine-relaxation regression resolved: deltas don't use the Zod refine (validate imperatively), so REMOVE it (not relax) once applySpecRules owns both header-only and no-keyword cases. Added RENAMED (out-of-scope), lowercase, and the new no-body-line-valid-today scenarios; pinned exact message + prefix. Still 4 deltas; validates --strict; empirical evidence section added to design. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: converge validate/view/archive onto canonical resolution (#1182, #1202, #1156) Implements the resolution/validation parity bug bundle planned in openspec/changes/fix-validate-view-resolution-parity. Each fix points a divergent read/validate path at the canonical implementation a sibling command already gets right, with parity tests guarding against re-forking. #1182 — validate resolves changes like status. validate now resolves a change by directory existence (shared getAvailableChanges) instead of requiring proposal.md, at all three sites (targeted, bulk, interactive selector). A scaffolded/still-authoring change is validated rather than reported Unknown item; a resolved-but-invalid change exits non-zero. show.ts and the deprecated noun-form change validate are scoped out. #1182b — validateChangeDeltaSpecs recurses the nested multi-area layout (specs/<area>/<capability>/spec.md) via a new findDeltaSpecFiles walker, so a resolved multi-area change validates its deltas instead of reporting "No delta sections found". #1202 — getTaskProgressForChange resolves task progress through the tracked-tasks artifact's generates glob (the same resolveArtifactOutputs status uses), aggregating checkboxes across every matched tasks.md scoped to the change dir, with a never-throw fallback to a single top-level tasks.md. Updates all four callers (view/list/archive x2) for the new projectRoot arg and folds the second copy in change.ts onto the helper. Fixes view's Draft misclassification and the archive incomplete-task gate that let an unfinished glob-tasks change archive (data safety). #1156 — the SHALL/MUST body-keyword hint applies to main specs. applySpecRules recovers the requirement header via extractRequirementsSection and emits the targeted hint (header-only) or generic message (no keyword), exactly once; the Zod refine is removed (deltas never used it). The actionable sentence is byte-identical to the change-delta path. Adds parity/regression tests (Decision 7): validate<->status resolution incl. exit code, view/archive resolve the same files as status, and the main-spec<->delta actionable-sentence parity. Full suite green (1791 passed; only the pre-existing, environment-specific zsh-installer failures remain). Change validates --strict; all 36 repo specs pass --specs --strict with no new false positives. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
169 lines
6.7 KiB
TypeScript
169 lines
6.7 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 { getTaskProgressForChange } from '../../src/utils/task-progress.js';
|
|
import { resolveArtifactOutputs } from '../../src/core/artifact-graph/index.js';
|
|
|
|
/**
|
|
* #1202 — task progress is resolved through the tracked-tasks artifact's
|
|
* `generates` glob (the same file-resolution `openspec status` uses), not a
|
|
* fixed `changes/<name>/tasks.md` path.
|
|
*/
|
|
describe('getTaskProgressForChange (#1202 tracked-tasks resolution)', () => {
|
|
let projectRoot: string;
|
|
let changesDir: string;
|
|
|
|
const GLOB_SCHEMA = [
|
|
'name: glob-tasks',
|
|
'version: 1',
|
|
'description: tasks artifact uses a nested glob',
|
|
'artifacts:',
|
|
' - id: proposal',
|
|
' generates: proposal.md',
|
|
' description: Proposal',
|
|
' template: proposal.md',
|
|
' requires: []',
|
|
' - id: tasks',
|
|
' generates: "**/tasks.md"',
|
|
' description: Nested tasks',
|
|
' template: tasks.md',
|
|
' requires: [proposal]',
|
|
'apply:',
|
|
' requires: [tasks]',
|
|
' tracks: "**/tasks.md"',
|
|
'',
|
|
].join('\n');
|
|
|
|
beforeEach(async () => {
|
|
projectRoot = path.join(os.tmpdir(), `openspec-taskprogress-${Date.now()}-${Math.round(performance.now())}`);
|
|
changesDir = path.join(projectRoot, 'openspec', 'changes');
|
|
await fs.mkdir(changesDir, { recursive: true });
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await fs.rm(projectRoot, { recursive: true, force: true });
|
|
});
|
|
|
|
async function writeGlobSchema(): Promise<void> {
|
|
const schemaDir = path.join(projectRoot, 'openspec', 'schemas', 'glob-tasks');
|
|
await fs.mkdir(schemaDir, { recursive: true });
|
|
await fs.writeFile(path.join(schemaDir, 'schema.yaml'), GLOB_SCHEMA, 'utf-8');
|
|
}
|
|
|
|
async function writeChange(name: string, files: Record<string, string>, schema = 'glob-tasks'): Promise<string> {
|
|
const changeDir = path.join(changesDir, name);
|
|
await fs.mkdir(changeDir, { recursive: true });
|
|
if (schema) {
|
|
await fs.writeFile(path.join(changeDir, '.openspec.yaml'), `schema: ${schema}\n`, 'utf-8');
|
|
}
|
|
for (const [rel, content] of Object.entries(files)) {
|
|
const full = path.join(changeDir, rel);
|
|
await fs.mkdir(path.dirname(full), { recursive: true });
|
|
await fs.writeFile(full, content, 'utf-8');
|
|
}
|
|
return changeDir;
|
|
}
|
|
|
|
it('aggregates checkboxes across nested tasks.md files matched by the glob', async () => {
|
|
await writeGlobSchema();
|
|
await writeChange('globchange', {
|
|
'backend/tasks.md': '- [x] 1.1 a\n- [x] 1.2 b\n',
|
|
'frontend/tasks.md': '- [x] 2.1 a\n- [ ] 2.2 b\n- [ ] 2.3 c\n',
|
|
});
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'globchange', projectRoot);
|
|
expect(progress).toEqual({ total: 5, completed: 3 });
|
|
});
|
|
|
|
it('resolves the same set of files status resolves (resolution-mechanism parity)', async () => {
|
|
await writeGlobSchema();
|
|
const changeDir = await writeChange('globchange', {
|
|
'backend/tasks.md': '- [x] a\n- [x] b\n',
|
|
'frontend/tasks.md': '- [x] a\n- [ ] b\n- [ ] c\n',
|
|
});
|
|
|
|
// `status` detects the tasks artifact via resolveArtifactOutputs(changeDir, generates).
|
|
const statusFiles = resolveArtifactOutputs(changeDir, '**/tasks.md');
|
|
expect(statusFiles).toHaveLength(2);
|
|
|
|
// The helper's aggregate equals the checkbox sum over exactly those files.
|
|
let total = 0;
|
|
let completed = 0;
|
|
for (const file of statusFiles) {
|
|
const content = await fs.readFile(file, 'utf-8');
|
|
total += (content.match(/^[-*]\s+\[[\sx]\]/gim) ?? []).length;
|
|
completed += (content.match(/^[-*]\s+\[x\]/gim) ?? []).length;
|
|
}
|
|
const progress = await getTaskProgressForChange(changesDir, 'globchange', projectRoot);
|
|
expect(progress).toEqual({ total, completed });
|
|
});
|
|
|
|
it('scopes resolution to the change dir (excludes archive/ and sibling changes)', async () => {
|
|
await writeGlobSchema();
|
|
await writeChange('target', { 'backend/tasks.md': '- [x] a\n- [ ] b\n' });
|
|
// Decoys that must NOT be counted.
|
|
await fs.mkdir(path.join(changesDir, 'archive', 'old'), { recursive: true });
|
|
await fs.writeFile(path.join(changesDir, 'archive', 'old', 'tasks.md'), '- [x] x\n- [x] y\n', 'utf-8');
|
|
await writeChange('sibling', { 'backend/tasks.md': '- [x] s1\n- [x] s2\n' });
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'target', projectRoot);
|
|
expect(progress).toEqual({ total: 2, completed: 1 });
|
|
});
|
|
|
|
it('identifies the tracked artifact by apply.tracks even when it is not named "tasks"', async () => {
|
|
const schemaDir = path.join(projectRoot, 'openspec', 'schemas', 'custom-track');
|
|
await fs.mkdir(schemaDir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(schemaDir, 'schema.yaml'),
|
|
[
|
|
'name: custom-track',
|
|
'version: 1',
|
|
'artifacts:',
|
|
' - id: proposal',
|
|
' generates: proposal.md',
|
|
' description: Proposal',
|
|
' template: proposal.md',
|
|
' requires: []',
|
|
' - id: checklist',
|
|
' generates: "work/*.md"',
|
|
' description: Work checklist',
|
|
' template: tasks.md',
|
|
' requires: [proposal]',
|
|
'apply:',
|
|
' requires: [checklist]',
|
|
' tracks: "work/*.md"',
|
|
'',
|
|
].join('\n'),
|
|
'utf-8'
|
|
);
|
|
await writeChange('customchange', { 'work/a.md': '- [x] a\n- [ ] b\n' }, 'custom-track');
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'customchange', projectRoot);
|
|
expect(progress).toEqual({ total: 2, completed: 1 });
|
|
});
|
|
|
|
it('falls back to a single top-level tasks.md when the schema cannot be resolved (no crash)', async () => {
|
|
await writeChange('badschema', { 'tasks.md': '- [x] a\n- [ ] b\n' }, 'does-not-exist');
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'badschema', projectRoot);
|
|
expect(progress).toEqual({ total: 2, completed: 1 });
|
|
});
|
|
|
|
it('counts a single top-level tasks.md unchanged under the default schema', async () => {
|
|
// No project-local schema, no .openspec.yaml -> default spec-driven (tracks tasks.md).
|
|
await writeChange('plain', { 'tasks.md': '- [x] a\n- [x] b\n- [ ] c\n' }, '');
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'plain', projectRoot);
|
|
expect(progress).toEqual({ total: 3, completed: 2 });
|
|
});
|
|
|
|
it('reports zero tasks when no file matches the tracked glob', async () => {
|
|
await writeGlobSchema();
|
|
await writeChange('notasks', {}); // schema set, but no tasks.md anywhere
|
|
|
|
const progress = await getTaskProgressForChange(changesDir, 'notasks', projectRoot);
|
|
expect(progress).toEqual({ total: 0, completed: 0 });
|
|
});
|
|
});
|