Files
gstack/test/helpers/docsync-contract.ts
T
garrytanandcapy-ai[bot] 3712b79711 fix(review): pre-landing review fixes for the paid flaky-case repairs
Pass 1 of /ship's review loop on #3516 (core, four specialists, native and
outside adversarial, Red Team). Fixed in the diff:

- test/skill-e2e-ship-docsync.test.ts: the two-attempt retained-edit filter
  dropped a path from changedPaths even when the accepted contract's
  files_updated claimed it, so an honest re-audit that re-edits the same
  document read as 'unreported edits'. acceptedChangedPaths() in
  test/helpers/docsync-contract.ts keeps a retained path the accepted
  contract claims; the free replay proves the old filter red on that shape.
- test/helpers/ship-hook-actor.ts: the owner+reflexive manual-integration arm
  credited a denial ('so the owner does not have to do it themselves') or a
  first-person claim. ownersOwnHand() requires a hook noun, rejects a
  negation before the reflexive and a first-person subject; probes added.
- scripts/resolvers/plan-gates.ts + review/sections/manifest.json: the
  no-plan path still said 'Emit Step 1.5's Scope Check once' and the STOP
  trigger 'finishing Step 1.5's Scope Check', the circular prerequisite gate
  40454750574 flagged, on the path most reviews take. Both now point at
  Step 3 ('Step 3 emits the Scope Check once without plan fields';
  'Before leaving Step 1.5').
- review/SKILL.md.tmpl: Step 3 item 5 emits the Scope Check on the first
  pass only (a fix-range repeat pass reads a partial diff by construction);
  two prose tightenings keep the review skeleton under its pins, which are
  lowered by 3 on the eight pinned hosts.
- test/helpers/docsync-interface.ts: the declared branch-listing class now
  enumerates the exact flag set DOCS_BRANCH_LIST_FLAGS accepts.

Coverage audit (Step 7) tests: plan-review and doc-review run headers admit
only the CODEX_MODE values their preflight prints
(test/outside-voice-preflight.test.ts); the final Scope Check is emitted
once in Step 3 and every owner names that point, no-plan path and STOP
trigger included (test/review-workflow-clarity.test.ts).

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-10-27 15:29:15 +00:00

91 lines
5.0 KiB
TypeScript

import * as path from 'node:path';
export interface DocsCompletion {
schema_version: 1;
audit_id: string;
status: 'updated' | 'current' | 'blocked';
files_updated: string[];
files_reviewed: string[];
documentation_section: string;
blockers: string[];
decisions: string[];
}
const keys = ['schema_version', 'audit_id', 'status', 'files_updated', 'files_reviewed', 'documentation_section', 'blockers', 'decisions'];
export function parseDocsCompletion(output: string, auditId: string): DocsCompletion {
const result = JSON.parse(output.trimEnd().split('\n').at(-1)!);
if (!result || Array.isArray(result) || typeof result !== 'object' ||
Object.keys(result).sort().join() !== [...keys].sort().join()) throw new Error('completion fields');
if (result.schema_version !== 1 || result.audit_id !== auditId) throw new Error('completion identity');
if (!['updated', 'current', 'blocked'].includes(result.status)) throw new Error('completion status');
for (const field of ['files_updated', 'files_reviewed', 'blockers', 'decisions']) {
if (!Array.isArray(result[field]) || result[field].some((v: unknown) => typeof v !== 'string' || !v.trim())) {
throw new Error(`completion ${field}`);
}
}
if (typeof result.documentation_section !== 'string' || !result.documentation_section.trim()) throw new Error('completion markdown');
for (const field of ['files_updated', 'files_reviewed']) {
const paths: string[] = result[field];
if (new Set(paths).size !== paths.length || paths.some(p => path.posix.isAbsolute(p) || p.includes('\\') ||
p.split('/').some(part => !part || part === '.' || part === '..') || /[*?\[\]]/.test(p))) throw new Error('completion paths');
}
if (result.status === 'blocked' ? result.blockers.length === 0 : result.blockers.length !== 0) throw new Error('completion blockers');
if (result.status === 'current' && result.files_updated.length !== 0 ||
result.status === 'updated' && result.files_updated.length === 0) throw new Error('completion edits');
return result;
}
export function vetDocsCompletion(result: DocsCompletion, evidence: {
settled: boolean;
markerSeen: boolean;
headUnchanged: boolean;
indexUnchanged: boolean;
candidateUnchanged: boolean;
readOnly: boolean;
changedPaths: string[];
allowedDocs: string[];
}): void {
if (!evidence.settled || !evidence.markerSeen) throw new Error('unsettled or unmarked child');
if (!evidence.headUnchanged || !evidence.indexUnchanged) throw new Error('Git ownership violation');
if (!evidence.candidateUnchanged) throw new Error('stale candidate');
if (evidence.readOnly && evidence.changedPaths.length) throw new Error('read-only mutation');
if ([...evidence.changedPaths].sort().join('\0') !== [...result.files_updated].sort().join('\0')) throw new Error('unreported edits');
const forbidden = /(?:^|\/)(?:VERSION|CHANGELOG(?:\.[^/]*)?|TODOS(?:\.[^/]*)?|package(?:-lock)?\.json|[^/]*lock[^/]*|manifest\.json)$/i;
if (evidence.changedPaths.some(p => forbidden.test(p) || !evidence.allowedDocs.includes(p))) throw new Error('non-doc mutation');
}
/**
* The changed paths the accepted (last) attempt answers for. A rejected earlier attempt's reported edit stays in the tree
* (Blocked recovery preserves partial content), so it is not the accepted attempt's unreported edit; the accepted attempt
* answers for it again only when its own `files_updated` claims it (an honest re-audit that re-edited the same document).
*/
export function acceptedChangedPaths(changed: string[], contracts: DocsCompletion[]): string[] {
const accepted = contracts.at(-1)!;
const retained = contracts.slice(0, -1).flatMap(earlier => earlier.files_updated);
return changed.filter(p => !retained.includes(p) || accepted.files_updated.includes(p));
}
export function extractDocsDispatch(section: string): string {
const begin = section.indexOf('**Subagent prompt:**');
const end = section.indexOf('**Parent processing:**');
if (begin < 0 || end <= begin) throw new Error('documentation dispatch markers moved');
return section.slice(begin + '**Subagent prompt:**'.length, end)
.split('\n').map(line => line.replace(/^> ?/, '')).join('\n').trim();
}
export function docsDispatchIndex(calls: Array<{ tool: string; input: unknown }>): number {
return docsDispatchIndices(calls)[0] ?? -1;
}
/**
* Every /document-release dispatch, in order. The audit gate's attempt budget is an initial audit plus one repair/re-audit, so a
* run has one or two; the parent's accepted contract is the last (gate 40465691803: the parent rejected attempt 1 for a false
* claim in its section, re-audited over its retained edit, and reported attempt 2's section).
*/
export function docsDispatchIndices(calls: Array<{ tool: string; input: unknown }>): number[] {
return calls.flatMap((call, index) => ['Agent', 'Task'].includes(call.tool) &&
/document-release\/SKILL\.md|executing the \/document-release workflow/i.test(JSON.stringify(call.input)) &&
!/Parent processing:|## Step 19: Create PR\/MR/.test(JSON.stringify(call.input)) ? [index] : []);
}