mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-16 13:21:30 +01:00
pregate: review fixes for clear --run (re-run veto, profiled lanes fail closed, no pull_request runs, user-policy keys)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
29cc8ff6a0
commit
c04aa4c69e
8 files changed
+75
-24
No files matched your search
+7
-5
@@ -221,10 +221,11 @@ function cmdClear(root: string, rest: string[]): number {
|
||||
if (!read.file) { process.stderr.write(resultLine('gstack-pregate clear', 'PREGATE_STALE', `${out} is missing or invalid; run gstack-pregate first`) + '\n'); return EXIT.fail; }
|
||||
const runs = rest.flatMap((a, i) => a === '--run' ? [rest[i + 1]!] : []);
|
||||
const runUrl = flag(rest, '--run-url');
|
||||
const checked = runs.length || runUrl ? runCheck(root, rest.includes('--allow-repo-commands')) : undefined;
|
||||
if (checked && 'error' in checked && runs.length) { process.stderr.write(`gstack-pregate clear: ${checked.error}\n`); return EXIT.fail; }
|
||||
const bundleLane = flag(rest, '--bundle-lane');
|
||||
const checked = runs.length || runUrl || bundleLane ? runCheck(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 ? `; the base branch declares a run profile for ${lane}, so it clears only with --run` : ''}\n`); return EXIT.fail; }
|
||||
const evidence = checked && !('error' in checked) ? checked : undefined;
|
||||
const decision = clearDecision(read.file, lane, { runUrl, runs, bundleLane: flag(rest, '--bundle-lane'), receiptPath: flag(rest, '--receipt'), evidence }, root);
|
||||
const decision = clearDecision(read.file, lane, { runUrl, runs, bundleLane, receiptPath: flag(rest, '--receipt'), evidence }, 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`);
|
||||
@@ -235,17 +236,18 @@ function cmdClear(root: string, rest: string[]): number {
|
||||
if (/ runs=\S+ profiles=/.test(decision.receipt)) process.stdout.write(`REUSE: accepted ${lane} ${decision.receipt}\n`);
|
||||
if (decision.substitution) process.stdout.write(`PREGATE_RECEIPT_SUBSTITUTED: ${describeSubstitution(decision.substitution)}\n`);
|
||||
process.stdout.write(`PREGATE_CLEARED: ${lane} receipt=${decision.receipt} verdict=${file.verdict}${decision.attested ? ` (attested, not validated: ${lane} has no machine-checkable receipt)` : ''}\n`);
|
||||
if (checked && 'error' in checked) process.stderr.write(`gstack-pregate clear: run profiles unavailable (${checked.error}); ${lane} was recorded without run verification\n`);
|
||||
return EXIT.ok;
|
||||
}
|
||||
|
||||
/** The run-evidence inputs for `clear --run`: the base branch's run profiles, this repository on GitHub, and the gate's inventory command (a pin-file command, so only with --allow-repo-commands). */
|
||||
function runCheck(root: string, allowRepoCommands: boolean): RunCheck | { error: string } {
|
||||
function runCheck(root: string, lane: string, allowRepoCommands: boolean): RunCheck | { error: string; profiled?: boolean } {
|
||||
const base = resolveBaseBranch(root);
|
||||
const loaded = loadConfigFromBase(root, base);
|
||||
if (isConfigUnavailable(loaded)) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is unreadable (${loaded.detail}); run profiles come only from the base` };
|
||||
if (loaded.errors.length) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is invalid: ${loaded.errors.map(e => `${e.path}: ${e.message}`).join('; ')}` };
|
||||
const repo = /github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/.exec(gitOut(root, ['remote', 'get-url', 'origin']) ?? '')?.[1];
|
||||
if (!repo) return { error: 'origin is not a github.com repository; run evidence is read from GitHub Actions' };
|
||||
if (!repo) return { error: 'origin is not a github.com repository; run evidence is read from GitHub Actions', profiled: lane === REMOTE_GATE_LANE ? !!loaded.config.remote_gate_runs : !!loaded.config.run_profiles[lane] };
|
||||
return {
|
||||
repo, deps: ghRunDeps(repo, root), profiles: loaded.config.run_profiles, gateRuns: loaded.config.remote_gate_runs, now: new Date(),
|
||||
inventory: command => {
|
||||
|
||||
+21
-6
@@ -592,7 +592,10 @@ on prose: a pasted URL is only a pointer the verifier resolves.
|
||||
```
|
||||
|
||||
Profiles are read only from `origin/<base>`, so a pull request can tighten
|
||||
them but never relax them. Each profile names the workflow file, the events it
|
||||
them but never relax them. That covers the profile, not the suite it names: the
|
||||
workflow file a run executed and the inventory command are the branch's own, as
|
||||
the remote gate's script already is, so a diff to either is reviewed like any
|
||||
other gate change. Each profile names the workflow file, the events it
|
||||
accepts, every job that must have passed (each exactly once), and the artifact
|
||||
holding the run's `tree.json`. `max_age_hours` (1–168, default 24) bounds how
|
||||
old the run may be, and `os` (`Linux`, `macOS`, `Windows`) requires
|
||||
@@ -613,8 +616,12 @@ once:
|
||||
- `tree.json` names this run, attempt, event and head. It is not a reuse
|
||||
record (a reuse is never evidence). Its tree equals the tree git computes for
|
||||
the run's head commit.
|
||||
- No newer run of the same workflow on that head, or on pregate.json's own
|
||||
head, failed, was cancelled or is still running.
|
||||
- No run of the same workflow on that head, or on pregate.json's own head,
|
||||
whose newest attempt started after this run was created failed, was
|
||||
cancelled or is still running (`run_started_at`, so a red re-run of an older
|
||||
run counts, and re-running this run does not hide a failure in between).
|
||||
- Its event is `push` or `workflow_dispatch`. A `pull_request` run tests the
|
||||
merge commit, not the head tree, so no profile may accept it.
|
||||
- The run finished within `max_age_hours`, and on the profile's OS when it
|
||||
names one.
|
||||
- For `pregate.json/remote_gate`: there is exactly one verified run per
|
||||
@@ -632,13 +639,21 @@ verification is named with its own reason (`fork_run`, `event_mismatch`,
|
||||
`run_not_success`, `job_missing`, `artifact_mismatch`, `artifact_reused`,
|
||||
`tree_mismatch`, `newer_run_vetoes`, `run_stale`, `os_mismatch`, `api_error`,
|
||||
…); the clear-level codes are `no_verified_run`, `tree_mismatch` (runs on
|
||||
different trees), `inventory_failed`, `inventory_empty`, `inventory_uncovered`
|
||||
and `no_tests`. Accepted, `clear` prints `REUSE: accepted <lane> <receipt>`, and
|
||||
different trees), `tree_not_stamp_only`, `inventory_failed`, `inventory_empty`,
|
||||
`inventory_uncovered` and `no_tests`. A wrong run count or a lane with no
|
||||
profile is a usage error (exit 2), not a REUSE refusal. When the base config or
|
||||
the GitHub origin cannot be read, `--run` fails, and so do `--run-url` and
|
||||
`--bundle-lane` for a lane the base profiles; any other lane is recorded as
|
||||
before, with a warning naming the cause. Accepted, `clear` prints `REUSE: accepted <lane> <receipt>`, and
|
||||
the receipt reads
|
||||
`remote-gate tree=<t12> tests=<n> runs=<id>/<attempt>,… profiles=<p>,…
|
||||
heads=<h12> verified=<time>` (with `accepted-for=` and the substitution for a
|
||||
stamp-only predecessor). A lane with its own profile gets `run tree=… runs=…`
|
||||
the same way, and for such a lane `--run-url` is verified as `--run` is. A
|
||||
the same way, and for such a lane `--run-url` is verified as `--run` is and
|
||||
`--bundle-lane` is refused. `gstack-ship-queue ready --dispatch-ci` still
|
||||
records its dispatched runs by URL; routing it through the verifier is the
|
||||
next change (P3b), so a repository that declares lane profiles clears those
|
||||
lanes with `gstack-pregate clear --run`. A
|
||||
lane with no profile keeps today's `--run-url` recording.
|
||||
|
||||
**`verify` stays offline.** The check ran at `clear`. `gstack-pregate verify`,
|
||||
|
||||
@@ -307,10 +307,10 @@ export function loadConfigFromUser(file: string, knownChecks: readonly string[]
|
||||
return { ...parseConfig('{}', knownChecks), errors: [{ code: 'PREGATE_CONFIG_INVALID', path: file, message: `cannot read the user-owned policy: ${(e as Error).message}` }], present: true, label: `user ${file}`, kind: 'user' };
|
||||
}
|
||||
const load = parseConfig(text, knownChecks);
|
||||
// `sealed` (the pre-push guard) and `price_file` (gstack-eval-plan) read only the git copies, so a non-null value in the user file would look active and do nothing.
|
||||
// `sealed` (the pre-push guard), `price_file` (gstack-eval-plan) and the run profiles (`clear --run`) read only the git copies, so a non-null value in the user file would look active and do nothing.
|
||||
let raw: unknown = null;
|
||||
try { raw = JSON.parse(text); } catch { /* parseConfig reported it */ }
|
||||
const ignored = raw && typeof raw === 'object' && !Array.isArray(raw) ? ['sealed', 'price_file'].filter(k => (raw as Record<string, unknown>)[k] != null) : [];
|
||||
const ignored = raw && typeof raw === 'object' && !Array.isArray(raw) ? ['sealed', 'price_file', 'run_profiles', 'remote_gate_runs'].filter(k => { const v = (raw as Record<string, unknown>)[k]; return v != null && !(k === 'run_profiles' && typeof v === 'object' && Object.keys(v).length === 0); }) : [];
|
||||
// parseConfig names the repo copy for a JSON error; this file is not it.
|
||||
const errors = [...load.errors.map(e => e.path === PREGATE_CONFIG_PATH ? { ...e, path: file } : e), ...ignored.map(k => ({ code: 'PREGATE_CONFIG_INVALID' as const, path: k, message: `the user-owned policy covers gstack-pregate run only; ${k} is read from ${PREGATE_CONFIG_PATH} on the base branch` }))];
|
||||
return { ...load, errors, present: true, label: `user ${file}`, kind: 'user', digest: createHash('sha256').update(text).digest('hex') };
|
||||
|
||||
@@ -225,6 +225,7 @@ export function clearDecision(file: PregateFile, lane: string, input: ClearInput
|
||||
if (!target) return { refused: 'usage', message: `no requires-remote obligation named ${lane}; obligations: ${list.map(r => r.lane).join(', ') || '(none)'}` };
|
||||
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.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` };
|
||||
let text: string;
|
||||
@@ -294,7 +295,7 @@ function clearByRuns(file: PregateFile, lane: string, refs: string[], check: Run
|
||||
const trees = [...new Set(evidence.map(e => e.tree))];
|
||||
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 sub = treeSubstitution(file, trees[0]!, lane, repoRoot);
|
||||
if ('refused' in sub) return sub;
|
||||
if ('refused' in sub) return { ...sub, message: `REUSE: refused reason=tree_not_stamp_only — ${sub.message}` };
|
||||
const tests = evidence.reduce((n, e) => n + (e.tests ?? e.files.length), 0);
|
||||
if (isGate) {
|
||||
const listed = check.inventory(check.gateRuns!.inventory);
|
||||
|
||||
+6
-4
@@ -5,7 +5,7 @@
|
||||
* obligation, a platform lane) may accept a run that already passed on the
|
||||
* identical tree, but only on the runner's own record, never on prose: the
|
||||
* GitHub API's record of the run, the tree git computes from the run's head
|
||||
* commit, and the `tested-tree` artifact (tree.json) the run uploaded itself.
|
||||
* commit, and the profile's artifact (its tree.json) the run uploaded itself.
|
||||
* `verifyRun` refuses unless every check holds:
|
||||
*
|
||||
* the run belongs to this repository and ran for a same-repository head;
|
||||
@@ -34,7 +34,7 @@ export interface RunProfile { workflow: string; events: string[]; jobs: string[]
|
||||
export interface RemoteGateRuns { profiles: string[]; inventory: string }
|
||||
export interface ApiRun {
|
||||
id: number; run_attempt: number; status: string; conclusion: string | null; event: string; head_sha: string;
|
||||
path?: string; created_at?: string; updated_at?: string;
|
||||
path?: string; created_at?: string; run_started_at?: string; updated_at?: string;
|
||||
repository?: { full_name: string } | null; head_repository?: { full_name: string } | null;
|
||||
}
|
||||
export interface ApiJob { name: string; conclusion: string | null }
|
||||
@@ -86,7 +86,7 @@ export function runProfileErrors(profiles: unknown, gateRuns: unknown): Array<{
|
||||
const v = p[k];
|
||||
if (!Array.isArray(v) || v.length === 0 || v.length > 32 || v.some(s => typeof s !== 'string' || !s.trim())) errors.push({ path: `${at}.${k}`, message: 'must be a non-empty array of up to 32 names' });
|
||||
}
|
||||
if (Array.isArray(p.events) && p.events.some(e => e !== 'push' && e !== 'workflow_dispatch' && e !== 'pull_request')) errors.push({ path: `${at}.events`, message: 'events are push, workflow_dispatch or pull_request' });
|
||||
if (Array.isArray(p.events) && p.events.some(e => e !== 'push' && e !== 'workflow_dispatch')) errors.push({ path: `${at}.events`, message: 'events are push or workflow_dispatch (a pull_request run tests the merge commit, not the head tree)' });
|
||||
if (typeof p.artifact !== 'string' || !NAME.test(p.artifact)) errors.push({ path: `${at}.artifact`, message: 'must be the artifact name holding tree.json' });
|
||||
if ('max_age_hours' in p && (!Number.isInteger(p.max_age_hours) || (p.max_age_hours as number) < 1 || (p.max_age_hours as number) > 168)) errors.push({ path: `${at}.max_age_hours`, message: 'must be an integer from 1 to 168' });
|
||||
if ('os' in p && (typeof p.os !== 'string' || !/^(Linux|macOS|Windows)$/.test(p.os))) errors.push({ path: `${at}.os`, message: 'must be Linux, macOS or Windows' });
|
||||
@@ -106,6 +106,8 @@ export function runProfileErrors(profiles: unknown, gateRuns: unknown): Array<{
|
||||
}
|
||||
|
||||
const fail = (reason: RunRefusal, detail: string): RunVerdict => ({ ok: false, reason, detail });
|
||||
/** When a run's newest attempt started. A run vetoes the candidate when it started after the candidate was created: a red re-run of an older run counts, and re-running the candidate does not hide a failure in between. */
|
||||
const started = (r: ApiRun): string => r.run_started_at ?? r.created_at ?? '';
|
||||
|
||||
/**
|
||||
* The verdict for run `runRef` under `profile`. `vetoHeads` are further heads
|
||||
@@ -138,7 +140,7 @@ export function verifyRun(deps: RunDeps, o: { repo: string; runRef: string; prof
|
||||
}
|
||||
const heads = [...new Set([run.head_sha, ...(o.vetoHeads ?? []).filter(h => SHA.test(h))])];
|
||||
for (const head of heads) {
|
||||
const newer = deps.runsForHead(p.workflow, head).filter(r => r.id !== id && (r.created_at ?? '') > (run.created_at ?? '') && !(r.status === 'completed' && r.conclusion === 'success'));
|
||||
const newer = deps.runsForHead(p.workflow, head).filter(r => r.id !== id && started(r) > (run.created_at ?? '') && !(r.status === 'completed' && r.conclusion === 'success'));
|
||||
if (newer.length) return fail('newer_run_vetoes', `newer run ${newer[0]!.id} of ${p.workflow} on ${head.slice(0, 12)} is ${newer[0]!.status === 'completed' ? newer[0]!.conclusion : newer[0]!.status}`);
|
||||
}
|
||||
let rec: TreeRecord;
|
||||
|
||||
@@ -24,9 +24,9 @@ const PROFILES: Record<string, RunProfile> = {
|
||||
};
|
||||
const GATE_RUNS = { profiles: ['test', 'e2e'], inventory: 'printf "test/a.test.ts\\ntest/b.test.ts\\n"' };
|
||||
|
||||
function fixture(): FixtureRepo {
|
||||
function fixture(extra: Record<string, unknown> = {}): FixtureRepo {
|
||||
const repo = makeFixtureRepo({
|
||||
pregate: { ...BASE_PREGATE, remote_gate: 'node scripts/remote-gate.js', dependencies: { ...BASE_PREGATE.dependencies, 'CHANGELOG.md': [], VERSION: [] } },
|
||||
pregate: { ...BASE_PREGATE, ...extra, remote_gate: 'node scripts/remote-gate.js', dependencies: { ...BASE_PREGATE.dependencies, 'CHANGELOG.md': [], VERSION: [] } },
|
||||
baseFiles: { '.gstack/ship-policy.json': JSON.stringify(POLICY, null, 2) + '\n', VERSION: '1.0.0\n', 'CHANGELOG.md': '# Changelog\n\n## [Unreleased]\n\n- add\n' },
|
||||
});
|
||||
repos.push(repo);
|
||||
@@ -129,7 +129,7 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
expect('refused' in empty && empty.message).toContain('inventory command listed no test files');
|
||||
}, 120_000);
|
||||
|
||||
test('a lane with its own profile clears from --run-url through the verifier; a lane without one keeps the plain run-URL record, even when the base config cannot be read', async () => {
|
||||
test('a lane with its own profile clears from --run-url through the verifier; a lane without one keeps the plain run-URL record, and so does a repository whose run profiles cannot be read (a non-GitHub origin), with a warning', async () => {
|
||||
const repo = fixture();
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const base = await pregateAt(repo);
|
||||
@@ -143,10 +143,33 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo
|
||||
const failed = clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts'], conclusion: 'failure' }], { profiles: { ...PROFILES, [PLATFORM]: PROFILES.test! } }) }, repo.work);
|
||||
expect('refused' in failed && failed.refused).toBe('PREGATE_RECEIPT_INVALID');
|
||||
expect(clearDecision(file, PLATFORM, { runUrl: url, evidence: check(repo, []) }, repo.work)).toEqual({ receipt: url, attested: false });
|
||||
const bundled = clearDecision(file, PLATFORM, { bundleLane: 'macos', evidence: check(repo, [], { profiles: { ...PROFILES, [PLATFORM]: PROFILES.test! } }) }, repo.work);
|
||||
expect('refused' in bundled && `${bundled.refused}: ${bundled.message}`).toBe(`usage: ${PLATFORM} has a run profile on the base branch; clear it with --run <id|url>, which verifies the run`);
|
||||
expect(clearDecision(file, PLATFORM, { bundleLane: 'macos', evidence: check(repo, []) }, repo.work)).toEqual({ receipt: 'bundle-lane:macos', attested: false });
|
||||
const unprofiled = clearDecision(file, PLATFORM, { runs: ['200'], evidence: check(repo, []) }, repo.work);
|
||||
expect('refused' in unprofiled && `${unprofiled.refused}: ${unprofiled.message}`).toContain(`usage: --run clears ${PLATFORM} only when the base branch's .gstack/pregate.json declares a run_profiles entry named`);
|
||||
const gateFromUrl = clearDecision(file, LANE, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts', 'test/b.test.ts'] }]) }, repo.work);
|
||||
expect('refused' in gateFromUrl && `${gateFromUrl.refused}: ${gateFromUrl.message}`).toBe('usage: pregate.json/remote_gate clears with exactly 2 run(s), one per profile (test, e2e); got 1');
|
||||
const oneProfile = clearDecision(file, LANE, { runUrl: url, evidence: check(repo, [{ id: 200, profile: 'test', head, files: ['test/a.test.ts', 'test/b.test.ts'] }], { gateRuns: { profiles: ['test'], inventory: 'true' } }) }, repo.work);
|
||||
if ('refused' in oneProfile) throw new Error(oneProfile.message);
|
||||
expect(oneProfile.receipt).toStartWith(`remote-gate tree=${file.tree.slice(0, 12)} tests=10 runs=200/1 profiles=test `);
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), JSON.stringify(file));
|
||||
const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', PLATFORM, '--run-url', url]);
|
||||
expect([r.status, r.err]).toEqual([EXIT.ok, expect.any(String)]);
|
||||
expect([r.status, r.err]).toEqual([EXIT.ok, expect.stringContaining('origin is not a github.com repository')]);
|
||||
expect(r.err).toContain(`${PLATFORM} was recorded without run verification`);
|
||||
const viaRun = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--run', '200', '--run', '201', '--allow-repo-commands']);
|
||||
expect([viaRun.status, viaRun.err]).toEqual([EXIT.fail, expect.stringContaining('origin is not a github.com repository')]);
|
||||
}, 120_000);
|
||||
|
||||
test('a lane the base profiles never falls back to an unverified record when the GitHub origin cannot be read', async () => {
|
||||
const repo = fixture({ run_profiles: PROFILES, remote_gate_runs: GATE_RUNS });
|
||||
const file = await pregateAt(repo);
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), JSON.stringify(file));
|
||||
const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--run-url', 'https://github.com/fx/fx/actions/runs/200']);
|
||||
expect([r.status, r.err]).toEqual([EXIT.fail, expect.stringContaining(`the base branch declares a run profile for ${LANE}, so it clears only with --run`)]);
|
||||
expect(JSON.parse(fs.readFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), 'utf8')).requires_remote[0].receipt).toBeNull();
|
||||
}, 120_000);
|
||||
|
||||
test('offline verify refuses a run receipt recorded for another tree', async () => {
|
||||
|
||||
@@ -144,12 +144,16 @@ describe('gstack-pregate with a user-owned policy', () => {
|
||||
expect(invalid.err).toContain(`fix: edit ${userPolicy} directly`);
|
||||
expect(invalid.err).not.toContain('.gstack/pregate.json has');
|
||||
|
||||
for (const [key, value] of [['sealed', { paths: ['evals/**'] }], ['price_file', 'evals/calls.json']] as const) {
|
||||
const profile = { workflow: 'test.yml', events: ['push'], jobs: ['full-suite'], artifact: 'full-suite-tree' };
|
||||
for (const [key, value] of [['sealed', { paths: ['evals/**'] }], ['price_file', 'evals/calls.json'], ['run_profiles', { test: profile }]] as const) {
|
||||
writePolicy(userPolicy, { [key]: value });
|
||||
const r = run();
|
||||
expect(r.status).toBe(EXIT.refused);
|
||||
expect(r.err).toContain(`covers gstack-pregate run only; ${key}`);
|
||||
}
|
||||
// An empty run_profiles is the documented default, not a policy, so it is accepted.
|
||||
writePolicy(userPolicy, { run_profiles: {}, local: LOCAL_ALL });
|
||||
expect(run().err).not.toContain('PREGATE_CONFIG_INVALID');
|
||||
// A null price_file is the documented default, not a policy, so it is accepted.
|
||||
writePolicy(userPolicy, { price_file: null, local: LOCAL_ALL });
|
||||
expect(run().err).not.toContain('PREGATE_CONFIG_INVALID');
|
||||
|
||||
@@ -91,6 +91,10 @@ describe('verifyRun', () => {
|
||||
expect(reason(world({ others: [newer('in_progress', null)] }))).toBe('newer_run_vetoes');
|
||||
expect(reason(world({ others: [newer('completed', 'success')] }))).toBe('ok');
|
||||
expect(reason(world({ others: [{ ...newer('completed', 'failure'), created_at: '2026-10-29T09:00:00Z' }] }))).toBe('ok');
|
||||
// A re-run keeps its run's created_at; its newest attempt started after the candidate, so its red result still vetoes.
|
||||
expect(reason(world({ others: [{ ...newer('completed', 'failure'), created_at: '2026-10-29T09:00:00Z', run_started_at: '2026-10-29T11:00:00Z' }] }))).toBe('newer_run_vetoes');
|
||||
// Re-running the candidate itself does not hide a failure that started after it was first created.
|
||||
expect(reason(world({ run: { ...w.run, run_started_at: '2026-10-29T12:00:00Z' }, others: [newer('completed', 'failure')] }))).toBe('newer_run_vetoes');
|
||||
});
|
||||
|
||||
test('a newer failure on another head the consumer names (same tree, the lane\'s own head) vetoes too', () => {
|
||||
@@ -117,7 +121,7 @@ describe('verifyRun', () => {
|
||||
describe('profiles, coverage and receipts', () => {
|
||||
test('runProfileErrors accepts a well-formed pair and names every malformed field', () => {
|
||||
expect(runProfileErrors({ test: PROFILE, e2e: { ...PROFILE, workflow: 'e2e.yml', jobs: ['e2e-full-suite'], artifact: 'e2e-full-suite-tree', os: 'Linux', max_age_hours: 12 } }, { profiles: ['test', 'e2e'], inventory: 'bash scripts/pregate-remote-gate.sh --list' })).toEqual([]);
|
||||
const errors = runProfileErrors({ bad: { workflow: '../x.yml', events: ['schedule'], jobs: [], artifact: '', max_age_hours: 0, os: 'BeOS', extra: 1 } }, { profiles: ['missing'], inventory: 'a\nb' }).map(e => e.path);
|
||||
const errors = runProfileErrors({ bad: { workflow: '../x.yml', events: ['pull_request'], jobs: [], artifact: '', max_age_hours: 0, os: 'BeOS', extra: 1 } }, { profiles: ['missing'], inventory: 'a\nb' }).map(e => e.path);
|
||||
expect(errors).toEqual(expect.arrayContaining(['run_profiles["bad"].extra', 'run_profiles["bad"].workflow', 'run_profiles["bad"].events', 'run_profiles["bad"].jobs', 'run_profiles["bad"].artifact', 'run_profiles["bad"].max_age_hours', 'run_profiles["bad"].os', 'remote_gate_runs.profiles', 'remote_gate_runs.inventory']));
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user