mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
/ship can clear its test gate from CI on a branch stacked on another branch (GST-3381) (#4689)
When a branch is stacked on another branch, /ship can now clear its test gate from a green CI run instead of refusing with `base_mismatch`. Teams that ship stacked branches were stuck: the record named the stacked base, but the check read run profiles from the default branch. Nothing to do: branches based on main behave exactly as before. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/adversarial-native#3 reader=adversarial-native
This commit is contained in:
1 parent
54723680fc
commit
9d9ba2f057
6 files changed
+154
-17
No files matched your search
+9
-5
@@ -6,7 +6,7 @@
|
||||
* [--allow-repo-commands] [--policy-from base|head] [--out <pregate.json>]
|
||||
* [--timeout <s>] [--stall-timeout <s>] [--remote --spend-cap <usd>] [--run <id>] [--from-run <id|url>] [--no-ci-carry] [--explain] [--json]
|
||||
* gstack-pregate verify [--out <pregate.json>] [--json] publication check: current tree, every registered check, no fail/incomplete, obligations cleared
|
||||
* gstack-pregate clear --remote <workflow.yml/job> --run-url <url> | --run <id|url> [--run …] [--allow-repo-commands] | --bundle-lane <label> | --receipt <file> [--out <pregate.json>]
|
||||
* gstack-pregate clear --remote <workflow.yml/job> --run-url <url> | --run <id|url> [--run …] [--allow-repo-commands] | --bundle-lane <label> | --receipt <file> [--base <branch>] [--out <pregate.json>]
|
||||
* [--flaky-exception "<test file>::<case>" … --pr <n> [--grant <approval id>]] a run with failures, under the owner's grant
|
||||
* gstack-pregate lanes [--explain] the lane list and platform tiers read from .github/workflows
|
||||
* gstack-pregate validate | init [--explain] [--force] the working-tree .gstack/pregate.json
|
||||
@@ -58,7 +58,8 @@ const HELP = `gstack-pregate — cheap checks before anything paid or remote (do
|
||||
differs from pregate.json's only in the base branch's stamp rule is accepted and recorded as a
|
||||
substitution, docs/pregate.md#remote-gate-stamp-only); a
|
||||
test_backend/<backend> run URL is recorded as attested, not validated. --run <id|url> (repeatable)
|
||||
verifies GitHub Actions runs against the base branch's run_profiles instead (docs/pregate.md#run-evidence):
|
||||
verifies GitHub Actions runs against run_profiles instead (docs/pregate.md#run-evidence), read from the base
|
||||
pregate.json was recorded against (a --base naming another branch refuses, base_mismatch):
|
||||
one run of the profile named after the lane, or for pregate.json/remote_gate one run per
|
||||
remote_gate_runs profile covering the gate's inventory (needs --allow-repo-commands); where a lane has a
|
||||
profile, --run-url is verified the same way. --flaky-exception "<test file>::<case>" (at most 3) --pr <n>
|
||||
@@ -126,7 +127,7 @@ function flag(args: string[], name: string): string | undefined { const i = args
|
||||
const VERB_FLAGS: Record<string, [string[], string[]]> = {
|
||||
run: [['--stage', '--only', '--base', '--policy-from', '--out', '--timeout', '--stall-timeout', '--spend-cap', '--run', '--from-run'], ['--allow-repo-commands', '--explain', '--json', '--remote', '--no-ci-carry']],
|
||||
verify: [['--out'], ['--json']],
|
||||
clear: [['--remote', '--run-url', '--run', '--bundle-lane', '--receipt', '--out', '--flaky-exception', '--pr', '--grant'], ['--allow-repo-commands']],
|
||||
clear: [['--remote', '--run-url', '--run', '--bundle-lane', '--receipt', '--out', '--flaky-exception', '--pr', '--grant', '--base'], ['--allow-repo-commands']],
|
||||
lanes: [[], ['--explain', '--json']],
|
||||
validate: [[], ['--json']],
|
||||
init: [[], ['--explain', '--force']],
|
||||
@@ -270,10 +271,13 @@ function cmdClear(root: string, rest: string[]): number {
|
||||
const runs = rest.flatMap((a, i) => a === '--run' ? [rest[i + 1]!] : []);
|
||||
const runUrl = flag(rest, '--run-url');
|
||||
const bundleLane = flag(rest, '--bundle-lane');
|
||||
const checked = runs.length || runUrl || bundleLane ? buildRunCheck(root, lane, rest.includes('--allow-repo-commands')) : undefined;
|
||||
const recordedBase = baseBranchOf(read.file.base);
|
||||
const base = resolveBaseBranch(root, flag(rest, '--base') ?? recordedBase ?? undefined);
|
||||
if (flag(rest, '--base') !== undefined && recordedBase && base !== recordedBase) { process.stderr.write(`gstack-pregate clear: receipt refused — REUSE: refused reason=base_mismatch — pregate.json was recorded against origin/${recordedBase}, but run profiles come from origin/${base}; ${lane} stays uncleared; fix: clear without --base, which reads the record's own base origin/${recordedBase}; or rerun gstack-pregate --base ${base}, then clear again ${resultCodeSuffix('PREGATE_RECEIPT_INVALID')}\n`); return EXIT.fail; }
|
||||
const checked = runs.length || runUrl || bundleLane ? buildRunCheck(root, lane, rest.includes('--allow-repo-commands'), base) : 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, allowRepoCommands: rest.includes('--allow-repo-commands') }, root);
|
||||
const decision = clearDecision(read.file, lane, { runUrl, runs, bundleLane, receiptPath: flag(rest, '--receipt'), evidence, flaky, allowRepoCommands: rest.includes('--allow-repo-commands'), base }, 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`);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
important: blocker
|
||||
---
|
||||
**`/ship` on a branch stacked on another branch can now clear its remote test gate from a green CI run.** `gstack-pregate clear --run` reads the run profiles of the base the record was made against instead of `origin/HEAD`'s, and the CI reuse inside `gstack-pregate --base <branch>` clears the gate the same way; `--base` naming a different branch still refuses. docs/pregate.md#run-evidence (GST-3381)
|
||||
+5
-2
@@ -963,8 +963,11 @@ once:
|
||||
|
||||
Then, for the lane:
|
||||
|
||||
- pregate.json was recorded against this repository's base, whose profiles
|
||||
apply (`base_mismatch` otherwise).
|
||||
- The run profiles come from the base pregate.json was recorded against (its
|
||||
`base` field), so a branch stacked on another branch clears from that
|
||||
branch's profiles, and so does the CI carry inside a `--base <branch>` run.
|
||||
`clear --base <branch>` naming any other branch refuses (`base_mismatch`).
|
||||
A stamp-only substitution still reads `origin/HEAD`'s stamp rule, as above.
|
||||
- Each profile gets its own run (a run id given twice is a usage error), and
|
||||
every run verifies under its profile. The assignment is searched, so a run
|
||||
valid for two profiles cannot starve the other. A lane with a profile needs
|
||||
|
||||
@@ -5035,8 +5035,9 @@ as attested rather than validated.
|
||||
|
||||
`gstack-pregate clear --run <id|url>` refusals use this code too: the line
|
||||
reads `gstack-pregate clear: receipt refused — REUSE: refused reason=<code> —
|
||||
…`, and the GitHub Actions runs offered did not verify against the base
|
||||
branch's `run_profiles`. Each reason code and
|
||||
…`, and the GitHub Actions runs offered did not verify against the
|
||||
`run_profiles` of the base `pregate.json` was recorded against (`--base`
|
||||
naming another branch refuses `base_mismatch`). Each reason code and
|
||||
what it checks is listed in [run evidence](pregate.md#run-evidence).
|
||||
|
||||
`gstack-pregate clear --remote <workflow.yml/job> --run-url <url>` on a lane
|
||||
|
||||
@@ -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, undefined, ctx.allowRepoCommands);
|
||||
const d = clearByRuns(view, REMOTE_GATE_LANE, [ctx.fromRun.ref], check, ctx.repoRoot, undefined, ctx.allowRepoCommands, ctx.base);
|
||||
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}`;
|
||||
@@ -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; allowRepoCommands?: boolean }
|
||||
export interface ClearInput { runUrl?: string; bundleLane?: string; receiptPath?: string; runs?: string[]; evidence?: RunCheck; flaky?: FlakyInput; allowRepoCommands?: boolean; /** The branch whose run profiles `evidence` holds (gstack-pregate clear: the record's own); absent, origin/HEAD's. */ base?: string }
|
||||
/** 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; dispatchable?: (p: RunProfile) => 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 };
|
||||
@@ -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 }, input.allowRepoCommands);
|
||||
return clearByRuns(file, lane, refs, input.evidence, repoRoot, { ...input.flaky, cases }, input.allowRepoCommands, input.base);
|
||||
}
|
||||
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, undefined, input.allowRepoCommands);
|
||||
if (input.runs?.length || (input.runUrl && profiled)) return clearByRuns(file, lane, [...(input.runs ?? []), ...(input.runUrl ? [input.runUrl] : [])], input.evidence, repoRoot, undefined, input.allowRepoCommands, input.base);
|
||||
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` };
|
||||
@@ -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[] }, allowRepoCommands = false): ClearDecision {
|
||||
function clearByRuns(file: PregateFile, lane: string, refs: string[], check: RunCheck | undefined, repoRoot: string, flaky?: FlakyInput & { cases: string[] }, allowRepoCommands = false, profilesBase?: string): 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] : [];
|
||||
@@ -407,10 +407,10 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
|
||||
if (refs.length !== names.length) return { refused: 'usage', message: `${lane} clears with exactly ${names.length} run(s), one per profile (${names.join(', ')}); got ${refs.length}` };
|
||||
const ids = refs.map(ref => parseRunRef(ref, check.repo) ?? ref);
|
||||
if (new Set(ids).size !== ids.length) return { refused: 'usage', message: `${lane} needs a different run for each profile; got ${refs.join(', ')}` };
|
||||
// The profiles are the base branch's; a pregate.json recorded against another base names another authority.
|
||||
const base = resolveBaseBranch(repoRoot);
|
||||
// The profiles are one base branch's (the record's own, for gstack-pregate clear); a pregate.json recorded against another base names another authority.
|
||||
const base = profilesBase ?? resolveBaseBranch(repoRoot);
|
||||
const recorded = baseBranchOf(file.base);
|
||||
if (recorded && recorded !== base) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=base_mismatch — pregate.json was recorded against origin/${recorded}, but run profiles come from this repository's base origin/${base}; ${lane} stays uncleared`, fix: baseMismatchFix(repoRoot, base, recorded) };
|
||||
if (recorded && recorded !== base) return { refused: 'PREGATE_RECEIPT_INVALID', message: `REUSE: refused reason=base_mismatch — pregate.json was recorded against origin/${recorded}, but run profiles come from origin/${base}; ${lane} stays uncleared`, fix: profilesBase ? `clear without --base, which reads the record's own base origin/${recorded}; or rerun gstack-pregate --base ${base}, then clear again` : baseMismatchFix(repoRoot, base, recorded) };
|
||||
const verdicts = new Map<string, ReturnType<typeof verifyRun>>();
|
||||
const verdict = (name: string, ref: string) => {
|
||||
const key = `${name}\0${ref}`;
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* GST-3381 (b): a pregate.json recorded against a stacked base (a branch other than origin/HEAD's) clears its remote gate
|
||||
* from that base's run profiles. `gstack-pregate clear --run` reads the base from the record it clears, and the CI carry
|
||||
* inside a `--base <branch>` run (what `gstack-ship-release accept --base` runs) clears against the same base. A
|
||||
* clear told another base with --base still refuses base_mismatch. The Actions API is a gh shim (bin) or a fake (library).
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { EXIT, type PregateFile } from '../lib/headless-artifacts';
|
||||
import { buildContext } from '../lib/pregate/context';
|
||||
import { runPregate, type RunCheck } from '../lib/pregate/index';
|
||||
import { buildRunCheck } from '../lib/pregate/run-check';
|
||||
import type { ApiRun, RunProfile } from '../lib/run-evidence';
|
||||
import { BASE_PREGATE, cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';
|
||||
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
||||
|
||||
const LANE = 'pregate.json/remote_gate';
|
||||
const NAME = 'ci-reuse/free-tests';
|
||||
const LOCAL_OS = process.platform === 'darwin' ? 'macOS' : 'Linux';
|
||||
const PROFILE: RunProfile = { workflow: 'free-tests.yml', events: ['pull_request', 'workflow_dispatch'], jobs: ['unit'], artifact: 'tested-tree', os: LOCAL_OS };
|
||||
const FREE = ['test/retry.test.js', 'test/util.test.js'];
|
||||
const GATE_RUNS = { profiles: [NAME], inventory: 'printf "test/retry.test.js\\ntest/util.test.js\\n"', skipped: 'grep -E "^test/nightly/" "$PREGATE_FILES_FILE" || true' };
|
||||
|
||||
/** main and the stacked base `stack` both declare the profile; the feature branch sits on `stack` and touches two subjects. */
|
||||
function stackedFixture(): FixtureRepo {
|
||||
const repo = makeFixtureRepo({ pregate: { ...BASE_PREGATE, remote_gate: 'node scripts/remote-gate.js', run_profiles: { [NAME]: PROFILE }, remote_gate_runs: GATE_RUNS } });
|
||||
repos.push(repo);
|
||||
repo.git('checkout', '-q', '-b', 'stack', 'main');
|
||||
commit(repo, { 'docs/stack.md': '# the stacked base\n' }, 'stacked base');
|
||||
repo.git('push', '-q', 'origin', 'stack');
|
||||
repo.git('checkout', '-q', 'feature');
|
||||
repo.git('reset', '-q', '--hard', 'stack');
|
||||
commit(repo, { 'lib/util.js': 'exports.add = (a, b) => a + b + 0;\n', 'lib/retry.js': 'exports.MAX_RETRIES = 3;\nexports.TIMEOUT_MS = 5000;\nexports.retry = (fn) => fn();\nexports.touched = true;\n' }, 'touch two subjects');
|
||||
return repo;
|
||||
}
|
||||
|
||||
/** Run 200 of free-tests.yml at HEAD, green, finished ten minutes ago, its tree.json listing FREE. */
|
||||
function greenRun(repo: FixtureRepo) {
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const finished = new Date(Date.now() - 600_000).toISOString();
|
||||
const run: ApiRun = { id: 200, run_attempt: 1, status: 'completed', conclusion: 'success', event: 'workflow_dispatch', head_sha: head, path: '.github/workflows/free-tests.yml', created_at: finished, updated_at: finished, repository: { full_name: 'fx/fx' }, head_repository: { full_name: 'fx/fx' } };
|
||||
const jobs = [{ name: 'unit', conclusion: 'success', completed_at: finished }];
|
||||
const tree = { run_id: 200, run_attempt: 1, event: 'workflow_dispatch', sha: head, tree: repo.git('rev-parse', 'HEAD^{tree}'), os: [LOCAL_OS], files: FREE, tests: FREE.length * 4 };
|
||||
return { head, run, jobs, tree };
|
||||
}
|
||||
|
||||
/** A gh on PATH that answers only the Actions reads ghRunDeps makes for run 200, from greenRun. */
|
||||
function ghShim(repo: FixtureRepo): Record<string, string> {
|
||||
const dir = path.join(repo.root, 'gh-shim');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, 'data.json'), JSON.stringify(greenRun(repo)));
|
||||
fs.writeFileSync(path.join(dir, 'gh'), [
|
||||
'#!/usr/bin/env node',
|
||||
`const d = require(${JSON.stringify(path.join(dir, 'data.json'))}); const a = process.argv.slice(2); const fs = require('fs');`,
|
||||
'const p = a.find(x => x.startsWith(\'repos/\')) || \'\'; const lines = xs => { for (const x of xs) console.log(JSON.stringify(x)); process.exit(0); };',
|
||||
'if (a[0] === \'run\' && a[1] === \'download\' && a[2] === \'200\') { fs.writeFileSync(a[a.indexOf(\'--dir\') + 1] + \'/tree.json\', JSON.stringify(d.tree)); process.exit(0); }',
|
||||
'if (a[0] === \'api\' && p === \'repos/fx/fx/actions/runs/200\') { console.log(JSON.stringify(d.run)); process.exit(0); }',
|
||||
'if (a[0] === \'api\' && p.startsWith(\'repos/fx/fx/actions/runs/200/attempts/1/jobs?\')) lines(d.jobs);',
|
||||
'if (a[0] === \'api\' && p.startsWith(\'repos/fx/fx/actions/workflows/free-tests.yml/runs?head_sha=\')) lines(p.includes(d.head) ? [d.run] : []);',
|
||||
'if (a[0] === \'api\' && p.startsWith(\'repos/fx/fx/actions/runs/200/artifacts?\')) lines([{ id: 1, name: \'tested-tree\', size_in_bytes: 200, expired: false }]);',
|
||||
'console.error(\'gh shim: unsupported \' + a.join(\' \')); process.exit(1);',
|
||||
'',
|
||||
].join('\n'), { mode: 0o755 });
|
||||
return { PATH: `${dir}${path.delimiter}${process.env.PATH ?? ''}` };
|
||||
}
|
||||
|
||||
async function stackedPregate(repo: FixtureRepo, fromRun?: RunCheck): Promise<{ file: PregateFile; progress: string[] }> {
|
||||
const progress: string[] = [];
|
||||
const loaded = buildContext({ repoRoot: repo.work, base: 'stack', policyFrom: 'base', allowRepoCommands: true, env: { ...process.env, ...repo.env }, progress: l => progress.push(l), cores: 4, testBackend: 'local' });
|
||||
if (!('ctx' in loaded)) throw new Error('fixture context refused');
|
||||
if (fromRun) loaded.ctx.fromRun = { ref: '200', check: fromRun };
|
||||
else loaded.ctx.ciCarry = false;
|
||||
return { file: await runPregate(loaded.ctx, { stage: 'tests' }), progress };
|
||||
}
|
||||
const gate = (file: PregateFile) => file.requires_remote?.find(r => r.lane === LANE);
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('a pregate.json recorded against a stacked base clears from that base (GST-3381)', () => {
|
||||
// Value: protects=a /ship on a branch whose base is not origin/HEAD's can clear its remote gate from a green CI run;
|
||||
// fails_when=clear reads run profiles from origin/HEAD's branch and refuses base_mismatch (GSTA-724/725/726, Vorflux on rust-engine/main);
|
||||
// why_new=GST-3381 (b); seam=the gstack-pregate bin with a gh shim
|
||||
test('clear --run reads the record\'s base; --base naming another branch still refuses base_mismatch', async () => {
|
||||
const repo = stackedFixture();
|
||||
const { file } = await stackedPregate(repo);
|
||||
expect(file.base).toStartWith('origin/stack@');
|
||||
expect(gate(file)?.receipt).toBeNull();
|
||||
const out = path.join(repo.work, '.gstack/tmp/pregate.json');
|
||||
fs.mkdirSync(path.dirname(out), { recursive: true });
|
||||
fs.writeFileSync(out, JSON.stringify(file));
|
||||
repo.git('remote', 'set-url', 'origin', 'https://github.com/fx/fx.git');
|
||||
const copy = path.join(repo.work, '.gstack/tmp/pregate-other.json');
|
||||
fs.copyFileSync(out, copy);
|
||||
const env = ghShim(repo);
|
||||
const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--run', '200', '--allow-repo-commands'], env);
|
||||
expect([r.status, r.err]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
expect(r.out).toContain(`REUSE: accepted ${LANE} remote-gate tree=${file.tree.slice(0, 12)} tests=8 skipped=1 runs=200/1 profiles=${NAME} `);
|
||||
expect(JSON.parse(fs.readFileSync(out, 'utf8')).requires_remote[0].receipt).toStartWith(`remote-gate tree=${file.tree.slice(0, 12)} `);
|
||||
const other = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--run', '200', '--base', 'main', '--out', copy, '--allow-repo-commands'], env);
|
||||
expect([other.status, other.err]).toEqual([EXIT.fail, expect.stringContaining('REUSE: refused reason=base_mismatch — pregate.json was recorded against origin/stack, but run profiles come from origin/main')]);
|
||||
expect(JSON.parse(fs.readFileSync(copy, 'utf8')).requires_remote[0].receipt).toBeNull();
|
||||
const bundle = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--bundle-lane', 'free', '--base', 'main', '--out', copy], env);
|
||||
expect([bundle.status, bundle.err]).toEqual([EXIT.fail, expect.stringContaining('REUSE: refused reason=base_mismatch — pregate.json was recorded against origin/stack, but run profiles come from origin/main')]);
|
||||
expect(JSON.parse(fs.readFileSync(copy, 'utf8')).requires_remote[0].receipt).toBeNull();
|
||||
}, 120_000);
|
||||
|
||||
// Value: protects=accept's pregate rerun (--base <stacked base>) clears the gate from the run it carried, as on main;
|
||||
// fails_when=the carry's clear compares the record against origin/HEAD's branch and leaves the gate uncleared;
|
||||
// why_new=GST-3381 (b), the same base check on the accept route; seam=runPregate with a fake run API
|
||||
test('the CI carry inside a --base run clears the gate against that base', async () => {
|
||||
const repo = stackedFixture();
|
||||
repo.git('remote', 'set-url', 'origin', 'https://github.com/fx/fx.git');
|
||||
const built = buildRunCheck(repo.work, null, true, 'stack');
|
||||
repo.git('remote', 'set-url', 'origin', repo.origin);
|
||||
if ('error' in built) throw new Error(built.error);
|
||||
const { run, jobs, tree, head } = greenRun(repo);
|
||||
const check: RunCheck = { ...built, repo: 'fx/fx', deps: { run: () => run, runsForHead: (_wf, sha) => (sha === head ? [run] : []), jobs: () => jobs, artifact: () => tree, commitTree: sha => repo.git('rev-parse', `${sha}^{tree}`) } };
|
||||
const { file, progress } = await stackedPregate(repo, check);
|
||||
const obligation = gate(file)!;
|
||||
expect(progress).not.toContainEqual(expect.stringContaining('base_mismatch'));
|
||||
expect([obligation.receipt, obligation.cleared_by]).toEqual([expect.stringMatching(new RegExp(`^remote-gate tree=${file.tree.slice(0, 12)} tests=8 skipped=1 runs=200/1 `)), 'ci-carry']);
|
||||
expect(file.verdict).toBe('requires-remote cleared');
|
||||
}, 120_000);
|
||||
});
|
||||
Reference in new issue
Block a user