Skip to content

Commit d9c3c22

Browse files
committed
fix(pm): close the workflows split's review holes
The contract review at d51132b found C2 triggers that read Tier S: - an if: is now H unless the base holds it for the same owner and text, or its job is new, so a renamed gate step beside a dummy is H; - the reader refuses flow mappings, double-quoted escapes, indicator-led lines and a child under a valued node; - the credential pattern reads any case and the index spelling; - a needs: change in either direction on an existing job is H. Each hole carries its pin; the header names run-text edits as a known limit. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jU8C3iu8fsXdU4Rm8o
1 parent d51132b commit d9c3c22

2 files changed

Lines changed: 76 additions & 31 deletions

File tree

‎.claude/skills/pm-dispatch/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ PM 的工作是循环:选卡 → 认领 → 派发 → 收集 → 复核 → 报
200200
- ④ 轮报单列 awaiting a human merge 并现读请审人;⛔ 未请审不在 chat 报「等你批」,先补请。
201201
- skills 车道自有 PR:纯代码面如 `scripts/pm/` 由本席按达档自审(清单不减)后落地。
202202
- 受管面两层:Tier S = `.claude/**`+下行 S 面,余皆 Tier H 等人批;S 经达档 PASS 后 ready → 入队。
203-
- 本仓 `.github/workflows/**` 按 diff 定档:发布路径、C2 触发或读不出 ⇒ H,余 S(`readWorkflowDiff`)。
203+
- 本仓 `.github/workflows/**` 由 `readWorkflowDiff` 定档:发布路径、C2 触发、拒读或未读 ⇒ H,余 S。
204204
- 入队资格:每 check 绿或预期 skip,⛔ 非必查子集;名单 check-expected-skips.mjs 只判 objectstack。
205205
- 非必查红是真缺陷或坏门,归 PM 入队前处置;第三种按设计而红,三条全立才可带红入队:
206206
- 源码自述 pushed 分支上按设计而红、不跑 `merge_group`、PR 评论记明门与因,缺一即否。

‎scripts/pm/check-governed-merges.mjs‎

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,12 @@
470470
*
471471
* H by PATH — the release, publish and deploy files in
472472
* `WORKFLOW_TIER_H_FILES`, each with its reason, any edit at all.
473-
* H by DIFF (C2) — an added or changed `permissions:`; a `secrets.*` or
474-
* `github.token` line added, changed or moved; `pull_request_target`;
475-
* a `uses:` (or image) not already used at the base; a deleted job, a
476-
* changed literal check-run name or a lost `needs:`; a new
477-
* `continue-on-error`; an `if:` new or changed on an existing job or step.
473+
* H by DIFF (C2) — an added or changed `permissions:`; a `secrets` or
474+
* `github.token` line (any case, dot or index) added, changed or moved;
475+
* `pull_request_target`; a `uses:` (or image) not already used at the
476+
* base; a deleted job, a changed literal check-run name or a changed
477+
* `needs:`; a new `continue-on-error`; an `if:` the base does not hold for
478+
* the same owner with the same text, unless its job is new on the head.
478479
* S otherwise — a contract-review PASS on the current head, every check
479480
* green, and the owning seat lands it (the Tier S landing above).
480481
*
@@ -483,10 +484,17 @@
483484
* added `|| true`, `set +e`, `exit 0` or `OS_SKIP_`/`OS_DISABLE_`/`OS_ALLOW_`;
484485
* a gate invocation or a `uses:` dropped; a changed trigger set or workflow
485486
* name; a new job with a computed or colliding name; a new, deleted or
486-
* non-YAML file. ⛔ Fail closed: a copy the line reader cannot parse (anchors,
487-
* tags, tabs, flow spanning lines…), an unreadable commit, a missing base or
488-
* no reading at all is H — so `--test`, which has paths only, always says H,
489-
* and `--pr` reads the diff only on a checkout holding both commits.
487+
* non-YAML file. ⛔ Fail closed: a copy the line reader refuses (anchors,
488+
* tags, tabs, flow mappings, flow spanning lines, double-quoted escapes, a
489+
* line led by an indicator, a valued node with children…), an unreadable
490+
* commit, a missing base or no reading at all is H — so `--test`, which has
491+
* paths only, always says H, and `--pr` reads the diff only on a checkout
492+
* holding both commits.
493+
*
494+
* Known limit, S by the ruling: the TEXT of a `run:` or `shell:` edit is not
495+
* judged beyond a dropped gate token or an added risky pattern, so
496+
* `echo "pnpm check:x"`, `|| :` or `shell: bash {0}` read S. The contract
497+
* review of record is the control there.
490498
*
491499
* `readWorkflowDiff` is the one reader; the queue guard calls it per queued
492500
* commit and `--branch` / `--pr` per PR. The reader is dependency-free on
@@ -1075,7 +1083,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
10751083
'⭐ the argv is CLOSED: a flag the mode does not read, or a second repository beside a bare --pr, is refused': 22,
10761084
'the per-row repository scope (ruled B2, 2026-10-13)': 20,
10771085
'the nested `ui/` workspace rows, on the register (#25712)': 16,
1078-
'⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 45,
1086+
'⭐ the workflows split: Tier H by path or by C2 trigger, else Tier S (ruling record 6722205630)': 61,
10791087
});
10801088

