Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Keep the OK release App token out of jobs that run package code (#5560)
Nick Gomez719b92c87133
diff --git a/.github/scripts/point-release-plan.mjs b/.github/scripts/point-release-plan.mjsindex dfe5c0301..5b092f421 100644--- a/.github/scripts/point-release-plan.mjs+++ b/.github/scripts/point-release-plan.mjs@@ -5,9 +5,13 @@ import { pathToFileURL } from 'node:url';import {computePointReleaseVersion,evaluateAnchorGuard,+ parseBumpVerdicts,readAnchorVersion,realGit,+ recordBumpVerdicts,runGit,+ serializeBumpVerdicts,+ withBumpVerdicts,} from '../../scripts/compute-stable-version.mjs';import {describeNoSelection,@@ -396,6 +400,33 @@ export function guardMainResetDeltaIds({ deltaIds }) {const MAIN_RESET_REPO = 'inkeep/agents-private';+export const APP_CREDENTIAL_HELPER =+ '!f() { test "$1" = get || return 0; echo username=x-access-token; echo "password=$GH_TOKEN"; }; f';++export const pushTagArgs = (tag) => [+ '-c',+ 'credential.helper=',+ '-c',+ `credential.helper=${APP_CREDENTIAL_HELPER}`,+ 'push',+ 'origin',+ tag,+];++export function readFixBumps({ mode, fixRefs }, git) {+ const verdicts = new Map();+ if (mode === 'revert') return verdicts;+ const reading = recordBumpVerdicts(git, verdicts);+ for (const ref of fixRefs) {+ const sha = git.revParse(ref);+ const before = git.changesetBlobs(`${sha}^`);+ for (const [id, blob] of git.changesetBlobs(sha)) {+ if (before.get(id) !== blob) reading.bumpTypeOf(sha, id);+ }+ }+ return verdicts;+}+export class PointReleaseRefusal extends Error {constructor(code, message) {super(message);@@ -685,7 +716,7 @@ export function formatReleaseNotes(plan) {return `${lines.join('\n')}\n`;}-function realIo() {+export function realIo() {return {readAnchorVersion,fs: {@@ -718,7 +749,7 @@ function realIo() {void runGit(['-c', 'core.editor=true', mode === 'revert' ? 'revert' : 'cherry-pick', '--continue']),headSha: () => runGit(['rev-parse', 'HEAD']).trim(),tag: (tag, sha) => void runGit(['tag', tag, sha]),- pushTag: (tag) => void runGit(['push', 'origin', tag]),+ pushTag: (tag) => void runGit(pushTagArgs(tag)),},gh: {selectNativeConfigPrebuild: (syntheticSha) => {@@ -773,11 +804,34 @@ function log(...args) {process.stderr.write(`${args.join(' ')}\n`);}+function readBumpsMain() {+ let verdicts;+ try {+ verdicts = readFixBumps({ mode: process.env.MODE, fixRefs: parseFixRefs(process.env.FIX_REFS) }, realGit);+ } catch (err) {+ console.error(`::error::point-release-plan --read-bumps: ${messageOf(err)}`);+ process.exit(1);+ }+ log(`Read the bump of ${verdicts.size} changeset(s) written by ${process.env.MODE} refs ${process.env.FIX_REFS}.`);+ if (process.env.GITHUB_OUTPUT) {+ appendFileSync(process.env.GITHUB_OUTPUT, `bump_verdicts=${serializeBumpVerdicts(verdicts)}\n`);+ }+}+function main() {+ if (process.argv[2] === '--read-bumps') {+ readBumpsMain();+ return;+ }+const dryRun = process.env.DRY_RUN !== 'false';let plan;try {+ const io = realIo();+ if (process.env.BUMP_VERDICTS !== undefined) {+ io.git = withBumpVerdicts(io.git, parseBumpVerdicts(process.env.BUMP_VERDICTS));+ }plan = runPointRelease({mode: process.env.MODE,@@ -789,7 +843,7 @@ function main() {selfRepo: process.env.GITHUB_REPOSITORY || '',bridgeConfigured: process.env.BRIDGE_CONFIGURED === 'true',},- realIo(),+ io,);} catch (err) {const message = err instanceof Error ? err.message : String(err);diff --git a/.github/scripts/point-release-plan.test.mjs b/.github/scripts/point-release-plan.test.mjsindex 9085636f0..bb412bebf 100644--- a/.github/scripts/point-release-plan.test.mjs+++ b/.github/scripts/point-release-plan.test.mjs@@ -1,7 +1,14 @@-import { readFileSync } from 'node:fs';+import { spawnSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { delimiter, join } from 'node:path';+import { fileURLToPath, pathToFileURL } from 'node:url';import { Project, ts } from 'ts-morph';-import { describe, expect, test } from 'vitest';+import { afterEach, describe, expect, test } from 'vitest';+import { gitAt, withBumpVerdicts } from '../../scripts/compute-stable-version.mjs';+import { gitCleanEnv } from '../../scripts/git-clean-env.mjs';import {+ APP_CREDENTIAL_HELPER,deriveEntryLevelResolution,formatReleaseNotes,guardAnchor,@@ -14,7 +21,9 @@ import {guardTagFree,parseFixRefs,parseResolvePaths,+ pushTagArgs,RESOLVABLE_PATHS,+ readFixBumps,runPointRelease,verifyWorkspaceMatchesLockfile,} from './point-release-plan.mjs';@@ -1507,3 +1516,296 @@ describe('git escape rule self-test', () => {expect(inspectGitEscapes(`${declarations} const = ;`).census).toEqual(['syntax']);});});++describe('readFixBumps, run by the job that holds no release credential', () => {+ const blobGit = ({ blobs, bumps = {} }) => {+ const reads = [];+ return {+ reads,+ revParse: (ref) => `${ref}-sha`,+ changesetBlobs: (sha) => new Map(Object.entries(blobs[sha] ?? {})),+ bumpTypeOf: (sha, id) => {+ reads.push(`${sha}:${id}`);+ return bumps[id] ?? 'patch';+ },+ };+ };++ test('reads every changeset a fix ref adds or rewrites, keyed by blob, and no other', () => {+ const git = blobGit({+ blobs: {+ 'fix1-sha^': { 'keep-a': 'blob-keep', edited: 'blob-edited-before' },+ 'fix1-sha': { 'keep-a': 'blob-keep', edited: 'blob-edited-after', 'shiny-fix': 'blob-shiny' },+ },+ bumps: { 'shiny-fix': 'minor' },+ });+ const verdicts = readFixBumps({ mode: 'cherry-pick', fixRefs: ['fix1'] }, git);+ expect(Object.fromEntries(verdicts)).toEqual({ 'blob-edited-after': 'patch', 'blob-shiny': 'minor' });+ expect(git.reads).toEqual(['fix1-sha:edited', 'fix1-sha:shiny-fix']);+ });++ test('reads each ref of a batch against its own parent', () => {+ const git = blobGit({+ blobs: {+ 'fix1-sha^': {},+ 'fix1-sha': { 'fix1-cs': 'blob-1' },+ 'fix2-sha^': { 'fix1-cs': 'blob-1' },+ 'fix2-sha': { 'fix1-cs': 'blob-1', 'fix2-cs': 'blob-2' },+ },+ });+ const verdicts = readFixBumps({ mode: 'cherry-pick', fixRefs: ['fix1', 'fix2'] }, git);+ expect([...verdicts.keys()]).toEqual(['blob-1', 'blob-2']);+ expect(git.reads).toEqual(['fix1-sha:fix1-cs', 'fix2-sha:fix2-cs']);+ });++ test('revert mode reads no changeset frontmatter', () => {+ const git = blobGit({ blobs: { 'bad1-sha': { culprit: 'blob-culprit' } } });+ expect(readFixBumps({ mode: 'revert', fixRefs: ['bad1'] }, git).size).toBe(0);+ expect(git.reads).toEqual([]);+ });+});++describe('runPointRelease in the release job, which has no Changesets reader', () => {+ const cherryPickChangesets = {+ 'stable-sha': ['keep-a'],+ 'synthetic-sha': ['keep-a', 'shiny-fix'],+ fix1: ['keep-a', 'shiny-fix'],+ 'fix1^': ['keep-a'],+ };+ const releaseJobIo = (verdicts) => {+ const io = makeIo({ changesets: cherryPickChangesets });+ const git = {+ ...io.git,+ changesetBlobs: (sha) => new Map((cherryPickChangesets[sha] ?? []).map((id) => [id, `blob-${id}`])),+ bumpTypeOf: () => {+ throw new Error('the Changesets reader is not installed in this job');+ },+ };+ io.git = withBumpVerdicts(git, new Map(Object.entries(verdicts)));+ return io;+ };+ const ship = { mode: 'cherry-pick', fixRefs: ['fix1'], dryRun: false, selfRepo: 'inkeep/open-knowledge' };++ test('ships from the verdicts alone, never calling the reader', () => {+ const io = releaseJobIo({ 'blob-shiny-fix': 'patch' });+ const plan = runPointRelease(ship, io);+ expect(plan.tag).toBe('v0.32.1');+ expect(io.calls).toMatchObject({ tag: 1, pushTag: 1, createRelease: 1 });+ });++ test('a minor verdict still refuses as a non-patch bump', () => {+ const io = releaseJobIo({ 'blob-shiny-fix': 'minor' });+ let refusal;+ try {+ runPointRelease(ship, io);+ } catch (err) {+ refusal = err;+ }+ expect(refusal?.code).toBe('bump-not-patch');+ expect(io.calls).toEqual({ tag: 0, pushTag: 0, createRelease: 0, dispatch: 0 });+ });++ test('a changeset the reader job did not read fails closed before anything remote', () => {+ const io = releaseJobIo({ 'blob-unrelated': 'patch' });+ expect(() => runPointRelease(ship, io)).toThrow(/no bump verdict for \.changeset\/shiny-fix\.md/);+ expect(io.calls).toEqual({ tag: 0, pushTag: 0, createRelease: 0, dispatch: 0 });+ });+});++describe('the tag push credential', () => {+ const { GH_TOKEN: _ambient, ...withoutToken } = gitCleanEnv();+ const fill = (env, configured = []) =>+ spawnSync('git', [...configured, ...pushTagArgs('v0.0.0').slice(0, 4), 'credential', 'fill'], {+ input: 'protocol=https\nhost=github.com\n\n',+ encoding: 'utf8',+ env: { ...withoutToken, GIT_TERMINAL_PROMPT: '0', ...env },+ });++ test('pushes only the named tag to origin, after resetting every configured helper', () => {+ expect(pushTagArgs('v1.2.3')).toEqual([+ '-c',+ 'credential.helper=',+ '-c',+ `credential.helper=${APP_CREDENTIAL_HELPER}`,+ 'push',+ 'origin',+ 'v1.2.3',+ ]);+ });++ test('answers a credential request with GH_TOKEN as the App installation token', () => {+ const res = fill({ GH_TOKEN: 'placeholder-app-token' });+ expect(res.status, res.stderr).toBe(0);+ expect(res.stdout).toContain('username=x-access-token\npassword=placeholder-app-token\n');+ });++ test('a helper configured beforehand is reset rather than consulted', () => {+ const res = fill({ GH_TOKEN: 'placeholder-app-token' }, [+ '-c',+ 'credential.helper=!f() { echo username=someone-else; echo password=persisted-credential; }; f',+ ]);+ expect(res.stdout).not.toContain('persisted-credential');+ expect(res.stdout).toContain('password=placeholder-app-token\n');+ });++ test('without GH_TOKEN it supplies an empty password, so the push cannot authenticate', () => {+ const res = fill({});+ expect(res.stdout).toContain('password=\n');+ });+});++describe('a bump read in one job is found by blob in the other', () => {+ const roots = [];+ afterEach(() => {+ while (roots.length) rmSync(roots.pop(), { recursive: true, force: true });+ });+ const git = (cwd, ...args) => {+ const res = spawnSync('git', ['-c', 'user.name=t', '-c', '[email protected]', ...args], {+ cwd,+ env: gitCleanEnv(),+ encoding: 'utf8',+ });+ if (res.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${res.stderr}`);+ return res.stdout.trim();+ };+ const changeset = (root, id, type) => {+ mkdirSync(join(root, '.changeset'), { recursive: true });+ writeFileSync(join(root, '.changeset', `${id}.md`), `---\n"@inkeep/open-knowledge": ${type}\n---\n\nA change.\n`);+ };++ test('a cherry-picked changeset keeps the blob its fix commit wrote', () => {+ const root = mkdtempSync(join(tmpdir(), 'point-release-bumps-'));+ roots.push(root);+ git(root, 'init', '-q', '-b', 'main');+ changeset(root, 'keep-a', 'patch');+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'stable');+ const stable = git(root, 'rev-parse', 'HEAD');+ writeFileSync(join(root, 'unrelated.txt'), 'soaking\n');+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'unsoaked');+ changeset(root, 'shiny-fix', 'minor');+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'fix');+ const fix = git(root, 'rev-parse', 'HEAD');++ const verdicts = readFixBumps({ mode: 'cherry-pick', fixRefs: [fix] }, gitAt(root));+ expect([...verdicts.values()]).toEqual(['minor']);++ git(root, 'checkout', '-q', '--detach', stable);+ git(root, 'cherry-pick', fix);+ const synthetic = git(root, 'rev-parse', 'HEAD');+ expect(synthetic).not.toBe(fix);++ const releaseJob = withBumpVerdicts(+ {+ ...gitAt(root),+ bumpTypeOf: () => {+ throw new Error('the Changesets reader is not installed in this job');+ },+ },+ verdicts,+ );+ expect(releaseJob.bumpTypeOf(synthetic, 'shiny-fix')).toBe('minor');+ });+});++describe('the production entry points the release workflows run', () => {+ const SCRIPT = realpathSync(fileURLToPath(new URL('./point-release-plan.mjs', import.meta.url)));+ 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: _inherited, ...cleanEnv } = gitCleanEnv();+ const git = (cwd, ...args) => {+ const res = spawnSync('git', ['-c', 'user.name=t', '-c', '[email protected]', ...args], {+ cwd,+ env: gitCleanEnv(),+ encoding: 'utf8',+ });+ if (res.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${res.stderr}`);+ return res.stdout.trim();+ };+ const fixRepo = (fixBump) => {+ const root = scratch('point-release-read-bumps-');+ const changeset = (id, type) => {+ mkdirSync(join(root, '.changeset'), { recursive: true });+ writeFileSync(join(root, '.changeset', `${id}.md`), `---\n"@inkeep/open-knowledge": ${type}\n---\n\nA change.\n`);+ };+ git(root, 'init', '-q', '-b', 'main');+ changeset('keep-a', 'patch');+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'stable');+ changeset('shiny-fix', fixBump);+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'fix');+ return { root, fix: git(root, 'rev-parse', 'HEAD'), blob: git(root, 'rev-parse', 'HEAD:.changeset/shiny-fix.md') };+ };+ const runScript = (cwd, args, env) => {+ const output = join(scratch('point-release-output-'), 'github-output');+ writeFileSync(output, '');+ const res = spawnSync(process.execPath, [SCRIPT, ...args], {+ cwd,+ encoding: 'utf8',+ env: { ...cleanEnv, GITHUB_OUTPUT: output, ...env },+ });+ return { ...res, output: readFileSync(output, 'utf8') };+ };++ test('realIo pushes the tag with every configured helper reset and the App helper set', () => {+ const bin = scratch('point-release-fake-git-');+ const argvFile = join(bin, 'argv');+ writeFileSync(join(bin, 'git'), '#!/bin/sh\nfor arg in "$@"; do printf \'%s\\n\' "$arg"; done > "$ARGV_FILE"\n', {+ mode: 0o755,+ });+ const res = spawnSync(+ process.execPath,+ [+ '--input-type=module',+ '-e',+ `const { realIo } = await import(${JSON.stringify(pathToFileURL(SCRIPT).href)}); realIo().git.pushTag('v9.9.9');`,+ ],+ { cwd: bin, encoding: 'utf8', env: { ...cleanEnv, PATH: `${bin}${delimiter}${cleanEnv.PATH}`, ARGV_FILE: argvFile } },+ );+ expect(res.status, res.stderr).toBe(0);+ expect(readFileSync(argvFile, 'utf8').split('\n').filter(Boolean)).toEqual([+ '-c',+ 'credential.helper=',+ '-c',+ `credential.helper=${APP_CREDENTIAL_HELPER}`,+ 'push',+ 'origin',+ 'v9.9.9',+ ]);+ });++ test('--read-bumps writes the bump of each changeset a fix ref writes, keyed by blob id', () => {+ const { root, fix, blob } = fixRepo('minor');+ const res = runScript(root, ['--read-bumps'], { MODE: 'cherry-pick', FIX_REFS: fix });+ expect(res.status, res.stderr).toBe(0);+ expect(res.output).toBe(`bump_verdicts={"${blob}":"minor"}\n`);+ });++ test('--read-bumps writes {} in revert mode without reading frontmatter it could not parse', () => {+ const { root, fix } = fixRepo('Major');+ const revert = runScript(root, ['--read-bumps'], { MODE: 'revert', FIX_REFS: fix });+ expect(revert.status, revert.stderr).toBe(0);+ expect(revert.output).toBe('bump_verdicts={}\n');++ const cherryPick = runScript(root, ['--read-bumps'], { MODE: 'cherry-pick', FIX_REFS: fix });+ expect(cherryPick.status).toBe(1);+ expect(cherryPick.output).toBe('');+ });++ test('an empty BUMP_VERDICTS stops the release run with an error naming the read-bumps output', () => {+ const res = runScript(scratch('point-release-empty-verdicts-'), [], { 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/release-cascade-shape.test.mjs b/.github/scripts/release-cascade-shape.test.mjsindex 23a1c065e..94f36d58e 100644--- a/.github/scripts/release-cascade-shape.test.mjs+++ b/.github/scripts/release-cascade-shape.test.mjs@@ -1,7 +1,7 @@// biome-ignore-all lint/suspicious/noTemplateCurlyInString: shell and GitHub expression fixtures must remain literal.import { execFileSync } from 'node:child_process';import { createHash } from 'node:crypto';-import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { createRequire } from 'node:module';import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';@@ -1286,8 +1286,17 @@ describe('every job that reads changesets installs the Changesets reader first',importsReader(resolve(dirname(file), spec), seen),);};- const readsChangesets = (step) =>- [...(step.run ?? '').matchAll(/[\w./-]+\.mjs\b/g)].some(([path]) => importsReader(resolve(OK_ROOT, path)));+ const VERDICT_MODE_SCRIPTS = new Set([+ join(OK_ROOT, 'scripts', 'compute-stable-version.mjs'),+ join(OK_ROOT, '.github', 'scripts', 'point-release-plan.mjs'),+ ]);+ const readsChangesets = (step) => {+ const readers = [...(step.run ?? '').matchAll(/[\w./-]+\.mjs\b/g)]+ .map(([path]) => resolve(OK_ROOT, path))+ .filter((file) => importsReader(file));+ if (readers.length === 0) return false;+ return step.env?.BUMP_VERDICTS === undefined || readers.some((file) => !VERDICT_MODE_SCRIPTS.has(file));+ };const readerJobs = readdirSync(WORKFLOWS).filter((file) => file.endsWith('.yml')).flatMap((file) =>@@ -1301,8 +1310,8 @@ describe('every job that reads changesets installs the Changesets reader first',expect(readerJobs.map(({ job }) => job)).toEqual(expect.arrayContaining(['bug-lane.yml#bug-lane',- 'point-release.yml#point-release',- 'promote-stable.yml#promote',+ 'point-release.yml#read-bumps',+ 'promote-stable.yml#read-bumps','release.yml#release','select-beta-to-promote.yml#evaluate',]),@@ -1315,6 +1324,309 @@ describe('every job that reads changesets installs the Changesets reader first',.map(({ job }) => job);expect(uninstalled).toEqual([]);});++ test('BUMP_VERDICTS exempts only a script that implements verdict mode', () => {+ const env = { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}' };+ expect(readsChangesets({ env, run: 'node scripts/compute-stable-version.mjs "$BETA_TAG"' })).toBe(false);+ expect(readsChangesets({ env, run: 'node .github/scripts/point-release-plan.mjs' })).toBe(false);+ expect(readsChangesets({ env, run: 'node scripts/compute-next-beta.mjs' })).toBe(true);+ expect(+ readsChangesets({ env, run: 'node scripts/compute-stable-version.mjs v1\nnode scripts/compute-next-beta.mjs' }),+ ).toBe(true);+ expect(readsChangesets({ run: 'node scripts/compute-stable-version.mjs "$BETA_TAG"' })).toBe(true);+ });+});++describe('the release App credential never shares a job with installed packages', () => {+ const OK_ROOT = join(WORKFLOWS, '..', '..');+ const credentialWorkflows = ['point-release.yml', 'promote-stable.yml'];+ const jobs = credentialWorkflows.flatMap((file) =>+ Object.entries(parse(read(file)).jobs).map(([id, job]) => ({ name: `${file}#${id}`, job })),+ );+ const steps = (job) => job.steps ?? [];+ const commands = (step) =>+ (step.run ?? '')+ .split('\n')+ .filter((line) => !line.trim().startsWith('#'))+ .join('\n');+ const COMMAND_START = '(?:^|[;&|({`])';+ const COMMAND_PREFIX =+ '(?:if|elif|then|do|else|while|until|!|(?:exec|sudo|xargs|env|time|nohup|command)(?:\\s+-\\S+)*|timeout(?:\\s+-\\S+)*\\s+\\S+|[A-Za-z_]\\w*=\\S*)';+ const PACKAGE_RUNNER = '(?:pnpm|pnpx|npm|npx|yarn|bun|bunx|corepack)\\b';+ const PACKAGE_COMMAND = new RegExp(`${COMMAND_START}\\s*(?:${COMMAND_PREFIX}\\s+)*${PACKAGE_RUNNER}`, 'm');+ const PACKAGE_FREE_ACTIONS = [+ 'actions/checkout@',+ 'actions/setup-node@',+ 'actions/create-github-app-token@',+ 'actions/upload-artifact@',+ ];+ const compositeSteps = (uses, root) => {+ const dir = join(root, uses);+ const file = ['action.yml', 'action.yaml'].map((name) => join(dir, name)).find((path) => existsSync(path));+ if (!file) throw new Error(`local action ${uses} has no action.yml`);+ const action = parse(readFileSync(file, 'utf8'));+ return action.runs?.using === 'composite' ? action.runs.steps : null;+ };+ const packageRoutes = (stepList, root = OK_ROOT, seen = new Set()) =>+ stepList.flatMap((step) => {+ const routes = PACKAGE_COMMAND.test(commands(step)) ? [step.name ?? step.run] : [];+ if (step.uses?.startsWith('./')) {+ if (seen.has(step.uses)) return routes;+ const inner = compositeSteps(step.uses, root);+ return inner === null+ ? [...routes, step.uses]+ : [...routes, ...packageRoutes(inner, root, new Set([...seen, step.uses])).map((r) => `${step.uses} > ${r}`)];+ }+ if (step.uses && !PACKAGE_FREE_ACTIONS.some((prefix) => step.uses.startsWith(prefix))) {+ return [...routes, step.uses];+ }+ return routes;+ });+ const installs = (job) => packageRoutes(steps(job)).length > 0;+ const mintsAppToken = (job) =>+ steps(job).some((step) => step.uses?.startsWith('actions/create-github-app-token@'));++ const REFUSAL = 'Refuse bumps read for a different beta';+ const expressions = (value, path = []) => {+ if (typeof value === 'string') {+ if (path.at(-1) === 'if') return [{ path, expr: value.trim() }];+ return [...value.matchAll(/\$\{\{([\s\S]*?)\}\}/g)].map(([, body]) => ({ path, expr: body.trim() }));+ }+ if (value && typeof value === 'object') {+ return Object.entries(value).flatMap(([key, item]) => expressions(item, [...path, key]));+ }+ return [];+ };+ const isSanctionedRead = (job, { path, expr }) => {+ if (path[0] !== 'steps' || path[2] !== 'env') return false;+ if (path[3] === 'BUMP_VERDICTS') return expr === 'needs.read-bumps.outputs.bump_verdicts';+ return (+ path[3] === 'READ_BUMPS_BETA_TAG' &&+ job.steps[path[1]]?.name === REFUSAL &&+ expr === 'needs.read-bumps.outputs.beta_tag'+ );+ };+ const strayReaderReads = (job) =>+ expressions(job)+ .filter((found) => /\bneeds\b/.test(found.expr) && !isSanctionedRead(job, found))+ .map(({ path, expr }) => `${path.join('.')}: ${expr}`);++ const fixtureRoot = mkdtempSync(join(tmpdir(), 'release-cascade-local-actions-'));+ afterAll(() => rmSync(fixtureRoot, { recursive: true, force: true }));+ const localAction = (name, action, file = 'action.yml') => {+ const dir = join(fixtureRoot, '.github', 'actions', name);+ mkdirSync(dir, { recursive: true });+ writeFileSync(join(dir, file), JSON.stringify(action));+ return `./.github/actions/${name}`;+ };+ const composite = (...actionSteps) => ({ name: 'fixture', runs: { using: 'composite', steps: actionSteps } });+ const INSTALLING_COMPOSITE = localAction(+ 'installs',+ composite({ name: 'Install', shell: 'bash', run: 'pnpm install --frozen-lockfile' }),+ );+ const NESTED_COMPOSITE = localAction('nested', composite({ name: 'Inner', uses: INSTALLING_COMPOSITE }));+ const PACKAGE_FREE_COMPOSITE = localAction(+ 'package-free',+ composite({ name: 'Probe', shell: 'bash', run: 'node scripts/probe.mjs' }, { uses: 'actions/setup-node@v6' }),+ );+ const NODE_ACTION = localAction('node-action', { name: 'fixture', runs: { using: 'node24', main: 'index.js' } });+ const LOOPING_COMPOSITE = localAction('loop', composite({ name: 'Self', uses: './.github/actions/loop' }));+ const YAML_SPELLED_COMPOSITE = localAction(+ 'yaml-spelled',+ composite({ name: 'Install', shell: 'bash', run: 'npm ci' }),+ 'action.yaml',+ );++ test('the package-route detector bites on every form that would reopen the exposure', () => {+ const job = (step) => ({ steps: [step] });+ for (const run of [+ 'pnpm install --frozen-lockfile',+ 'pnpm --filter=. install --ignore-scripts',+ 'pnpm -r install',+ 'set -e; npm ci',+ 'cd x && npx some-tool',+ 'corepack enable',+ 'FOO=1 pnpm exec vitest',+ 'out=$(yarn add left-pad)',+ 'if pnpm install; then echo ok; fi',+ 'if ! npm ci; then exit 1; fi',+ 'if true; then :; elif npm ci; then :; fi',+ 'while ! pnpm install; do sleep 5; done',+ 'until pnpm install; do sleep 5; done',+ '! npm ci',+ '{ pnpm install; }',+ 'time pnpm install',+ 'time -p npm ci',+ 'timeout 300 pnpm install',+ 'timeout --signal=KILL 300 npm ci',+ 'nohup pnpm install &',+ 'command pnpm install',+ 'if ! timeout 300 pnpm install; then exit 1; fi',+ 'if x; then pnpm install; fi',+ 'for a in b; do npm ci; done',+ 'if x; then :; else npm ci; fi',+ 'exec pnpm install',+ 'sudo npm ci',+ 'echo a | xargs npm install',+ 'env npm ci',+ 'echo y | npx some-tool',+ '(npm ci)',+ 'out=`npm ci`',+ 'pnpx some-tool',+ 'bun install',+ 'bunx some-tool',+ 'set -e\npnpm install',+ ]) {+ expect(installs(job({ run })), run).toBe(true);+ }+ expect(installs(job({ uses: 'pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86' }))).toBe(true);+ for (const run of [+ 'node scripts/compute-stable-version.mjs "$BETA_TAG"',+ 'echo "dispatches publish-stable to release.yml for npm. npm latest does NOT move"',+ '# pnpm exec changeset version runs in main-reset',+ ' # if ! timeout 300 pnpm install; then exit 1; fi',+ '# x; pnpm install',+ ' # x; pnpm install',+ 'bunyan --version',+ ]) {+ expect(installs(job({ run })), run).toBe(false);+ }+ for (const uses of [+ 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1',+ 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e',+ 'actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3',+ 'actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a',+ ]) {+ expect(installs(job({ uses })), uses).toBe(false);+ }+ });++ test('the detector reads local actions from their action.yml, through nested composites', () => {+ const routes = (uses) => packageRoutes([{ name: 'Use it', uses }], fixtureRoot);+ expect(routes(INSTALLING_COMPOSITE)).toEqual([`${INSTALLING_COMPOSITE} > Install`]);+ expect(routes(NESTED_COMPOSITE)).toEqual([`${NESTED_COMPOSITE} > ${INSTALLING_COMPOSITE} > Install`]);+ expect(routes(NODE_ACTION)).toEqual([NODE_ACTION]);+ expect(routes(PACKAGE_FREE_COMPOSITE)).toEqual([]);+ expect(routes(LOOPING_COMPOSITE)).toEqual([]);+ expect(routes(YAML_SPELLED_COMPOSITE)).toEqual([`${YAML_SPELLED_COMPOSITE} > Install`]);+ expect(() => routes('./.github/actions/absent')).toThrow('local action ./.github/actions/absent has no action.yml');+ });++ test('each workflow has exactly one job that installs and one that mints, and they differ', () => {+ for (const file of credentialWorkflows) {+ const own = jobs.filter(({ name }) => name.startsWith(`${file}#`));+ const installers = own.filter(({ job }) => installs(job)).map(({ name }) => name);+ const minters = own.filter(({ job }) => mintsAppToken(job)).map(({ name }) => name);+ expect(installers, file).toHaveLength(1);+ expect(minters, file).toHaveLength(1);+ expect(installers[0], file).not.toBe(minters[0]);+ }+ });++ test('a job that installs packages references no secret and holds a read-only GITHUB_TOKEN', () => {+ for (const { name, job } of jobs.filter(({ job }) => installs(job))) {+ expect(JSON.stringify(job), name).not.toMatch(/secrets\.|create-github-app-token|app-token|bridge-token/);+ expect(job.permissions, name).toEqual({ contents: 'read' });+ }+ });++ test('a job that mints an App token has no package route, local composite actions included', () => {+ for (const { name, job } of jobs.filter(({ job }) => mintsAppToken(job))) {+ expect(packageRoutes(steps(job)), name).toEqual([]);+ expect(job.needs, name).toBe('read-bumps');+ }+ });++ test('the reader-output scan sees every way a job can read read-bumps', () => {+ const verdictStep = {+ name: 'Compute',+ env: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}' },+ run: 'node scripts/compute-stable-version.mjs "$BETA_TAG"',+ };+ const refusal = {+ name: REFUSAL,+ env: {+ RESOLVED: '${{ steps.resolve.outputs.beta_tag }}',+ READ_BUMPS_BETA_TAG: '${{ needs.read-bumps.outputs.beta_tag }}',+ },+ run: 'test "$RESOLVED" = "$READ_BUMPS_BETA_TAG"',+ };+ const prose = { name: 'Announce', run: 'echo "the release needs a published beta"' };+ const sanctioned = { needs: 'read-bumps', steps: [verdictStep, refusal, prose] };+ expect(strayReaderReads(sanctioned)).toEqual([]);+ const withStep = (step) => ({ ...sanctioned, steps: [verdictStep, refusal, { name: 'Stray', ...step }] });+ const withRefusalEnv = (env) => ({ ...sanctioned, steps: [verdictStep, { ...refusal, env: { ...refusal.env, ...env } }] });+ const strays = {+ 'job-level env': { ...sanctioned, env: { BETA_TAG: '${{ needs.read-bumps.outputs.beta_tag }}' } },+ 'job-level if': { ...sanctioned, if: "needs.read-bumps.outputs.beta_tag != ''" },+ 'job-level outputs': { ...sanctioned, outputs: { beta: '${{ needs.read-bumps.outputs.beta_tag }}' } },+ 'job-level name': { ...sanctioned, name: 'Promote ${{ needs.read-bumps.outputs.beta_tag }}' },+ 'single-quoted index': withStep({ env: { B: "${{ needs['read-bumps'].outputs['beta_tag'] }}" } }),+ 'double-quoted index': withStep({ env: { B: '${{ needs["read-bumps"].outputs["beta_tag"] }}' } }),+ 'whole needs object': withStep({ run: 'echo ${{ toJSON(needs) }}' }),+ 'whole outputs object': withStep({ env: { O: '${{ toJSON(needs.read-bumps.outputs) }}' } }),+ 'whole job by index': withStep({ env: { O: "${{ toJSON(needs['read-bumps']) }}" } }),+ 'step-level if': withStep({ if: "needs.read-bumps.outputs.beta_tag == 'v1.0.0-beta.1'" }),+ 'expression inside a run block': withStep({ run: 'git tag x "${{ needs.read-bumps.outputs.beta_tag }}"' }),+ 'bump_verdicts outside BUMP_VERDICTS': withStep({ env: { V: '${{ needs.read-bumps.outputs.bump_verdicts }}' } }),+ 'beta_tag outside the refusal step': withStep({+ env: { READ_BUMPS_BETA_TAG: '${{ needs.read-bumps.outputs.beta_tag }}' },+ }),+ 'the refusal step reading another expression': withRefusalEnv({+ READ_BUMPS_BETA_TAG: '${{ toJSON(needs.read-bumps.outputs) }}',+ }),+ 'the refusal step reading beta_tag under another name': withRefusalEnv({+ ALSO_BETA_TAG: '${{ needs.read-bumps.outputs.beta_tag }}',+ }),+ 'BUMP_VERDICTS reading another output': withStep({+ env: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.beta_tag }}' },+ }),+ 'an action input named BUMP_VERDICTS': withStep({+ uses: './.github/actions/consumer',+ with: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}' },+ }),+ 'a service container env named BUMP_VERDICTS': {+ ...sanctioned,+ services: { cache: { image: 'redis:7', env: { BUMP_VERDICTS: '${{ needs.read-bumps.outputs.bump_verdicts }}' } } },+ },+ };+ for (const [form, job] of Object.entries(strays)) {+ expect(strayReaderReads(job), form).not.toEqual([]);+ }+ });++ test('a job that mints an App token takes only bump_verdicts from the reader job', () => {+ for (const { name, job } of jobs.filter(({ job }) => mintsAppToken(job))) {+ const verdictSteps = steps(job).filter((step) => step.env?.BUMP_VERDICTS !== undefined);+ expect(verdictSteps.length, name).toBeGreaterThan(0);+ for (const step of verdictSteps) {+ expect(step.env.BUMP_VERDICTS, `${name} ${step.name}`).toBe(+ '${{ needs.read-bumps.outputs.bump_verdicts }}',+ );+ }+ expect(strayReaderReads(job), name).toEqual([]);+ for (const step of steps(job).filter((candidate) => candidate.name === REFUSAL)) {+ expect(step.id, name).toBeUndefined();+ expect(step.if, name).toBeUndefined();+ expect(commands(step), name).toMatch(/if \[\[ "\$RESOLVED" != "\$READ_BUMPS_BETA_TAG" \]\]; then[\s\S]*exit 1/);+ expect(commands(step), name).toMatch(/Re-run all jobs/);+ expect(commands(step), name).toMatch(/explicit beta_tag/);+ }+ }+ });++ test('no checkout in either workflow persists a credential or receives an App token', () => {+ const checkouts = jobs.flatMap(({ name, job }) =>+ steps(job)+ .filter((step) => step.uses?.startsWith('actions/checkout@'))+ .map((step) => ({ name, step })),+ );+ expect(checkouts.length).toBe(4);+ for (const { name, step } of checkouts) {+ expect(step.with?.['persist-credentials'], name).toBe(false);+ expect(step.with?.token, name).toBeUndefined();+ }+ });});describe('Linux packaging ships the native prebuilds and checks them before upload', () => {diff --git a/.github/workflows/point-release.yml b/.github/workflows/point-release.ymlindex 95eb7e37a..51fdc91a4 100644--- a/.github/workflows/point-release.yml+++ b/.github/workflows/point-release.yml@@ -110,8 +110,45 @@ concurrency:cancel-in-progress: falsejobs:+ read-bumps:+ name: Read changeset bumps (no release 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 the fix refs write+ id: bumps+ env:+ MODE: ${{ inputs.mode }}+ FIX_REFS: ${{ inputs.fix_refs }}+ run: |+ set -euo pipefail+ git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main+ node .github/scripts/point-release-plan.mjs --read-bumps+point-release:name: ${{ inputs.dry_run && 'Plan' || 'Ship' }} point release (${{ inputs.mode }})+ needs: read-bumpsruns-on: ubuntu-latesttimeout-minutes: 20steps:@@ -134,23 +171,13 @@ jobs:# the synthetic commit, and walking ancestry to prove each fix ref is# already on main.fetch-depth: 0- # Persist the App token into .git/config so the later `git push origin- # <tag>` runs as the App. Without this the push falls back to- # GITHUB_TOKEN and hits the workflow-change policy on any stable whose- # .github/workflows/ tree differs from main HEAD.- token: ${{ steps.app-token.outputs.token }}+ persist-credentials: false- name: Set up Nodeuses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0with: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: Prepare git for the synthetic commitrun: |set -euo pipefail@@ -218,6 +245,7 @@ jobs:# "no cross-repo credential" and skips the main-reset dispatch.BRIDGE_GH_TOKEN: ${{ steps.bridge-token.outputs.token }}BRIDGE_CONFIGURED: ${{ steps.bridge-check.outputs.configured }}+ BUMP_VERDICTS: ${{ needs.read-bumps.outputs.bump_verdicts }}MODE: ${{ inputs.mode }}FIX_REFS: ${{ inputs.fix_refs }}ANCHOR_DELTA_IDS: ${{ inputs.anchor_delta_ids }}diff --git a/.github/workflows/promote-stable.yml b/.github/workflows/promote-stable.ymlindex 60707b3cd..3994259bc 100644--- a/.github/workflows/promote-stable.yml+++ b/.github/workflows/promote-stable.yml@@ -106,8 +106,78 @@ concurrency:cancel-in-progress: falsejobs:+ read-bumps:+ name: Read changeset bumps (no release credential)+ runs-on: ubuntu-latest+ timeout-minutes: 10+ permissions:+ contents: read+ outputs:+ beta_tag: ${{ steps.resolve.outputs.beta_tag }}+ 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: Resolve beta tag to promote+ id: resolve+ env:+ INPUT_BETA_TAG: ${{ inputs.beta_tag }}+ run: |+ set -euo pipefail+ if [[ -n "${INPUT_BETA_TAG:-}" ]]; then+ RESOLVED="$INPUT_BETA_TAG"+ echo "auto=false" >> "$GITHUB_OUTPUT"+ echo "Using explicitly provided beta tag: $RESOLVED"+ else+ RESOLVED=$(git tag --list 'v*-beta.*' --sort=-version:refname \+ | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$' \+ | head -n 1 || true)+ if [[ -z "$RESOLVED" ]]; then+ echo "::error::No vX.Y.Z-beta.N tags found to promote. Did the auto-cadence beta release run?"+ exit 1+ fi+ echo "auto=true" >> "$GITHUB_OUTPUT"+ echo "Auto-resolved newest beta tag: $RESOLVED"+ fi+ echo "beta_tag=$RESOLVED" >> "$GITHUB_OUTPUT"++ - name: Verify beta tag exists+ env:+ BETA_TAG: ${{ steps.resolve.outputs.beta_tag }}+ run: |+ set -euo pipefail+ if ! git rev-parse "refs/tags/${BETA_TAG}" >/dev/null 2>&1; then+ echo "::error::Beta tag '${BETA_TAG}' not found on the public repo. Did the auto-cadence release run?"+ exit 1+ fi+ echo "Tag ${BETA_TAG} resolves to $(git rev-parse "refs/tags/${BETA_TAG}")"++ - 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 the promotion adds+ id: bumps+ env:+ BETA_TAG: ${{ steps.resolve.outputs.beta_tag }}+ run: |+ set -euo pipefail+ node scripts/compute-stable-version.mjs "$BETA_TAG"+promote:name: Promote ${{ inputs.beta_tag || 'newest beta' }} to stable+ needs: read-bumpsruns-on: ubuntu-latesttimeout-minutes: 20steps:@@ -129,18 +199,7 @@ jobs:uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:fetch-depth: 0- # Persist the App token into .git/config so the later- # `git push origin "$STABLE_TAG"` step uses App identity.- # Without this, persist-credentials defaults to the workflow's- # GITHUB_TOKEN and the push hits the App-token workflow-change- # check on any beta whose .github/workflows/ tree differs from- # main HEAD.- token: ${{ steps.app-token.outputs.token }}- # We need to operate on the beta tag's SHA for the package.json- # override + pnpm exec changeset publish. We resolve and check it out- # explicitly below; default-branch checkout above is just so the- # workflow scripts (this file) live next to a writable working- # tree.+ persist-credentials: false- name: Resolve beta tag to promote# workflow_dispatch may carry an explicit beta_tag; repository_dispatch@@ -172,6 +231,18 @@ jobs:fiecho "beta_tag=$RESOLVED" >> "$GITHUB_OUTPUT"+ - name: Refuse bumps read for a different beta+ env:+ RESOLVED: ${{ steps.resolve.outputs.beta_tag }}+ READ_BUMPS_BETA_TAG: ${{ needs.read-bumps.outputs.beta_tag }}+ run: |+ set -euo pipefail+ if [[ "$RESOLVED" != "$READ_BUMPS_BETA_TAG" ]]; then+ echo "::error::read-bumps read changeset bumps for '${READ_BUMPS_BETA_TAG}', but this job resolved '${RESOLVED}'. Refusing to promote with bumps read for a different beta. This usually means only the failed jobs were re-run after a newer beta landed, which reuses read-bumps' earlier result. Re-run all jobs, or dispatch promote-stable with an explicit beta_tag."+ exit 1+ fi+ echo "read-bumps read the same beta this job resolved: ${RESOLVED}"+- name: Guard - auto-resolved beta is fully cut# Only the blank/auto dispatch path (promote-newest) needs this guard.# The explicit beta_tag path is an operator override that keeps the@@ -212,34 +283,16 @@ jobs:fiecho "Beta ${BETA_TAG} is complete (published, ${dmg} dmg, ${manifest} mac.yml); safe to promote."- - name: Verify beta tag exists- env:- BETA_TAG: ${{ steps.resolve.outputs.beta_tag }}- run: |- set -euo pipefail- # actions/checkout fetches all refs with fetch-depth: 0; verify- # the resolved tag is present.- if ! git rev-parse "refs/tags/${BETA_TAG}" >/dev/null 2>&1; then- echo "::error::Beta tag '${BETA_TAG}' not found on the public repo. Did the auto-cadence release run?"- exit 1- fi- echo "Tag ${BETA_TAG} resolves to $(git rev-parse "refs/tags/${BETA_TAG}")"-- name: Set up Nodeuses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0with: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: Compute stable version from beta tagid: verenv:BETA_TAG: ${{ steps.resolve.outputs.beta_tag }}+ BUMP_VERDICTS: ${{ needs.read-bumps.outputs.bump_verdicts }}run: |set -euo pipefail# Compute the stable version as a SINGLE semver bump over the current@@ -297,7 +350,10 @@ jobs:echo "Tag ${STABLE_TAG} already at ${BETA_SHA}; skipping git tag step."elsegit tag "$STABLE_TAG" "$BETA_SHA"- git push origin "$STABLE_TAG"+ # shellcheck disable=SC2016+ git -c credential.helper= \+ -c 'credential.helper=!f() { test "$1" = get || return 0; echo username=x-access-token; echo "password=$GH_TOKEN"; }; f' \+ push origin "$STABLE_TAG"fi- name: Aggregate beta release bodies since previous stablediff --git a/knip.config.ts b/knip.config.tsindex d3638888e..65f0e8807 100644--- a/knip.config.ts+++ b/knip.config.ts@@ -147,15 +147,11 @@ export default {'packages/server': {entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],project: 'src/**',- ignoreDependencies: [- '@types/shell-quote',- ],+ ignoreDependencies: ['@types/shell-quote'],},'packages/cli': {entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],- ignoreDependencies: [- 'yjs',- ],+ ignoreDependencies: ['yjs'],},'packages/desktop': {entry: [diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.tsindex a28cc2b18..8a60e5826 100644--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts@@ -1,4 +1,3 @@-import { readFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.tsindex 4fc2c11f9..6fcdc23f2 100644--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { normalizeBridge } from '@inkeep/open-knowledge-core';import { updateYFragment } from '@tiptap/y-tiptap';diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.tsindex 9f2f6feb6..40b5cdfd6 100644--- a/packages/app/tests/integration/interior-edit-freshness.test.ts+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.tsindex 2a085742b..93666af70 100644--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.tsindex 878d5196b..867598d34 100644--- a/packages/app/tests/integration/producer-guard-wiring.test.ts+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts@@ -1,4 +1,3 @@-import { setTimeout as wait } from 'node:timers/promises';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';import { afterAll, beforeAll, describe, expect, test } from 'vitest';diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.tsindex 4ada3cf26..0970ac12f 100644--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts@@ -1,4 +1,3 @@-import { randomUUID } from 'node:crypto';import { afterEach, describe, expect, test } from 'vitest';import { agentWriteMd, createTestServer, type TestServer } from './test-harness';diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.tsindex cbe2b705f..b632185e1 100644--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts@@ -1,4 +1,3 @@-import { execFileSync } from 'node:child_process';import { randomUUID } from 'node:crypto';import { join } from 'node:path';diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.tsindex 89bc9b4d9..c530ce4ba 100644--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts@@ -1,4 +1,3 @@-import { randomUUID } from 'node:crypto';import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';import type * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.tsindex a78aeb0e4..d3767adc9 100644--- a/packages/app/tests/integration/undo-after-rollback.test.ts+++ b/packages/app/tests/integration/undo-after-rollback.test.ts@@ -1,4 +1,3 @@-import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';import { afterAll, beforeAll, describe, expect, test } from 'vitest';import * as Y from 'yjs';diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.tsindex e7cc69c3f..b076f955c 100644--- a/packages/app/tests/integration/undo-recycle-reset.test.ts+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts@@ -1,4 +1,3 @@-import { writeFileSync } from 'node:fs';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.tsindex 9ddcd0730..7935e35f8 100644--- a/packages/app/tests/integration/undo-rederive-survival.test.ts+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts@@ -1,4 +1,3 @@-import { prependFrontmatter } from '@inkeep/open-knowledge-core';import { Plugin, PluginKey } from '@tiptap/pm/state';import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.tsindex 2a597ec3d..f4cc8a286 100644--- a/packages/core/src/bridge/compose.ts+++ b/packages/core/src/bridge/compose.ts@@ -1,4 +1,3 @@-import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.tsindex 01ef76a9f..8fb428b90 100644--- a/packages/core/src/bridge/doc-boundary-space.ts+++ b/packages/core/src/bridge/doc-boundary-space.ts@@ -1,4 +1,3 @@-import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.tsindex fb0ba5a7c..fc267cbea 100644--- a/packages/core/src/markdown/comment-promoter.ts+++ b/packages/core/src/markdown/comment-promoter.ts@@ -1,4 +1,3 @@-import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.tsindex fa3cfcd86..bfd7e3109 100644--- a/packages/core/src/markdown/merged-walker.ts+++ b/packages/core/src/markdown/merged-walker.ts@@ -1,4 +1,3 @@-import type { Nodes, Parent, Root } from 'mdast';import { SKIP, visit } from 'unist-util-visit';import type { VFile } from 'vfile';diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.tsindex 8be632ba4..4d3250d3a 100644--- a/packages/core/src/markdown/safe-url.ts+++ b/packages/core/src/markdown/safe-url.ts@@ -1,4 +1,3 @@-export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');diff --git a/scripts/compute-stable-version.mjs b/scripts/compute-stable-version.mjsindex 41688aa97..50e39ad43 100644--- a/scripts/compute-stable-version.mjs+++ b/scripts/compute-stable-version.mjs@@ -185,6 +185,15 @@ export function gitAt(cwd) {},changesetIds: (sha) =>changesetIdsFromTreePaths(runGit(['ls-tree', '--name-only', sha, '--', '.changeset/'], cwd).split('\n')),+ changesetBlobs: (sha) => {+ const blobs = new Map();+ for (const line of runGit(['ls-tree', sha, '--', '.changeset/'], cwd).split('\n')) {+ const [meta, path] = line.split('\t');+ const [id] = changesetIdsFromTreePaths([path ?? '']);+ if (id !== undefined) blobs.set(id, meta.split(' ')[2]);+ }+ return blobs;+ },isAncestor: (a, b) => {const res = spawnSync('git', ['merge-base', '--is-ancestor', a, b], { cwd, encoding: 'utf8', env: gitCleanEnv() });if (res.status === 0) return true;@@ -200,6 +209,61 @@ export function gitAt(cwd) {export const realGit = gitAt();+const BUMP_VERDICT_TYPES = new Set(['patch', 'minor', 'major', null]);++export function parseBumpVerdicts(raw) {+ if (String(raw ?? '').trim() === '') {+ throw new Error(+ 'BUMP_VERDICTS is empty: the read-bumps job wrote no bump_verdicts output, or this step does not ' ++ 'receive needs.read-bumps.outputs.bump_verdicts.',+ );+ }+ let parsed;+ try {+ parsed = JSON.parse(String(raw));+ } catch (err) {+ throw new Error(`bump verdicts are not JSON: ${err.message}`);+ }+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {+ throw new Error('bump verdicts must be a JSON object mapping changeset blob ids to bump types.');+ }+ for (const [blob, type] of Object.entries(parsed)) {+ if (!BUMP_VERDICT_TYPES.has(type)) {+ throw new Error(`bump verdict for blob ${blob} is ${JSON.stringify(type)}, not patch, minor, major or null.`);+ }+ }+ return new Map(Object.entries(parsed));+}++export const serializeBumpVerdicts = (verdicts) => JSON.stringify(Object.fromEntries(verdicts));++export function recordBumpVerdicts(git, verdicts) {+ return {+ ...git,+ bumpTypeOf: (sha, id) => {+ const type = git.bumpTypeOf(sha, id);+ verdicts.set(git.changesetBlobs(sha).get(id), type);+ return type;+ },+ };+}++export function withBumpVerdicts(git, verdicts) {+ return {+ ...git,+ bumpTypeOf: (sha, id) => {+ const blob = git.changesetBlobs(sha).get(id);+ if (blob === undefined || !verdicts.has(blob)) {+ throw new Error(+ `no bump verdict for .changeset/${id}.md at ${sha} (blob ${blob ?? 'absent'}); the job that ran the ` ++ 'Changesets reader did not read this changeset, so its bump is unknown here.',+ );+ }+ return verdicts.get(blob);+ },+ };+}+export function readAnchorVersion() {const pre = JSON.parse(readFileSync('.changeset/pre.json', 'utf8'));if (pre.mode !== 'pre') {@@ -304,9 +368,14 @@ function main() {process.exit(1);}+ const verdicts = new Map();let result;try {- result = computeStablePromotion(betaTag, realGit);+ const git =+ process.env.BUMP_VERDICTS === undefined+ ? recordBumpVerdicts(realGit, verdicts)+ : withBumpVerdicts(realGit, parseBumpVerdicts(process.env.BUMP_VERDICTS));+ result = computeStablePromotion(betaTag, git);} catch (err) {console.error(`::error::compute-stable-version: ${err.message}`);process.exit(1);@@ -332,6 +401,7 @@ function main() {`beta_sha=${result.betaSha ?? ''}`,`latest_stable_sha=${result.latestStableSha ?? ''}`,`delta_ids=${JSON.stringify(result.deltaIds ?? [])}`,+ `bump_verdicts=${serializeBumpVerdicts(verdicts)}`,];appendFileSync(process.env.GITHUB_OUTPUT, `${lines.join('\n')}\n`);}diff --git a/scripts/compute-stable-version.test.mjs b/scripts/compute-stable-version.test.mjsindex f73640f37..4a7734b44 100644--- a/scripts/compute-stable-version.test.mjs+++ b/scripts/compute-stable-version.test.mjs@@ -1,7 +1,8 @@import { spawnSync } from 'node:child_process';-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';import { afterEach, describe, expect, test } from 'vitest';import { loadChangesets, maxReleaseType } from './compute-next-beta.mjs';import {@@ -10,6 +11,9 @@ import {computeStablePromotion,evaluateAnchorGuard,gitAt,+ parseBumpVerdicts,+ recordBumpVerdicts,+ withBumpVerdicts,} from './compute-stable-version.mjs';import { gitCleanEnv } from './git-clean-env.mjs';@@ -432,3 +436,124 @@ describe('gitAt reads a commit\'s changesets the way Changesets reads the same texpect(() => gitAt(root).bumpTypeOf('HEAD', 'broken')).toThrow();});});++describe('parseBumpVerdicts', () => {+ test('reads a blob-to-bump object, keeping a null bump', () => {+ expect(parseBumpVerdicts('{"aaa":"minor","bbb":null}')).toEqual(+ new Map([+ ['aaa', 'minor'],+ ['bbb', null],+ ]),+ );+ });++ test.each([+ ['', /^BUMP_VERDICTS is empty: the read-bumps job wrote no bump_verdicts output/],+ [' \n', /^BUMP_VERDICTS is empty/],+ ['{', /^bump verdicts are not JSON/],+ ['[]', /JSON object/],+ ['null', /JSON object/],+ ['{"aaa":"huge"}', /aaa is "huge"/],+ ])('refuses %j', (raw, message) => {+ expect(() => parseBumpVerdicts(raw)).toThrow(message);+ });+});++describe('bump verdicts carry a read from one job to another by blob id', () => {+ test('a verdict recorded where the reader ran answers the same changeset where it cannot', () => {+ const root = committedChangesets({ 'quoted.md': bump(`"${OK}": "minor"`), 'plain.md': bump(`"${OK}": patch`) });+ const verdicts = new Map();+ const reading = recordBumpVerdicts(gitAt(root), verdicts);+ expect(reading.bumpTypeOf('HEAD', 'quoted')).toBe('minor');+ expect([...verdicts.values()]).toEqual(['minor']);++ const noReader = withBumpVerdicts(+ {+ ...gitAt(root),+ bumpTypeOf: () => {+ throw new Error('the Changesets reader is not installed in this job');+ },+ },+ verdicts,+ );+ expect(noReader.bumpTypeOf('HEAD', 'quoted')).toBe('minor');+ expect(() => noReader.bumpTypeOf('HEAD', 'plain')).toThrow(/no bump verdict for \.changeset\/plain\.md/);+ });+});++describe('the promote job computes the stable version with no node_modules at all', () => {+ const SCRIPTS = dirname(fileURLToPath(import.meta.url));+ const SCRIPT_FILES = ['compute-stable-version.mjs', 'compute-next-beta.mjs', 'git-clean-env.mjs'];++ function promotionFixture() {+ const root = mkdtempSync(join(tmpdir(), 'stable-version-promotion-'));+ repos.push(root);+ const commit = (name, body, tagName) => {+ mkdirSync(join(root, '.changeset'), { recursive: true });+ writeFileSync(join(root, '.changeset', name), body);+ git(root, ['add', '-A']);+ git(root, ['-c', 'user.name=t', '-c', '[email protected]', 'commit', '-q', '-m', name]);+ git(root, ['tag', tagName]);+ };+ git(root, ['init', '-q', '-b', 'main']);+ commit('keep.md', bump(`"${OK}": patch`), 'v0.30.1');+ commit('new-thing.md', bump(`"${OK}": minor`), 'v0.30.2-beta.1');+ return root;+ }++ function isolatedScripts() {+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'stable-version-no-node-modules-')));+ repos.push(dir);+ mkdirSync(join(dir, 'scripts'));+ for (const file of SCRIPT_FILES) copyFileSync(join(SCRIPTS, file), join(dir, 'scripts', file));+ return join(dir, 'scripts', 'compute-stable-version.mjs');+ }++ function run(script, cwd, env = {}) {+ const output = join(mkdtempSync(join(tmpdir(), 'stable-version-output-')), 'github-output');+ repos.push(dirname(output));+ writeFileSync(output, '');+ const { BUMP_VERDICTS: _inherited, ...base } = gitCleanEnv();+ const res = spawnSync(process.execPath, [script, 'v0.30.2-beta.1'], {+ cwd,+ encoding: 'utf8',+ env: { ...base, GITHUB_OUTPUT: output, ...env },+ });+ const outputs = Object.fromEntries(+ readFileSync(output, 'utf8')+ .split('\n')+ .filter(Boolean)+ .map((line) => [line.split('=')[0], line.split('=').slice(1).join('=')]),+ );+ return { ...res, outputs };+ }++ test('with the reader job verdicts it writes every output the reader job wrote', () => {+ const root = promotionFixture();+ const withReader = run(join(SCRIPTS, 'compute-stable-version.mjs'), root);+ expect(withReader.status, withReader.stderr).toBe(0);+ expect(withReader.outputs.stable_tag).toBe('v0.31.0');+ expect(Object.values(JSON.parse(withReader.outputs.bump_verdicts))).toEqual(['minor']);++ const withoutReader = run(isolatedScripts(), root, { BUMP_VERDICTS: withReader.outputs.bump_verdicts });+ expect(withoutReader.status, withoutReader.stderr).toBe(0);+ const { bump_verdicts: recorded, ...promotion } = withReader.outputs;+ expect(recorded).not.toBe('{}');+ expect(withoutReader.outputs).toEqual({ ...promotion, bump_verdicts: '{}' });+ });++ test('without verdicts the same isolated copy cannot load the reader, so the run above proves it never tried', () => {+ const root = promotionFixture();+ const res = run(isolatedScripts(), root);+ expect(res.status).toBe(1);+ expect(res.stderr).toMatch(/@changesets\/cli/);+ });++ test('an empty BUMP_VERDICTS stops the run with an error naming the read-bumps output, and writes nothing', () => {+ const root = promotionFixture();+ const res = run(isolatedScripts(), root, { 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.outputs).toEqual({});+ });+});