From 290a16ab6e0f44e70f722319d3093e859d20fdb3 Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:00:55 +0800 Subject: [PATCH] Gate the agent rule data and the tier runner behind a signature (#3095) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `.github/agent/` holds the data the gates read: risk tiers, who may record a PASS and the writers roster, who keeps an issue agent-ready, and the ruleset `gate-ruleset --check` compares against. Two of those files say "Editing this file is itself T3", which locks nothing: the tier picks which gate judges a change, never whether a person has to sign it. `risk-tier.yml` is the same shape one level down — report-only, out of `tests-ok`'s needs, and the source of the `risk-tier: …` line a review quotes. `gateFiles` now names the directory and that workflow, so rule data added later is covered by construction. The #2303 test learns the one stated exception: a workflow can need a signature without being a merge gate. Tests cover the four roster/rule files, the typo guard on the directory entry, the `judge()` counterexample both ways, and the negative controls. --- policy/gates.json | 2 + policy/gates.test.mjs | 98 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/policy/gates.json b/policy/gates.json index bd805bb4b..164d2dd25 100644 --- a/policy/gates.json +++ b/policy/gates.json @@ -12,10 +12,12 @@ ".github/scripts/enqueue-guard.mjs", ".github/scripts/enqueue-rules.mjs", ".github/scripts/gate-check.mjs", + ".github/agent/", ".github/workflows/test.yml", ".github/workflows/merge-gate.yml", ".github/workflows/enqueue-guard.yml", ".github/workflows/docker.yml", + ".github/workflows/risk-tier.yml", "policy/" ] } diff --git a/policy/gates.test.mjs b/policy/gates.test.mjs index 43435a90e..2b4c71433 100644 --- a/policy/gates.test.mjs +++ b/policy/gates.test.mjs @@ -16,6 +16,7 @@ import assert from 'node:assert/strict' import { readFileSync, readdirSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join, relative, resolve } from 'node:path' +import { gateFiles as signatureGateFiles, judge } from '../.github/scripts/policy-sign.mjs' const ROOT = fileURLToPath(new URL('..', import.meta.url)) const read = (path) => readFileSync(join(ROOT, path), 'utf8') @@ -30,6 +31,12 @@ const workflowFiles = readdirSync(join(ROOT, '.github/workflows')) .sort() .map((file) => `.github/workflows/${file}`) +// A workflow can need a signature without being a merge gate. `risk-tier.yml` reports the tier on +// every pull request and gates nothing, yet a review quotes the `risk-tier: …` line it writes, so a +// pull request could rewrite the evidence its own review cites (#3095). The manifest keeps it +// `gate: false` — it is not a required check — and this list names it explicitly instead. +const SIGNATURE_ONLY_WORKFLOWS = ['.github/workflows/risk-tier.yml'] + // The scripts a workflow starts, read from its `node ` steps. `base/` is stripped because the // judging workflows check the base commit out under that prefix and run the script from there. function runsOf(workflow) { @@ -80,8 +87,14 @@ test('#2303: every workflow the manifest marks as a gate is a gate file', () => ) // The other direction: a workflow quoted in `gateFiles` that the manifest does not call a gate is - // a stale entry, and it would ask for a signature the repository no longer requires. - const stale = [...gateFiles].filter((file) => file.startsWith('.github/workflows/') && !gateWorkflows.includes(file)) + // a stale entry, and it would ask for a signature the repository no longer requires. A workflow on + // the signature-only list is the stated exception, not a stale entry. + const stale = [...gateFiles].filter( + (file) => + file.startsWith('.github/workflows/') && + !gateWorkflows.includes(file) && + !SIGNATURE_ONLY_WORKFLOWS.includes(file), + ) assert.deepEqual(stale, [], `\`gateFiles\` names a workflow the manifest does not mark \`gate: true\`: ${stale.join(', ')}`) }) @@ -142,3 +155,84 @@ test('#2303: the image build is a gate file while the manifest calls it a gate', 'docker.yml builds the image a packaging change must start before it merges, so it is a gate file', ) }) + +// #3095: the rule data the gates read, and the workflow that produces the tier evidence a review +// quotes, were outside `gateFiles`. Two of the four files in `.github/agent/` carry the sentence +// "Editing this file is itself T3", and that sentence locks nothing: the tier decides which gate +// judges a change, never whether a person has to sign it. The directory is the entry, so rule data +// added later is covered by construction rather than by remembering another line. +const AGENT_DIR = '.github/agent/' +const agentRuleFiles = readdirSync(join(ROOT, AGENT_DIR)) + .filter((file) => file.endsWith('.json')) + .sort() +const TIER_RUNNER = '.github/workflows/risk-tier.yml' + +test('#3095: rule data under .github/agent/ is a gate file, as a directory', () => { + assert.ok(agentRuleFiles.length > 0, `${AGENT_DIR} holds no rule data, so this test would pass vacuously`) + const uncovered = agentRuleFiles + .map((file) => AGENT_DIR + file) + .filter((file) => signatureGateFiles([file]).length === 0) + assert.deepEqual( + uncovered, + [], + `the rules that decide what counts as ready, as a PASS and as T3 need a person's signature; add \`${AGENT_DIR}\` to \`gateFiles\` in policy/gates.json: ${uncovered.join(', ')}`, + ) + + // The typo guard, as a test rather than an eyeball: a misspelt directory entry is the one failure + // mode that never reports itself, because it keeps returning [] and nobody notices until it is used. + assert.ok( + policy.gateFiles.includes(AGENT_DIR), + `\`gateFiles\` carries no \`${AGENT_DIR}\` entry; a path entry that does not match the directory is a hole, not a gate`, + ) + + // And the entry is a directory, not four remembered lines: a rule file added after this change is + // covered without a second edit. + assert.deepEqual(signatureGateFiles([`${AGENT_DIR}added-later.json`]), [`${AGENT_DIR}added-later.json`]) +}) + +test('#3095: the tier runner is a gate file while the manifest still calls it report-only', () => { + const row = manifest.workflows.find((entry) => entry.workflow === TIER_RUNNER) + assert.ok(row !== undefined, `${TIER_RUNNER} has no row in docs/testing-layers.json`) + assert.equal( + row.gate, + false, + `the manifest no longer calls ${TIER_RUNNER} report-only; move the gateFiles entry and this test in the same change`, + ) + assert.deepEqual( + signatureGateFiles([TIER_RUNNER]), + [TIER_RUNNER], + `${TIER_RUNNER} writes the \`risk-tier: …\` line a review quotes and gates nothing itself, so a pull request could rewrite that evidence unsigned; add it to \`gateFiles\``, + ) + // The workflow really is the producer of the line, so the entry names a fact rather than a guess. + assert.match(read(TIER_RUNNER), /risk-tier: /, `${TIER_RUNNER} no longer writes the \`risk-tier: …\` line; then this entry is stale`) +}) + +test('#3095: a roster edit without `Policy-sign:` is refused, and a signing comment at the tip accepts it', () => { + const head = 'deadbeef'.repeat(5) + const author = 'HugoXK' + const comments = [{ id: 4312, body: `signing the gate change at ${head}`, user: { login: 'Birfy', type: 'User' } }] + + const refused = judge({ files: [`${AGENT_DIR}review-policy.json`], body: 'Fixes #3095', author, comments, head }) + assert.equal(refused.ok, false, 'a pull request that moves the reviewers roster and carries no signature is accepted today') + assert.match(refused.reason, /gate file changed/) + assert.deepEqual(refused.signable, [{ id: 4312, login: 'Birfy' }]) + + // The same change with a line naming a comment that names this tip is accepted — for both give ways + // a seat is recorded: the reviewers roster and the maintainers roster the controller trusts. + for (const roster of ['review-policy.json', 'controller.json']) { + const accepted = judge({ + files: [`${AGENT_DIR}${roster}`], + body: `Fixes #3095\n\nPolicy-sign: 4312`, + author, + comments, + head, + }) + assert.equal(accepted.ok, true, accepted.reason) + } +}) + +test('#3095: negative controls — an ordinary client file is not a gate change and policy/ still covers a new file', () => { + assert.deepEqual(signatureGateFiles(['plugins/social/client.js']), []) + assert.deepEqual(signatureGateFiles(['policy/new-gate-note.json']), ['policy/new-gate-note.json']) + assert.equal(new Set(policy.gateFiles).size, policy.gateFiles.length, '`gateFiles` lists an entry twice') +})