10811089
// DELETING an entry silences that battery's floor exactly as effectively as
@@ -1621,8 +1629,8 @@ export const WORKFLOW_TIER_H_FILES = Object.freeze([
16211629

16221630
/** The patterns an ADDED line may not carry without Tier H (biased cases: each can turn a check off or skip a gate). */
16231631
const WORKFLOW_RISKY_LINE = /\|\|\s*true\b|\bset\s+\+e\b|\bexit\s+0\b|\bOS_(?:SKIP|DISABLE|ALLOW)_[A-Z0-9_]+/;
1624-
/** A secret or the job's own token, wherever it is spelled. */
1625-
const WORKFLOW_CREDENTIAL = /\bsecrets\b|\bgithub\.token\b/;
1632+
/** `secrets` or the job's own token, in any case and by dot or index, as the expression evaluator reads them. */
1633+
const WORKFLOW_CREDENTIAL = /\bsecrets\b|\bgithub\s*(?:\.\s*token\b|\[\s*['"]token['"]\s*\])/i;
16261634
/** The gate invocations a run block carries, each as a token; one dropped from a file is Tier H (biased: a removed check). */
16271635
const WORKFLOW_INVOCATIONS = Object.freeze([
16281636
[/check:[A-Za-z0-9:._-]+/g, (m) => m[0]],
@@ -1667,6 +1675,8 @@ function stripYamlComment(line) {
16671675
function unreadableValue(value) {
16681676
const v = value.trim();
16691677
if (/^[&*!]/.test(v)) return 'an anchor, alias or tag';
1678+
// A flow mapping hides its keys (`- { name: Gate, if: false }`) from this reader, so any one but `{}` is refused.
1679+
if (v !== '{}' && /[{}]/.test(v.replace(/\$\{\{.*?\}\}/g, '').replace(/"(?:[^"\\]|\\.)*"|'[^']*'/g, ''))) return 'a flow mapping';
16701680
if (v.startsWith('{') || v.startsWith('[')) {
16711681
let depth = 0;
16721682
for (const c of v.replace(/"(?:[^"\\]|\\.)*"|'[^']*'/g, '')) {
@@ -1681,14 +1691,16 @@ function unreadableValue(value) {
16811691
/**
16821692
* A line-model reader of ONE workflow file — the subset of YAML the
16831693
* repository's workflows are written in: block mappings, block sequences,
1684-
* one-line flow collections, quoted and plain scalars (a plain scalar may
1694+
* one-line flow sequences, quoted and plain scalars (a plain scalar may
16851695
* continue on deeper lines), and `|` / `>` block scalars. Pure, no dependency:
16861696
* the queue guard's job imports this file before any install.
16871697
*
16881698
* ⛔ Fail closed: a tab in the indentation, a document marker or directive, an
1689-
* anchor, alias, tag or merge key, a flow collection spanning lines, a quote
1690-
* that never closes, or a line that is neither a key, an item nor a
1691-
* continuation answers `{ ok: false, line, reason }` — and an unread file is
1699+
* anchor, alias, tag or merge key, a flow mapping other than `{}`, a flow
1700+
* collection spanning lines, a quote that never closes, a double-quoted
1701+
* escape that spells a character, a line led by a YAML indicator, a child
1702+
* under a node with a scalar value, or a line that is neither a key, an item
1703+
* nor a continuation answers `{ ok: false, line, reason }` — and an unread file is
16921704
* Tier H. Returns `{ ok: true, root }`: nodes `{ indent, key, value, item,
16931705
* children, block, line }`.
16941706
*/
@@ -1705,8 +1717,12 @@ export function readWorkflowTree(text) {
17051717
if (node.item && top.indent === node.indent && !top.item && top.key !== null && top.value === '' && top.blockStyle === undefined) break;
17061718
stack.pop();
17071719
}
1708-
stack[stack.length - 1].children.push(node);
1720+
const parent = stack[stack.length - 1];
1721+
// A node with a scalar value and children is not YAML: refuse it rather than guess which one GitHub reads.
1722+
if (parent !== root && parent.value !== '') return false;
1723+
parent.children.push(node);
17091724
stack.push(node);
1725+
return true;
17101726
};
17111727
let block = null;
17121728
let last = null;
@@ -1729,11 +1745,13 @@ export function readWorkflowTree(text) {
17291745
if (lead === '' && (/^(?:---|\.\.\.)(?:\s|$)/.test(trimmed) || trimmed.startsWith('%'))) return fail(n, 'a document marker or directive');
17301746
let rest = stripYamlComment(trimmed);
17311747
if (rest === null) return fail(n, 'a quote that never closes on its line');
1748+
// `"i\x66"` is the key `if`: an escape that spells a character is refused, never compared raw.
1749+
if ((rest.match(/"(?:[^"\\]|\\.)*"/g) ?? []).some((q) => /\\[xuUNLP_]/.test(q))) return fail(n, 'a double-quoted escape (`\\x`, `\\u`, `\\U`, …)');
17321750
let indent = lead.length;
17331751
let item = null;
17341752
while (rest === '-' || rest.startsWith('- ')) {
17351753
item = { indent, key: null, value: '', item: true, children: [], block: [], line: n };
1736-
attach(item);
1754+
if (!attach(item)) return fail(n, 'a child under a node that already has a scalar value');
17371755
if (rest === '-') {
17381756
rest = '';
17391757
break;
@@ -1759,7 +1777,7 @@ export function readWorkflowTree(text) {
17591777
node.blockStyle = value;
17601778
block = { node, indent };
17611779
}
1762-
attach(node);
1780+
if (!attach(node)) return fail(n, 'a child under a node that already has a scalar value');
17631781
last = node;
17641782
continue;
17651783
}
@@ -1770,6 +1788,8 @@ export function readWorkflowTree(text) {
17701788
last = item;
17711789
continue;
17721790
}
1791+
// A continuation never starts with an indicator: `? permissions` / `: write-all` is an explicit key, not text.
1792+
if (/^[?:\-,[\]{}#&*!|>'"%@`]/.test(rest)) return fail(n, `a line led by the YAML indicator \`${rest[0]}\``);
17731793
if (last !== null && indent > last.indent && last.blockStyle === undefined && last.children.length === 0) {
17741794
last.value = `${last.value} ${rest}`.trim();
17751795
continue;
@@ -1952,8 +1972,8 @@ export function workflowDiffReasons(a, b, inventory) {
19521972
// between two COMPUTED names — a matrix job's shard count — changes no required context.
19531973
const computed = (name) => name.includes('${{');
19541974
if (now.name !== job.name && !(computed(now.name) && computed(job.name))) say(`a job's check-run name changed: \`${id}\` \`${job.name}\` → \`${now.name}\``);
1955-
const dropped = job.needs.filter((x) => !now.needs.includes(x));
1956-
if (dropped.length > 0) say(`a job's \`needs:\` lost ${dropped.map((x) => `\`${x}\``).join(', ')}: \`${id}\``);
1975+
// Either direction: a job whose dependency is skipped is skipped, and a skipped required check reads green.
1976+
if ([...new Set(job.needs)].sort().join() !== [...new Set(now.needs)].sort().join()) say(`a job's \`needs:\` changed: \`${id}\` [${job.needs.join(', ')}] → [${now.needs.join(', ')}]`);
19571977
}
19581978
}
19591979
for (const [id, job] of b.jobs) {
@@ -1963,16 +1983,14 @@ export function workflowDiffReasons(a, b, inventory) {
19631983
}
19641984
if (a.name !== b.name) say('the workflow `name:` changed');
19651985
if (a.events.join() !== b.events.join()) say(`the trigger set changed: [${a.events.join(', ')}] → [${b.events.join(', ')}]`);
1966-
// C2 — a new `continue-on-error`, or an `if:` on a job or step that already existed.
1986+
// C2 — a new `continue-on-error`, or an `if:` the base does not hold for the same owner with the same text.
1987+
// An owner is a name the author picks, so only a job NEW on the head may bring its own `if:`: a renamed step
1988+
// given `if: false` beside a dummy under the old name is in an existing job, and is H.
19671989
for (const fact of addedIn(a.coes, b.coes)) say(`a new \`continue-on-error\` at ${ownerWords(JSON.parse(fact)[0])}`);
1968-
const baseIfs = a.ifs.map((f) => JSON.stringify(f));
1969-
const lostOwner = (owner) => {
1970-
const job = owner.split('/')[0];
1971-
return [...a.owners.keys()].some((o) => o.startsWith(`${job}/`) && !b.owners.has(o));
1972-
};
1973-
for (const fact of addedIn(baseIfs, b.ifs.map((f) => JSON.stringify(f)))) {
1990+
for (const fact of addedIn(a.ifs.map((f) => JSON.stringify(f)), b.ifs.map((f) => JSON.stringify(f)))) {
19741991
const [owner] = JSON.parse(fact);
1975-
if (a.owners.has(owner) || lostOwner(owner)) say(`an \`if:\` added or changed on a job or step that already ran: ${ownerWords(owner)}`);
1992+
const jobId = owner === 'workflow' ? null : owner.split('/')[0].slice('job:'.length);
1993+
if (jobId === null || a.jobs.has(jobId)) say(`an \`if:\` added or changed in a job that already ran: ${ownerWords(owner)}`);
19761994
}
19771995
// Biased to H — each listed in the report.
19781996
for (const owner of new Set([...a.credentialOwners, ...b.credentialOwners, ...a.writeOwners, ...b.writeOwners])) {
@@ -5207,6 +5225,33 @@ async function selfTest() {
52075225
assert('C2-an-if-that-disables-a-step-is-H', isH(tierOf(edit(" if: github.event_name != 'schedule'", ' if: false')), /`if:` added or changed/));
52085226
assert('C2-an-if-that-disables-a-job-is-H', isH(tierOf(edit(' timeout-minutes: 20', ' timeout-minutes: 20\n if: false')), /`if:` added or changed .*`job:build`/));
52095227

5228+
// The contract review's holes (FAIL at d51132be): each is H now, pinned with the shape that slipped past.
5229+
const GATE_STEP = " - name: Gate\n if: github.event_name != 'schedule'\n";
5230+
const renamedDummy = tierOf(edit(GATE_STEP, " - name: Gate2\n if: false\n").replace(' - name: Build with the cache token', ' - name: Gate\n run: echo ok\n - name: Build with the cache token'));
5231+
assert('⛔ M1-a-renamed-gate-step-given-if-false-beside-a-dummy-under-the-old-name-is-H', isH(renamedDummy, /`if:` added or changed in a job that already ran: `job:build\/step:Gate2`/), show(renamedDummy));
5232+
const idDummy = tierOf(edit(GATE_STEP, " - id: gate2\n name: Gate\n if: false\n"));
5233+
assert('⛔ M1-a-gate-step-re-keyed-by-an-id-and-given-if-false-is-H', isH(idDummy, /`if:` added or changed in a job that already ran/), show(idDummy));
5234+
const newStepIf = tierOf(edit(' - run: pnpm vitest run', " - run: pnpm vitest run\n - name: Extra\n if: github.ref == 'refs/heads/main'\n run: echo extra"));
5235+
assert('⛔ M1-a-new-step-with-its-own-if-inside-an-existing-job-is-H', isH(newStepIf, /in a job that already ran: `job:shards\/step:Extra`/), show(newStepIf));
5236+
const flowStep = tierOf(edit(GATE_STEP, ' - { name: Gate, if: false }\n'));
5237+
assert('⛔ M2a-a-flow-mapped-step-is-refused-and-H', isH(flowStep, /does not parse .*a flow mapping/), show(flowStep));
5238+
assert('M2a-an-empty-flow-mapping-and-an-expression-still-parse', workflowFacts(edit(' merge_group:', ' merge_group: {}')).ok === true && workflowFacts(edit(' runs-on: ubuntu-latest\n timeout', " runs-on: ${{ inputs.os || 'ubuntu-latest' }}\n timeout")).ok === true);
5239+
const escaped = tierOf(edit(" if: github.event_name != 'schedule'", ' "i\\x66": false'));
5240+
assert('⛔ M2b-a-double-quoted-escape-spelling-a-key-is-refused-and-H', isH(escaped, /does not parse .*double-quoted escape/), show(escaped));
5241+
const escapedValue = tierOf(edit(' TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}', ' TURBO_TOKEN: "${{ secre\\x74s.TURBO_TOKEN }}"'));
5242+
assert('⛔ M2b-an-escape-inside-a-value-is-refused-too', isH(escapedValue, /does not parse .*double-quoted escape/), show(escapedValue));
5243+
for (const spelling of ['${{ Secrets.NPM_TOKEN }}', '${{ SECRETS.NPM_TOKEN }}', "${{ github['token'] }}", '${{ GitHub.Token }}', '${{ github . token }}']) {
5244+
const r = tierOf(edit(' - run: pnpm vitest run', ` - run: pnpm vitest run\n env:\n T: ${spelling}`));
5245+
assert(`⛔ M2c-a-credential-spelled-${spelling}-is-H`, isH(r, /token reference added, changed or moved/), show(r));
5246+
}
5247+
const explicitKey = tierOf(edit(' timeout-minutes: 20\n', ' timeout-minutes: 20\n ? permissions\n : write-all\n'));
5248+
assert('⛔ M2d-an-explicit-key-line-is-refused-and-H', isH(explicitKey, /does not parse .*YAML indicator/), show(explicitKey));
5249+
const valuedParent = tierOf(edit(' name: Build Core\n', ' name: Build Core\n if: false\n'));
5250+
assert('⛔ M2d-a-child-under-a-node-with-a-scalar-value-is-refused-and-H', isH(valuedParent, /does not parse/), show(valuedParent));
5251+
assert('M2d-a-plain-scalar-continuation-still-reads', workflowFacts(edit(' name: Build Core\n', ' name: Build\n Core\n')).ok === true);
5252+
const addedNeeds = tierOf(edit(' needs: [build]', ' needs: [build, opt-in]'));
5253+
assert('⛔ S1-a-needs-added-on-an-existing-job-is-H', isH(addedNeeds, /`needs:` changed: `shards` \[build\] → \[build, opt-in\]/), show(addedNeeds));
5254+
52105255
// The near-misses: each is Tier S.
52115256
const BUILD_RUN = ' run: pnpm turbo run build --filter=@objectstack/spec';
52125257
const reordered = edit(
@@ -5226,7 +5271,7 @@ async function selfTest() {
52265271
assert('biased-an-added-or-true-is-H', isH(tierOf(edit(' pnpm check:generated', ' pnpm check:generated || true')), /can skip a check/));
52275272
assert('biased-a-dropped-gate-invocation-is-H', isH(tierOf(edit(' node scripts/check-required-contexts.mjs\n', '')), /gate invocation dropped/));
52285273
assert('biased-a-changed-step-that-holds-a-secret-is-H', isH(tierOf(edit('--filter=@objectstack/spec', '--filter=@objectstack/core')), /already holds a secret or a write token/));
5229-
assert('biased-a-needs-that-lost-a-job-is-H', isH(tierOf(edit(' needs: [build]\n', '')), /`needs:` lost `build`/));
5274+
assert('biased-a-needs-that-lost-a-job-is-H', isH(tierOf(edit(' needs: [build]\n', '')), /`needs:` changed: `shards` \[build\] → \[\]/));
52305275
assert('biased-a-changed-trigger-set-is-H', isH(tierOf(edit(' merge_group:\n', '')), /trigger set changed/));
52315276
assert('biased-a-new-job-taking-a-name-already-in-use-is-H', isH(tierOf(`${BASE_WF} again:\n name: Build Core\n runs-on: ubuntu-latest\n steps:\n - run: echo hi\n`), /already in use/));
52325277

0 commit comments

Comments
 (0)