* feat(sdk): golden parity harness and query handler CJS alignment (#2302 Track A) Golden/read-only parity tests and registry alignment, query handler fixes (check-completion, state-mutation, commit, validate, summary, etc.), and WAITING.json dual-write for .gsd/.planning readers. Refs gsd-build/get-shit-done#2341 * fix(sdk): getMilestoneInfo matches GSD ROADMAP (🟡, last bold, STATE fallback) - Recognize in-flight 🟡 milestone bullets like 🚧. - Derive from last **vX.Y Title** before ## Phases when emoji absent. - Fall back to STATE.md milestone when ROADMAP is missing; use last bare vX.Y in cleaned text instead of first (avoids v1.0 from shipped list). - Fixes init.execute-phase milestone_version and buildStateFrontmatter after state.begin-phase (syncStateFrontmatter). * feat(sdk): phase list, plan task structure, requirements extract handlers - Register phase.list-plans, phase.list-artifacts, plan.task-structure, requirements.extract-from-plans (SDK-only; golden-policy exceptions). - Add unit tests; document in QUERY-HANDLERS.md. - writeProfile: honor --output, render dimensions, return profile_path and dimensions_scored. * feat(sdk): centralize getGsdAgentsDir in query helpers Extract agent directory resolution to helpers (GSD_AGENTS_DIR, primary ~/.claude/agents, legacy path). Use from init and docs-init init bundles. docs(15): add 15-CONTEXT for autonomous phase-15 run. * feat(sdk): query CLI CJS fallback and session correlation - createRegistry(eventStream, sessionId) threads correlation into mutation events - gsd-sdk query falls back to gsd-tools.cjs when no native handler matches (disable with GSD_QUERY_FALLBACK=off); stderr bridge warnings - Export createRegistry from @gsd-build/sdk; add sdk/README.md - Update QUERY-HANDLERS.md and registry module docs for fallback + sessionId - Agents: prefer node dist/cli.js query over cat/grep for STATE and plans * fix(sdk): init phase_found parity, docs-init agents path, state field extract - Normalize findPhase not-found to null before roadmap fallback (matches findPhaseInternal) - docs-init: use detectRuntime + resolveAgentsDir for checkAgentsInstalled - state.cjs stateExtractField: horizontal whitespace only after colon (YAML progress guard) - Tests: commit_docs default true; config-get golden uses temp config; golden integration green Refs: #2302 * refactor(sdk): share SessionJsonlRecord in profile-extract-messages CodeRabbit nit: dedupe JSONL record shape for isGenuineUserMessage and streamExtractMessages. * fix(sdk): address CodeRabbit major threads (paths, gates, audit, verify) - Resolve @file: and CLI JSON indirection relative to projectDir; guard empty normalized query command - plan.task-structure + intel extract/patch-meta: resolvePathUnderProject containment - check.config-gates: safe string booleans; plan_checker alias precedence over plan_check default - state.validate/sync: phaseTokenMatches + comparePhaseNum ordering - verify.schema-drift: token match phase dirs; files_modified from parsed frontmatter - audit-open: has_scan_errors, unreadable rows, human report when scans fail - requirements PLANNED key PLAN for root PLAN.md; gsd-tools timeout note - ingest-docs: repo-root path containment; classifier output slug-hash Golden parity test strips has_scan_errors until CJS adds field. * fix: Resolve CodeRabbit security and quality findings - Secure intel.ts and cli.ts against path traversal - Catch and validate git add status in commit.ts - Expand roadmap milestone marker extraction - Fix parsing array-of-objects in frontmatter YAML - Fix unhandled config evaluations - Improve coverage test parity mapping * test: raise planner character extraction limit to 48K * fix(sdk): resolve TS build error in docs-init passing config
126 lines
5.5 KiB
TypeScript
126 lines
5.5 KiB
TypeScript
/**
|
|
* Read-only subprocess golden checks (SDK vs gsd-tools.cjs JSON).
|
|
* Row data: `read-only-golden-rows.ts`. Policy: `golden-policy.ts`, `QUERY-HANDLERS.md`.
|
|
*/
|
|
import { describe, it, expect } from 'vitest';
|
|
import { captureGsdToolsOutput, captureGsdToolsStdout } from './capture.js';
|
|
import { createRegistry } from '../query/index.js';
|
|
import { resolve, dirname, normalize } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { execSync } from 'node:child_process';
|
|
import { READ_ONLY_JSON_PARITY_ROWS } from './read-only-golden-rows.js';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const REPO_ROOT = resolve(__dirname, '..', '..', '..');
|
|
|
|
describe('Read-only golden parity (JSON toEqual)', () => {
|
|
it.each(READ_ONLY_JSON_PARITY_ROWS)('$canonical matches gsd-tools.cjs JSON', async (row) => {
|
|
const gsdOutput = await captureGsdToolsOutput(row.cjs, row.cjsArgs, REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch(row.canonical, row.sdkArgs, REPO_ROOT);
|
|
expect(sdkResult.data).toEqual(gsdOutput);
|
|
});
|
|
});
|
|
|
|
describe('config-path (plain stdout vs SDK { path })', () => {
|
|
it('SDK path matches gsd-tools.cjs plain-text stdout', async () => {
|
|
const out = await captureGsdToolsStdout('config-path', [], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('config-path', [], REPO_ROOT);
|
|
const data = sdkResult.data as { path?: string };
|
|
expect(data.path).toBeDefined();
|
|
expect(normalize(data.path!.trim())).toBe(normalize(out.trim()));
|
|
});
|
|
});
|
|
|
|
describe('audit-open golden parity (excluding scanned_at)', () => {
|
|
it('SDK JSON matches gsd-tools.cjs except volatile scanned_at', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('audit-open', ['--json'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('audit-open', ['--json'], REPO_ROOT);
|
|
const strip = (d: unknown): Record<string, unknown> => {
|
|
const o = { ...(d as Record<string, unknown>) };
|
|
delete o.scanned_at;
|
|
delete o.has_scan_errors;
|
|
return o;
|
|
};
|
|
expect(strip(sdkResult.data)).toEqual(strip(gsdOutput));
|
|
});
|
|
});
|
|
|
|
describe('state.json golden parity (excluding last_updated)', () => {
|
|
it('SDK rebuilt frontmatter matches gsd-tools.cjs except volatile last_updated', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('state', ['json'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('state.json', [], REPO_ROOT);
|
|
const strip = (d: unknown): Record<string, unknown> => {
|
|
const o = { ...(d as Record<string, unknown>) };
|
|
delete o.last_updated;
|
|
return o;
|
|
};
|
|
expect(strip(sdkResult.data)).toEqual(strip(gsdOutput));
|
|
});
|
|
});
|
|
|
|
describe('summary.extract golden parity (with array-of-objects fix)', () => {
|
|
it('SDK JSON matches gsd-tools.cjs except for intentional array-of-objects parsing fix', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('summary-extract', ['sdk/src/golden/fixtures/summary-extract-sample.md'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('summary.extract', ['sdk/src/golden/fixtures/summary-extract-sample.md'], REPO_ROOT);
|
|
|
|
// The SDK correctly parses array-of-objects, whereas CJS parses them as strings.
|
|
// Patch the CJS output to reflect the CodeRabbit bugfix.
|
|
const patchedGsd = JSON.parse(JSON.stringify(gsdOutput));
|
|
if (patchedGsd.tech_added && Array.isArray(patchedGsd.tech_added)) {
|
|
patchedGsd.tech_added = patchedGsd.tech_added.map((t: any) =>
|
|
t === 'name: typescript' ? { name: 'typescript' } : t
|
|
);
|
|
}
|
|
|
|
expect(sdkResult.data).toEqual(patchedGsd);
|
|
});
|
|
});
|
|
|
|
describe('state.load golden parity', () => {
|
|
it('SDK load payload matches gsd-tools.cjs state load', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('state', ['load'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('state.load', [], REPO_ROOT);
|
|
expect(sdkResult.data).toEqual(gsdOutput);
|
|
});
|
|
});
|
|
|
|
describe('state.get golden parity', () => {
|
|
it('matches full STATE.md when no field (same as `state get` with no section)', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('state', ['get'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('state.get', [], REPO_ROOT);
|
|
expect(sdkResult.data).toEqual(gsdOutput);
|
|
});
|
|
|
|
it('matches single frontmatter field when `state get <field>`', async () => {
|
|
const gsdOutput = await captureGsdToolsOutput('state', ['get', 'milestone'], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('state.get', ['milestone'], REPO_ROOT);
|
|
expect(sdkResult.data).toEqual(gsdOutput);
|
|
});
|
|
});
|
|
|
|
describe('verify.commits golden parity', () => {
|
|
it('SDK output matches gsd-tools.cjs for two SHAs', async () => {
|
|
const revs = execSync('git rev-list --max-count=2 HEAD', { cwd: REPO_ROOT, encoding: 'utf-8' })
|
|
.trim()
|
|
.split('\n')
|
|
.filter(Boolean);
|
|
if (revs.length < 2) {
|
|
throw new Error('verify.commits parity requires at least 2 commits in checkout history');
|
|
}
|
|
const b = revs[0];
|
|
const a = revs[1];
|
|
const gsdOutput = await captureGsdToolsOutput('verify', ['commits', a, b], REPO_ROOT);
|
|
const registry = createRegistry();
|
|
const sdkResult = await registry.dispatch('verify.commits', [a, b], REPO_ROOT);
|
|
expect(sdkResult.data).toEqual(gsdOutput);
|
|
});
|
|
});
|