mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
/ship can finish when its docs audit fixes a reviewed doc after the last review round (GST-3532) (#4708)
/ship no longer gets stuck when its last-step docs audit corrects a line in a doc the review read, after the PR's last allowed review round. Why: gbrain#10059 had to skip its /ship record to land, because the only fix /ship offered was a third review round, which the two-round limit forbids. Nothing to do: the next /ship run asks for one small read of the audit's change on its own. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/red-team#2 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p2/adversarial-native#2 reader=adversarial-native
This commit is contained in:
1 parent
a88cc7c1be
commit
4ae9ec7b00
18 files changed
+274
-21
No files matched your search
@@ -348,6 +348,7 @@ gstack_result_anchor() {
|
||||
SHIP_RUN_RECORD_UNREADABLE) printf '%s' 'ship-run-record-unreadable' ;;
|
||||
GRANT_UNKNOWN) printf '%s' 'grant-unknown' ;;
|
||||
RECEIPT_CARRY_SCOPED_REVIEW) printf '%s' 'receipt-carry-scoped-review' ;;
|
||||
RECEIPT_DOCS_AUDIT_READ) printf '%s' 'receipt-docs-audit-read' ;;
|
||||
DOCS_AUDIT_BLOCKED) printf '%s' 'docs-audit-blocked' ;;
|
||||
DOCS_RESULT_INVALID) printf '%s' 'docs-result-invalid' ;;
|
||||
RECEIPT_PROSE_MISMATCH) printf '%s' 'receipt-prose-mismatch' ;;
|
||||
|
||||
+13
-1
@@ -161,6 +161,9 @@ write flags: --pr --head --base --version --gated-tree --predecessor --gate <jso
|
||||
with the content HEAD holds, each excluded or kept only because code names it (GST-1429); prints REVIEW_EXCLUDE_DOCS_AUDIT: and
|
||||
records HEAD's selection. Any other change, or an unreadable snapshot, refuses as above. --docs-pre <Prepare snapshot> (the same
|
||||
audit's first snapshot) narrows the audit's files to those whose content it changed, so uncommitted docs the review read stay.
|
||||
An audit file the review kept for its own content (gate path, gate tags, agent prose, a secret line) refuses with
|
||||
RECEIPT_DOCS_AUDIT_READ and writes a packet of the audit's change for one scoped reader, not a review round (GST-3532);
|
||||
--docs-audit-read <record.json> (its clean { head, paths, reviewer, verdict, packet_sha256 }) binds it as docs_audit_read.
|
||||
When a run audits twice, the last audit's post snapshot carries the earlier audit (gstack-docs-candidate snapshot --run --pre
|
||||
--carry): files the earlier audit edited reset too, to their content before it, when HEAD holds what it left; a carried audit of
|
||||
another run refuses (GST-1616).
|
||||
@@ -349,7 +352,15 @@ async function cmdWrite(rest: string[], json: boolean): Promise<number> {
|
||||
if (review.exclude.state === 'refused') { for (const l of review.exclude.lines) process.stderr.write(`${l}; nothing written\n`); return EXIT.refused; }
|
||||
const excludeNow = review.exclude.state === 'active' ? review.exclude.record : null;
|
||||
const excludeGiven = flag(rest, '--review-exclude') ?? 'none';
|
||||
const excludeBound = writeExcludeBinds(repoRoot, base, headSha ?? head, review, flag(rest, '--review-exclude'), flag(rest, '--docs-post'), flag(rest, '--docs-pre'));
|
||||
const excludeBound = writeExcludeBinds(repoRoot, base, headSha ?? head, review, flag(rest, '--review-exclude'), flag(rest, '--docs-post'), flag(rest, '--docs-pre'), flag(rest, '--docs-audit-read'));
|
||||
if (!excludeBound.ok && excludeBound.packet) {
|
||||
const at = headSha ?? head;
|
||||
const packet = path.resolve(repoRoot, git(['rev-parse', '--git-path', `gstack/docs-audit-read-${at.slice(0, 12)}.md`], repoRoot) ?? `.git/gstack/docs-audit-read-${at.slice(0, 12)}.md`);
|
||||
try { fs.mkdirSync(path.dirname(packet), { recursive: true }); fs.writeFileSync(packet, excludeBound.packet.text); }
|
||||
catch (e) { process.stderr.write(`gstack-ship-receipt write: ${excludeBound.why}, but the reader's packet ${packet} cannot be written (${(e as Error).message.split('\n')[0]}); make its directory writable, then rerun write; nothing written\n`); return EXIT.fail; }
|
||||
process.stderr.write(resultLine('gstack-ship-receipt write', 'RECEIPT_DOCS_AUDIT_READ', `${excludeBound.why}: one scoped reader (not a review round) reads ${packet}, then rerun write with --docs-audit-read <record.json> written outside the worktree ({"head":"${at}","paths":${JSON.stringify(excludeBound.packet.paths)},"reviewer":"<model>","verdict":"clean","packet_sha256":"${excludeBound.packet.sha256}"}); a finding goes to the lane's Captain; nothing written`) + '\n');
|
||||
return EXIT.fail;
|
||||
}
|
||||
if (!excludeBound.ok) {
|
||||
process.stderr.write(`gstack-ship-receipt write: field=review_exclude expected=${excludeNow?.digest ?? 'none'} recorded=${excludeGiven} source=${excludeNow?.source ?? `origin/${base} (no review_exclude_paths)`}: the --review-exclude argument names another selection than ${base}'s review_exclude_paths gives ${head.slice(0, 12)} (write compares the argument, not the review ledger)${flag(rest, '--review-exclude') === undefined ? '; no --review-exclude was given, so write compared none' : ''}${excludeBound.why ? `; the docs-audit exception does not apply: ${excludeBound.why}` : ''}; fix: when only Step 14.5's docs audit changed files under review_exclude_paths after the review, pass its --docs-post <audit-id>-post.json and --docs-pre <its Prepare snapshot>; otherwise rerun /ship's review on ${head.slice(0, 12)} (gstack-review-dispatch pass --base ${base}), run gstack-review-dispatch verify --ledger <ledger> and write with the --review-exclude <d> its REVIEW_EXCLUDE_RECORD: line prints (none when it prints no such line); nothing written (RECEIPT_INVALID)\n`);
|
||||
return EXIT.fail;
|
||||
@@ -410,6 +421,7 @@ async function cmdWrite(rest: string[], json: boolean): Promise<number> {
|
||||
base_red: pause ? receiptBaseRed(pause) : undefined,
|
||||
review_exclude: receiptExclude(review.exclude),
|
||||
review_exclude_fallback: receiptExcludeFallback(review.exclude),
|
||||
docs_audit_read: excludeBound.read,
|
||||
no_stop: noStopArg(flag(rest, '--no-stop')),
|
||||
};
|
||||
} catch (e: any) { process.stderr.write(`gstack-ship-receipt write: ${e.message}\n`); return EXIT.usage; }
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
**/ship can finish when its docs audit corrects a doc the review read, after the last review round.** Before, when Step 14.5's docs audit fixed a line in a gate-path doc (gbrain#10059: "4 times" to "2 times" in docs/guides/secret-store.md) after the round cap, `gstack-ship-receipt write` refused on `review_exclude` and offered only another review round, which the cap forbids, so the receipt had to be waived. Write now refuses with `RECEIPT_DOCS_AUDIT_READ`, writes a packet of the audit's change for one scoped reader, which is not a review round, and binds the reader's clean `--docs-audit-read` record into the receipt as `docs_audit_read` (GST-3532). A reader's finding, a stale record, an edit too large for one reader, or a change git can show only as binary still refuses. The docs audit steps also say a re-audit passes one flag for its one earlier audit: `--carry`, or `--carry-stopped` when that audit stopped first.
|
||||
@@ -1022,6 +1022,24 @@ receipt carried across a base merge or a test-only fix
|
||||
counters, because the reviewed product diff is unchanged or its only
|
||||
difference passed a scoped review.
|
||||
|
||||
<a id="docs-audit-edits-to-reviewed-docs"></a>
|
||||
### Docs-audit edits to reviewed docs (GST-3532)
|
||||
|
||||
The Step 14.5 docs audit runs after the review, so it can correct a line in a
|
||||
doc the review read for its own content: a gate path, a doc with gate tags,
|
||||
agent prose or a doc with a secret line, which `review_exclude_paths` keeps in
|
||||
the review. When that edit changes the selection, receipt write refuses with
|
||||
`RECEIPT_DOCS_AUDIT_READ` instead of asking for another review round, which the
|
||||
round cap may forbid (gbrain#10059 had to waive its receipt). The refusal writes
|
||||
a packet with the audit's change to those docs, at most 20 changed lines each,
|
||||
and the targeted brief. One scoped reader reads it. Like the bounded read
|
||||
above, that read is not a review round under R51 and needs no grant. Its clean
|
||||
record (`head`, `paths`, `reviewer`, `verdict`, `packet_sha256`) goes back
|
||||
to write with `--docs-audit-read`, and the receipt records it as
|
||||
`docs_audit_read`. A finding, a record for another head or packet, and a
|
||||
larger edit still refuse; a finding goes to the lane's Captain
|
||||
([troubleshooting](troubleshooting.md#receipt-docs-audit-read)).
|
||||
|
||||
## The scope knob
|
||||
|
||||
`.gstack/ship-policy.json` `review_scope` ([ship-policy.md#review-scope](ship-policy.md#review-scope)):
|
||||
|
||||
@@ -1715,6 +1715,8 @@ the reviewers read that selection.
|
||||
Write, carry and the queue make one exception (GST-1408, GST-1415, GST-1434, GST-1446): when the digests differ but the recorded selection and HEAD's give the PR's files the same selection, meaning the same applied patterns, the same excluded files and the same kept files with their reasons, write records HEAD's digest, carry carries the receipt and records HEAD's digest, and the queue (`ready`, train build, land) binds it. So a pattern the base gains, adds, removes or reverts that changes nothing about the PR's files does not void the review. No recorded selection (`none`) counts as the empty one. A receipt's record counts only when its digest is built from its list hash. Write gets only a digest, so it rebuilds the recorded selection: the digest binds when the `review_exclude_paths` the base held at some commit that changed the policy file, combined with HEAD's list hash, gives that digest. It prints `REVIEW_EXCLUDE_POLICY_MOVED:`. A digest no such policy gives, an omitted `--review-exclude`, a selection that differs over the PR's files and an unreadable base policy still refuse.
|
||||
Write makes one exception for Step 14.5's docs audit, which runs after the review (GST-1429): with `--docs-post <audit-id>-post.json` it accepts the reviewed digest when that digest is HEAD's selection with every file under a pattern that changed since the snapshot's HEAD reset to it, each such file is uncommitted in the snapshot with the content HEAD holds, each is excluded or kept only because code names it, and every other file is excluded or kept alike on both sides. With `--docs-pre <Prepare snapshot>` only the files whose content changed between the audit's two snapshots reset, to their Prepare content, so uncommitted docs the reviewers read stay as they are; content compares as git stores it or as it checks out (autocrlf, filters). It prints `REVIEW_EXCLUDE_DOCS_AUDIT:` and records HEAD's digest. Any other change to the selection, an audit file the exclusion keeps for another reason, an edit after the snapshot and a missing or unreadable snapshot still refuse. When one `/ship` run audits twice (a re-audit after a base merge and restamp), every snapshot names the run (`--run <invocation record>`), each post snapshot names its Prepare snapshot (`--pre`, recording the files the audit edited), and the re-audit's post snapshot carries the earlier one (`--carry <earlier -post.json>`; GST-1616). Write then also resets each file an earlier audit of the run edited, to its content before that audit, when HEAD (or the re-audit's Prepare snapshot) holds what the audit left; a file no audit edited still refuses, and a carried audit of another run is refused by the snapshot and by write. When an earlier audit stopped as blocked before its post snapshot, the re-audit's post snapshot carries it with `--carry-stopped <its Prepare snapshot>`, taken at the same HEAD, and its edits are what changed between the two Prepare snapshots (GST-3502). After a base merge, write does not count a file under a pattern that only the merged base changed (the PR's own three-dot diff leaves it alone), a re-audit that edited nothing still binds through the audits it carries, and the rebuilt selection binds the reviewed digest even when the merge moved the base policy (for example, added a pattern); a docs file the PR itself changes after the last audit still refuses (GST-3260).
|
||||
|
||||
An audit file the review kept for its own content (a gate path, gate tags, agent prose or a secret line) is a doc the reviewers read, so the exception binds it only after one scoped reader reads the audit's change: write refuses with `RECEIPT_DOCS_AUDIT_READ`, writes the packet, and binds a clean `--docs-audit-read <record.json>` into the receipt as `docs_audit_read`. That read is not a review round (GST-3532, [review-policy.md](review-policy.md#docs-audit-edits-to-reviewed-docs)).
|
||||
|
||||
**Adopting it.** (1) Open a PR on the base that adds the patterns and
|
||||
`min_gstack_version` at least `REVIEW_EXCLUDE_KEY_VERSION`, and ship it like any
|
||||
policy change. (2) Once it merges, bring the base into the results branch (a
|
||||
|
||||
@@ -7856,6 +7856,23 @@ none of carry's other checks would refuse; carry without `--dry-run` writes it.
|
||||
In /ship Step 1, `gstack-ship-preflight` prints the route as `NEXT: carry
|
||||
route (Step 1.4)`.
|
||||
|
||||
<a id="receipt-docs-audit-read"></a>
|
||||
### `RECEIPT_DOCS_AUDIT_READ`
|
||||
|
||||
**Meaning.** After the review, the Step 14.5 docs audit edited a doc the review
|
||||
read for its own content (a gate path, gate tags, agent prose or a secret line),
|
||||
and that edit changed the review selection. Write's docs-audit exception binds
|
||||
only docs the reviewers never read, so this change needs one reader first
|
||||
(GST-3532). It is not a review round, so the round cap doesn't stop it.
|
||||
|
||||
**Fix.** Give one reader the packet the refusal names. Save its clean verdict
|
||||
outside the worktree as `{"head", "paths", "reviewer", "verdict": "clean",
|
||||
"packet_sha256"}`, with the values the refusal prints, and rerun write with
|
||||
`--docs-audit-read <record.json>`. The receipt records it as `docs_audit_read`.
|
||||
A finding goes to the lane's Captain. An edit over 20 changed lines in one doc
|
||||
is too large for one reader and still takes the review
|
||||
([review-policy.md](review-policy.md#docs-audit-edits-to-reviewed-docs)).
|
||||
|
||||
<a id="receipt-carry-recheck"></a>
|
||||
### Scoped re-check after `RECEIPT_CARRY_PRODUCT_CHANGED` (J1, advice only)
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* The scoped read of a Step 14.5 docs-audit edit to a doc the reviewers read (GST-3532, gbrain#10059). Write's docs-audit
|
||||
* exception (lib/ship-receipt-depth.ts writeExcludeBinds) binds docs the exclusion hides or keeps because code names them; a doc
|
||||
* the review keeps for its own content (a gate path, gate tags, agent prose or a secret line) was read by the reviewers, so its
|
||||
* edit after the review needs a reader too. Instead of another review round, which the round cap forbids, one scoped reader reads
|
||||
* a packet of that audit change, the way carry's scoped review reads spliced hunks; it is not a review round under R51. Its clean
|
||||
* record, bound to the head and the packet, binds into the receipt as `docs_audit_read`. A finding, another head or packet, or an
|
||||
* edit over BOUNDED_LINES lines still refuses.
|
||||
*/
|
||||
import { spawnSync } from './spawn-sync';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { BOUNDED_LINES, packetBrief, readScopedReview } from './ship-patch';
|
||||
|
||||
/** Kept reasons that mean the reviewers read the doc for its own content; any other kept reason keeps refusing. */
|
||||
export const READ_REASONS: readonly string[] = ['gate-path', 'gate-tagged', 'agent-prose', 'secret-line'];
|
||||
|
||||
export interface DocsAuditRead { paths: string[]; reviewer: string; packet_sha256: string }
|
||||
export type DocsAuditPacket = { ok: true; text: string; sha256: string } | { ok: false; why: string };
|
||||
|
||||
/** The packet for the audit's change to `files`, each from its content before the audit (a blob id, or null when the audit added it) to HEAD's. */
|
||||
export function docsAuditPacket(root: string, head: string, files: ReadonlyArray<{ path: string; before: string | null }>): DocsAuditPacket {
|
||||
const git = (args: string[], input?: string) => { const r = spawnSync('git', ['-c', 'core.quotePath=false', ...args], { cwd: root, input, encoding: 'utf8', timeout: 60_000, maxBuffer: 64 * 1024 * 1024 }); return r.status === 0 ? r.stdout : null; };
|
||||
const sections: string[] = [];
|
||||
for (const { path: p, before } of files) {
|
||||
const after = git(['rev-parse', '--verify', '--quiet', `${head}:${p}`])?.trim();
|
||||
const from = before ?? git(['hash-object', '-w', '--stdin'], '')?.trim();
|
||||
const diff = after && from ? git(['diff', '--no-color', '--no-ext-diff', '-U3', from, after]) : null;
|
||||
if (diff === null) return { ok: false, why: `git could not diff ${p} from before the audit to HEAD` };
|
||||
const lines = diff.split('\n');
|
||||
const at = lines.findIndex(l => l.startsWith('@@'));
|
||||
if (at < 0 && diff.trim()) return { ok: false, why: `git shows the audit's change to ${p} with no text hunk (a binary or very large file), so one scoped reader cannot read it` };
|
||||
const hunks = at < 0 ? [] : lines.slice(at);
|
||||
const changed = hunks.filter(l => /^[+-]/.test(l)).length;
|
||||
if (changed > BOUNDED_LINES) return { ok: false, why: `the audit changed ${changed} lines of ${p}, a doc the reviewers read: too large for one scoped reader (at most ${BOUNDED_LINES})` };
|
||||
sections.push(`## ${p}\n\n\`\`\`diff\n${hunks.join('\n').trimEnd()}\n\`\`\`\n`);
|
||||
}
|
||||
const text = [`# Scoped review: the docs audit edited docs the reviewers read\n\nHEAD ${head.slice(0, 12)}. After the review, /ship's Step 14.5 docs audit changed these docs, which the review read for their own content (a gate path, gate tags, agent prose or a secret line). Read each change as gate text: does it still say what the code does, and does it change what a gate, cap, reviewer, approval, secret or money rule says? This one read replaces another review round (docs/review-policy.md#docs-audit-edits-to-reviewed-docs). Report clean, or findings at the blocking floor.\n`,
|
||||
...sections, `## Targeted brief\n\n${packetBrief()}\n`].join('\n');
|
||||
return { ok: true, text, sha256: createHash('sha256').update(text).digest('hex') };
|
||||
}
|
||||
|
||||
/** The reader's record for this packet at `head`: clean, covering every file, bound to the packet; else why it does not stand. */
|
||||
export function readDocsAuditRead(file: string, head: string, paths: readonly string[], sha256: string): { ok: true; read: DocsAuditRead } | { ok: false; why: string } {
|
||||
const r = readScopedReview(file, { head }, paths);
|
||||
if (!r.ok) return { ok: false, why: `--docs-audit-read: ${r.message}` };
|
||||
if (r.review.packet_sha256 !== sha256) return { ok: false, why: `--docs-audit-read: the record's packet_sha256 is ${r.review.packet_sha256?.slice(0, 12) ?? 'missing'}, not ${sha256.slice(0, 12)}: rerun the reader on the packet write names` };
|
||||
return { ok: true, read: { paths: [...paths], reviewer: r.review.reviewer, packet_sha256: sha256 } };
|
||||
}
|
||||
@@ -150,6 +150,8 @@ export interface ShipReceipt {
|
||||
review_exclude?: { source: string; patterns: string[]; applied: string[]; excluded: number; excluded_bytes: number; kept: number; gate_tagged: string[]; patterns_sha256: string; list_sha256: string; digest: string };
|
||||
/** The base policy failed only on its exclusion keys, so they were set aside and every file was reviewed (GST-3399): the policy's source and its errors. */
|
||||
review_exclude_fallback?: { source: string; errors: string[] };
|
||||
/** The scoped reader's clean read of Step 14.5 docs-audit edits to docs the review read (lib/docs-audit-read.ts, GST-3532). */
|
||||
docs_audit_read?: { paths: string[]; reviewer: string; packet_sha256: string };
|
||||
/** Routine stops the run recorded and went on past instead of waiting for a Captain (plan K1; GSTA-258 L5 writes them): one record per stop. */
|
||||
no_stop?: Array<{ class: NoStopClass; reason: string; evidence: string }>;
|
||||
}
|
||||
@@ -289,6 +291,7 @@ export const ARTIFACT_SCHEMAS = {
|
||||
review_targeted: { type: 'object', required: ['classes', 'rules', 'brief_sha', 'product_patch_id', 'status', 'findings', 'raised_by'], properties: { classes: { type: 'array', items: { enum: ['money', 'gate', 'auth', 'secret'] } }, rules: str, brief_sha: str, product_patch_id: str, status: { enum: ['done', 'failed', 'not-run'] }, findings: { type: 'integer', minimum: 0 }, raised_by: str } },
|
||||
review_exclude: { type: 'object', required: ['source', 'patterns', 'applied', 'excluded', 'excluded_bytes', 'kept', 'gate_tagged', 'patterns_sha256', 'list_sha256', 'digest'], properties: { source: str, patterns: strList, applied: strList, excluded: { type: 'integer', minimum: 0 }, excluded_bytes: { type: 'integer', minimum: 0 }, kept: { type: 'integer', minimum: 0 }, gate_tagged: strList, patterns_sha256: str, list_sha256: str, digest: str } },
|
||||
review_exclude_fallback: { type: 'object', required: ['source', 'errors'], properties: { source: str, errors: strList } },
|
||||
docs_audit_read: { type: 'object', required: ['paths', 'reviewer', 'packet_sha256'], properties: { paths: strList, reviewer: str, packet_sha256: str } },
|
||||
review_loop_exception: { type: 'object', required: ['accepted_by', 'date', 'via', 'reason'], properties: { accepted_by: str, date: str, via: str, reason: str, fix_check: { type: 'object', required: ['head', 'findings'], properties: { head: str, findings: { type: 'integer', minimum: 0 }, files: strList } }, second_pass: { type: 'object', required: ['head', 'deferred'], properties: { head: str, deferred: strList } } } },
|
||||
review_round_grants: { type: 'array', items: { type: 'object', required: ['kind', 'head', 'pr', 'by', 'reason', 'at', 'approval'], properties: { kind: { enum: ['extra-round', 'fix-check'] }, head: str, pr: { type: 'integer', minimum: 1 }, by: str, reason: str, at: str, approval: str, stop_run: str, findings: { type: 'array', items: str } } } },
|
||||
cleared_by_grant: { type: 'object', required: ['approval', 'run', 'ids'], properties: { approval: str, run: str, ids: strList } },
|
||||
|
||||
@@ -475,6 +475,11 @@ export const RELEASE_RESULT_CODES = {
|
||||
summary: 'the branch\'s own +/- lines are the reviewed ones, but the base edited context next to them, so the merge may have spliced the two (GST-384); the receipt carries only after a scoped review of those hunks',
|
||||
fix: 'dispatch one fix-check reviewer on the packet the refusal names, write its clean verdict as { head, paths, reviewer, verdict } and rerun carry with --scoped-review <record.json>; a blocking finding means /ship on the new head',
|
||||
},
|
||||
RECEIPT_DOCS_AUDIT_READ: {
|
||||
anchor: 'receipt-docs-audit-read',
|
||||
summary: 'the Step 14.5 docs audit edited a doc the review read for its own content (a gate path, gate tags, agent prose or a secret line) after the review, so the receipt binds only after one scoped reader reads that change (GST-3532); it is not a review round',
|
||||
fix: 'dispatch one reader on the packet the refusal names, write its clean verdict as { head, paths, reviewer, verdict, packet_sha256 } and rerun write with --docs-audit-read <record.json>; a finding goes to the lane\'s Captain',
|
||||
},
|
||||
DOCS_AUDIT_BLOCKED: {
|
||||
anchor: 'docs-audit-blocked',
|
||||
summary: 'the documentation audit (/ship Step 14.5) is blocked: gstack-ship-receipt docs-caps found a declared doc cap over, or gstack-ship-receipt write was given a blocked audit with no owner exception and refused to record the ship as audited',
|
||||
|
||||
+25
-10
@@ -38,6 +38,7 @@ import { branchSides } from './stamp-only';
|
||||
import { classifyFiles } from './tree-receipt';
|
||||
import { mergeChangelogs } from './changelog-check';
|
||||
import { bindReceipt, type ReceiptBindingCode } from './ship-receipt';
|
||||
import { READ_REASONS, docsAuditPacket, readDocsAuditRead, type DocsAuditRead } from './docs-audit-read';
|
||||
import { carriedAudits, docsExceptionLine, parseReceiptDocs, sameRun, type CarriedAudit } from './ship-receipt-docs';
|
||||
|
||||
export type ReceiptDepth = NonNullable<ShipReceipt['review_depth']>;
|
||||
@@ -345,13 +346,14 @@ const treatment = (x: ActiveExclusion, p: string) => (x.excluded.has(p) ? 'exclu
|
||||
* them left. When the whole carried list does not rebuild the reviewed selection, write retries without the oldest carried audits,
|
||||
* one at a time down to none (a review that ran between two audits already read the earlier one's edits); only that digest
|
||||
* mismatch retries, so an integrity refusal (an edit after an audit, a file changed between audits, a foreign HEAD) ends it, and
|
||||
* the refusal names the whole list's reason. A file the merged base changed since an audit's HEAD and the PR's own three-dot diff
|
||||
* the refusal names the whole list's reason, unless a retry matched the reviewed selection: then that retry's own refusal or
|
||||
* reader packet comes back. A file the merged base changed since an audit's HEAD and the PR's own three-dot diff
|
||||
* leaves alone holds no PR edit, so it is not counted as changed; a latest audit that changed nothing still binds through the audits
|
||||
* it carries; and the rebuilt selection binds the reviewed digest as carryExcludeBinds does, so a base policy change alone does not
|
||||
* void it (GST-3260). Content compares as git stores it or as it checks out (autocrlf, filters). Anything else, an unreadable
|
||||
* snapshot included, refuses with `why`.
|
||||
*/
|
||||
export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, flagged: string | undefined, docsPost: string | undefined, docsPre?: string): { ok: true; line?: string } | { ok: false; why?: string } {
|
||||
export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, flagged: string | undefined, docsPost: string | undefined, docsPre?: string, docsRead?: string): { ok: true; line?: string; read?: DocsAuditRead } | { ok: false; why?: string; packet?: { text: string; sha256: string; paths: string[] } } {
|
||||
const x = review.exclude;
|
||||
const given = flagged ?? 'none';
|
||||
const now = x.state === 'active' ? x.record.digest : 'none';
|
||||
@@ -398,7 +400,7 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
|
||||
if (!holds(head, p, post.hashes[p] ?? null)) return no(`${p} at HEAD is not the content the snapshot recorded (an edit after the audit)`);
|
||||
}
|
||||
const auditFiles = pre ? changed.filter(p => !(p in pre.hashes) || pre.hashes[p] !== post.hashes[p]) : changed;
|
||||
const bindAudits = (carried: CarriedAudit[]): { ok: true; line: string } | { ok: false; why: string; retry?: true } => {
|
||||
const bindAudits = (carried: CarriedAudit[]): { ok: true; line: string; read?: DocsAuditRead } | { ok: false; why: string; retry?: true; matched?: true; packet?: { text: string; sha256: string; paths: string[] } } => {
|
||||
const resets = new Map<string, { rev: string; want: unknown; from: string }>(auditFiles.map(p => [p, { rev: at, want: pre ? pre.hashes[p] : undefined, from: `--docs-pre ${docsPre}` }]));
|
||||
const left = new Map<string, { after: string | null; audit: string }>();
|
||||
for (const e of carried) {
|
||||
@@ -424,13 +426,14 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
|
||||
const run = (args: string[], input?: string) => { const r = spawnSync('git', args, { cwd: root, encoding: 'utf8', env, input, timeout: 60_000 }); return { ok: r.status === 0, out: (r.stdout ?? '').trim() }; };
|
||||
const treeEntry = (rev: string, p: string) => run(['ls-tree', '-z', '--full-tree', rev, '--', p]).out.split('\0').find(l => l.endsWith(`\t${p}`));
|
||||
let reset: string;
|
||||
const befores = new Map<string, string | null>();
|
||||
try {
|
||||
const entries: string[] = [];
|
||||
for (const [p, { rev, want, from }] of resets) {
|
||||
const atEntry = treeEntry(rev, p);
|
||||
if (want === undefined || (atEntry && holds(rev, p, want))) entries.push(atEntry ? `${atEntry}\0` : `0 ${'0'.repeat(rev.length)}\t${p}\0`);
|
||||
else if (want === null) entries.push(`0 ${'0'.repeat(rev.length)}\t${p}\0`);
|
||||
else if (typeof want === 'string' && run(['cat-file', '-e', `${want}^{blob}`]).ok) entries.push(`${(treeEntry(head, p) ?? atEntry ?? '100644').split(' ')[0]} blob ${want}\t${p}\0`);
|
||||
if (want === undefined || (atEntry && holds(rev, p, want))) { entries.push(atEntry ? `${atEntry}\0` : `0 ${'0'.repeat(rev.length)}\t${p}\0`); befores.set(p, atEntry ? blob(rev, p) : null); }
|
||||
else if (want === null) { entries.push(`0 ${'0'.repeat(rev.length)}\t${p}\0`); befores.set(p, null); }
|
||||
else if (typeof want === 'string' && run(['cat-file', '-e', `${want}^{blob}`]).ok) { entries.push(`${(treeEntry(head, p) ?? atEntry ?? '100644').split(' ')[0]} blob ${want}\t${p}\0`); befores.set(p, want); }
|
||||
else return no(`${p}'s content before the audit (${short(String(want))} in ${from}) is not in git's object store, so the selection the reviewers read cannot be rebuilt`);
|
||||
}
|
||||
const tree = run(['read-tree', head]).ok && run(['update-index', '-z', '--index-info'], entries.join('')).ok ? run(['write-tree']) : { ok: false, out: '' };
|
||||
@@ -441,20 +444,32 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
|
||||
const before = exclusionAt(root, ref, sha, reset, collectCommit(root, sha ?? ref, reset), review.tagged, 'gstack-ship-receipt');
|
||||
if (before.state !== 'active') return no(`the selection with ${files.join(',')} reset to before the audit cannot be read`);
|
||||
if (!carryExcludeBinds(before, { review_exclude: reviewedRecord(root, base, before, given) })) return { retry: true, ...no(`the reviewed digest ${short(given)} is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset to ${pre ? 'their --docs-pre content' : short(at)}${left.size ? ` and the files audit ${carried.map(e => e.audit_id).join(',')} edited reset to before that audit` : ''} (${short(before.record.digest)}), so more than the docs audit changed what the reviewers read`) };
|
||||
const late = (why: string) => ({ ...no(why), matched: true as const });
|
||||
const read = new Set<string>();
|
||||
for (const p of files) for (const [side, s] of [['the review', before], ['HEAD', x]] as const) {
|
||||
const t = treatment(s, p);
|
||||
if (!['absent', 'excluded', 'named-by-code'].includes(t)) return no(`${p} is ${t} at ${side}: the docs audit binds only docs the exclusion hides or keeps because code names them`);
|
||||
if (['absent', 'excluded', 'named-by-code'].includes(t)) continue;
|
||||
if (!READ_REASONS.includes(t)) return late(`${p} is ${t} at ${side}: the docs audit binds only docs the exclusion hides, keeps because code names them, or keeps for the reviewers to read (${READ_REASONS.join(', ')}), which one scoped reader reads`);
|
||||
read.add(p);
|
||||
}
|
||||
const audit = new Set(files);
|
||||
for (const p of new Set([...before.excluded, ...x.excluded, ...before.kept.map(k => k.path), ...x.kept.map(k => k.path)])) {
|
||||
if (!audit.has(p) && treatment(before, p) !== treatment(x, p)) return no(`${p} is ${treatment(before, p)} at the review and ${treatment(x, p)} at HEAD`);
|
||||
if (!audit.has(p) && treatment(before, p) !== treatment(x, p)) return late(`${p} is ${treatment(before, p)} at the review and ${treatment(x, p)} at HEAD`);
|
||||
}
|
||||
return { ok: true, line: `REVIEW_EXCLUDE_DOCS_AUDIT: reviewed=${short(given)} head=${short(x.record.digest)} snapshot=${short(at)} files=${files.join(',')}${carried.length ? ` audits=${[...carried.map(e => e.audit_id), post.audit_id].join(',')}` : ''} (the selection changed only by this /ship run's Step 14.5 docs audits' files under review_exclude_paths; the receipt records HEAD's)` };
|
||||
const line = `REVIEW_EXCLUDE_DOCS_AUDIT: reviewed=${short(given)} head=${short(x.record.digest)} snapshot=${short(at)} files=${files.join(',')}${carried.length ? ` audits=${[...carried.map(e => e.audit_id), post.audit_id].join(',')}` : ''} (the selection changed only by this /ship run's Step 14.5 docs audits' files under review_exclude_paths; the receipt records HEAD's)`;
|
||||
if (!read.size) return { ok: true, line };
|
||||
const paths = [...read].sort();
|
||||
const packet = docsAuditPacket(root, head, paths.map(p => ({ path: p, before: befores.get(p) ?? null })));
|
||||
if (!packet.ok) return late(packet.why);
|
||||
if (docsRead === undefined) return { ok: false, why: `${paths.join(',')} ${paths.length === 1 ? 'is a doc' : 'are docs'} the reviewers read, edited by the docs audit after the review`, matched: true, packet: { text: packet.text, sha256: packet.sha256, paths } };
|
||||
const record = readDocsAuditRead(docsRead, head, paths, packet.sha256);
|
||||
if (!record.ok) return late(record.why);
|
||||
return { ok: true, line: `${line}; read=${paths.join(',')} by ${record.read.reviewer}`, read: record.read };
|
||||
};
|
||||
let first: { ok: false; why: string } | undefined;
|
||||
for (let k = 0; k <= earlier.length; k++) {
|
||||
const r = bindAudits(earlier.slice(k));
|
||||
if (r.ok) return r;
|
||||
if (r.ok || r.matched) return r;
|
||||
first ??= r;
|
||||
if (!r.retry) return first;
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ const KEY_ORDER: Array<keyof ShipReceipt | 'docs'> = [
|
||||
'schema_version', 'pr', 'head', 'version', 'base', 'gated_tree', 'predecessor', 'tree', 'gate_reuse', 'gate', 'ci', 'ci_carried', 'spend_usd', 'calls',
|
||||
'session_kind', 'artifacts_consumed', 'run', 'thread', 'policy', 'queue_mode', 'preregistration', 'history',
|
||||
'head_tree', 'product_patch_id', 'gstack_version', 'review_depth', 'pregate', 'requires_remote', 'issues', 'approval', 'docs', 'review_loop',
|
||||
'review_loop_exception', 'review_round_grants', 'cleared_by_grant', 'cleared_by_trailer', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'design', 'review_exclude', 'review_exclude_fallback', 'carry', 'base_red', 'flaky_exception', 'no_stop',
|
||||
'review_loop_exception', 'review_round_grants', 'cleared_by_grant', 'cleared_by_trailer', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'design', 'review_exclude', 'review_exclude_fallback', 'docs_audit_read', 'carry', 'base_red', 'flaky_exception', 'no_stop',
|
||||
];
|
||||
|
||||
/** Keys in the fixed order so identifiers lead; undefined values are dropped. */
|
||||
|
||||
@@ -105,8 +105,8 @@ branch's copy (a PR cannot raise its own cap), prints one `DOCS_CAP: <path> <byt
|
||||
(`DOCS_CAP: none declared` without any) and exits 1 on any `over` or absent file: a
|
||||
blocked audit, repaired by trimming that file, never by raising the cap. Then save for Step 16 only post-child hashes (rerun the Prepare `snapshot`
|
||||
with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added,
|
||||
plus, on a re-audit, `--carry <its -post.json>` for each earlier audit of this run that saved one and `--carry-stopped <its Prepare snapshot>`
|
||||
for each that stopped before its post snapshot, so receipt write resets every audit's files; Step 16 `compare`s it; never type hashes), status, and keep the `<audit-id>-result.json` and private `<audit-id>-documentation.md`
|
||||
plus, on a re-audit, `--carry <the earlier audit's -post.json>`, or `--carry-stopped <its Prepare snapshot>` when it stopped before its post snapshot
|
||||
(each flag once), so receipt write resets both audits' files; Step 16 `compare`s it; never type hashes), status, and keep the `<audit-id>-result.json` and private `<audit-id>-documentation.md`
|
||||
that `result` wrote. That section file is the section's single source;
|
||||
reports and Step 19 insert it by command (`cat`) where they can, never retyped or edited.
|
||||
Save records once; cite files by path, never copying their content.
|
||||
@@ -136,8 +136,8 @@ auto-commit or push unexpected child commits.
|
||||
`RETRY_NOTE:` text verbatim.
|
||||
Repeat Prepare using current inputs and a fresh id/snapshot, run the remaining
|
||||
attempt, then validate it through Parent processing. When the stopped audit saved no post
|
||||
snapshot, the re-audit's post snapshot adds `--carry-stopped <the stopped audit's Prepare snapshot>`, keeping
|
||||
`--carry` for any earlier audit that saved one, so receipt write resets the stopped audit's edits too.
|
||||
snapshot, the re-audit's post snapshot takes `--carry-stopped <the stopped audit's Prepare snapshot>` in place of
|
||||
`--carry`, so receipt write resets the stopped audit's edits too.
|
||||
3. Otherwise STOP before commit/publication and do not launch another child.
|
||||
AskUserQuestion: stop for repair (recommended), or ship with the specific named
|
||||
documentation risk. Only an actual user exception counts, never a default,
|
||||
|
||||
@@ -103,8 +103,8 @@ branch's copy (a PR cannot raise its own cap), prints one `DOCS_CAP: <path> <byt
|
||||
(`DOCS_CAP: none declared` without any) and exits 1 on any `over` or absent file: a
|
||||
blocked audit, repaired by trimming that file, never by raising the cap. Then save for Step 16 only post-child hashes (rerun the Prepare `snapshot`
|
||||
with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added,
|
||||
plus, on a re-audit, `--carry <its -post.json>` for each earlier audit of this run that saved one and `--carry-stopped <its Prepare snapshot>`
|
||||
for each that stopped before its post snapshot, so receipt write resets every audit's files; Step 16 `compare`s it; never type hashes), status, and keep the `<audit-id>-result.json` and private `<audit-id>-documentation.md`
|
||||
plus, on a re-audit, `--carry <the earlier audit's -post.json>`, or `--carry-stopped <its Prepare snapshot>` when it stopped before its post snapshot
|
||||
(each flag once), so receipt write resets both audits' files; Step 16 `compare`s it; never type hashes), status, and keep the `<audit-id>-result.json` and private `<audit-id>-documentation.md`
|
||||
that `result` wrote. That section file is the section's single source;
|
||||
reports and Step 19 insert it by command (`cat`) where they can, never retyped or edited.
|
||||
Save records once; cite files by path, never copying their content.
|
||||
@@ -134,8 +134,8 @@ auto-commit or push unexpected child commits.
|
||||
`RETRY_NOTE:` text verbatim.
|
||||
Repeat Prepare using current inputs and a fresh id/snapshot, run the remaining
|
||||
attempt, then validate it through Parent processing. When the stopped audit saved no post
|
||||
snapshot, the re-audit's post snapshot adds `--carry-stopped <the stopped audit's Prepare snapshot>`, keeping
|
||||
`--carry` for any earlier audit that saved one, so receipt write resets the stopped audit's edits too.
|
||||
snapshot, the re-audit's post snapshot takes `--carry-stopped <the stopped audit's Prepare snapshot>` in place of
|
||||
`--carry`, so receipt write resets the stopped audit's edits too.
|
||||
3. Otherwise STOP before commit/publication and do not launch another child.
|
||||
AskUserQuestion: stop for repair (recommended), or ship with the specific named
|
||||
documentation risk. Only an actual user exception counts, never a default,
|
||||
|
||||
@@ -258,6 +258,9 @@ NS=$(~/.claude/skills/gstack/bin/gstack-no-stop list | sed -n 's/^NO_STOP_FILE:
|
||||
If write refuses `review_targeted` for a docs claim added after the read, or after a granted fix round (add its `--grant`), rerun Step 9's plan with `--range-base <its head>
|
||||
--targeted-ran <its targeted_patch_id>`; on `NEXT: targeted`, run that one reader (`pass`, its voices stage,
|
||||
`verify --targeted-out .gstack/tmp/targeted.json`) and write again.
|
||||
If write refuses `RECEIPT_DOCS_AUDIT_READ` (Step 14.5 edited a doc the review read), run its one scoped reader without asking:
|
||||
it is not a review round and needs no grant. Give one reader the packet it names, save the clean record it prints the
|
||||
shape of outside the worktree, and write again with `--docs-audit-read <record>`; a finding goes to the lane's Captain.
|
||||
A Step 5 red-base pause adds `--base-red <pause file>` (a conditional receipt the queue
|
||||
refuses, `QUEUE_RECEIPT_CONDITIONAL`). `--docs` reads the record Step 14.5 saved (`{status, scope[, exception]}`): the
|
||||
receipt carries it as `docs`, and a `blocked` status without the owner's exception,
|
||||
|
||||
@@ -241,6 +241,9 @@ NS=$(~/.claude/skills/gstack/bin/gstack-no-stop list | sed -n 's/^NO_STOP_FILE:
|
||||
If write refuses `review_targeted` for a docs claim added after the read, or after a granted fix round (add its `--grant`), rerun Step 9's plan with `--range-base <its head>
|
||||
--targeted-ran <its targeted_patch_id>`; on `NEXT: targeted`, run that one reader (`pass`, its voices stage,
|
||||
`verify --targeted-out .gstack/tmp/targeted.json`) and write again.
|
||||
If write refuses `RECEIPT_DOCS_AUDIT_READ` (Step 14.5 edited a doc the review read), run its one scoped reader without asking:
|
||||
it is not a review round and needs no grant. Give one reader the packet it names, save the clean record it prints the
|
||||
shape of outside the worktree, and write again with `--docs-audit-read <record>`; a finding goes to the lane's Captain.
|
||||
A Step 5 red-base pause adds `--base-red <pause file>` (a conditional receipt the queue
|
||||
refuses, `QUEUE_RECEIPT_CONDITIONAL`). `--docs` reads the record Step 14.5 saved (`{status, scope[, exception]}`): the
|
||||
receipt carries it as `docs`, and a `blocked` status without the owner's exception,
|
||||
|
||||
@@ -234,7 +234,7 @@ describe('gstack-docs-candidate', () => {
|
||||
// ci-37198445662 gate-census-2: ship-docsync-completion/-store parents spent 45-78 s of model time
|
||||
// retyping hash maps, child output and records into several artifacts after the child returned.
|
||||
const gate = fs.readFileSync(path.resolve(import.meta.dir, '..', 'ship/sections/documentation.md.tmpl'), 'utf8').replace(/\s+/g, ' ');
|
||||
expect(gate).toContain('post-child hashes (rerun the Prepare `snapshot` with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added, plus, on a re-audit, `--carry <its -post.json>` for each earlier audit of this run that saved one and `--carry-stopped <its Prepare snapshot>` for each that stopped before its post snapshot, so receipt write resets every audit\'s files; Step 16 `compare`s it; never type hashes)');
|
||||
expect(gate).toContain('post-child hashes (rerun the Prepare `snapshot` with only `--out <audit-id>-post.json` changed and `--pre <its Prepare snapshot>` added, plus, on a re-audit, `--carry <the earlier audit\'s -post.json>`, or `--carry-stopped <its Prepare snapshot>` when it stopped before its post snapshot (each flag once), so receipt write resets both audits\' files; Step 16 `compare`s it; never type hashes)');
|
||||
expect(gate).toContain('Save records once; cite files by path, never copying their content.');
|
||||
const { dir, root, record } = repo();
|
||||
const args = ['--audit-id', 'a1', '--mode', 'edit', '--base', 'main', '--docs', 'handbook'];
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* GST-3532 (GBRA-615, gbrain#10059): Step 14.5's docs audit corrected one line in a doc the review keeps for reviewers to read
|
||||
* (docs/guides/secret-store.md, a gate path) after the PR's last review round. Receipt write refused on review_exclude, because
|
||||
* the docs-audit exception binds only docs the exclusion hides or keeps because code names them, and the only fix it offered was
|
||||
* another review round, which the round cap forbids. Write now asks for one scoped reader of that audit change instead (not a
|
||||
* review round under R51): it writes the packet, and a clean record bound to the packet binds into the receipt. A finding, a stale
|
||||
* record, or an edit too large for one reader still refuses.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT } from '../lib/headless-artifacts';
|
||||
import { REVIEW_EXCLUDE_KEY_VERSION } from '../lib/ship-policy';
|
||||
import { cleanup, commit, makeFixtureRepo, runBin, write, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
const DOC = 'docs/guides/secret-store.md';
|
||||
const policyText = JSON.stringify({ review_exclude_paths: ['docs/**'], min_gstack_version: REVIEW_EXCLUDE_KEY_VERSION }) + '\n';
|
||||
const STORE = ['# Secret store', '', 'A token is read from the store and retried 4 times on a timeout.', ''];
|
||||
|
||||
/** The PR adds the store and its doc; the review reads them; the docs audit then edits the doc (`lines` replace the retry line) and adds a page the exclusion hides, which changes the selection. */
|
||||
function auditedAfterReview(lines = ['A token is read from the store and retried 2 times on a timeout.'], { store = STORE, crlf = false } = {}) {
|
||||
const repo = makeFixtureRepo({ prefix: 'gst3532-', baseFiles: { '.gstack/ship-policy.json': policyText, 'lib/index.js': 'exports.i = 1;\n' } });
|
||||
repos.push(repo);
|
||||
if (crlf) repo.git('config', 'core.autocrlf', 'true');
|
||||
commit(repo, { 'lib/secret-store.js': 'exports.retries = 2;\n', [DOC]: store.join('\n') }, 'feat: secret store');
|
||||
if (crlf) { fs.rmSync(path.join(repo.work, DOC)); repo.git('checkout', '--', DOC); expect(fs.readFileSync(path.join(repo.work, DOC), 'utf8')).toContain('\r\n'); }
|
||||
const plan = JSON.parse(runBin(repo, 'gstack-review-plan', ['--base', 'main', '--gate-tagged', '0', '--json']).out);
|
||||
const reviewed = plan.review_exclude.digest as string;
|
||||
const base = repo.git('rev-parse', 'origin/main');
|
||||
const snapshot = (out: string, extra: string[] = []) => runBin(repo, 'gstack-docs-candidate', ['snapshot', '--out', out, '--audit-id', 'ship-docs-1', '--mode', 'edit', '--base', base, '--docs', 'docs', '--run', '/records/ship-record.md', ...extra]);
|
||||
const pre = path.join(repo.root, 'docs-audit.json');
|
||||
expect(snapshot(pre).status).toBe(0);
|
||||
write(repo.work, DOC, [store[0], store[1], ...lines, ''].join('\n'));
|
||||
write(repo.work, 'docs/guides/restore.md', '# Restore\n\nRestore reads the sealed copy back.\n');
|
||||
const post = path.join(repo.root, 'ship-docs-1-post.json');
|
||||
expect(snapshot(post, ['--pre', pre]).status).toBe(0);
|
||||
commit(repo, {}, 'docs audit');
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const body = path.join(repo.root, 'body.md');
|
||||
const writeReceipt = (extra: string[] = []) => runBin(repo, 'gstack-ship-receipt', ['write', '--pr', '10059', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body,
|
||||
'--review-exclude', reviewed, '--docs-post', post, '--docs-pre', pre,
|
||||
'--review-targeted', JSON.stringify({ classes: ['money', 'gate', 'auth', 'secret'], rules: 'r', brief_sha: 'a'.repeat(64), status: 'done', findings: 0, raised_by: 'targeted', head }), ...extra]);
|
||||
const record = (over: Record<string, unknown>) => { const f = path.join(repo.root, 'docs-read.json'); fs.writeFileSync(f, JSON.stringify({ head, paths: [DOC], reviewer: 'claude-opus-5-5', verdict: 'clean', ...over })); return f; };
|
||||
return { repo, head, body, writeReceipt, record };
|
||||
}
|
||||
const packetOf = (err: string) => /reads (\S+\.md)/.exec(err)?.[1];
|
||||
const shaOf = (err: string) => /"packet_sha256":"([0-9a-f]{64})"/.exec(err)?.[1];
|
||||
|
||||
describe('a docs-audit edit to a doc the reviewers read takes one scoped reader after the round cap (GST-3532)', () => {
|
||||
// Value: protects=a /ship run whose docs audit corrected a reviewed gate-path doc after the last round still gets its receipt
|
||||
// (gbrain#10059 was waived to land); fails_when=write offers only another review round, or binds without anyone reading the
|
||||
// audit's change; seam=gstack-ship-receipt write --docs-post --docs-audit-read; no_claim=gh
|
||||
test('the gbrain#10059 shape: write asks for one reader, and its clean record binds into the receipt', () => {
|
||||
const s = auditedAfterReview();
|
||||
const ask = s.writeReceipt();
|
||||
expect(ask.status).toBe(EXIT.fail);
|
||||
expect(ask.err).toContain('RECEIPT_DOCS_AUDIT_READ');
|
||||
expect(ask.err).toContain('not a review round');
|
||||
const packet = packetOf(ask.err)!;
|
||||
const text = fs.readFileSync(packet, 'utf8');
|
||||
expect(text).toContain('-A token is read from the store and retried 4 times on a timeout.');
|
||||
expect(text).toContain('+A token is read from the store and retried 2 times on a timeout.');
|
||||
const w = s.writeReceipt(['--docs-audit-read', s.record({ packet_sha256: shaOf(ask.err) })]);
|
||||
expect({ status: w.status, err: w.status === EXIT.ok ? '' : w.err }).toEqual({ status: EXIT.ok, err: '' });
|
||||
expect(w.err).toContain('REVIEW_EXCLUDE_DOCS_AUDIT:');
|
||||
expect(JSON.parse(/```gstack-ship-receipt\n([\s\S]*?)\n```/.exec(fs.readFileSync(s.body, 'utf8'))![1]!).docs_audit_read).toEqual({ paths: [DOC], reviewer: 'claude-opus-5-5', packet_sha256: shaOf(ask.err) });
|
||||
}, 240_000);
|
||||
|
||||
// Value: protects=a reader's finding, a record for another packet or head, and an edit too big for one reader keep refusing
|
||||
// (negative controls); fails_when=any record binds; seam=gstack-ship-receipt write --docs-audit-read; no_claim=-
|
||||
test('a finding, a stale record or a large edit still refuses', () => {
|
||||
const s = auditedAfterReview();
|
||||
const sha = shaOf(s.writeReceipt().err);
|
||||
const finding = s.writeReceipt(['--docs-audit-read', s.record({ packet_sha256: sha, verdict: 'findings' })]);
|
||||
expect(finding.status).toBe(EXIT.fail);
|
||||
expect(finding.err).toContain('not clean');
|
||||
const stale = s.writeReceipt(['--docs-audit-read', s.record({ packet_sha256: '0'.repeat(64) })]);
|
||||
expect(stale.status).toBe(EXIT.fail);
|
||||
expect(stale.err).toContain('packet_sha256');
|
||||
const other = s.writeReceipt(['--docs-audit-read', s.record({ packet_sha256: sha, head: '0'.repeat(40) })]);
|
||||
expect(other.status).toBe(EXIT.fail);
|
||||
const big = auditedAfterReview(Array.from({ length: 25 }, (_, i) => `Line ${i} of a rewritten section.`));
|
||||
const r = big.writeReceipt();
|
||||
expect(r.status).toBe(EXIT.fail);
|
||||
expect(r.err).not.toContain('RECEIPT_DOCS_AUDIT_READ');
|
||||
expect(r.err).toContain('too large for one scoped reader');
|
||||
}, 240_000);
|
||||
|
||||
// Value: protects=the packet shows the reader every line the audit changed, including doc lines that begin with "-- " or "++ ",
|
||||
// and builds from git's blob when autocrlf left the snapshot hashing CRLF bytes; fails_when=the packet drops such a line, or
|
||||
// write refuses because the snapshot's CRLF hash is no git object; seam=gstack-ship-receipt write --docs-post; no_claim=-
|
||||
test('the packet keeps dash-led doc lines and survives autocrlf', () => {
|
||||
const dashed = auditedAfterReview([STORE[2]!, '++ The sealed copy is kept for a day.'], { store: [...STORE.slice(0, 3), '-- The old copy is kept for a week.', ''] });
|
||||
const ask = dashed.writeReceipt();
|
||||
expect(ask.err).toContain('RECEIPT_DOCS_AUDIT_READ');
|
||||
const text = fs.readFileSync(packetOf(ask.err)!, 'utf8');
|
||||
expect(text).toContain('\n--- The old copy is kept for a week.\n');
|
||||
expect(text).toContain('\n+++ The sealed copy is kept for a day.\n');
|
||||
const crlf = auditedAfterReview(undefined, { crlf: true });
|
||||
const w = crlf.writeReceipt();
|
||||
expect(w.err).toContain('RECEIPT_DOCS_AUDIT_READ');
|
||||
expect(fs.readFileSync(packetOf(w.err)!, 'utf8')).toContain('+A token is read from the store and retried 2 times on a timeout.');
|
||||
}, 240_000);
|
||||
|
||||
// Value: protects=an audit change git shows with no text hunk (a NUL byte, or a doc over core.bigFileThreshold) refuses instead of
|
||||
// handing the reader an empty packet a clean record would bind; fails_when=write asks for a reader of an empty diff;
|
||||
// seam=gstack-ship-receipt write --docs-post; no_claim=-
|
||||
test('a change git shows with no text hunk refuses', () => {
|
||||
const nul = auditedAfterReview(['A token is read from the store and retried\0 2 times on a timeout.']).writeReceipt();
|
||||
const big = auditedAfterReview();
|
||||
big.repo.git('config', 'core.bigFileThreshold', '16');
|
||||
const large = big.writeReceipt();
|
||||
for (const r of [nul, large]) {
|
||||
expect(r.status).toBe(EXIT.fail);
|
||||
expect(r.err).not.toContain('RECEIPT_DOCS_AUDIT_READ');
|
||||
expect(r.err).toContain('with no text hunk');
|
||||
}
|
||||
}, 240_000);
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 308,
|
||||
"why": "One scoped reader for a docs-audit edit to a reviewed doc, plus the one-carry-flag wording and review fixes: hunk-only packet lines, CRLF-safe packet base, later-attempt refusals kept."
|
||||
}
|
||||
Reference in new issue
Block a user