Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Keep secrets out of the OK bug-lane and selector reader jobs (#5570)

Nick Gomezee4707d45862
diff --git a/.github/scripts/bug-lane.mjs b/.github/scripts/bug-lane.mjs
index 4317216c8..de088dfc8 100644
--- a/.github/scripts/bug-lane.mjs
+++ b/.github/scripts/bug-lane.mjs
@@ -1,7 +1,13 @@
import { execFileSync, spawnSync } from 'node:child_process';
import { appendFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
-import { realGit } from '../../scripts/compute-stable-version.mjs';
+import {
+ parseBumpVerdicts,
+ realGit,
+ recordBumpVerdicts,
+ serializeBumpVerdicts,
+ withBumpVerdicts,
+} from '../../scripts/compute-stable-version.mjs';
import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';
import { makeResolveChangesetPrUrl, makeResolveIssuesForUrl } from './select-beta-to-promote.mjs';
@@ -152,12 +158,19 @@ export function makeIsInStable(stable, git = (args) => spawnSync('git', args, {
};
}
-function realPendingChangesets() {
- const ids = realGit.changesetIds('HEAD');
+export function readPendingBumps(git) {
+ const verdicts = new Map();
+ const reading = recordBumpVerdicts(git, verdicts);
+ for (const id of git.changesetIds('HEAD')) reading.bumpTypeOf('HEAD', id);
+ return verdicts;
+}
+
+function realPendingChangesets(git) {
+ const ids = git.changesetIds('HEAD');
const entries = [];
for (const id of ids) {
- const bump = realGit.bumpTypeOf('HEAD', id);
+ const bump = git.bumpTypeOf('HEAD', id);
const line = runGit([
'log',
'--diff-filter=A',
@@ -173,7 +186,24 @@ function realPendingChangesets() {
return entries;
}
+function readBumpsMain() {
+ const verdicts = readPendingBumps(realGit);
+ console.log(`bug-lane: read the bump of ${verdicts.size} pending changeset(s).`);
+ if (process.env.GITHUB_OUTPUT) {
+ appendFileSync(process.env.GITHUB_OUTPUT, `bump_verdicts=${serializeBumpVerdicts(verdicts)}\n`);
+ }
+}
+
async function main() {
+ if (process.argv[2] === '--read-bumps') {
+ readBumpsMain();
+ return;
+ }
+
+ const git =
+ process.env.BUMP_VERDICTS === undefined
+ ? realGit
+ : withBumpVerdicts(realGit, parseBumpVerdicts(process.env.BUMP_VERDICTS));
const stable = realNewestStableTag();
if (!stable) {
console.log('::notice::bug-lane: no stable tag exists yet; nothing to point-release over.');
@@ -182,7 +212,7 @@ async function main() {
}
const result = await evaluateBugLane({
- pendingChangesets: realPendingChangesets(),
+ pendingChangesets: realPendingChangesets(git),
isInStable: makeIsInStable(stable),
resolveChangesetPrUrl: makeResolveChangesetPrUrl(process.env.LINK_REPO || DEFAULT_LINK_REPO),
resolveIssuesForUrl: makeResolveIssuesForUrl(process.env.LINEAR_API_KEY),
diff --git a/.github/scripts/bug-lane.test.mjs b/.github/scripts/bug-lane.test.mjs
index ab6b7f12d..4d96241fb 100644
--- a/.github/scripts/bug-lane.test.mjs
+++ b/.github/scripts/bug-lane.test.mjs
@@ -1,10 +1,11 @@
import { execFileSync, spawnSync } from 'node:child_process';
-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
-import { afterAll, beforeAll, describe, expect, test } from 'vitest';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';
-import { evaluateBugLane, makeIsInStable } from './bug-lane.mjs';
+import { evaluateBugLane, makeIsInStable, readPendingBumps } from './bug-lane.mjs';
const FIX_A = 'a'.repeat(40);
const FIX_B = 'b'.repeat(40);
@@ -202,3 +203,192 @@ describe('makeIsInStable', () => {
expect(() => makeIsInStable('v1.0.0', broken)(laterOnMain)).toThrow(/merge-base/);
});
});
+
+describe('readPendingBumps, run by the job that holds no credential', () => {
+ test('reads every changeset pending at HEAD, keyed by blob, and reads nothing else', () => {
+ const reads = [];
+ const git = {
+ changesetIds: (sha) => (sha === 'HEAD' ? ['fix-crash', 'new-thing'] : []),
+ changesetBlobs: (sha) =>
+ new Map(sha === 'HEAD' ? [['fix-crash', 'blob-fix'], ['new-thing', 'blob-feat']] : []),
+ bumpTypeOf: (sha, id) => {
+ reads.push(`${sha}:${id}`);
+ return id === 'new-thing' ? 'minor' : 'patch';
+ },
+ };
+ expect(Object.fromEntries(readPendingBumps(git))).toEqual({ 'blob-fix': 'patch', 'blob-feat': 'minor' });
+ expect(reads).toEqual(['HEAD:fix-crash', 'HEAD:new-thing']);
+ });
+
+ test('an empty pile reads as no verdicts', () => {
+ const git = {
+ changesetIds: () => [],
+ changesetBlobs: () => new Map(),
+ bumpTypeOf: () => {
+ throw new Error('nothing to read');
+ },
+ };
+ expect(readPendingBumps(git).size).toBe(0);
+ });
+});
+
+describe('the bug-lane entry points the two jobs run', () => {
+ const SCRIPT = realpathSync(fileURLToPath(new URL('./bug-lane.mjs', import.meta.url)));
+ const OK_ROOT = join(dirname(SCRIPT), '..', '..');
+ const COPIED = [
+ '.github/scripts/bug-lane.mjs',
+ '.github/scripts/select-beta-to-promote.mjs',
+ 'scripts/compute-stable-version.mjs',
+ 'scripts/compute-next-beta.mjs',
+ 'scripts/git-clean-env.mjs',
+ ];
+ const dirs = [];
+ afterEach(() => {
+ while (dirs.length) rmSync(dirs.pop(), { recursive: true, force: true });
+ });
+ const scratch = (prefix) => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
+ dirs.push(dir);
+ return dir;
+ };
+ const { BUMP_VERDICTS: _verdicts, LINEAR_API_KEY: _key, LINK_REPO: _repo, ...cleanEnv } = gitCleanEnv();
+ const git = (cwd, ...args) =>
+ execFileSync('git', ['-c', 'user.name=t', '-c', '[email protected]', '-c', 'commit.gpgsign=false', ...args], {
+ cwd,
+ encoding: 'utf8',
+ env: gitCleanEnv(),
+ }).trim();
+ const pendingRepo = () => {
+ const root = scratch('bug-lane-entry-');
+ const commit = (id, type, subject) => {
+ mkdirSync(join(root, '.changeset'), { recursive: true });
+ writeFileSync(join(root, '.changeset', `${id}.md`), `---\n"@inkeep/open-knowledge": ${type}\n---\n\n${id}\n`);
+ git(root, 'add', '-A');
+ git(root, 'commit', '-q', '-m', subject);
+ return git(root, 'rev-parse', 'HEAD');
+ };
+ git(root, 'init', '-q', '-b', 'main');
+ writeFileSync(join(root, 'README.md'), 'stable\n');
+ git(root, 'add', '-A');
+ git(root, 'commit', '-q', '-m', 'stable');
+ git(root, 'tag', 'v1.0.0');
+ const fix = commit('fix-crash', 'patch', 'fix: stop the crash (#101)');
+ const feat = commit('new-thing', 'minor', 'feat: a new thing (#102)');
+ return {
+ root,
+ fix,
+ feat,
+ blobs: {
+ fix: git(root, 'rev-parse', 'HEAD:.changeset/fix-crash.md'),
+ feat: git(root, 'rev-parse', 'HEAD:.changeset/new-thing.md'),
+ },
+ };
+ };
+ const isolatedScript = () => {
+ const dir = scratch('bug-lane-no-node-modules-');
+ for (const file of COPIED) {
+ mkdirSync(dirname(join(dir, file)), { recursive: true });
+ copyFileSync(join(OK_ROOT, file), join(dir, file));
+ }
+ return join(dir, '.github', 'scripts', 'bug-lane.mjs');
+ };
+ const linearStub = () => {
+ const dir = scratch('bug-lane-linear-');
+ const preload = join(dir, 'linear.mjs');
+ const calls = join(dir, 'calls');
+ writeFileSync(
+ preload,
+ [
+ "import { appendFileSync } from 'node:fs';",
+ 'globalThis.fetch = async (url, init) => {',
+ ' appendFileSync(process.env.LINEAR_CALLS, `${JSON.stringify({ url: String(url), authorization: init.headers.authorization, body: JSON.parse(init.body) })}\\n`);',
+ " return new Response(JSON.stringify({ data: { attachmentsForURL: { nodes: [{ issue: { identifier: 'PRD-1', labels: { nodes: [{ name: 'Bug' }] } } }] } } }), { status: 200 });",
+ '};',
+ '',
+ ].join('\n'),
+ );
+ writeFileSync(calls, '');
+ return { preload, calls, read: () => readFileSync(calls, 'utf8').split('\n').filter(Boolean).map((line) => JSON.parse(line)) };
+ };
+ const run = (script, cwd, { args = [], env = {}, preload } = {}) => {
+ const output = join(scratch('bug-lane-output-'), 'github-output');
+ writeFileSync(output, '');
+ const res = spawnSync(process.execPath, [...(preload ? ['--import', preload] : []), script, ...args], {
+ cwd,
+ encoding: 'utf8',
+ env: { ...cleanEnv, GITHUB_OUTPUT: output, ...env },
+ });
+ return { ...res, output: readFileSync(output, 'utf8') };
+ };
+
+ test('--read-bumps writes the bump of every pending changeset, keyed by blob id', () => {
+ const { root, blobs } = pendingRepo();
+ const res = run(SCRIPT, root, { args: ['--read-bumps'] });
+ expect(res.status, res.stderr).toBe(0);
+ expect(res.output).toBe(`bump_verdicts={"${blobs.fix}":"patch","${blobs.feat}":"minor"}\n`);
+ });
+
+ test('with the reader job verdicts and no node_modules it makes the same Linear queries and writes the same outputs', () => {
+ const { root, fix } = pendingRepo();
+ const verdicts = run(SCRIPT, root, { args: ['--read-bumps'] }).output.trim().slice('bump_verdicts='.length);
+
+ const withReader = linearStub();
+ const reader = run(SCRIPT, root, {
+ env: { LINEAR_API_KEY: 'placeholder-linear-key', LINEAR_CALLS: withReader.calls },
+ preload: withReader.preload,
+ });
+ expect(reader.status, reader.stderr).toBe(0);
+
+ const withoutReader = linearStub();
+ const verdictMode = run(isolatedScript(), root, {
+ env: { LINEAR_API_KEY: 'placeholder-linear-key', LINEAR_CALLS: withoutReader.calls, BUMP_VERDICTS: verdicts },
+ preload: withoutReader.preload,
+ });
+ expect(verdictMode.status, verdictMode.stderr).toBe(0);
+
+ expect(verdictMode.output).toBe(`fix_refs=${fix}\nstable=v1.0.0\nfix_tickets={"${fix}":["PRD-1"]}\n`);
+ expect(verdictMode.output).toBe(reader.output);
+ expect(withoutReader.read()).toEqual([
+ {
+ url: 'https://api.linear.app/graphql',
+ authorization: 'placeholder-linear-key',
+ body: expect.objectContaining({ variables: { url: 'https://github.com/inkeep/agents-private/pull/101' } }),
+ },
+ ]);
+ expect(withoutReader.read()).toEqual(withReader.read());
+ expect(verdictMode.stdout).toContain('"feat: a new thing (#102)" -> not-patch-only');
+ });
+
+ test('without verdicts the same isolated copy cannot load the reader, so the run above proves it never tried', () => {
+ const { root } = pendingRepo();
+ const res = run(isolatedScript(), root);
+ expect(res.status).toBe(1);
+ expect(res.stderr).toMatch(/@changesets\/cli/);
+ expect(res.output).toBe('');
+ });
+
+ test('a changeset the reader job did not read stops the tick before Linear or any output', () => {
+ const { root, blobs } = pendingRepo();
+ const linear = linearStub();
+ const res = run(isolatedScript(), root, {
+ env: {
+ LINEAR_API_KEY: 'placeholder-linear-key',
+ LINEAR_CALLS: linear.calls,
+ BUMP_VERDICTS: JSON.stringify({ [blobs.fix]: 'patch' }),
+ },
+ preload: linear.preload,
+ });
+ expect(res.status).toBe(1);
+ expect(res.stderr).toMatch(/no bump verdict for \.changeset\/new-thing\.md/);
+ expect(res.output).toBe('');
+ expect(linear.read()).toEqual([]);
+ });
+
+ test('an empty BUMP_VERDICTS stops the tick with an error naming the read-bumps output', () => {
+ const { root } = pendingRepo();
+ const res = run(isolatedScript(), root, { env: { BUMP_VERDICTS: '' } });
+ expect(res.status).toBe(1);
+ expect(res.stderr).toMatch(/BUMP_VERDICTS is empty: the read-bumps job wrote no bump_verdicts output/);
+ expect(res.output).toBe('');
+ });
+});
diff --git a/.github/scripts/evaluate-smoke-alarm.mjs b/.github/scripts/evaluate-smoke-alarm.mjs
index 992ff6b27..8bbca28f1 100644
--- a/.github/scripts/evaluate-smoke-alarm.mjs
+++ b/.github/scripts/evaluate-smoke-alarm.mjs
@@ -9,6 +9,7 @@ export const CONSECUTIVE_NON_PASS_THRESHOLD = 3;
export const STALE_FAST_TIER_WINDOW_DAYS = 14;
const SMOKE_JOB_NAME = "Smoke the fast-tier candidate's DMG";
+const DISPATCH_JOB_NAME = 'Dispatch the smoke-proven fast-tier candidate';
const EVALUATE_JOB_NAME = 'Evaluate 24h soak + business-hours gate';
const REMEMBERED_FAILURE_STEP_NAME =
'Skip the fast-tier candidate whose DMG already failed the smoke';
@@ -74,8 +75,12 @@ export function buildHistory({ runs, jobsForRun }) {
) {
return { at: run.createdAt, qualified: false, verdict: null, promoted: false };
}
- const dispatch = (smoke.steps ?? []).find((s) => s.name === DISPATCH_STEP_NAME);
- const receipt = (smoke.steps ?? []).find((s) => s.name === DISPATCH_RECEIPT_STEP_NAME);
+ const steps = [
+ ...(smoke.steps ?? []),
+ ...(jobs.find((j) => j.name === DISPATCH_JOB_NAME)?.steps ?? []),
+ ];
+ const dispatch = steps.find((s) => s.name === DISPATCH_STEP_NAME);
+ const receipt = steps.find((s) => s.name === DISPATCH_RECEIPT_STEP_NAME);
if (receipt?.conclusion === 'skipped' && dispatch?.conclusion === 'success') {
return { at: run.createdAt, qualified: false, verdict: null, promoted: false };
}
@@ -87,8 +92,7 @@ export function buildHistory({ runs, jobsForRun }) {
promoted,
failureStage: promoted
? null
- : ((smoke.steps ?? []).find((s) => s.conclusion === 'failure')?.name ??
- SMOKE_OR_DISPATCH_STAGE),
+ : (steps.find((s) => s.conclusion === 'failure')?.name ?? SMOKE_OR_DISPATCH_STAGE),
};
});
return resolveRememberedSkips(history, runs);
diff --git a/.github/scripts/evaluate-smoke-alarm.test.mjs b/.github/scripts/evaluate-smoke-alarm.test.mjs
index 7de98ef40..967f2b648 100644
--- a/.github/scripts/evaluate-smoke-alarm.test.mjs
+++ b/.github/scripts/evaluate-smoke-alarm.test.mjs
@@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, test } from 'vitest';
+import { parse } from 'yaml';
import {
alarmObservation,
buildHistory,
@@ -574,3 +575,110 @@ describe('a remembered smoke failure stays visible to the alarm', () => {
});
});
});
+
+describe('a fast-tier dispatch that runs in its own job', () => {
+ const runs = [{ databaseId: 1, createdAt: daysAgo(1) }];
+ const smoked = {
+ name: "Smoke the fast-tier candidate's DMG",
+ status: 'completed',
+ conclusion: 'success',
+ steps: [
+ { name: "Download the candidate's DMG", conclusion: 'success' },
+ { name: 'Smoke the DMG', conclusion: 'success' },
+ ],
+ };
+ const dispatchJob = (conclusion, steps) => ({
+ name: 'Dispatch the smoke-proven fast-tier candidate',
+ status: 'completed',
+ conclusion,
+ steps,
+ });
+ const entryFor = (...jobs) => buildHistory({ runs, jobsForRun: () => jobs })[0];
+
+ test('a dispatch job whose dispatch and receipt succeeded is a pass', () => {
+ const jobs = [
+ smoked,
+ dispatchJob('success', [
+ { name: 'Dispatch promote-stable for the smoke-proven candidate', conclusion: 'success' },
+ { name: 'Record a successful fast-tier dispatch', conclusion: 'success' },
+ ]),
+ ];
+ expect(entryFor(...jobs)).toEqual({ at: daysAgo(1), qualified: true, verdict: 'pass', promoted: true, failureStage: null });
+ });
+
+ test('a dispatch job skipped after a non-pass smoke is a qualified non-pass at the smoke stage', () => {
+ expect(entryFor(smoked, dispatchJob('skipped', []))).toEqual({
+ at: daysAgo(1),
+ qualified: true,
+ verdict: 'non-pass',
+ promoted: false,
+ failureStage: 'Smoke or dispatch',
+ });
+ });
+
+ test('a dispatch the in-flight guard skipped did not qualify, as when the smoke job dispatched', () => {
+ const jobs = [
+ smoked,
+ dispatchJob('success', [
+ { name: 'Dispatch promote-stable for the smoke-proven candidate', conclusion: 'success' },
+ { name: 'Record a successful fast-tier dispatch', conclusion: 'skipped' },
+ ]),
+ ];
+ expect(entryFor(...jobs)).toMatchObject({ qualified: false, verdict: null, promoted: false });
+ });
+
+ test('a failed dispatch names the dispatch step as the failing stage', () => {
+ const jobs = [
+ smoked,
+ dispatchJob('failure', [
+ { name: 'Dispatch promote-stable for the smoke-proven candidate', conclusion: 'failure' },
+ { name: 'Record a successful fast-tier dispatch', conclusion: 'skipped' },
+ ]),
+ ];
+ expect(entryFor(...jobs)).toMatchObject({
+ qualified: true,
+ verdict: 'non-pass',
+ failureStage: 'Dispatch promote-stable for the smoke-proven candidate',
+ });
+ });
+
+ test('the step that reports a failed dispatch leaves the failing stage on the dispatch step', () => {
+ const jobs = [
+ smoked,
+ dispatchJob('failure', [
+ { name: 'Dispatch promote-stable for the smoke-proven candidate', conclusion: 'failure' },
+ { name: 'Record a successful fast-tier dispatch', conclusion: 'skipped' },
+ { name: 'Report a failed fast-tier dispatch', conclusion: 'success' },
+ ]),
+ ];
+ const entry = entryFor(...jobs);
+ expect(entry).toEqual({
+ at: daysAgo(1),
+ qualified: true,
+ verdict: 'non-pass',
+ promoted: false,
+ failureStage: 'Dispatch promote-stable for the smoke-proven candidate',
+ });
+ expect(alarmObservation({ history: [entry, entry, entry], nowMs: NOW, armed: true })).toMatchObject({
+ alarm: true,
+ incident: 'Dispatch promote-stable for the smoke-proven candidate',
+ });
+ });
+
+ test('the workflow puts the dispatch and its receipt in that job, gated on a passing smoke', () => {
+ const { jobs } = parse(
+ readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'workflows', 'select-beta-to-promote.yml'), 'utf8'),
+ );
+ const named = (name) => Object.values(jobs).filter((job) => job.name === name);
+ const [smoke] = named("Smoke the fast-tier candidate's DMG");
+ const [dispatch] = named('Dispatch the smoke-proven fast-tier candidate');
+ expect(named('Dispatch the smoke-proven fast-tier candidate')).toHaveLength(1);
+ expect(dispatch.if).toBe("needs.smoke-fast-tier-candidate.outputs.verdict == 'pass'");
+ const stepNames = (job) => job.steps.map((step) => step.name);
+ expect(stepNames(dispatch)).toEqual(
+ expect.arrayContaining(['Dispatch promote-stable for the smoke-proven candidate', 'Record a successful fast-tier dispatch']),
+ );
+ expect(stepNames(smoke)).not.toContain('Dispatch promote-stable for the smoke-proven candidate');
+ expect(stepNames(smoke)).not.toContain('Record a successful fast-tier dispatch');
+ });
+});
diff --git a/.github/scripts/release-alert-state.test.mjs b/.github/scripts/release-alert-state.test.mjs
index 788eb31a7..b3809919b 100644
--- a/.github/scripts/release-alert-state.test.mjs
+++ b/.github/scripts/release-alert-state.test.mjs
@@ -1,11 +1,12 @@
import { execFile } from 'node:child_process';
-import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { createServer } from 'node:http';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { promisify } from 'node:util';
-import { afterEach, expect, test } from 'vitest';
+import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
+import { parse } from 'yaml';
import { notifyReleaseIncident } from './release-alert-state.mjs';
const dirs = [];
@@ -131,3 +132,192 @@ test('the CLI delivers through HTTP, persists success, suppresses repeats and re
);
}
});
+
+describe('the alarm hands the acknowledgement from the job that restores it to the job that pages', () => {
+ const OK_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
+ const { jobs } = parse(readFileSync(join(OK_ROOT, '.github', 'workflows', 'select-beta-to-promote.yml'), 'utf8'));
+ const stepRun = (job, name) => {
+ const found = jobs[job].steps.filter((step) => step.name === name);
+ if (found.length !== 1) throw new Error(`select-beta-to-promote.yml#${job} has ${found.length} steps named ${name}`);
+ return found[0].run;
+ };
+ const handOn = stepRun('read-smoke-incident', 'Hand on the acknowledgement state');
+ const write = stepRun('page-smoke-incident', 'Write the handed-over acknowledgement');
+ const page = stepRun('page-smoke-incident', 'Page the release channel');
+
+ const readOutputs = (file) => {
+ const lines = readFileSync(file, 'utf8').split('\n');
+ const outputs = {};
+ for (let i = 0; i < lines.length; i += 1) {
+ const line = lines[i];
+ if (line === '') continue;
+ const equals = line.indexOf('=');
+ const heredoc = line.indexOf('<<');
+ if (heredoc !== -1 && (equals === -1 || heredoc < equals)) {
+ const delimiter = line.slice(heredoc + 2);
+ const value = [];
+ for (i += 1; lines[i] !== delimiter; i += 1) {
+ if (i >= lines.length) throw new Error(`no closing ${delimiter}`);
+ value.push(lines[i]);
+ }
+ outputs[line.slice(0, heredoc)] = value.join('\n');
+ } else {
+ outputs[line.slice(0, equals)] = line.slice(equals + 1);
+ }
+ }
+ return outputs;
+ };
+
+ let scratch;
+ let server;
+ let webhook;
+ const received = [];
+ beforeAll(async () => {
+ scratch = mkdtempSync(join(tmpdir(), 'release-alert-handover-'));
+ server = createServer(async (request, response) => {
+ let body = '';
+ for await (const chunk of request) body += chunk;
+ received.push(JSON.parse(body).text);
+ response.end('ok');
+ });
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
+ webhook = `http://127.0.0.1:${server.address().port}/slack`;
+ });
+ afterAll(async () => {
+ rmSync(scratch, { recursive: true, force: true });
+ server.closeAllConnections();
+ await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
+ });
+
+ let runs = 0;
+ const runStep = async (script, env) => {
+ const dir = join(scratch, `step-${(runs += 1)}`);
+ mkdirSync(dir);
+ const file = join(dir, 'step.sh');
+ const output = join(dir, 'github-output');
+ writeFileSync(file, script);
+ writeFileSync(output, '');
+ const { SLACK_RELEASES_WEBHOOK_URL: _r, SLACK_WEBHOOK_URL: _s, GITHUB_OUTPUT: _o, NODE_OPTIONS: _n, ...base } = process.env;
+ const { status, stderr } = await new Promise((resolve) => {
+ execFile(
+ 'bash',
+ ['--noprofile', '--norc', '-eo', 'pipefail', file],
+ {
+ cwd: OK_ROOT,
+ timeout: 20_000,
+ env: { ...base, PATH: `${dirname(process.execPath)}:${base.PATH}`, GITHUB_OUTPUT: output, ...env },
+ },
+ (error, _stdout, err) => resolve({ status: error ? (error.code ?? error.signal) : 0, stderr: err }),
+ );
+ });
+ return { status, stderr, outputs: status === 0 ? readOutputs(output) : {} };
+ };
+
+ const pageWith = async (statePath, alarm) => {
+ received.length = 0;
+ const res = await runStep(page, {
+ SLACK_RELEASES_WEBHOOK_URL: webhook,
+ GITHUB_SERVER_URL: 'https://github.com',
+ GITHUB_REPOSITORY: 'inkeep/open-knowledge',
+ GITHUB_RUN_ID: '1',
+ REASONS: alarm.reasons,
+ ALERT_INCIDENT: alarm.incident,
+ ALERT_STATE_PATH: statePath,
+ });
+ const saved = existsSync(statePath) && !lstatSync(statePath).isDirectory() ? readFileSync(statePath, 'utf8') : null;
+ return { paged: res.status === 0, notified: res.outputs.notified ?? null, sent: [...received], saved, stderr: res.stderr };
+ };
+
+ const singleJob = (restored, alarm) => pageWith(restored, alarm);
+ const splitJobs = async (restored, alarm) => {
+ const handed = await runStep(handOn, { ALERT_STATE_PATH: restored });
+ if (handed.status !== 0) return { readerFailed: true };
+ const statePath = join(scratch, `paging-${(runs += 1)}.json`);
+ const written = await runStep(write, { ALERT_STATE: handed.outputs.state, ALERT_STATE_PATH: statePath });
+ if (written.status !== 0) throw new Error(`the write step failed: ${written.stderr}`);
+ return pageWith(statePath, alarm);
+ };
+
+ const now = Date.now();
+ const hour = 3_600_000;
+ const incident = { incident: 'Smoke or dispatch', reasons: '3 consecutive fast-tier attempts did not complete successfully' };
+ const recovery = { incident: '', reasons: '' };
+ const cases = [
+ { name: 'no acknowledgement in the cache', state: undefined, alarm: incident },
+ { name: 'the same incident acknowledged an hour ago', state: { incident: 'Smoke or dispatch', notifiedAt: now - hour }, alarm: incident },
+ { name: 'the same incident acknowledged a day ago', state: { incident: 'Smoke or dispatch', notifiedAt: now - 25 * hour }, alarm: incident },
+ { name: 'a different incident acknowledged', state: { incident: 'Download the candidate\'s DMG', notifiedAt: now - hour }, alarm: incident },
+ { name: 'an open incident that has now recovered', state: { incident: 'Smoke or dispatch', notifiedAt: now - hour }, alarm: recovery },
+ { name: 'a recovery already acknowledged', state: { incident: null, notifiedAt: now - hour }, alarm: recovery },
+ { name: 'an acknowledgement with extra keys', state: { incident: 'Smoke or dispatch', notifiedAt: now - hour, extra: 'x' }, alarm: incident },
+ { name: 'a pretty-printed acknowledgement', raw: `{\n "incident": "Smoke or dispatch",\n "notifiedAt": ${now - hour}\n}\n`, alarm: incident },
+ { name: 'a garbled acknowledgement', raw: '{"incident":', alarm: incident },
+ { name: 'an empty acknowledgement', raw: '', alarm: incident },
+ { name: 'an acknowledgement of the wrong shape', state: { incident: 5, notifiedAt: 0 }, alarm: incident },
+ { name: 'an acknowledgement with no timestamp', state: { incident: 'Smoke or dispatch' }, alarm: incident },
+ { name: 'an acknowledgement that is not an object', raw: '[1,2]', alarm: incident },
+ ];
+
+ test.each(cases)('$name pages exactly as the single job did', async ({ state, raw, alarm }) => {
+ const restored = join(scratch, `restored-${(runs += 1)}.json`);
+ if (state !== undefined) writeFileSync(restored, JSON.stringify(state));
+ if (raw !== undefined) writeFileSync(restored, raw);
+ const before = await singleJob(restored, alarm);
+ if (state !== undefined) writeFileSync(restored, JSON.stringify(state));
+ if (raw !== undefined) writeFileSync(restored, raw);
+ if (state === undefined && raw === undefined) rmSync(restored, { force: true });
+ const after = await splitJobs(restored, alarm);
+ const fresh = (saved) => (saved === null ? null : { ...JSON.parse(saved), notifiedAt: JSON.parse(saved).notifiedAt >= now ? 'now' : JSON.parse(saved).notifiedAt });
+ expect({ ...after, saved: after.paged ? fresh(after.saved) : null, stderr: undefined }).toEqual({
+ ...before,
+ saved: before.paged ? fresh(before.saved) : null,
+ stderr: undefined,
+ });
+ if (!before.paged) expect(after.stderr).toBe(before.stderr);
+ });
+
+ test('the cases cover a page, a reminder, a recovery, silence and every rejection', async () => {
+ const outcomes = [];
+ for (const { name, state, raw, alarm } of cases) {
+ const restored = join(scratch, `coverage-${(runs += 1)}.json`);
+ if (state !== undefined) writeFileSync(restored, JSON.stringify(state));
+ if (raw !== undefined) writeFileSync(restored, raw);
+ const { paged, sent, stderr } = await splitJobs(restored, alarm);
+ outcomes.push([name, paged ? (sent.length > 0 ? [...sent[0]][0] : 'silent') : /Invalid release alert state/.test(stderr) ? 'invalid' : 'unparseable']);
+ }
+ expect(Object.fromEntries(outcomes)).toEqual({
+ 'no acknowledgement in the cache': '🚨',
+ 'the same incident acknowledged an hour ago': 'silent',
+ 'the same incident acknowledged a day ago': '🚨',
+ 'a different incident acknowledged': '🚨',
+ 'an open incident that has now recovered': 'βœ…',
+ 'a recovery already acknowledged': 'silent',
+ 'an acknowledgement with extra keys': 'silent',
+ 'a pretty-printed acknowledgement': 'silent',
+ 'a garbled acknowledgement': 'unparseable',
+ 'an empty acknowledgement': 'unparseable',
+ 'an acknowledgement of the wrong shape': 'invalid',
+ 'an acknowledgement with no timestamp': 'invalid',
+ 'an acknowledgement that is not an object': 'invalid',
+ });
+ });
+
+ test('a dangling link where the acknowledgement should be reads as no acknowledgement in both shapes', async () => {
+ const restored = join(scratch, `dangling-${(runs += 1)}.json`);
+ const target = join(scratch, `nowhere-${runs}.json`);
+ symlinkSync(target, restored);
+ const before = await singleJob(restored, incident);
+ rmSync(target, { force: true });
+ const after = await splitJobs(restored, incident);
+ expect(after.sent).toEqual(before.sent);
+ expect(after.sent).toHaveLength(1);
+ });
+
+ test('a directory where the acknowledgement should be pages nothing in either shape', async () => {
+ const restored = join(scratch, `directory-${(runs += 1)}`);
+ mkdirSync(restored);
+ const before = await singleJob(restored, incident);
+ expect(before).toMatchObject({ paged: false, sent: [] });
+ expect(await splitJobs(restored, incident)).toEqual({ readerFailed: true });
+ });
+});
diff --git a/.github/scripts/release-cascade-shape.test.mjs b/.github/scripts/release-cascade-shape.test.mjs
index 94f36d58e..de0bb29a0 100644
--- a/.github/scripts/release-cascade-shape.test.mjs
+++ b/.github/scripts/release-cascade-shape.test.mjs
@@ -1040,21 +1040,40 @@ describe('every release-pipeline post prefers the releases webhook', () => {
});
test('fast-tier attempts have one incident reporter and save only successful acknowledgements', () => {
- const refusal = workflowStep(
- selectBeta,
- 'select-beta-to-promote.yml',
- 'Record a fast-tier refusal',
- );
- expect(refusal).not.toContain('curl');
- expect(refusal).not.toContain('SLACK_WEBHOOK_URL');
- expect(stepAfter(selectBeta, 'Page the release channel')).toContain(
- "if: steps.alarm.outputs.observed == 'true'",
+ const { jobs } = parse(selectBeta);
+ const attemptJobs = ['smoke-fast-tier-candidate', 'dispatch-fast-tier-candidate'];
+ const reports = attemptJobs.flatMap((id) =>
+ jobs[id].steps.filter((step) => /\bfailure\(\)/.test(step.if ?? '')).map((step) => `${id}: ${step.name}`),
);
+ expect(reports).toEqual([
+ 'smoke-fast-tier-candidate: Record a fast-tier refusal',
+ 'dispatch-fast-tier-candidate: Report a failed fast-tier dispatch',
+ ]);
+ for (const id of attemptJobs) {
+ for (const step of jobs[id].steps) {
+ const text = JSON.stringify(step);
+ expect(text, `${id}: ${step.name}`).not.toContain('curl');
+ expect(text, `${id}: ${step.name}`).not.toMatch(/SLACK_\w*WEBHOOK_URL/);
+ }
+ }
+ for (const id of ['read-smoke-incident', 'page-smoke-incident']) {
+ expect(jobs[id].if, id).toBe("needs.aggregate-smoke-alarm.outputs.observed == 'true'");
+ }
expect(stepAfter(selectBeta, 'Remember the smoke incident acknowledgement')).toContain(
"if: steps.page.outcome == 'success' && steps.page.outputs.notified == 'true'",
);
});
+ test('a failed fast-tier dispatch reports that the smoke passed and nothing was dispatched', () => {
+ const [report] = parse(selectBeta).jobs['dispatch-fast-tier-candidate'].steps.filter(
+ (step) => step.name === 'Report a failed fast-tier dispatch',
+ );
+ expect(report.if).toBe('failure()');
+ expect(report.run).toMatch(/smoke passed for \$\{CANDIDATE\}, but the dispatch failed, so promote-stable was not dispatched/);
+ expect(report.run).toMatch(/smoke passed for \$\{CANDIDATE\}, but the dispatch failed and promote-stable was not dispatched/);
+ expect(report.run).not.toMatch(/refused|verdict=/);
+ });
+
test('a beta whose DMG failed the smoke is remembered by tag and not re-smoked on later ticks', () => {
const { jobs } = parse(selectBeta);
const step = (job, name) => {
@@ -1289,6 +1308,8 @@ describe('every job that reads changesets installs the Changesets reader first',
const VERDICT_MODE_SCRIPTS = new Set([
join(OK_ROOT, 'scripts', 'compute-stable-version.mjs'),
join(OK_ROOT, '.github', 'scripts', 'point-release-plan.mjs'),
+ join(OK_ROOT, '.github', 'scripts', 'bug-lane.mjs'),
+ join(OK_ROOT, '.github', 'scripts', 'select-beta-to-promote.mjs'),
]);
const readsChangesets = (step) => {
const readers = [...(step.run ?? '').matchAll(/[\w./-]+\.mjs\b/g)]
@@ -1309,11 +1330,11 @@ describe('every job that reads changesets installs the Changesets reader first',
test('the sweep finds every job that runs a version script', () => {
expect(readerJobs.map(({ job }) => job)).toEqual(
expect.arrayContaining([
- 'bug-lane.yml#bug-lane',
+ 'bug-lane.yml#read-bumps',
'point-release.yml#read-bumps',
'promote-stable.yml#read-bumps',
'release.yml#release',
- 'select-beta-to-promote.yml#evaluate',
+ 'select-beta-to-promote.yml#read-bumps',
]),
);
});
@@ -1627,6 +1648,315 @@ describe('the release App credential never shares a job with installed packages'
expect(step.with?.token, name).toBeUndefined();
}
});
+
+ describe('the Linear key, Slack webhooks and write tokens never share a job with installed packages', () => {
+ const readerWorkflows = {
+ 'bug-lane.yml': ['read-bumps'],
+ 'select-beta-to-promote.yml': ['read-bumps', 'smoke-fast-tier-candidate', 'read-smoke-incident'],
+ };
+ const PINNED_CACHE_SAVE = /^actions\/cache\/save@[0-9a-f]{40}$/;
+ const PINNED_CACHE_RESTORE = /^actions\/cache\/restore@[0-9a-f]{40}$/;
+ const extractsNothing = (step) =>
+ PINNED_CACHE_SAVE.test(step.uses ?? '') ||
+ (PINNED_CACHE_RESTORE.test(step.uses ?? '') && String(step.with?.['lookup-only']) === 'true');
+ const SETUP_NODE = /^actions\/setup-node@/;
+ const setupNodeRestoresNothing = (step) =>
+ step.with?.cache === undefined && /^false$/i.test(String(step.with?.['package-manager-cache']));
+ const routesOf = (job) => {
+ const kept = steps(job).filter((step) => !extractsNothing(step));
+ return [
+ ...packageRoutes(kept),
+ ...kept.filter((step) => SETUP_NODE.test(step.uses ?? '') && !setupNodeRestoresNothing(step)).map((step) => step.uses),
+ ];
+ };
+ const writesWith = (permissions) =>
+ permissions === undefined ||
+ permissions === 'write-all' ||
+ (typeof permissions === 'object' && Object.values(permissions).includes('write'));
+ const otherSecrets = (value) =>
+ expressions(value)
+ .map(({ expr }) => expr.replace(/\bsecrets\.GITHUB_TOKEN\b/g, ''))
+ .filter((expr) => /\bsecrets\b/.test(expr));
+ const holdsCredential = (workflow, job) =>
+ writesWith(job.permissions ?? workflow.permissions) ||
+ otherSecrets(job).length > 0 ||
+ otherSecrets(workflow.env ?? {}).length > 0;
+ const SANCTIONED_IF =
+ /^(?:always\(\) && )?needs\.smoke-fast-tier-candidate\.outputs\.verdict == '(?:pass|fail)'$/;
+ const readerOutputReads = (job, readers) => {
+ const others = new RegExp(
+ `\\bneeds\\.(?!(?:${readers.join('|')})\\.)[A-Za-z_][\\w-]*\\.outputs\\.[A-Za-z_][\\w-]*`,
+ 'g',
+ );
+ return expressions(job)
+ .filter(({ path, expr }) => {
+ if (!/\bneeds\b/.test(expr)) return false;
+ if (path.length === 1 && path[0] === 'if' && SANCTIONED_IF.test(expr)) return false;
+ if (path[0] === 'steps' && path[2] === 'env' && path[3] === 'BUMP_VERDICTS' && path.length === 4) {
+ return expr !== 'needs.read-bumps.outputs.bump_verdicts';
+ }
+ if (path[0] === 'steps' && path[2] === 'env' && path[3] === 'ALERT_STATE' && path.length === 4) {
+ return expr !== 'needs.read-smoke-incident.outputs.state';
+ }
+ return /\bneeds\b/.test(expr.replace(others, ''));
+ })
+ .map(({ path, expr }) => `${path.join('.')}: ${expr}`);
+ };
+ const all = Object.entries(readerWorkflows).flatMap(([file, readers]) => {
+ const workflow = parse(read(file));
+ return Object.entries(workflow.jobs).map(([id, job]) => ({ file, id, job, workflow, readers }));
+ });
+
+ test('the jobs with a package route or a cache extraction are exactly the reader jobs, one per role', () => {
+ for (const [file, readers] of Object.entries(readerWorkflows)) {
+ const installers = all.filter((j) => j.file === file && routesOf(j.job).length > 0).map((j) => j.id);
+ expect(installers, file).toEqual(readers);
+ }
+ });
+
+ test('a job with a package route or a cache extraction references no secret but GITHUB_TOKEN and holds no write scope', () => {
+ const installers = all.filter(({ job }) => routesOf(job).length > 0);
+ expect(installers.length).toBe(4);
+ for (const { file, id, job, workflow } of installers) {
+ expect(job.permissions, `${file}#${id}`).toBeDefined();
+ expect(writesWith(job.permissions), `${file}#${id}`).toBe(false);
+ expect(otherSecrets(job), `${file}#${id}`).toEqual([]);
+ expect(otherSecrets(workflow.env ?? {}), file).toEqual([]);
+ expect(holdsCredential(workflow, job), `${file}#${id}`).toBe(false);
+ }
+ });
+
+ test('every job that holds a credential has no package route and extracts no cache entry', () => {
+ const holders = all.filter(({ workflow, job }) => holdsCredential(workflow, job)).map(({ file, id }) => `${file}#${id}`);
+ expect(holders).toEqual([
+ 'bug-lane.yml#bug-lane',
+ 'select-beta-to-promote.yml#evaluate',
+ 'select-beta-to-promote.yml#dispatch-fast-tier-candidate',
+ 'select-beta-to-promote.yml#page-smoke-incident',
+ ]);
+ for (const { file, id, job } of all.filter((j) => holdsCredential(j.workflow, j.job))) {
+ expect(routesOf(job), `${file}#${id}`).toEqual([]);
+ }
+ });
+
+ test('the token scopes of every job are pinned, with the alarm read-only and the failure marker empty', () => {
+ const effective = Object.fromEntries(
+ all.map(({ file, id, job, workflow }) => [`${file}#${id}`, job.permissions ?? workflow.permissions]),
+ );
+ const dispatcher = { contents: 'read', actions: 'write' };
+ const reader = { contents: 'read' };
+ expect(effective).toEqual({
+ 'bug-lane.yml#read-bumps': reader,
+ 'bug-lane.yml#bug-lane': dispatcher,
+ 'select-beta-to-promote.yml#read-bumps': reader,
+ 'select-beta-to-promote.yml#evaluate': dispatcher,
+ 'select-beta-to-promote.yml#smoke-fast-tier-candidate': reader,
+ 'select-beta-to-promote.yml#dispatch-fast-tier-candidate': dispatcher,
+ 'select-beta-to-promote.yml#remember-smoke-failure': {},
+ 'select-beta-to-promote.yml#aggregate-smoke-alarm': { contents: 'read', actions: 'read' },
+ 'select-beta-to-promote.yml#read-smoke-incident': {},
+ 'select-beta-to-promote.yml#page-smoke-incident': reader,
+ });
+ });
+
+ test('the only actions excused from the route sweep are a pinned cache save and a pinned lookup-only restore', () => {
+ const sha = '668228422ae6a00e4ad889ee87cd7109ec5666a7';
+ const restore = `actions/cache/restore@${sha}`;
+ const path = 'smoke-incident.json';
+ const excused = {
+ 'a pinned save': { uses: `actions/cache/save@${sha}`, with: { path, key: 'k' } },
+ 'a pinned lookup-only restore': { uses: restore, with: { path, key: 'k', 'lookup-only': true } },
+ 'a pinned lookup-only restore spelled as a string': { uses: restore, with: { path, key: 'k', 'lookup-only': 'true' } },
+ };
+ for (const [form, step] of Object.entries(excused)) {
+ expect(routesOf({ steps: [step] }), form).toEqual([]);
+ }
+ const extracting = {
+ 'a pinned restore that extracts': { uses: restore, with: { path, key: 'k', 'restore-keys': 'k-' } },
+ 'a pinned restore with lookup-only false': { uses: restore, with: { path, key: 'k', 'lookup-only': false } },
+ 'a pinned restore whose lookup-only is an expression': {
+ uses: restore,
+ with: { path, key: 'k', 'lookup-only': '${{ inputs.lookup }}' },
+ },
+ 'the combined cache action, which restores and extracts': { uses: `actions/cache@${sha}`, with: { path, key: 'k' } },
+ 'the combined cache action with lookup-only': { uses: `actions/cache@${sha}`, with: { path, key: 'k', 'lookup-only': true } },
+ 'an unpinned save': { uses: 'actions/cache/save@v5', with: { path, key: 'k' } },
+ 'an unpinned lookup-only restore': { uses: 'actions/cache/restore@v5', with: { path, key: 'k', 'lookup-only': true } },
+ 'a lookalike lookup-only restore': { uses: `someone/cache/restore@${sha}`, with: { path, key: 'k', 'lookup-only': true } },
+ 'a package installer action': { uses: 'pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86' },
+ };
+ for (const [form, step] of Object.entries(extracting)) {
+ expect(routesOf({ steps: [step] }), form).toEqual([step.uses]);
+ }
+ expect(routesOf({ steps: [excused['a pinned save'], { name: 'Install', run: 'pnpm install' }] })).toEqual(['Install']);
+ });
+
+ test('a setup-node step counts as a cache extraction unless it names no cache and turns the package-manager cache off', () => {
+ const uses = 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e';
+ const extracting = {
+ 'a cache input': { uses, with: { 'node-version': '24', cache: 'pnpm' } },
+ 'no inputs at all': { uses },
+ 'only a node version': { uses, with: { 'node-version': '24' } },
+ 'package-manager-cache set by an expression': {
+ uses,
+ with: { 'node-version': '24', 'package-manager-cache': '${{ inputs.package-manager-cache }}' },
+ },
+ 'package-manager-cache true': { uses, with: { 'node-version': '24', 'package-manager-cache': true } },
+ 'package-manager-cache spelled as the string true': { uses, with: { 'node-version': '24', 'package-manager-cache': 'true' } },
+ 'a cache input beside package-manager-cache false': {
+ uses,
+ with: { 'node-version': '24', cache: 'pnpm', 'package-manager-cache': false },
+ },
+ 'an unpinned setup-node with a cache input': { uses: 'actions/setup-node@v6', with: { cache: 'npm' } },
+ };
+ for (const [form, step] of Object.entries(extracting)) {
+ expect(routesOf({ steps: [step] }), form).toEqual([step.uses]);
+ }
+ const excused = {
+ 'no cache input and package-manager-cache false': { uses, with: { 'node-version': '24', 'package-manager-cache': false } },
+ 'the same, spelled as a string': { uses, with: { 'node-version': '24', 'package-manager-cache': 'false' } },
+ 'the same, in capitals': { uses, with: { 'node-version': '24', 'package-manager-cache': 'FALSE' } },
+ };
+ for (const [form, step] of Object.entries(excused)) {
+ expect(routesOf({ steps: [step] }), form).toEqual([]);
+ }
+ });
+
+ test('each reader job hands on only the one output its consumers need', () => {
+ const outputs = all
+ .filter(({ job }) => routesOf(job).length > 0)
+ .map(({ file, id, job }) => [`${file}#${id}`, Object.keys(job.outputs ?? {})]);
+ expect(Object.fromEntries(outputs)).toEqual({
+ 'bug-lane.yml#read-bumps': ['bump_verdicts'],
+ 'select-beta-to-promote.yml#read-bumps': ['bump_verdicts'],
+ 'select-beta-to-promote.yml#smoke-fast-tier-candidate': ['verdict'],
+ 'select-beta-to-promote.yml#read-smoke-incident': ['state'],
+ });
+ });
+
+ test('a job that runs no package code takes only bump_verdicts, the smoke verdict and the acknowledgement from a reader job', () => {
+ for (const { file, id, job, readers } of all.filter((j) => routesOf(j.job).length === 0)) {
+ expect(readerOutputReads(job, readers), `${file}#${id}`).toEqual([]);
+ for (const step of steps(job).filter((s) => s.env?.BUMP_VERDICTS !== undefined)) {
+ expect(step.env.BUMP_VERDICTS, `${file}#${id}`).toBe('${{ needs.read-bumps.outputs.bump_verdicts }}');
+ }
+ }
+ const consumers = all
+ .filter(({ job, readers }) =>
+ expressions(job).some(({ expr }) => readers.some((reader) => expr.includes(`needs.${reader}.`))),
+ )
+ .filter(({ job }) => routesOf(job).length === 0)
+ .map(({ file, id }) => `${file}#${id}`);
+ expect(consumers).toEqual([
+ 'bug-lane.yml#bug-lane',
+ 'select-beta-to-promote.yml#evaluate',
+ 'select-beta-to-promote.yml#dispatch-fast-tier-candidate',
+ 'select-beta-to-promote.yml#remember-smoke-failure',
+ 'select-beta-to-promote.yml#page-smoke-incident',
+ ]);
+ const [write] = steps(parse(selectBeta).jobs['page-smoke-incident']).filter((s) => s.env?.ALERT_STATE !== undefined);
+ expect(write.env.ALERT_STATE).toBe('${{ needs.read-smoke-incident.outputs.state }}');
+ });
+
+ test('the credential classifier sees every way a job can hold one', () => {
+ const workflow = { permissions: { contents: 'read' } };
+ const readOnly = { permissions: { contents: 'read' } };
+ const step = (env) => ({ steps: [{ run: 'true', env }] });
+ expect(holdsCredential(workflow, { ...readOnly, ...step({ GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }) })).toBe(false);
+ expect(holdsCredential(workflow, { ...readOnly, ...step({ GH_TOKEN: '${{ github.token }}' }) })).toBe(false);
+ const holders = {
+ 'a write permission': { permissions: { contents: 'read', actions: 'write' } },
+ 'write-all': { permissions: 'write-all' },
+ 'a workflow-level write it inherits': [{ permissions: { actions: 'write' } }, {}],
+ 'no permissions anywhere': [{}, {}],
+ 'a named secret in a step env': { ...readOnly, ...step({ KEY: '${{ secrets.LINEAR_API_KEY }}' }) },
+ 'an indexed secret': { ...readOnly, ...step({ KEY: "${{ secrets['SLACK_WEBHOOK_URL'] }}" }) },
+ 'every secret': { ...readOnly, ...step({ ALL: '${{ toJSON(secrets) }}' }) },
+ 'a secret in a run block': { ...readOnly, steps: [{ run: 'curl -d x "${{ secrets.SLACK_WEBHOOK_URL }}"' }] },
+ 'a secret in an action input': { ...readOnly, steps: [{ uses: 'x/y@v1', with: { token: '${{ secrets.APP_KEY }}' } }] },
+ 'a secret in job-level env': { ...readOnly, env: { KEY: '${{ secrets.LINEAR_API_KEY }}' } },
+ 'a secret in workflow-level env': [{ ...workflow, env: { KEY: '${{ secrets.LINEAR_API_KEY }}' } }, readOnly],
+ };
+ for (const [form, value] of Object.entries(holders)) {
+ const [wf, job] = Array.isArray(value) ? value : [workflow, value];
+ expect(holdsCredential(wf, job), form).toBe(true);
+ }
+ });
+
+ test('the reader-output scan sees every way a credentialed job can read a reader job', () => {
+ const readers = ['read-bumps', 'smoke-fast-tier-candidate', 'read-smoke-incident'];
+ const verdictStep = {
+ name: 'Select',
+ env: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}', LINEAR_API_KEY: '${{ secrets.LINEAR_API_KEY }}' },
+ run: 'node .github/scripts/select-beta-to-promote.mjs',
+ };
+ const candidateStep = { name: 'Dispatch', env: { CANDIDATE: '${{ needs.evaluate.outputs.fast_tier_candidate }}' }, run: 'gh workflow run x' };
+ const stateStep = {
+ name: 'Write',
+ env: { ALERT_STATE: '${{ needs.read-smoke-incident.outputs.state }}', ALERT_STATE_PATH: 'state.json' },
+ run: 'printf "%s" "$ALERT_STATE" > "$ALERT_STATE_PATH"',
+ };
+ const sanctioned = {
+ if: "needs.smoke-fast-tier-candidate.outputs.verdict == 'pass'",
+ steps: [verdictStep, candidateStep, stateStep],
+ };
+ expect(readerOutputReads(sanctioned, readers)).toEqual([]);
+ expect(readerOutputReads({ ...sanctioned, if: "always() && needs.smoke-fast-tier-candidate.outputs.verdict == 'fail'" }, readers)).toEqual([]);
+ const withStep = (stray) => ({ ...sanctioned, steps: [verdictStep, candidateStep, stateStep, { name: 'Stray', ...stray }] });
+ const strays = {
+ 'another read-bumps output': withStep({ env: { X: '${{ needs.read-bumps.outputs.beta_tag }}' } }),
+ 'bump_verdicts under another name': withStep({ env: { V: '${{ needs.read-bumps.outputs.bump_verdicts }}' } }),
+ 'BUMP_VERDICTS reading another output': withStep({ env: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.other }}' } }),
+ 'BUMP_VERDICTS as an action input': withStep({ uses: 'x/y@v1', with: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}' } }),
+ 'the smoke verdict in a step env': withStep({ env: { VERDICT: '${{ needs.smoke-fast-tier-candidate.outputs.verdict }}' } }),
+ 'the candidate from the smoke job': withStep({ env: { CANDIDATE: '${{ needs.smoke-fast-tier-candidate.outputs.candidate }}' } }),
+ 'a step-level if on the smoke verdict': withStep({ if: "needs.smoke-fast-tier-candidate.outputs.verdict == 'pass'" }),
+ 'a job-level if on another smoke output': { ...sanctioned, if: "needs.smoke-fast-tier-candidate.outputs.dmg == 'x'" },
+ 'a job-level if that widens the verdict test': { ...sanctioned, if: "needs.smoke-fast-tier-candidate.outputs.verdict != 'fail'" },
+ 'a reader job result': withStep({ if: "needs.read-bumps.result == 'success'" }),
+ 'whole needs object': withStep({ run: 'echo "${{ toJSON(needs) }}"' }),
+ 'indexed reader job': withStep({ env: { X: "${{ needs['read-bumps'].outputs['bump_verdicts'] }}" } }),
+ 'a reader output inside a run block': withStep({ run: 'echo "${{ needs.read-bumps.outputs.bump_verdicts }}"' }),
+ 'job-level env': { ...sanctioned, env: { X: '${{ needs.read-bumps.outputs.bump_verdicts }}' } },
+ 'job-level outputs': { ...sanctioned, outputs: { x: '${{ needs.smoke-fast-tier-candidate.outputs.verdict }}' } },
+ 'the acknowledgement under another name': withStep({ env: { STATE: '${{ needs.read-smoke-incident.outputs.state }}' } }),
+ 'the acknowledgement inside a run block': withStep({ run: 'echo "${{ needs.read-smoke-incident.outputs.state }}"' }),
+ 'ALERT_STATE reading another output': withStep({ env: { ALERT_STATE: '${{ needs.read-smoke-incident.outputs.other }}' } }),
+ 'ALERT_STATE as an action input': withStep({ uses: 'x/y@v1', with: { ALERT_STATE: '${{ needs.read-smoke-incident.outputs.state }}' } }),
+ 'the acknowledgement reader result': withStep({ if: "needs.read-smoke-incident.result == 'success'" }),
+ };
+ for (const [form, job] of Object.entries(strays)) {
+ expect(readerOutputReads(job, readers), form).not.toEqual([]);
+ }
+ });
+
+ test('no checkout in these workflows persists a credential', () => {
+ const checkouts = all.flatMap(({ file, id, job }) =>
+ steps(job)
+ .filter((step) => step.uses?.startsWith('actions/checkout@'))
+ .map((step) => ({ name: `${file}#${id}`, step })),
+ );
+ expect(checkouts.length).toBe(7);
+ for (const { name, step } of checkouts) {
+ expect(step.with?.['persist-credentials'], name).toBe(false);
+ expect(step.with?.token, name).toBeUndefined();
+ }
+ });
+
+ test('the fast-tier dispatch takes its candidate from the evaluate job and dispatches as before', () => {
+ const { jobs: selectJobs } = parse(selectBeta);
+ const dispatch = selectJobs['dispatch-fast-tier-candidate'];
+ expect(dispatch.needs).toEqual(['evaluate', 'smoke-fast-tier-candidate']);
+ const [step] = dispatch.steps.filter((s) => s.name === 'Dispatch promote-stable for the smoke-proven candidate');
+ expect(step.env).toEqual({
+ GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
+ GH_REPO: '${{ github.repository }}',
+ CANDIDATE: '${{ needs.evaluate.outputs.fast_tier_candidate }}',
+ });
+ expect(commands(step)).toContain('gh workflow run promote-stable.yml -f beta_tag="$CANDIDATE" -f dispatched_by="$SELF_URL"');
+ expect(commands(step)).toMatch(/gh run list --workflow=promote-stable\.yml/);
+ });
+ });
});
describe('Linux packaging ships the native prebuilds and checks them before upload', () => {
diff --git a/.github/scripts/select-beta-to-promote.mjs b/.github/scripts/select-beta-to-promote.mjs
index 2eec3ef3f..1079ec228 100644
--- a/.github/scripts/select-beta-to-promote.mjs
+++ b/.github/scripts/select-beta-to-promote.mjs
@@ -1,7 +1,14 @@
import { execFileSync, spawnSync } from 'node:child_process';
import { appendFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
-import { computeStablePromotion, realGit } from '../../scripts/compute-stable-version.mjs';
+import {
+ computeStablePromotion,
+ parseBumpVerdicts,
+ realGit,
+ recordBumpVerdicts,
+ serializeBumpVerdicts,
+ withBumpVerdicts,
+} from '../../scripts/compute-stable-version.mjs';
import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';
const BETA_TAG_RE = /^v\d+\.\d+\.\d+-beta\.\d+$/;
@@ -279,14 +286,55 @@ export function makeResolveIssuesForUrl(apiKey) {
};
}
+export function readUnshippedBumps({ betaTags, isAlreadyShipped, git, log = () => {} }) {
+ const verdicts = new Map();
+ const reading = recordBumpVerdicts(git, verdicts);
+ for (const beta of betaTags) {
+ if (isAlreadyShipped(beta)) break;
+ try {
+ computeStablePromotion(beta, reading);
+ } catch (err) {
+ log(`::warning::Could not read the changeset bumps of ${beta}; its fast-tier verdict will degrade: ${err.message}`);
+ }
+ }
+ return verdicts;
+}
+
+function realBetaTags() {
+ return parseBetaTags(
+ execFileSync('git', ['tag', '--list', 'v*-beta.*', '--sort=-version:refname'], {
+ encoding: 'utf8',
+ env: gitCleanEnv(),
+ }),
+ );
+}
+
+function readBumpsMain() {
+ const verdicts = readUnshippedBumps({
+ betaTags: realBetaTags(),
+ isAlreadyShipped: makeRealIsAlreadyShipped(resolveLatestStableSha()),
+ git: realGit,
+ log: console.log,
+ });
+ console.log(`Read the bump of ${verdicts.size} changeset(s) across the unshipped betas.`);
+ if (process.env.GITHUB_OUTPUT) {
+ appendFileSync(process.env.GITHUB_OUTPUT, `bump_verdicts=${serializeBumpVerdicts(verdicts)}\n`);
+ }
+}
+
async function main() {
+ if (process.argv[2] === '--read-bumps') {
+ readBumpsMain();
+ return;
+ }
+
+ const git =
+ process.env.BUMP_VERDICTS === undefined
+ ? realGit
+ : withBumpVerdicts(realGit, parseBumpVerdicts(process.env.BUMP_VERDICTS));
const soakSeconds = Number(process.env.SOAK_SECONDS || '86400');
const armed = process.env.FAST_TIER_ARMED === 'true';
- const rawTags = execFileSync('git', ['tag', '--list', 'v*-beta.*', '--sort=-version:refname'], {
- encoding: 'utf8',
- env: gitCleanEnv(),
- });
- const betaTags = parseBetaTags(rawTags);
+ const betaTags = realBetaTags();
const latestStableSha = resolveLatestStableSha();
const isAlreadyShipped = makeRealIsAlreadyShipped(latestStableSha);
@@ -338,7 +386,7 @@ async function main() {
fastTarget = fastCandidate.kind === 'select' ? fastCandidate.target : '';
verdict = await evaluateFastTier({
candidate: fastTarget,
- computeDelta: (betaTag) => computeStablePromotion(betaTag, realGit),
+ computeDelta: (betaTag) => computeStablePromotion(betaTag, git),
resolveChangesetPrUrl: makeResolveChangesetPrUrl(process.env.LINK_REPO || DEFAULT_LINK_REPO),
resolveIssuesForUrl: makeResolveIssuesForUrl(process.env.LINEAR_API_KEY),
});
diff --git a/.github/scripts/select-beta-to-promote.test.mjs b/.github/scripts/select-beta-to-promote.test.mjs
index e817fe18e..0bb59f26a 100644
--- a/.github/scripts/select-beta-to-promote.test.mjs
+++ b/.github/scripts/select-beta-to-promote.test.mjs
@@ -1,15 +1,17 @@
-import { execFileSync } from 'node:child_process';
-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { delimiter, dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { afterEach, describe, expect, test } from 'vitest';
-import { computeStablePromotion } from '../../scripts/compute-stable-version.mjs';
+import { computeStablePromotion, withBumpVerdicts } from '../../scripts/compute-stable-version.mjs';
import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';
import {
evaluateFastTier,
makeResolveChangesetPrUrl,
makeResolveIssuesForUrl,
parseBetaTags,
+ readUnshippedBumps,
resolveTier,
selectPromotion,
} from './select-beta-to-promote.mjs';
@@ -742,3 +744,268 @@ describe('makeResolveIssuesForUrl (real HTTP handling)', () => {
}
});
});
+
+describe('readUnshippedBumps, run by the job that holds no credential', () => {
+ const SHAS = {
+ 'v1.0.0': 'stable-sha',
+ 'v1.2.0-beta.1': 'newest-sha',
+ 'v1.1.1-beta.0': 'older-sha',
+ 'v1.0.0-beta.3': 'shipped-sha',
+ 'v0.9.9-beta.0': 'below-sha',
+ };
+ const BLOBS = {
+ 'stable-sha': { old: 'blob-old' },
+ 'newest-sha': { old: 'blob-old', fix: 'blob-fix', feat: 'blob-feat' },
+ 'older-sha': { old: 'blob-old', fix: 'blob-fix-first-draft' },
+ 'shipped-sha': { old: 'blob-old', ancient: 'blob-ancient' },
+ 'below-sha': { old: 'blob-old', below: 'blob-below' },
+ };
+ const BETAS = ['v1.2.0-beta.1', 'v1.1.1-beta.0', 'v1.0.0-beta.3', 'v0.9.9-beta.0'];
+ const shipped = (tag) => tag === 'v1.0.0-beta.3';
+ const blobGit = ({ broken = '' } = {}) => {
+ const reads = [];
+ return {
+ reads,
+ revParse: (ref) => SHAS[ref],
+ newestStableTag: () => 'v1.0.0',
+ isAncestor: () => false,
+ changesetIds: (sha) => Object.keys(BLOBS[sha] ?? {}),
+ changesetBlobs: (sha) => new Map(Object.entries(BLOBS[sha] ?? {})),
+ bumpTypeOf: (sha, id) => {
+ reads.push(`${sha}:${id}`);
+ if (`${sha}:${id}` === broken) throw new Error('unparseable frontmatter');
+ return id === 'feat' ? 'minor' : 'patch';
+ },
+ };
+ };
+
+ test('reads the delta of every beta above the first shipped one, keyed by blob, and none below it', () => {
+ const git = blobGit();
+ const verdicts = readUnshippedBumps({ betaTags: BETAS, isAlreadyShipped: shipped, git });
+ expect(Object.fromEntries(verdicts)).toEqual({
+ 'blob-fix': 'patch',
+ 'blob-feat': 'minor',
+ 'blob-fix-first-draft': 'patch',
+ });
+ expect(git.reads).toEqual(['newest-sha:fix', 'newest-sha:feat', 'older-sha:fix']);
+ });
+
+ test('a beta it cannot read is reported and skipped, and the other betas are still read', () => {
+ const git = blobGit({ broken: 'newest-sha:feat' });
+ const logged = [];
+ const verdicts = readUnshippedBumps({ betaTags: BETAS, isAlreadyShipped: shipped, git, log: (m) => logged.push(m) });
+ expect(logged).toEqual([expect.stringMatching(/^::warning::Could not read the changeset bumps of v1\.2\.0-beta\.1.*unparseable frontmatter/)]);
+ expect(verdicts.get('blob-fix-first-draft')).toBe('patch');
+ expect(verdicts.has('blob-feat')).toBe(false);
+ });
+
+ test('the selector answers a candidate from the verdicts alone, and a beta the reader skipped degrades to delta-error', async () => {
+ const reader = blobGit({ broken: 'newest-sha:feat' });
+ const verdicts = readUnshippedBumps({ betaTags: BETAS, isAlreadyShipped: shipped, git: reader });
+ const selector = withBumpVerdicts(
+ {
+ ...blobGit(),
+ bumpTypeOf: () => {
+ throw new Error('the Changesets reader is not installed in this job');
+ },
+ },
+ verdicts,
+ );
+ const tier = (candidate) =>
+ evaluateFastTier({
+ candidate,
+ computeDelta: (beta) => computeStablePromotion(beta, selector),
+ resolveChangesetPrUrl: () => 'https://github.com/inkeep/agents-private/pull/1',
+ resolveIssuesForUrl: async () => ({ issues: [{ identifier: 'PRD-1', labels: ['Bug'] }] }),
+ });
+ expect(await tier('v1.1.1-beta.0')).toMatchObject({ qualifies: true, bump: 'patch', deltaCount: 1 });
+ const degraded = await tier('v1.2.0-beta.1');
+ expect(degraded).toMatchObject({ qualifies: false, reason: 'delta-error' });
+ expect(degraded.warnings).toEqual([expect.stringMatching(/no bump verdict for \.changeset\/feat\.md/)]);
+ });
+});
+
+describe('the selector entry points the two jobs run', () => {
+ const SCRIPT = realpathSync(fileURLToPath(new URL('./select-beta-to-promote.mjs', import.meta.url)));
+ const OK_ROOT = join(dirname(SCRIPT), '..', '..');
+ const COPIED = [
+ '.github/scripts/select-beta-to-promote.mjs',
+ 'scripts/compute-stable-version.mjs',
+ 'scripts/compute-next-beta.mjs',
+ 'scripts/git-clean-env.mjs',
+ ];
+ const dirs = [];
+ afterEach(() => {
+ while (dirs.length) rmSync(dirs.pop(), { recursive: true, force: true });
+ });
+ const scratch = (prefix) => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
+ dirs.push(dir);
+ return dir;
+ };
+ const {
+ BUMP_VERDICTS: _verdicts,
+ LINEAR_API_KEY: _key,
+ LINK_REPO: _repo,
+ SOAK_SECONDS: _soak,
+ FAST_TIER_ARMED: _armed,
+ ...cleanEnv
+ } = gitCleanEnv();
+ const git = (cwd, ...args) =>
+ execFileSync('git', ['-c', 'user.name=t', '-c', '[email protected]', '-c', 'commit.gpgsign=false', ...args], {
+ cwd,
+ encoding: 'utf8',
+ env: gitCleanEnv(),
+ }).trim();
+ const betaRepo = () => {
+ const root = scratch('select-beta-entry-');
+ const commit = (id, type, subject, tag) => {
+ mkdirSync(join(root, '.changeset'), { recursive: true });
+ writeFileSync(join(root, '.changeset', `${id}.md`), `---\n"@inkeep/open-knowledge": ${type}\n---\n\n${id}\n`);
+ git(root, 'add', '-A');
+ git(root, 'commit', '-q', '-m', subject);
+ git(root, 'tag', tag);
+ };
+ git(root, 'init', '-q', '-b', 'main');
+ commit('keep', 'patch', 'chore: the shipped change (#100)', 'v1.0.0');
+ commit('fix-crash', 'patch', 'fix: stop the crash (#201)', 'v1.0.1-beta.0');
+ commit('new-thing', 'minor', 'feat: a new thing (#202)', 'v1.1.0-beta.0');
+ return {
+ root,
+ blobs: {
+ fix: git(root, 'rev-parse', 'HEAD:.changeset/fix-crash.md'),
+ feat: git(root, 'rev-parse', 'HEAD:.changeset/new-thing.md'),
+ },
+ };
+ };
+ const ghBin = (script) => {
+ const bin = scratch('select-beta-gh-');
+ writeFileSync(join(bin, 'gh'), script, { mode: 0o755 });
+ return bin;
+ };
+ const releaseGh = () => {
+ const meta = (minutesAgo) =>
+ JSON.stringify({
+ isDraft: false,
+ publishedAt: new Date(Date.now() - minutesAgo * 60_000).toISOString(),
+ assets: [{ name: 'OpenKnowledge-Beta-universal.dmg' }, { name: 'beta-mac.yml' }],
+ });
+ return ghBin(
+ [
+ '#!/bin/sh',
+ 'case "$3" in',
+ ` v1.1.0-beta.0) printf '%s' '${meta(10)}' ;;`,
+ ` v1.0.1-beta.0) printf '%s' '${meta(120)}' ;;`,
+ ' *) echo "release not found" >&2; exit 1 ;;',
+ 'esac',
+ '',
+ ].join('\n'),
+ );
+ };
+ const isolatedScript = () => {
+ const dir = scratch('select-beta-no-node-modules-');
+ for (const file of COPIED) {
+ mkdirSync(dirname(join(dir, file)), { recursive: true });
+ copyFileSync(join(OK_ROOT, file), join(dir, file));
+ }
+ return join(dir, '.github', 'scripts', 'select-beta-to-promote.mjs');
+ };
+ const linearStub = () => {
+ const dir = scratch('select-beta-linear-');
+ const preload = join(dir, 'linear.mjs');
+ const calls = join(dir, 'calls');
+ writeFileSync(
+ preload,
+ [
+ "import { appendFileSync } from 'node:fs';",
+ 'globalThis.fetch = async (url, init) => {',
+ ' appendFileSync(process.env.LINEAR_CALLS, `${JSON.stringify({ url: String(url), authorization: init.headers.authorization, body: JSON.parse(init.body) })}\\n`);',
+ " return new Response(JSON.stringify({ data: { attachmentsForURL: { nodes: [{ issue: { identifier: 'PRD-1', labels: { nodes: [{ name: 'Bug' }] } } }] } } }), { status: 200 });",
+ '};',
+ '',
+ ].join('\n'),
+ );
+ writeFileSync(calls, '');
+ return { preload, calls, read: () => readFileSync(calls, 'utf8').split('\n').filter(Boolean).map((line) => JSON.parse(line)) };
+ };
+ const run = (script, cwd, { args = [], env = {}, bin, preload } = {}) => {
+ const output = join(scratch('select-beta-output-'), 'github-output');
+ writeFileSync(output, '');
+ const res = spawnSync(process.execPath, [...(preload ? ['--import', preload] : []), script, ...args], {
+ cwd,
+ encoding: 'utf8',
+ env: { ...cleanEnv, GITHUB_OUTPUT: output, ...(bin ? { PATH: `${bin}${delimiter}${cleanEnv.PATH}` } : {}), ...env },
+ });
+ return { ...res, output: readFileSync(output, 'utf8') };
+ };
+ const readBumps = (root) =>
+ run(SCRIPT, root, { args: ['--read-bumps'], bin: ghBin('#!/bin/sh\necho "the reader job must not call gh" >&2\nexit 97\n') });
+
+ test('--read-bumps writes the bump of every changeset an unshipped beta adds, keyed by blob id, without gh', () => {
+ const { root, blobs } = betaRepo();
+ const res = readBumps(root);
+ expect(res.status, res.stderr).toBe(0);
+ expect(res.output).toBe(`bump_verdicts={"${blobs.fix}":"patch","${blobs.feat}":"minor"}\n`);
+ });
+
+ test('with the reader job verdicts and no node_modules it makes the same Linear queries and writes the same outputs', () => {
+ const { root } = betaRepo();
+ const verdicts = readBumps(root).output.trim().slice('bump_verdicts='.length);
+ const env = { LINEAR_API_KEY: 'placeholder-linear-key', FAST_TIER_ARMED: 'true', SOAK_SECONDS: '86400' };
+ const bin = releaseGh();
+
+ const withReader = linearStub();
+ const reader = run(SCRIPT, root, { env: { ...env, LINEAR_CALLS: withReader.calls }, bin, preload: withReader.preload });
+ expect(reader.status, reader.stderr).toBe(0);
+
+ const withoutReader = linearStub();
+ const verdictMode = run(isolatedScript(), root, {
+ env: { ...env, LINEAR_CALLS: withoutReader.calls, BUMP_VERDICTS: verdicts },
+ bin,
+ preload: withoutReader.preload,
+ });
+ expect(verdictMode.status, verdictMode.stderr).toBe(0);
+
+ expect(verdictMode.output).toBe(
+ [
+ 'target=',
+ 'tier=',
+ 'fast_tier_candidate=v1.0.1-beta.0',
+ 'soak_tier=fast',
+ 'fast_armed=true',
+ 'fast_candidate=v1.0.1-beta.0',
+ 'fast_qualifies=true',
+ 'fast_reason=patch-only-and-bug-linked',
+ 'fast_bump=patch',
+ 'fast_delta_count=1',
+ 'fast_bug_linked=true',
+ '',
+ ].join('\n'),
+ );
+ expect(verdictMode.output).toBe(reader.output);
+ expect(withoutReader.read()).toEqual([
+ {
+ url: 'https://api.linear.app/graphql',
+ authorization: 'placeholder-linear-key',
+ body: expect.objectContaining({ variables: { url: 'https://github.com/inkeep/agents-private/pull/201' } }),
+ },
+ ]);
+ expect(withoutReader.read()).toEqual(withReader.read());
+ });
+
+ test('without verdicts the same isolated copy degrades the fast tier because it cannot load the reader', () => {
+ const { root } = betaRepo();
+ const res = run(isolatedScript(), root, { env: { FAST_TIER_ARMED: 'true' }, bin: releaseGh() });
+ expect(res.status, res.stderr).toBe(0);
+ expect(res.output).toContain('fast_reason=delta-error\n');
+ expect(res.stdout).toMatch(/Soak-tier predicate degraded: delta-error v1\.0\.1-beta\.0: .*@changesets\/cli/);
+ });
+
+ test('an empty BUMP_VERDICTS stops the tick with an error naming the read-bumps output, and writes nothing', () => {
+ const { root } = betaRepo();
+ const res = run(isolatedScript(), root, { env: { BUMP_VERDICTS: '' }, bin: releaseGh() });
+ expect(res.status).toBe(1);
+ expect(res.stderr).toMatch(/BUMP_VERDICTS is empty: the read-bumps job wrote no bump_verdicts output/);
+ expect(res.output).toBe('');
+ });
+});
diff --git a/.github/workflows/bug-lane.yml b/.github/workflows/bug-lane.yml
index de40166a9..ee43d81d8 100644
--- a/.github/workflows/bug-lane.yml
+++ b/.github/workflows/bug-lane.yml
@@ -73,16 +73,18 @@ concurrency:
cancel-in-progress: true
jobs:
- bug-lane:
- name: Evaluate qualifying fixes
+ read-bumps:
+ name: Read changeset bumps (no credential)
runs-on: ubuntu-latest
timeout-minutes: 10
+ permissions:
+ contents: read
+ outputs:
+ bump_verdicts: ${{ steps.bumps.outputs.bump_verdicts }}
steps:
- - name: Checkout with full history and tags
+ - name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- fetch-depth: 0
- fetch-tags: true
persist-credentials: false
- name: Set up Node
@@ -96,12 +98,36 @@ jobs:
corepack enable
pnpm install --frozen-lockfile --filter=. --ignore-scripts
+ - name: Read the bump of every pending changeset
+ id: bumps
+ run: node .github/scripts/bug-lane.mjs --read-bumps
+
+ bug-lane:
+ name: Evaluate qualifying fixes
+ needs: read-bumps
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Checkout with full history and tags
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ fetch-depth: 0
+ fetch-tags: true
+ persist-credentials: false
+
+ - name: Set up Node
+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
+ with:
+ node-version: "24"
+ package-manager-cache: false
+
- name: Evaluate qualifying fixes
id: evaluate
env:
# Optional, same posture as the soak tier: absent, every fix resolves
# "not bug-linked" and the lane is inert rather than wrong.
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
+ BUMP_VERDICTS: ${{ needs.read-bumps.outputs.bump_verdicts }}
# Writes fix_refs (comma-joined), stable and fix_tickets to
# GITHUB_OUTPUT; per-commit verdicts land as notices. Logic + tests:
# .github/scripts/bug-lane.{mjs,test.mjs}.
diff --git a/.github/workflows/select-beta-to-promote.yml b/.github/workflows/select-beta-to-promote.yml
index 58d58738d..330992173 100644
--- a/.github/workflows/select-beta-to-promote.yml
+++ b/.github/workflows/select-beta-to-promote.yml
@@ -54,15 +54,14 @@ name: Select beta to promote
# This is a different axis from the selection `tier` output, which reports how
# the 24h selection itself was made. The soak-tier verdict and the DMG-smoke
# leg ARE wired together: a qualifying verdict nominates the beta as
-# `fast_tier_candidate`, and the smoke leg is the only dispatcher for it.
+# `fast_tier_candidate`.
#
# The fast SOAK tier is ARMED, smoke-gated. With `FAST_TIER_ARMED` "true", a
# qualifying cut (patch-only + bug-linked delta, fully cut, >=1h soak) is
-# nominated as `fast_tier_candidate`, and the macOS smoke leg below β€” the ONLY
-# dispatcher for fast promotions β€” smokes the actual DMG before dispatching
-# promote-stable, around the clock. The hours-gated direct dispatch still
+# nominated as `fast_tier_candidate`, and the macOS smoke leg below
+# smokes the actual DMG, around the clock. The hours-gated direct dispatch still
# promotes only the 24h selection; SOAK_SECONDS stays 86400 on that path. A
-# smoke refusal pages Slack and leaves the beta on the normal soak. Disarming
+# smoke refusal leaves the beta on the normal soak. Disarming
# is one edit back to "false" β€” the "Soak tiers" section of RELEASES.md is the
# operator-facing record.
#
@@ -83,13 +82,6 @@ name: Select beta to promote
# check skips when a promote-stable run is already in_progress/queued, and
# (3) the script stops at the first already-shipped beta (commit contained in the
# latest stable) and never selects one whose changes are already released.
-#
-# FAST TIER (FR5a), ARMED: a second job smokes an under-soaked beta's DMG and,
-# only on a clean smoke, dispatches promote-stable early. It is gated on
-# `fast_tier_candidate`, which is empty on ticks where nothing qualifies, and on
-# ticks whose candidate's DMG already failed the smoke. A fail or an error
-# verdict only ever declines the early promotion β€” the 24h path is untouched and
-# the gate can never block a release. The operator record is RELEASES.md.
on:
schedule:
@@ -152,14 +144,45 @@ env:
# finding when the tier is in fact armed. Two literals would drift and the
# alarm would page about a tier that is switched off.
# Armed 2026-07-31 by owner decision after the prerequisites in the "Soak
- # tiers" section of RELEASES.md were met (smoke leg wired as the only fast
- # dispatcher; per-refusal Slack paging; point-release revert lane proven).
+ # tiers" section of RELEASES.md were met (per-refusal Slack paging;
+ # point-release revert lane proven).
# Disarming is flipping this back to "false" in a reviewed PR.
FAST_TIER_ARMED: "true"
jobs:
+ read-bumps:
+ name: Read changeset bumps (no credential)
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ outputs:
+ bump_verdicts: ${{ steps.bumps.outputs.bump_verdicts }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+
+ - name: Set up Node
+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
+ with:
+ node-version: "24"
+
+ - name: Install root dependencies for the Changesets reader
+ run: |
+ set -euo pipefail
+ corepack enable
+ pnpm install --frozen-lockfile --filter=. --ignore-scripts
+
+ - name: Read the bump of every changeset an unshipped beta adds
+ id: bumps
+ run: node .github/scripts/select-beta-to-promote.mjs --read-bumps
+
evaluate:
name: Evaluate 24h soak + business-hours gate
+ needs: read-bumps
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
@@ -215,12 +238,7 @@ jobs:
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "24"
-
- - name: Install root dependencies for the Changesets reader
- run: |
- set -euo pipefail
- corepack enable
- pnpm install --frozen-lockfile --filter=. --ignore-scripts
+ package-manager-cache: false
- name: Select the beta to promote
id: select
@@ -239,6 +257,7 @@ jobs:
# "unresolvable" and the tier degrades to standard, which is the
# expected steady state until an operator provisions the secret.
LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}
+ BUMP_VERDICTS: ${{ needs.read-bumps.outputs.bump_verdicts }}
# Writes target=, tier=, soak_tier= (plus the predicate inputs) to
# GITHUB_OUTPUT; an empty target => no-op. Exits non-zero (fails the job)
# on any non-404 gh/git infra error β€” a fail-loud retry-next-tick, never
@@ -277,8 +296,8 @@ jobs:
# Hours-gated, standard tier only. `target` is always the 24h selection β€”
# a fast-tier cut never reaches this step; it is nominated as
- # `fast_tier_candidate` and promotes (around the clock) only through the
- # macOS smoke leg below, after its DMG smokes clean. Letting soak_tier
+ # `fast_tier_candidate` and promotes (around the clock) only
+ # after its DMG smokes clean. Letting soak_tier
# reopen this gate would promote a 1h cut with no artifact check.
- name: Guard against an in-flight promotion, then dispatch
if: steps.hours.outputs.open == 'true' && steps.select.outputs.target != ''
@@ -331,15 +350,15 @@ jobs:
} >> "$GITHUB_STEP_SUMMARY"
if [[ -n "$CHILD" ]]; then echo "::notice::promote-stable run: ${CHILD}"; fi
- # FR5a β€” selection-time DMG smoke for the fast tier: the ONLY dispatcher for
- # fast-tier promotions, running around the clock (no business-hours gate).
+ # FR5a β€” selection-time DMG smoke for the fast tier, running around the clock
+ # (no business-hours gate).
#
# Runs only on ticks where the armed soak-tier verdict nominated a candidate
# (`fast_tier_candidate` non-empty); every other tick skips it at zero cost.
#
# This job NEVER blocks a release. It cannot fail the 24h path: the evaluate
# job has already dispatched (or not) by the time this runs, on its own
- # decision, and this job only ever ADDS an early promotion. A fail or an error
+ # decision. A fail or an error
# verdict simply means no fast-tier dispatch happens and the beta waits out
# its normal 24h soak on a later tick.
#
@@ -348,8 +367,8 @@ jobs:
# is not harmlessly idempotent β€” the next tick evaluates NEWER inputs, a
# fresher beta shadows the nominated candidate, and the qualified cut never
# gets its answer. The job still holds no state a crash could corrupt: it
- # downloads to the runner's scratch, mounts through the helper (which
- # detaches on SIGTERM), and its only effect is the final dispatch.
+ # downloads to the runner's scratch and mounts through the helper (which
+ # detaches on SIGTERM).
smoke-fast-tier-candidate:
name: Smoke the fast-tier candidate's DMG
needs: evaluate
@@ -357,6 +376,8 @@ jobs:
# Apple Silicon: the DMG is a Universal build, but launching it needs macOS.
runs-on: macos-26
timeout-minutes: 30
+ permissions:
+ contents: read
outputs:
verdict: ${{ steps.smoke.outputs.verdict }}
steps:
@@ -396,15 +417,31 @@ jobs:
exit 0
fi
# The driver exits non-zero on fail and error. `|| true` is correct
- # here and only here: this job must never fail, and the verdict it
- # wrote to GITHUB_OUTPUT is the signal the dispatch below reads.
+ # here and only here: this job must never fail.
node .github/scripts/smoke-packaged-dmg.mjs "$DMG" || true
+ - name: Record a fast-tier refusal
+ if: failure() || steps.smoke.outputs.verdict != 'pass'
+ env:
+ CANDIDATE: ${{ needs.evaluate.outputs.fast_tier_candidate }}
+ VERDICT: ${{ steps.smoke.outputs.verdict }}
+ run: |
+ set -uo pipefail
+ echo "::notice::Fast tier refused for ${CANDIDATE} (verdict=${VERDICT:-unknown}). The 24h tier is unaffected; this beta promotes normally once it has soaked."
+ echo "Fast tier refused for ${CANDIDATE}; verdict=${VERDICT:-unknown}. The aggregate incident reporter owns Slack notifications." >> "$GITHUB_STEP_SUMMARY"
+
+ dispatch-fast-tier-candidate:
+ name: Dispatch the smoke-proven fast-tier candidate
+ needs: [evaluate, smoke-fast-tier-candidate]
+ if: needs.smoke-fast-tier-candidate.outputs.verdict == 'pass'
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
- name: Dispatch promote-stable for the smoke-proven candidate
id: dispatch
- if: steps.smoke.outputs.verdict == 'pass'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GH_REPO: ${{ github.repository }}
CANDIDATE: ${{ needs.evaluate.outputs.fast_tier_candidate }}
run: |
set -euo pipefail
@@ -425,15 +462,14 @@ jobs:
if: steps.dispatch.outputs.dispatched == 'true'
run: echo "The smoke-proven candidate was dispatched."
- - name: Record a fast-tier refusal
- if: failure() || steps.smoke.outputs.verdict != 'pass'
+ - name: Report a failed fast-tier dispatch
+ if: failure()
env:
CANDIDATE: ${{ needs.evaluate.outputs.fast_tier_candidate }}
- VERDICT: ${{ steps.smoke.outputs.verdict }}
run: |
set -uo pipefail
- echo "::notice::Fast tier refused for ${CANDIDATE} (verdict=${VERDICT:-unknown}). The 24h tier is unaffected; this beta promotes normally once it has soaked."
- echo "Fast tier refused for ${CANDIDATE}; verdict=${VERDICT:-unknown}. The aggregate incident reporter owns Slack notifications." >> "$GITHUB_STEP_SUMMARY"
+ echo "::notice::The DMG smoke passed for ${CANDIDATE}, but the dispatch failed, so promote-stable was not dispatched. The 24h tier is unaffected; this beta promotes normally once it has soaked."
+ echo "The DMG smoke passed for ${CANDIDATE}, but the dispatch failed and promote-stable was not dispatched. The aggregate incident reporter owns Slack notifications." >> "$GITHUB_STEP_SUMMARY"
remember-smoke-failure:
name: Remember the candidate's failed smoke
@@ -441,6 +477,7 @@ jobs:
if: always() && needs.smoke-fast-tier-candidate.outputs.verdict == 'fail'
runs-on: ubuntu-latest
timeout-minutes: 5
+ permissions: {}
steps:
- name: Write the failure marker
env:
@@ -468,6 +505,13 @@ jobs:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
timeout-minutes: 10
+ permissions:
+ contents: read
+ actions: read
+ outputs:
+ observed: ${{ steps.alarm.outputs.observed }}
+ incident: ${{ steps.alarm.outputs.incident }}
+ reasons: ${{ steps.alarm.outputs.reasons }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -478,6 +522,7 @@ jobs:
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "24"
+ package-manager-cache: false
- name: Evaluate the aggregate alarm
id: alarm
@@ -490,23 +535,79 @@ jobs:
FAST_TIER_ARMED: ${{ env.FAST_TIER_ARMED }}
run: node .github/scripts/evaluate-smoke-alarm.mjs
+ read-smoke-incident:
+ name: Read the smoke incident acknowledgement (no credential)
+ needs: aggregate-smoke-alarm
+ if: needs.aggregate-smoke-alarm.outputs.observed == 'true'
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ permissions: {}
+ outputs:
+ state: ${{ steps.state.outputs.state }}
+ steps:
- name: Restore the smoke incident acknowledgement
- if: steps.alarm.outputs.observed == 'true'
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ${{ runner.temp }}/smoke-incident.json
key: smoke-incident-v1-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: smoke-incident-v1-
+ - name: Hand on the acknowledgement state
+ id: state
+ env:
+ ALERT_STATE_PATH: ${{ runner.temp }}/smoke-incident.json
+ run: |
+ set -euo pipefail
+ if [[ ! -e "$ALERT_STATE_PATH" ]]; then
+ echo "state=absent" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ delimiter="ACK_$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')"
+ {
+ echo "state<<${delimiter}"
+ cat "$ALERT_STATE_PATH"
+ echo
+ echo "$delimiter"
+ } >> "$GITHUB_OUTPUT"
+
+ page-smoke-incident:
+ name: Page the release channel about the fast-tier gate
+ needs: [aggregate-smoke-alarm, read-smoke-incident]
+ if: needs.aggregate-smoke-alarm.outputs.observed == 'true'
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Set up Node
+ uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
+ with:
+ node-version: "24"
+ package-manager-cache: false
+
+ - name: Write the handed-over acknowledgement
+ env:
+ ALERT_STATE: ${{ needs.read-smoke-incident.outputs.state }}
+ ALERT_STATE_PATH: ${{ runner.temp }}/smoke-incident.json
+ run: |
+ set -euo pipefail
+ if [[ "$ALERT_STATE" != "absent" ]]; then
+ printf '%s' "$ALERT_STATE" > "$ALERT_STATE_PATH"
+ fi
+
- name: Page the release channel
id: page
- if: steps.alarm.outputs.observed == 'true'
continue-on-error: true
env:
SLACK_RELEASES_WEBHOOK_URL: ${{ secrets.SLACK_RELEASES_WEBHOOK_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- REASONS: ${{ steps.alarm.outputs.reasons }}
- ALERT_INCIDENT: ${{ steps.alarm.outputs.incident }}
+ REASONS: ${{ needs.aggregate-smoke-alarm.outputs.reasons }}
+ ALERT_INCIDENT: ${{ needs.aggregate-smoke-alarm.outputs.incident }}
ALERT_STATE_PATH: ${{ runner.temp }}/smoke-incident.json
run: |
set -euo pipefail