Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(ci): verify advertised tips for pregate publication (#13386)
[._.]/ Adam Eivy05b487b26229
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.mdindex 0ce1703fdc..e6fdb1ef86 100644--- a/docs/GITHUB_ACTIONS.md+++ b/docs/GITHUB_ACTIONS.md@@ -244,7 +244,11 @@ pushed head, and the impact planner skips what it attests to:planner compares it with the head commit's tree on the PR. A SHA is nevercompared, for the same reason `scripts/verify-ci-status.js` compares trees:the content is what was tested. The commit must already be on the upstream- remote (the one `branch.<name>.remote` names); GitHub only accepts a status+ remote (the one `branch.<name>.remote` names). Local tracking containment is+ checked first; if stale after a URL/path push, exact advertised branch tips+ are checked through that remote without fetching or changing the checkout.+ Unreadable or malformed remote evidence refuses publication verification.+ GitHub only accepts a statuson a commit it has, which is why attesting is a step after `git push`, not apregate flag.- **The merge ref is not the head tree.** The receipt vouches for the headdiff --git a/scripts/pregate-attest.js b/scripts/pregate-attest.jsindex a6427a18f5..8a1d7019ff 100644--- a/scripts/pregate-attest.js+++ b/scripts/pregate-attest.js@@ -226,11 +226,19 @@ export function runAttest({ argv = [], cwd = REPO_ROOT, exec = spawnSync, log =const target = `${repository.owner}/${repository.repo}`;const treeOf = (commit) => git(['rev-parse', '--verify', '--quiet', `${commit}^{tree}`]);- // Remote-tracking refs are current right after a push; a commit nothing- // under `<remote>/` contains has not been pushed (or not fetched back).+ // Keep the local containment fast path. URL/path pushes may leave these+ // refs stale, so ask the configured remote through its existing transport+ // for exact advertised branch tips without fetching or changing the tree.const isPushed = (commit) => {const branches = git(['branch', '-r', '--contains', commit, '--format=%(refname:short)']);- return branches !== null && branches.split('\n').some((name) => name.startsWith(`${remote}/`));+ if (branches !== null && branches.split('\n').some((name) => name.startsWith(`${remote}/`))) return true;+ const advertised = git(['ls-remote', '--heads', remote]);+ if (advertised === null) throw refusal(`cannot verify publication of ${commit.slice(0, 9)} on ${remote}: remote branch tips could not be read; check remote access, then attest again.`);+ const tips = advertised ? advertised.split('\n') : [];+ if (tips.some((line) => !/^[0-9a-f]{40}\trefs\/heads\/[^\s]+$/.test(line))) {+ throw refusal(`cannot verify publication of ${commit.slice(0, 9)} on ${remote}: malformed remote branch tips; no status posted.`);+ }+ return tips.some((line) => line.startsWith(`${commit}\t`));};if (options.revoke !== null) {diff --git a/scripts/pregate-attest.test.js b/scripts/pregate-attest.test.jsindex fac950de27..2215d68edf 100644--- a/scripts/pregate-attest.test.js+++ b/scripts/pregate-attest.test.js@@ -6,6 +6,10 @@* `runAttest` with an injected exec, so the only thing left to a live run is* `gh`'s own authentication.*/+import { spawnSync } from 'node:child_process';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';import { describe, expect, it } from 'vitest';import { parseArgs, planAttestation, resolveRepository, runAttest, statusRequest, USAGE } from './pregate-attest.js';import {@@ -210,6 +214,7 @@ describe('runAttest', () => {[/^git remote get-url upstream$/, '[email protected]:acme/widget.git'],[/^git rev-parse --verify --quiet .*\^\{tree\}$/, TREE],[/^git branch -r --contains .* --format=/, 'upstream/feature\nfork/feature'],+ [/^git ls-remote --heads upstream$/, `${BASE}\trefs/heads/main`],[/^git symbolic-ref --short -q refs\/remotes\/upstream\/HEAD$/, 'upstream/main'],[/^git merge-base upstream\/main /, BASE],];@@ -257,6 +262,69 @@ describe('runAttest', () => {}});+ it('refuses unreadable or malformed remote publication evidence without posting', () => {+ for (const result of [{ status: 1, stderr: 'unreachable' }, `${SHA}\trefs/tags/only`, 'malformed']) {+ const calls = [];+ const output = io();+ const exec = fakeExec(gitTable([+ [/^git branch -r --contains/, ''], [/^git ls-remote --heads upstream$/, result],+ ]), calls);+ expect(run({ exec, ...output, readReceipt: () => green })).toBe(1);+ expect(output.err[0]).toMatch(/cannot verify publication/);+ expect(calls.some((call) => call.startsWith('gh api'))).toBe(false);+ }+ });++ it('attests an explicit-path push with stale tracking refs using real Git, without changing the checkout', () => {+ const root = mkdtempSync(join(tmpdir(), 'pregate-published-'));+ const remote = join(root, 'remote.git');+ const cwd = join(root, 'checkout');+ const git = (...args) => {+ const result = spawnSync('git', args, { cwd: root, encoding: 'utf8' });+ if (result.status !== 0) throw new Error(result.stderr);+ return result.stdout.trim();+ };+ try {+ git('init', '--bare', remote);+ git('init', '-b', 'main', cwd);+ git('-C', cwd, 'config', 'user.name', 'Fixture');+ git('-C', cwd, 'config', 'user.email', '[email protected]');+ git('-C', cwd, 'remote', 'add', 'origin', remote);+ const commit = (text) => {+ writeFileSync(join(cwd, 'file'), text);+ git('-C', cwd, 'add', 'file');+ git('-C', cwd, 'commit', '-m', text);+ return git('-C', cwd, 'rev-parse', 'HEAD');+ };+ commit('initial');+ git('-C', cwd, 'push', '-u', 'origin', 'main');+ const published = commit('published');+ git('-C', cwd, 'push', remote, 'main');+ expect(git('-C', cwd, 'branch', '-r', '--contains', published)).toBe('');+ const before = git('-C', cwd, 'show-ref');+ const calls = [];+ const exec = (command, args, options) => {+ if (command === 'gh') {+ calls.push(args);+ return { status: 0, stdout: args[0] === 'repo' ? JSON.stringify({ nameWithOwner: 'acme/widget', url: 'https://github.com/acme/widget' }) : '{}' };+ }+ return spawnSync(command, args, options);+ };+ const attest = () => run({ cwd, exec, ...io(), readReceipt: () => receipt({ tree: git('-C', cwd, 'rev-parse', 'HEAD^{tree}'), stages: [stage('scan')] }) });+ expect(attest()).toBe(0);+ expect(calls.filter((args) => args[0] === 'api')).toHaveLength(1);+ expect(git('-C', cwd, 'show-ref')).toBe(before);+ expect(git('-C', cwd, 'status', '--porcelain')).toBe('');+ commit('unpublished');+ expect(attest()).toBe(1);+ git('-C', cwd, 'remote', 'set-url', 'origin', join(root, 'missing.git'));+ expect(attest()).toBe(1);+ expect(calls.filter((args) => args[0] === 'api')).toHaveLength(1);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+ });+it('narrows the attestation when the receipt base is not the default branch merge base, and says so', () => {const { out, log, error } = io();const calls = [];