Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/gstack-pregate
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function cmdClear(root: string, rest: string[]): number {
const checked = runs.length || runUrl || bundleLane ? buildRunCheck(root, lane, rest.includes('--allow-repo-commands')) : undefined;
if (checked && 'error' in checked && (runs.length || checked.profiled)) { process.stderr.write(`gstack-pregate clear: ${checked.error}${checked.profiled ? `; ${lane} may have a run profile on the base branch, so it clears only with a verified --run` : ''}\n`); return EXIT.fail; }
const evidence = checked && !('error' in checked) ? checked : undefined;
const decision = clearDecision(read.file, lane, { runUrl, runs, bundleLane, receiptPath: flag(rest, '--receipt'), evidence, flaky }, root);
const decision = clearDecision(read.file, lane, { runUrl, runs, bundleLane, receiptPath: flag(rest, '--receipt'), evidence, flaky, allowRepoCommands: rest.includes('--allow-repo-commands') }, root);
if ('refused' in decision) {
if (decision.refused === 'usage') { process.stderr.write(`gstack-pregate clear: ${decision.message}\n`); return EXIT.usage; }
process.stderr.write(`gstack-pregate clear: receipt refused — ${decision.message}; fix: ${decision.fix ?? RESULT_CODES.PREGATE_RECEIPT_INVALID.fix} ${resultCodeSuffix('PREGATE_RECEIPT_INVALID')}\n`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **`gstack-pregate clear --receipt` accepts a remote gate run from before a merged release when the release only regenerated a declared release output.** A PR that merged a release commit was refused because a generated file the policy lists in `release_outputs` was checked against the `stamp_files` list first, and `clear` never reran the release tool the way the tree receipt does. A `release_outputs` path is now judged by the release-output rule, and with `--allow-repo-commands` `clear` reruns `release_tool` on the head and accepts an output it regenerates byte for byte. Without the flag the receipt is refused as before, and the refusal now says to pass it. A hand edit to the generated file, or any path outside `release_outputs`, is still refused.
11 changes: 9 additions & 2 deletions docs/pregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ receipt for H when the two trees differ only as a stamp does:
`version-manifest`, `manifest-version`, `lockfile-root-version`,
`changelog-heading`, `changelog-fragments` for the CHANGELOG under the fold,
`changelog_fragments` for a folded fragment's deletion, `stamp_files`,
`stamp_paths`, `release_outputs`). `clear` prints the same
`stamp_paths`, `release_outputs`, `release_tool`). `clear` prints the same
as `PREGATE_RECEIPT_SUBSTITUTED: …`, `verify` repeats it on its ok line, and
the ship receipt carries the receipt string. The receipt's own tests and
failed checks apply as before (its exit status is checked only when
Expand All @@ -686,7 +686,14 @@ receipt for H when the two trees differ only as a stamp does:
`*_KEY_VERSION` written as the next minor, #3512) (so two trees
at the same version refuse such a hunk as `other`), while the built-in
version-file, manifest, lockfile and CHANGELOG rules compare content and do
not check the direction of the version move. The obligation stays uncleared; rerun
not check the direction of the version move. A `release_outputs` file that is
more than those rewrites, such as a generated file a merged release commit
added rows to, is a stamp, rule `release_tool`, when the policy's
`release_tool`, rerun on pregate.json's head, writes it byte for byte (the
tree receipt's rule, GST-1176, GST-3067). The tool is repo code, so `clear`
reruns it only with `--allow-repo-commands`; without the flag the file is
refused and the refusal says to pass it. A `release_outputs` path is judged
by this rule even when `stamp_files` does not list it. The obligation stays uncleared; rerun
the gate on the head, or make the extra change a stamp under the repo's
rule.

Expand Down
9 changes: 6 additions & 3 deletions docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2991,9 +2991,12 @@ rule. The tool is repo code, so the receipt reruns it only with
each stamped prefix; without the flag the file stays `changed`. The rerun is
the Version Gate's: the stamped head (CHANGELOG folded, fragments deleted), a
bare environment and a 120-second limit, so an output that depends on anything
else fails closed as `changed`. With `stamp_files` set, a file outside it
is `changed (stamp_files: not in the repo's stamp_files allowlist)` whatever
its diff. Any other byte is a change. A diff git cannot produce between the two
else fails closed as `changed`. `gstack-pregate clear --receipt
--allow-repo-commands` applies the same rule to a remote gate receipt from a
predecessor tree (GST-3067). With `stamp_files` set, a file outside it and
outside `release_outputs` is `changed (stamp_files: not in the repo's
stamp_files allowlist)` whatever its diff; a `release_outputs` path is judged
by the release-output rule above. Any other byte is a change. A diff git cannot produce between the two
heads fails closed with `EVIDENCE_IDENTITY_UNKNOWN` and git's reason; it never
reads as no change.

Expand Down
8 changes: 6 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4742,13 +4742,17 @@ it refuses `caller_job_skipped` when its `<calling job> / <lane job>` job did no

Another tree is accepted in exactly one case: it differs from `pregate.json`'s
tree only in the repo's stamp rule (`.gstack/ship-policy.json` on the base
branch: `stamp_files`, `stamp_patterns`, the built-in version, manifest,
lockfile and CHANGELOG forms), judged by the tree receipt's own classifier on a
branch: `stamp_files`, `stamp_patterns`, `release_outputs`, the built-in
version, manifest, lockfile and CHANGELOG forms), judged by the tree receipt's own classifier on a
`git diff` of the two trees ([the gate ran ahead of the
stamp](pregate.md#remote-gate-stamp-only)). The refusal line then says `and the
trees differ beyond the stamp rule of <policy>: <path> (<rule>: <why>, line
<n>)`, and the path it names is the one that is not a stamp: a file outside
`stamp_files`, or a stamp file with a hunk that is not the old → new rewrite.
A `release_outputs` file that is more than that rewrite is a stamp (rule
`release_tool`) only when `release_tool`, rerun on the head, writes it byte for
byte; `clear` reruns it only with `--allow-repo-commands`, and without the flag
the refusal's reason includes `release_tool reruns only under --allow-repo-commands`.
`the gated tree <t> is not an object in this repository` means the gated
commit is not fetched here, so the two trees cannot be compared. Three more
refusals close the substitution without classifying anything: `lists the test
Expand Down
18 changes: 9 additions & 9 deletions lib/pregate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function carryGate(ctx: PregateContext, file: PregateFile): string | null {
const check = ctx.fromRun.check as RunCheck;
if (!check.gateRuns) return null;
const view: PregateFile = { ...file, requires_remote: file.requires_remote!.map(r => (r === gate ? { ...r, tests: [...new Set([...carried, ...r.tests])] } : r)) };
const d = clearByRuns(view, REMOTE_GATE_LANE, [ctx.fromRun.ref], check, ctx.repoRoot);
const d = clearByRuns(view, REMOTE_GATE_LANE, [ctx.fromRun.ref], check, ctx.repoRoot, undefined, ctx.allowRepoCommands);
if (!('receipt' in d)) return `CI_CARRY: ${REMOTE_GATE_LANE} stays uncleared (${d.message})`;
clearObligation(file, REMOTE_GATE_LANE, d.receipt, 'ci-carry', d.substitution);
return `CI_CARRY: cleared ${REMOTE_GATE_LANE} ${d.receipt}`;
Expand Down Expand Up @@ -275,7 +275,7 @@ function userPolicyChange(file: PregateFile): string | null {
return `${absent} now holds a user-owned policy, and pregate.json was recorded under the defaults; rerun gstack-pregate`;
}

export interface ClearInput { runUrl?: string; bundleLane?: string; receiptPath?: string; runs?: string[]; evidence?: RunCheck; flaky?: FlakyInput }
export interface ClearInput { runUrl?: string; bundleLane?: string; receiptPath?: string; runs?: string[]; evidence?: RunCheck; flaky?: FlakyInput; allowRepoCommands?: boolean }
/** What a run clear needs: the base branch's run profiles, the verifier's dependencies, the clock, and the remote gate's inventory. */
export interface RunCheck { repo: string; deps: RunDeps; profiles: Record<string, RunProfile>; gateRuns: RemoteGateRuns | null; now: Date; unchanged?: (p: RunProfile) => string | null; docsOnly?: (head: string) => boolean; inventory: (command: string, tree: string, selected?: string[]) => string[] | { error: string }; failures?: FailureDeps }
export type ClearDecision = { receipt: string; attested: boolean; substitution?: PregateReceiptSubstitution; exception?: PregateException } | { refused: 'usage' | 'PREGATE_RECEIPT_INVALID'; message: string; fix?: string };
Expand Down Expand Up @@ -313,10 +313,10 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput
const refs = [...(input.runs ?? []), ...(input.runUrl ? [input.runUrl] : [])];
if (!refs.length) return { refused: 'usage', message: '--flaky-exception needs --run <id|url>: an exception reads GitHub Actions runs' };
if (!input.flaky.pr) return { refused: 'usage', message: '--flaky-exception needs --pr <n>, the pull request the grant binds' };
return clearByRuns(file, lane, refs, input.evidence, repoRoot, { ...input.flaky, cases });
return clearByRuns(file, lane, refs, input.evidence, repoRoot, { ...input.flaky, cases }, input.allowRepoCommands);
}
const profiled = input.evidence && (lane === REMOTE_GATE_LANE ? input.evidence.gateRuns : input.evidence.profiles[lane]);
if (input.runs?.length || (input.runUrl && profiled)) return clearByRuns(file, lane, [...(input.runs ?? []), ...(input.runUrl ? [input.runUrl] : [])], input.evidence, repoRoot);
if (input.runs?.length || (input.runUrl && profiled)) return clearByRuns(file, lane, [...(input.runs ?? []), ...(input.runUrl ? [input.runUrl] : [])], input.evidence, repoRoot, undefined, input.allowRepoCommands);
if (input.bundleLane && profiled && lane !== REMOTE_GATE_LANE) return { refused: 'usage', message: `${lane} has a run profile on the base branch; clear it with --run <id|url>, which verifies the run` };
if (target.lane === REMOTE_GATE_LANE) {
if (!input.receiptPath) return { refused: 'usage', message: `${lane} clears only with --receipt <file> holding the remote gate's PREGATE_REMOTE: tree=… tests=… failed=… line (a run URL is not checkable); or rerun gstack-pregate --remote` };
Expand All @@ -329,7 +329,7 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput
if (!report) return { refused: 'PREGATE_RECEIPT_INVALID', message: `${input.receiptPath} has no PREGATE_REMOTE: line; ${lane} stays uncleared` };
const own = remoteReportProblem(report, report.tree);
if (own) return { refused: 'PREGATE_RECEIPT_INVALID', message: `${own}; ${lane} stays uncleared` };
const sub = treeSubstitution(file, report.tree, lane, repoRoot);
const sub = treeSubstitution(file, report.tree, lane, repoRoot, input.allowRepoCommands);
if ('refused' in sub) return sub;
const substitution = sub.substitution;
const problem = remoteReportProblem(report, substitution ? report.tree : file.tree);
Expand Down Expand Up @@ -381,13 +381,13 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput
}

/** The stamp-only substitution that lets a receipt for `gatedTree` clear pregate.json's tree, none when the trees are equal, or the refusal. */
function treeSubstitution(file: PregateFile, gatedTree: string, lane: string, repoRoot: string): { substitution?: PregateReceiptSubstitution } | Extract<ClearDecision, { refused: string }> {
function treeSubstitution(file: PregateFile, gatedTree: string, lane: string, repoRoot: string, allowRepoCommands = false): { substitution?: PregateReceiptSubstitution } | Extract<ClearDecision, { refused: string }> {
if (gatedTree === file.tree) return {};
// The stamp rule is the ship's own base branch's policy (origin/HEAD, as regate reads it), never a branch the artifact names.
const base = resolveBaseBranch(repoRoot);
const recorded = baseBranchOf(file.base);
if (recorded && recorded !== base) return { refused: 'PREGATE_RECEIPT_INVALID', message: `${treeMismatch(gatedTree, file.tree)}; pregate.json was recorded against origin/${recorded}, not this repository's base origin/${base}, so the stamp rule that would class the difference is not the base's; ${lane} stays uncleared`, fix: baseMismatchFix(repoRoot, base, recorded) };
const s = substituteStampOnlyTree(repoRoot, base, gatedTree, file.tree);
const s = substituteStampOnlyTree(repoRoot, base, gatedTree, file.tree, { allowRepoCommands, head: file.head });
if ('problem' in s) return { refused: 'PREGATE_RECEIPT_INVALID', message: `${s.problem}; ${lane} stays uncleared`, fix: s.fix };
return { substitution: s.substitution };
}
Expand All @@ -399,7 +399,7 @@ function treeSubstitution(file: PregateFile, gatedTree: string, lane: string, re
* does not run (never an inventory file); any other lane needs one verified run of the profile named after it. The run
* tree must be pregate.json's tree or a stamp-only predecessor of it, exactly as a gate report's tree must.
*/
function clearByRuns(file: PregateFile, lane: string, refs: string[], check: RunCheck | undefined, repoRoot: string, flaky?: FlakyInput & { cases: string[] }): ClearDecision {
function clearByRuns(file: PregateFile, lane: string, refs: string[], check: RunCheck | undefined, repoRoot: string, flaky?: FlakyInput & { cases: string[] }, allowRepoCommands = false): ClearDecision {
if (!check) return { refused: 'usage', message: `--run needs the base branch's run_profiles; none could be read` };
const isGate = lane === REMOTE_GATE_LANE;
const names = isGate ? check.gateRuns?.profiles ?? [] : check.profiles[lane] ? [lane] : [];
Expand Down Expand Up @@ -442,7 +442,7 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
if (trees.length > 1) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=tree_mismatch — the runs tested different trees (${trees.map(t => t.slice(0, 12)).join(', ')}); ${lane} stays uncleared` };
const off = red && evidence.find(e => e.head_sha !== file.head || e.tree !== file.tree);
if (off) return { refused: 'PREGATE_RECEIPT_INVALID', message: `FLAKY_EXCEPTION: refused reason=head_mismatch — run ${off.run_id} attempt ${off.run_attempt} tested head ${off.head_sha.slice(0, 12)} tree ${off.tree.slice(0, 12)}, not pregate.json's head ${(file.head ?? '').slice(0, 12)} tree ${file.tree.slice(0, 12)}; an exception binds the exact head and tree, never a stamp-only predecessor; ${lane} stays uncleared` };
const sub = treeSubstitution(file, trees[0]!, lane, repoRoot);
const sub = treeSubstitution(file, trees[0]!, lane, repoRoot, allowRepoCommands);
if ('refused' in sub) return { ...sub, message: `REUSE: refused reason=tree_not_stamp_only — ${sub.message}` };
const idle = evidence.filter(e => (e.tests ?? e.files.length) === 0);
if (idle.length) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=no_tests — ${idle.map(e => `run ${e.run_id} (${e.profile})`).join(', ')} records no tests; ${lane} stays uncleared` };
Expand Down
13 changes: 9 additions & 4 deletions lib/pregate/remote-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* `substituteStampOnlyTree` is the one accepted substitution. The gated tree
* and the head tree are diffed path by path, and every differing file is
* classified by the tree receipt's own rule (lib/tree-receipt.ts
* `classifyFiles`, the changelog_fragments fold included: the repo's `stamp_files` allowlist and `stamp_patterns`
* `classifyFiles` and, under --allow-repo-commands, `regenerateReleaseOutputs`, which reruns release_tool on
* pregate.json's head for a release output that is more than version rewrites, GST-3067; the changelog_fragments fold included: the repo's `stamp_files` allowlist and `stamp_patterns`
* templates from `.gstack/ship-policy.json` on the base branch, beside the
* built-in version-file, manifest-version, lockfile-root-version and
* changelog-heading forms). The receipt is accepted for the head only when
Expand All @@ -33,7 +34,7 @@ import { spawnSync } from 'node:child_process';
import type { PregateReceiptSubstitution } from '../headless-artifacts';
import { parseUnifiedDiff, versionAtRef } from '../restamp';
import { isUnavailable, loadPolicyFromBase, SHIP_POLICY_PATH } from '../ship-policy';
import { classifyFiles } from '../tree-receipt';
import { classifyFiles, regenerateReleaseOutputs } from '../tree-receipt';
import { treeMismatch } from './checks/lanes';

/** What `clear` records when a remote_gate receipt from a stamp-only predecessor tree is accepted for the head (the pregate.json shape, lib/headless-artifacts.ts). */
Expand Down Expand Up @@ -75,7 +76,7 @@ export function baseMismatchFix(repoRoot: string, base: string, recorded: string
* problem (opening with the same tree-mismatch clause `remoteReportProblem`
* prints) with the fix.
*/
export function substituteStampOnlyTree(repoRoot: string, base: string, gatedTree: string, headTree: string): SubstitutionResult {
export function substituteStampOnlyTree(repoRoot: string, base: string, gatedTree: string, headTree: string, opts: { allowRepoCommands?: boolean; head?: string } = {}): SubstitutionResult {
const short = (t: string) => t.slice(0, 12);
const mismatch = treeMismatch(gatedTree, headTree);
const rerun = `rerun the remote gate on tree ${short(headTree)} and pass its output with --receipt, or run gstack-pregate --stage tests --remote --spend-cap <usd> --allow-repo-commands`;
Expand Down Expand Up @@ -103,7 +104,11 @@ export function substituteStampOnlyTree(repoRoot: string, base: string, gatedTre
if (diff === null) return { problem: `${mismatch}; git diff ${short(gatedTree)} ${short(headTree)} failed`, fix: rerun };
const inventory = git(repoRoot, ['diff-tree', '-r', '-z', '--name-only', '--no-renames', '--ignore-submodules=none', '--end-of-options', gatedTree, headTree]);
if (inventory === null) return { problem: `${mismatch}; git diff-tree ${short(gatedTree)} ${short(headTree)} failed`, fix: rerun };
const files = classifyFiles(repoRoot, parseUnifiedDiff(diff), gatedTree, headTree, loaded.policy, versionRel, oldV, newV);
// release_tool reruns on a commit (it stages a worktree), so only on pregate.json's head and only when that commit is the recorded tree.
const headCommit = opts.head && OBJECT_ID.test(opts.head) && git(repoRoot, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${opts.head}^{tree}`]) === headTree ? opts.head : null;
const regen = regenerateReleaseOutputs({ repoRoot, files: classifyFiles(repoRoot, parseUnifiedDiff(diff), gatedTree, headTree, loaded.policy, versionRel, oldV, newV), head: headCommit ?? '', policy: loaded.policy, version: newV, run: !!opts.allowRepoCommands && !!headCommit });
const notRerun = !opts.allowRepoCommands ? 'release_tool reruns only under --allow-repo-commands: rerun this clear with it to accept the output release_tool regenerates byte for byte' : `release_tool not rerun: pregate.json's head ${(opts.head ?? 'none').slice(0, 12)} is not a commit at tree ${short(headTree)}`;
const files = regen.files.map(f => regen.pending.includes(f.path) ? { ...f, residual: `${f.residual}; ${notRerun}` } : f);
if (!files.length) return { problem: `${mismatch}; the trees differ but git diff produced no file entry to classify`, fix: rerun };
const expected = new Set(inventory.split('\0').filter(Boolean));
const seen = new Set(files.map(f => f.path));
Expand Down
Loading
Loading