From 4d864db15c5ef031f9d383466a48a1a5637ae60b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 07:32:52 +0000 Subject: [PATCH] fix(pm): the landing door reads the opt-in dogfood lane's check run on the head Maintainer ruling 7269391948 (letter D): a labelled breaking pull has the dogfood battery run by a CI runner, and `label-write.mjs --land` reads that result instead of the typed report field. - `land-dogfood-lane.mjs` (new): the two questions the door asks, a success check run named `Dogfood battery (opt-in)` on the head sha (any such run, never the newest of that name) and whether the pull's own file list changes the lane's workflow (a pull may not certify itself). - `label-write.mjs`: `landDogfoodGate` calls it; the report, sibling-pull, tie and commit-walk readers are deleted with their cases, each flip named in the self-test. - `l1-face.mjs`: a marked PR is judged on the lane, with the door's verdicts. - `ensure-pm-labels.sh`: `needs:dogfood-battery`. - `os-dev.md`, `l1-review-checklist.md`, `landing-operations.md` point at the lane; the report template's typed field is removed. Claude-Session: https://claude.ai/code/session_01ADHkmRJUY9Ncce14hVHd25 Co-authored-by: Claude --- .claude/agents/os-dev.md | 7 +- .../references/l1-review-checklist.md | 2 +- .../references/landing-operations.md | 2 +- scripts/pm/ensure-pm-labels.sh | 13 + scripts/pm/l1-face.mjs | 54 +- scripts/pm/label-write.mjs | 625 ++++++------------ scripts/pm/land-dogfood-lane.mjs | 157 +++++ 7 files changed, 434 insertions(+), 426 deletions(-) create mode 100644 scripts/pm/land-dogfood-lane.mjs diff --git a/.claude/agents/os-dev.md b/.claude/agents/os-dev.md index aa8d8131826..b14915fc071 100644 --- a/.claude/agents/os-dev.md +++ b/.claude/agents/os-dev.md @@ -213,9 +213,9 @@ model: opus - 范围按本地验证范围节圈定;`packages/cli` 的卡本地只欠 `unit` 层,`integration` 层声明给 CI。 - `packages/cli` 卡与 driver/kernel 启动路径的分层跑法住 pm-dispatch `references/dev-traps.md`,碰到才读。 - Draft PR 指向 `main`,正文首行 `Fixes #`;合并不应关卡时用 `Part of #`,并说明留下哪一半。 -- 全量 dogfood 只在终 head 跑一次,仅当标题带 `!` 或 `Clause-②:` 带 `(narrowing)` 臂(yes/no 皆算)。 -- 命令同 CI:按 ① 建闭包,锁下 `pnpm --filter @objectstack/dogfood test`;⛔ 无 `OS_TEST_SHARD`、无路径。 -- 红 = 本改动的后果(陈旧 fixture)同 PR 修,余照报;⛔ 永不跳过或收窄;计数记 `dogfood_battery`。 +- 全量 dogfood ⛔ 不在本地跑:标题带 `!` 或 `Clause-②:` 带 `(narrowing)` 臂(yes/no 皆算)⇒ 席位给 PR 挂 `needs:dogfood-battery`,CI 在其 head 跑三段。 +- 落地门只读该 head 上 `Dogfood battery (opt-in)` 的 success,⛔ 不读报告;每次 push 换 head 即欠新一轮,dev 不自挂该标签。 +- 红 = 本改动的后果(陈旧 fixture)同 PR 修,余照报;⛔ 该类 PR 不改 `.github/workflows/dogfood-optin.yml`:不能自证。 - 认领的 `Clause-②:`、`Metadata-protocol:` 两行照抄进 PR 正文行首;无则零写,⛔ 不自造。 - 两行同抄进 changeset 正文行首;`Check Changeset` 读 PR 正文:kind 即 `minor`,`none` 即 `patch`。 - 种类非 `none` 或带 `(narrowing)` ⇒ 按 diff 加写 `Skills-docs:` 行;拼法与分工住认领模板。 @@ -318,7 +318,6 @@ model: opus "summary": "what was implemented, 2-4 sentences", "tests": "commands run + pass/fail evidence (real output excerpts); ablation only where a tested behaviour changed: rebuild + on-disk mutation proof", "gates": "local subset: each command + exit code captured before any pipe + --ran reconciliation; every family CI runs: the PR's check-runs (name + conclusion) cited, not re-run locally", - "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm | · the lock's VERDICT line · Test Files N/N · Tests M/M · every failure named", "mcp_calls": " — MCP GitHub calls with tool names; a write tool in the list = this report is refused", "api_writes": " — REST proxy writes, each endpoint listed", "classifier_refusals": [ diff --git a/.claude/skills/pm-dispatch/references/l1-review-checklist.md b/.claude/skills/pm-dispatch/references/l1-review-checklist.md index b3a90acc526..c58f7e39d4c 100644 --- a/.claude/skills/pm-dispatch/references/l1-review-checklist.md +++ b/.claude/skills/pm-dispatch/references/l1-review-checklist.md @@ -50,7 +50,7 @@ - 门禁读数钉当前 head:run `head_sha` 或 dev 所抄短 sha 不符 `head.sha`、或没抄 ⇒ 双向不入账。 - ⛔ 非当前 head 上的 `cancelled` 零动作、永不重跑:新推送自带全套 run。 - 席位核对门禁证据 = check-runs(名+结论);本地并集只证本地子集,⛔ 不替缺席者。 -- `!` 或 `(narrowing)`:入队前核 `dogfood_battery` 钉 head、全量、红已修/已报;缺或收窄 ⇒ REWORK。 +- `!` 或 `(narrowing)`:入队前核 head 上 `Dogfood battery (opt-in)` success;缺则挂 `needs:dogfood-battery`。 - 把发送或写挪到应答之后的 PR:dogfood 门禁不跑于 PR、跑于队列,全绿 PR 照样被队列弹出。 - ⇒ 入队前 grep `packages/qa/dogfood/test` 里应答后紧读该副作用的用例,同一 PR 改为有界等待。 diff --git a/.claude/skills/pm-dispatch/references/landing-operations.md b/.claude/skills/pm-dispatch/references/landing-operations.md index 7e53c62b6c1..3a9fa4601db 100644 --- a/.claude/skills/pm-dispatch/references/landing-operations.md +++ b/.claude/skills/pm-dispatch/references/landing-operations.md @@ -58,7 +58,7 @@ - 车道 PM 的权责三件:验收(L1 清单)、首次入队、确认 MERGED;落地执行在案判决,非自批。 - 首次入队:ACCEPT 后挂 6–9 分钟 flip 定点,到点核门禁 job 结论。 - 绿即落地评论与 `pr_ready`+`automerge_enable` 一笔中继:`label-write --land`;未绿按阶梯重挂定点。 - `--land` 拒 `!`/`(narrowing)` PR,除非卡上最新受信 os-dev-report 的 dogfood 钉 head(`os-dev.md`)。 + `--land` 拒 `!`/`(narrowing)` PR,除非 head 上 dogfood 泳道(`needs:dogfood-battery`)为 success。 - 写节流拒(exit 10) ⇒ 待 `node scripts/pm/write-pace.mjs --status` 现空槽再重试。 - CI success webhook 不可靠:⛔ 不坐等,也 ⛔ 不忙轮询;定点文本照定时器写法纪律。 - undraft 429 ⇒ 卡记 `resets at`,到点一次重试裸 op(`rest-channel.md`),⛔ 不重发评论、不报阻塞。 diff --git a/scripts/pm/ensure-pm-labels.sh b/scripts/pm/ensure-pm-labels.sh index d0a13a1b65d..af4e6bfb23c 100644 --- a/scripts/pm/ensure-pm-labels.sh +++ b/scripts/pm/ensure-pm-labels.sh @@ -381,6 +381,19 @@ gh label create needs:pack-smoke -R objectstack-ai/objectstack -c 006b75 -d "Opt # belongs to: an opt-in pre-merge check. gh label create needs:upgrade-harness -R objectstack-ai/objectstack -c 006b75 -d "Opt-in pre-merge 18.x upgrade harness: an 18.0 database boots on this PR's merge preview (#24522)" 2>/dev/null || true +# needs:dogfood-battery — the opt-in pre-merge dogfood battery (#38688, maintainer +# ruling 7269391948, letter D, 「云端流水线代跑」). Its first consumer is the job +# guard in `.github/workflows/dogfood-optin.yml`, which runs the three queue +# shards on the PR's merge preview only while this label is on the PR. Unlike +# its two siblings above it has a second consumer in scripts/pm/: the landing +# door (`label-write.mjs --land`, through `land-dogfood-lane.mjs`) refuses a +# breaking or narrowing PR until that lane's `Dogfood battery (opt-in)` check +# run concludes `success` on the PR's head, and its refusal tells the seat to +# add this label. The owning seat hangs it by hand on the head it means to +# land; nothing auto-applies it, and every later push to a labelled PR is +# another full run. Same colour as its family: an opt-in pre-merge check. +gh label create needs:dogfood-battery -R objectstack-ai/objectstack -c 006b75 -d "Opt-in pre-merge dogfood battery: the three queue shards on a breaking PR head (ruling D, #38688)" 2>/dev/null || true + # needs:contract-review — a MARKER, never a gate; rules in # .claude/skills/pm-dispatch/references/contract-review.md 〈等 L2 标记〉. The # dispatching seat hangs it on the PR at ACCEPT when either clause-② limb hits diff --git a/scripts/pm/l1-face.mjs b/scripts/pm/l1-face.mjs index 45bea9f4ae5..994e2a5d6c4 100644 --- a/scripts/pm/l1-face.mjs +++ b/scripts/pm/l1-face.mjs @@ -14,7 +14,7 @@ * The L1 checklist asks every seat to re-read the same mechanical facts by hand on every dev report: the PR's shape, * the card relation its first line declares, whether a closing keyword sits next to another OPEN card, the release * path, a changeset per published package, the declaration lines, the two floor checks at the head, every other check, - * whether the dogfood battery is owed, and the `+0/-0` NUL suspects. This file is that reading, one line per item with + * whether the dogfood battery is proven on the head, and the `+0/-0` NUL suspects. This file is that reading, one line per item with * its verdict — `ok`, `flag` or `not measured` — and the evidence. ⛔ It writes nothing, and it is a READER, not a * gate: no exit code here is a merge condition. * @@ -31,8 +31,13 @@ * with `check-changeset-no-major.mjs`' `entriesIn` (⛔ no fifth copy of the entry regex); * 5. `/git/blobs/SHA` for every `+0/-0` file: NUL bytes and lines, the blob's own answer. * - * The `Clause-②:` and `Metadata-protocol:` lines are read by `clause2-line.mjs`, and the dogfood markers by - * `label-write.mjs`' `landDogfoodMarkers` — the readers the gates use. + * The `Clause-②:` and `Metadata-protocol:` lines are read by `clause2-line.mjs`, the dogfood markers by + * `label-write.mjs`' `landDogfoodMarkers`, and the lane's check run and the lane's workflow in the file list by + * `land-dogfood-lane.mjs`' two verdicts — the readers the gates use. A marked PR is JUDGED on what the landing door + * will read: the opt-in lane's `success` on this head (reading 1's check-runs) and a file list that leaves the lane + * alone (reading 2). ⛔ Nothing typed in a report is read. One difference from the door is named, not hidden: reading + * 1 asks `filter=latest`, the door `filter=all`, so a success a later red re-run of the SAME workflow run superseded + * reads `flag` here and passes there. * * ## What it does NOT read — named in the footer of every run * @@ -66,6 +71,7 @@ import { closingKeywordTargets, DECISION_INBOX_LABEL, DEFAULT_SWEEP_REPO, h7Part import { readClause2Line, readMetadataProtocolLine } from './clause2-line.mjs'; import { ghApi, readAllPages } from './gh-pages.mjs'; import { landDogfoodMarkers } from './label-write.mjs'; +import { DOGFOOD_LANE_CHECK, DOGFOOD_LANE_LABEL, DOGFOOD_LANE_WORKFLOW, dogfoodLaneCheckVerdict, dogfoodLaneFilesVerdict } from './land-dogfood-lane.mjs'; import { fixtureReaders, gitLsRemote, readPrState } from './pr-state.mjs'; const REPO_ROOT = fileURLToPath(new URL('../../', import.meta.url)); @@ -107,7 +113,7 @@ export const RULE_FILES = Object.freeze({ '亲核 Lint & Repo Gates 与 TypeScript Type Check 皆 `success`', '入队另要求全 check 绿', '门禁读数钉当前 head', - '`!` 或 `(narrowing)`:入队前核 `dogfood_battery`', + '`!` 或 `(narrowing)`:入队前核 head 上 `Dogfood battery (opt-in)` success', '`+0/-0` 先疑 NUL,以 blob 定论', '要求源侧写转义序列', '`l1-face.mjs --pr N`', @@ -129,7 +135,7 @@ export const UNREAD_ITEMS = Object.freeze([ 'a PR that moves a send or a write after the response: grep `packages/qa/dogfood/test` for a case that reads the side effect right after the response, made a bounded wait in the same PR', 'adjacent in-place fixes (the four conditions), one-shot codegen in the diff, move/split growth past a pure move', 'test evidence: real commands and output, positive controls, `.d.ts` byte-identity readings, git-answerable API reads', - "gate readings in the report pinned to this head, and the report's `dogfood_battery` against it", + 'gate readings in the report pinned to this head', 'assertions and benefit (the envelope `code`/`status`, sweep direction and build order), premise, stop conditions and deletions', "`mergeable_state`, the queue and reviews — read with `pr-state.mjs` (its line is printed above)", ]); @@ -344,7 +350,20 @@ export function readFace({ repo, number, get = ghApi, lsRemote = gitLsRemote, sl { const m = landDogfoodMarkers({ title: pr.title, body }); if (m.unreadable) item('dogfood', NOT_MEASURED, m.unreadable); - else if (m.markers.length) item('dogfood', FLAG, `owed — ${m.markers.join(' and ')}: the full battery on ${short(head)}, recorded under \`dogfood_battery\` (flagged, not judged)`); + else if (m.markers.length) { + // What the landing door will read (`label-write.mjs --land`): the lane's success ON THIS HEAD, and a file list + // that leaves the lane alone. Judged with the door's own two verdicts, never a second spelling of either. + const owed = `owed — ${m.markers.join(' and ')}`; + const lane = dogfoodLaneCheckVerdict(tap.runs, head); + const edits = files ? dogfoodLaneFilesVerdict(files) : null; + const waiting = tap.runs.some((r) => r?.name === DOGFOOD_LANE_CHECK && r.status !== 'completed'); + if (!files) item('dogfood', NOT_MEASURED, `${owed}: ${filesGap}, so whether this PR changes \`${DOGFOOD_LANE_WORKFLOW}\` is unread`); + else if (edits.touched) item('dogfood', FLAG, `${owed}: this PR changes \`${DOGFOOD_LANE_WORKFLOW}\`, so it may not certify itself with that lane — the lane change lands on its own`); + else if (!checks) item('dogfood', NOT_MEASURED, `${owed}: the head's check-runs did not read`); + else if (lane.success) item('dogfood', OK, `${owed}: \`${DOGFOOD_LANE_CHECK}\` concluded success at ${short(head)} (check run ${lane.success.id ?? 'id not read'})`); + else if (waiting) item('dogfood', NOT_MEASURED, `${owed}: \`${DOGFOOD_LANE_CHECK}\` is still running at ${short(head)}`); + else item('dogfood', FLAG, `${owed}: no success of \`${DOGFOOD_LANE_CHECK}\` at ${short(head)} (${lane.seen === 0 ? 'no run of that name' : lane.tally}) — add \`${DOGFOOD_LANE_LABEL}\` and wait for the run`); + } else item('dogfood', OK, 'not owed (no `!` before the title\'s colon, no `(narrowing)` arm)'); } @@ -588,7 +607,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ 'PR shape and the card relation: the first line, the shared parser, other open cards': 12, 'scope and changeset: the release path, published packages, empty changesets': 10, 'declarations: Clause-②, Metadata-protocol and the Skills-docs line they owe': 6, - 'gate evidence at the head: the floor checks, every other check via pr-state, dogfood owed': 7, + // Raised 7 → 13 with the lane: a marked PR is judged on the lane's check run at the head and on its own file list. + 'gate evidence at the head: the floor checks, every other check via pr-state, dogfood owed': 13, '+0/-0: the blob decides': 5, 'the face and the CLI: the unread footer, exits and usage': 8, }); @@ -631,7 +651,7 @@ export function selfTest() { const REQ = '_Requested by **Sales** · [project thread](https://claude.ai/code/project/x?thread=y)_'; const bodyOf = (...lines) => [ATTR, REQ, ...lines].join('\n'); const BODY = bodyOf('Part of #500', 'Clause-②: no', 'Metadata-protocol: none', '', 'What changes.'); - const run = (name, conclusion = 'success', status = 'completed') => ({ name, status, conclusion: status === 'completed' ? conclusion : null, check_suite: { id: 1 } }); + const run = (name, conclusion = 'success', status = 'completed') => ({ name, status, conclusion: status === 'completed' ? conclusion : null, check_suite: { id: 1 }, head_sha: HEAD, app: { slug: 'github-actions' } }); const file = (filename, over = {}) => ({ filename, status: 'modified', additions: 3, deletions: 1, sha: sha('b'), ...over }); const row = (over = {}) => ({ number: 7, state: 'open', draft: true, merged_at: null, mergeable_state: 'clean', head: { sha: HEAD }, base: { ref: 'main' }, auto_merge: null, title: 'feat(pm): x', body: BODY, labels: [{ name: SKIP_CHANGESET_LABEL }], changed_files: 2, ...over }); const fixture = (over = {}) => ({ @@ -726,8 +746,22 @@ export function selfTest() { const skip = read(fixture(runs(run('Lint & Repo Gates'), run('TypeScript Type Check'), run('Build Docs', 'skipped'), run('Lint UI', 'skipped')))); t('⭐ every other check is pr-state\'s judgement: an expected skip passes, an unexpected one flags', [v(skip, 'all-checks'), at(skip, 'all-checks').evidence.includes('1 unexpected skip (Lint UI)')], [FLAG, true]); t('a pending check leaves all-checks not measured', v(read(fixture(runs(run('Lint & Repo Gates'), run('TypeScript Type Check'), run('Test Core', null, 'queued')))), 'all-checks'), NOT_MEASURED); - t('⭐ `!` before the title\'s colon owes the dogfood battery — flagged, not judged', [v(read(fixture({ row: { title: 'feat(pm)!: x' } })), 'dogfood'), v(read(fixture({ row: { body: bodyOf('Part of #500', 'Clause-②: yes (narrowing)', 'Metadata-protocol: narrowed', 'Skills-docs: none — internal') } })), 'dogfood')], [FLAG, FLAG]); - t('unreadable check-runs leave both check items not measured', [v(read(fixture({ check_runs: { [HEAD]: null } })), 'floor-checks'), v(read(fixture({ check_runs: { [HEAD]: null } })), 'all-checks')], [NOT_MEASURED, NOT_MEASURED]); + const BANG = { title: 'feat(pm)!: x' }; + const NARROWING = { body: bodyOf('Part of #500', 'Clause-②: yes (narrowing)', 'Metadata-protocol: narrowed', 'Skills-docs: none — internal') }; + const FLOOR = [run('Lint & Repo Gates'), run('TypeScript Type Check')]; + const LANE = (conclusion = 'success', status = 'completed') => run(DOGFOOD_LANE_CHECK, conclusion, status); + const marked = (laneRuns, over = {}) => read(fixture({ row: BANG, check_runs: { [HEAD]: [...FLOOR, ...laneRuns] }, ...over })); + const noLane = read(fixture({ row: BANG })); + t('⭐ FLIPPED by ruling D (was: "`!` before the title\'s colon owes the dogfood battery — flagged, not judged"): a marked PR is now JUDGED on the lane — a `!` title or a `(narrowing)` arm with no lane run at the head flags, naming the label to add', [v(noLane, 'dogfood'), v(read(fixture({ row: NARROWING })), 'dogfood'), at(noLane, 'dogfood').evidence.includes(`no run of that name) — add \`${DOGFOOD_LANE_LABEL}\` and wait for the run`)], [FLAG, FLAG, true], at(noLane, 'dogfood').evidence); + const proven = marked([LANE('skipped'), LANE('skipped'), LANE()]); + t('⭐ a marked PR whose head carries the lane\'s success reads ok — beside two `skipped` runs of the same name: any success on the head, never the newest', [v(proven, 'dogfood'), at(proven, 'dogfood').evidence.includes(`\`${DOGFOOD_LANE_CHECK}\` concluded success at`)], [OK, true], at(proven, 'dogfood').evidence); + t('⭐ only `skipped` runs, or a failure, flag — with their tally', [v(marked([LANE('skipped'), LANE('skipped')]), 'dogfood'), at(marked([LANE('skipped'), LANE('skipped')]), 'dogfood').evidence.includes('(skipped ×2)'), v(marked([LANE('failure')]), 'dogfood')], [FLAG, true, FLAG]); + t('a lane run still in progress is not measured, never ok and never a flag', v(marked([LANE(null, 'in_progress')]), 'dogfood'), NOT_MEASURED); + t('⛔ a success under a SHARD\'s name is not the lane\'s aggregate: flags', v(marked([run('Dogfood battery shard (1/3, opt-in)')]), 'dogfood'), FLAG); + const selfCert = marked([LANE()], { files: { 7: [file(DOGFOOD_LANE_WORKFLOW), file('.claude/skills/a.md')] } }); + t('⭐ a marked PR whose file list changes the lane\'s workflow flags EVEN WITH a success on its head: it may not certify itself', [v(selfCert, 'dogfood'), at(selfCert, 'dogfood').evidence.includes('the lane change lands on its own')], [FLAG, true], at(selfCert, 'dogfood').evidence); + t('…and an UNMARKED PR is not owed, whatever it edits and with no lane run', [v(read(fixture()), 'dogfood'), v(read(fixture({ files: { 7: [file(DOGFOOD_LANE_WORKFLOW), file('.claude/skills/a.md')] } })), 'dogfood')], [OK, OK]); + t('unreadable check-runs leave both check items not measured, and a marked PR\'s dogfood item with them', [v(read(fixture({ check_runs: { [HEAD]: null } })), 'floor-checks'), v(read(fixture({ check_runs: { [HEAD]: null } })), 'all-checks'), v(read(fixture({ row: BANG, check_runs: { [HEAD]: null } })), 'dogfood')], [NOT_MEASURED, NOT_MEASURED, NOT_MEASURED]); } battery('+0/-0: the blob decides'); diff --git a/scripts/pm/label-write.mjs b/scripts/pm/label-write.mjs index 0319eb3d221..0e8cd6f0836 100644 --- a/scripts/pm/label-write.mjs +++ b/scripts/pm/label-write.mjs @@ -184,19 +184,22 @@ * * ## `--land` on a breaking or narrowing pull — the dogfood battery gate * - * Pull-request CI skips the dogfood shards by design (two speeds); `.claude/agents/os-dev.md` makes up for it by - * having the dev run the full battery once on the final head of a pull whose title carries `!` before its colon or - * whose `Clause-②:` line carries a `(narrowing)` arm, and record it under the report's `dogfood_battery`. A pull that - * lands without that run is ejected by the queue's dogfood shards and takes its batch with it. So `--land` judges it - * BEFORE anything else in the fold (`landDogfoodGate`), on step ①'s own read of the pull's title and body: + * Pull-request CI skips the dogfood shards by design (two speeds), so a pull that breaks them is first seen by the + * merge queue, which ejects it and rebuilds every entry behind it. A pull whose title carries `!` before its colon or + * whose `Clause-②:` line carries a `(narrowing)` arm therefore owes the battery on its own head BEFORE it queues. + * Maintainer ruling 7269391948 (letter D, 「云端流水线代跑」) moved that proof off the dev's box: a CI runner runs the + * three shards on a labelled pull (`.github/workflows/dogfood-optin.yml`, label `needs:dogfood-battery`) and this door + * reads the result. ⛔ It reads NOTHING an agent typed: the os-dev report's old `dogfood_battery` field is gone, and no + * report, card thread or commit walk is read here. So `--land` judges it BEFORE anything else in the fold + * (`landDogfoodGate`), on step ①'s own read of the pull's title and body: * * repo only a pull in a repository that CARRIES the battery is judged: `LAND_DOGFOOD_BATTERY_REPOS`, today - * objectstack-ai/objectstack alone — the one repository with the `@objectstack/dogfood` battery and the - * queue's dogfood shards. Anywhere else (cloud, hotcrm, …) the os-dev report can only say `n/a` and no - * queue shard can eject the pull, so judging it would refuse every marked pull for good: it is NOT - * judged, zero reads, and the fold prints a ✓ line naming the repository. A `--repo` that does not read - * as `owner/name` is judged as before — the battery repository stays fail-closed. A repository that - * gains a battery joins the list in the same pull that adds it. + * objectstack-ai/objectstack alone — the one repository with the `@objectstack/dogfood` battery, the + * queue's dogfood shards and the opt-in lane. Anywhere else (cloud, hotcrm, …) no lane can publish the + * check and no queue shard can eject the pull, so judging it would refuse every marked pull for good: it + * is NOT judged, zero reads, and the fold prints a ✓ line naming the repository. A `--repo` that does not + * read as `owner/name` is judged as before — the battery repository stays fail-closed. A repository that + * gains a battery joins the list in the same pull that adds its lane. * * marker the title's `!` (`titleBreakingMarker`): everything before the title's FIRST colon, ending in `!` * (`fix(pm)!: …`, `feat!: …`) — on main's bang subjects it agrees with the changeset-side reader @@ -205,28 +208,22 @@ * or a `(narrowing)` arm read by `clause2-line.mjs`'s ONE reader — a `malformed` or a `near-miss` line is * unreadable and refuses, never an absent arm; a body with no `Clause-②:` line at all declares no arm and * is not judged, as Check Changeset reads it. No marker ⇒ not judged, zero extra reads. - * report the NEWEST `os-dev-report` on the card the pull delivers (`deliveredCardNumber`) among comments by the - * relay's identity or a governed approver (`recordAuthorTrusted`) — newest-of, marker and payload - * candidates are the patrol's readers, called, ⛔ never a second parser. When that report's `pr` names - * ANOTHER pull (siblings on one card), the newest trusted report whose `pr` names THIS pull, or none — a - * null or URL-less `pr` names no pull, so in that fallback it is not this pull's and is passed over too. - * A FOLD — one closing keyword per card, at equal strength — delivers no single card, and - * `deliveredCardNumber` reports that tie rather than break it (the queue guard's record pairing stays - * refusing on it). The gate then reads EVERY tied card (`deliveredCardsAtStrongest`, the same - * enumeration), each thread whole, under the same author filter and sibling rule, and lands when SOME - * tied card's report carries a battery the head reaches; the verdict never depends on which card is read - * first, and a refusal names every tied card and why each failed. A body naming no card still refuses. - * sha its `dogfood_battery` must open with a sha that is the pull's head, or that a first-parent walk from the - * head reaches over merges of the base alone: each step's commit has exactly two parents, the second one - * on the base branch (`GET /compare/{parent2}...{base}` answers `ahead` or `identical`). + * lane `land-dogfood-lane.mjs`, whose header is the authority on both questions and which this file only + * calls (`readDogfoodLane`), on the `GET /pulls/{n}` answer: + * edits a marked pull whose own FILE LIST changes the lane's workflow is refused — a run on its head is + * a run of its own edit, so it may not certify itself; the lane change lands on its own. + * success a completed check run named `Dogfood battery (opt-in)` with conclusion `success` ON THE HEAD + * SHA — any such run on that sha, ⛔ never the newest run of that name: an unrelated label event + * on the same head publishes a `skipped` run of the same name. A success on an older head is not + * this head's: a push, a merge of the base included, owes a new run (the label re-runs it). * - * FAIL CLOSED: an unreadable marker, no card, no report, an unparsable one, an `n/a` battery, one naming no sha, a - * truncated thread (`LAND_COMMENT_PAGE_CAP`), an unreadable commit or compare, or a walk past `LAND_MERGE_HOP_CAP` is a - * refusal — ⛔ zero writes, the line quoting the title and naming the marker, the report comment and its - * `dogfood_battery` text, and what clears it (`landDogfoodRefusal`). NOT MEASURED is never a pass here. A read the - * platform did not answer (`doCall`'s verdict other than `ok`: refused, failed, rate-limited) is exit 3, PREREQUISITE, - * like every other unread in this file; a judged refusal is exit 2. The ✓ line says the sha alone was judged: whether - * the battery was full and its reds fixed or reported stays the L1 checklist's. + * FAIL CLOSED: an unreadable marker, a pull read with no full head sha or no `changed_files`, a file list not read + * whole, a pull that edits the lane, and a head with no `success` of that name (none at all, only `skipped`, a failure, + * a run in progress, a truncated listing) are refusals — ⛔ zero writes, the line quoting the title and naming the + * marker, the head, why, and what clears it (`landDogfoodRefusal`): add `needs:dogfood-battery` and wait for the run. + * NOT MEASURED is never a pass here. A read the platform did not answer (`doCall`'s verdict other than `ok`: refused, + * failed, rate-limited) is exit 3, PREREQUISITE, like every other unread in this file; a judged refusal is exit 2. The + * ✓ line names the check run it passed on; what the battery covers is the lane's own contract, not this door's. * * ## `--handoff` — the seat's Tier H hand-off as ONE relay stroke, RELAY-ONLY * @@ -446,13 +443,11 @@ import { DECISION_INBOX_LABEL, EXIT_PREREQUISITE_NOT_MET, GOVERNED_PR_AWAITING_MERGE_LABEL, - OS_DEV_REPORT_MARKER, PM_EXCLUSIVE_STATE_LABELS, PM_RESIDUE_LABELS, PM_STATE_CLAIM, PROXY_FLAG, RELEASE_COMMENT_MARKER, - devReportPayloadCandidates, latestMarkedComment, markerMatches, proxyRearmPlan, @@ -467,11 +462,11 @@ import { } from './check-half-states.mjs'; import { GOVERNED_TIER_H, GOVERNED_TIER_S, LOW_RISK_CHANGESET_PATH, sizeLimbFires, slugFromRemote } from './check-governed-merges.mjs'; // The `--land` dogfood gate's readers (header: `--land` on a breaking or narrowing pull), each CALLED from its owner: -// the one `Clause-②:` reader, the card a pull delivers, the relay's identity and the record leg's author trust. +// the one `Clause-②:` reader, and the lane's conclusion on the head (`land-dogfood-lane.mjs`). import { quoteLine, readClause2Line } from './clause2-line.mjs'; -import { deliveredCardNumber, deliveredCardsAtStrongest } from './record-recognisers.mjs'; +import { DOGFOOD_LANE_APP, DOGFOOD_LANE_CHECK, DOGFOOD_LANE_CHECK_PAGE_CAP, DOGFOOD_LANE_LABEL, DOGFOOD_LANE_WORKFLOW, dogfoodLaneCheckVerdict, dogfoodLaneFilesVerdict, readDogfoodLane } from './land-dogfood-lane.mjs'; import { RELAY_COMMENT_AUTHOR } from './fleet-write/ops.mjs'; -import { GOVERNED_APPROVERS, NARROWED_RULING, RECOGNISER_SOURCES, loadRecordRecognisers, narrowedReading, readRecordThreads, recordAuthorTrusted, recordPassVerdict, recordTrustedAuthors, recordVerdict } from './check-governed-queue-guard.mjs'; +import { GOVERNED_APPROVERS, NARROWED_RULING, RECOGNISER_SOURCES, loadRecordRecognisers, narrowedReading, readRecordThreads, recordAuthorTrusted, recordPassVerdict, recordVerdict } from './check-governed-queue-guard.mjs'; // `--handoff`'s record reading loads the guard's recognisers through the guard's OWN loader, handed these two // namespaces for the two specifiers it imports (`RECOGNISER_SOURCES`). ⛔ Never a dynamic import from here: // `check-handover.mjs` imports post-stamped, which reaches this file through `fleet-write/dispatch.mjs`, so a dynamic @@ -1375,8 +1370,8 @@ const USAGE = [ ' --comment-file PATH beside a label/assignee change folds the comment (a Claim:, a Release:, a verdict) into the', ' SAME stroke, comment first, judged by post-stamped\'s own path (stamp, signature, keyed lines); --land appends', ' pr_ready then automerge_enable on a pull request. RELAY-ONLY; every part is read back on its own ④ line.', - ' --land on a pull whose title carries `!` or whose Clause-② line a (narrowing) arm first needs the card\'s newest', - ' trusted os-dev-report to show dogfood_battery run on the head (or below it over merges of the base only); else exit 2.', + ' --land on a pull whose title carries `!` or whose Clause-② line a (narrowing) arm first needs a `success` check run', + ' named `Dogfood battery (opt-in)` on the head sha (label `needs:dogfood-battery`), and a diff that leaves that lane alone; else exit 2.', ' A `## Contract review` record naming CONTRACT_REVIEW_TIER folds only with --tier-evidence PATH, the reviewing run\'s', ' transcript, passed by verify-review-tier.mjs (post-stamped\'s rule; the path stays local).', ' --handoff hands a Tier H pull to its approvers in ONE stroke: the request comment, `pm:awaiting-merge`, the', @@ -1714,14 +1709,8 @@ export async function runLabelWrite(options, deps = {}) { // `--land` on a breaking or narrowing pull — the dogfood battery gate (header) // --------------------------------------------------------------------------- -/** Where the rule this gate holds lives: the full battery runs once on the final head of a `!` or `(narrowing)` pull. */ +/** Where the rule this gate holds lives: a `!` or `(narrowing)` pull is labelled for the lane, and this door reads the lane. */ export const LAND_DOGFOOD_RULE_PATH = '.claude/agents/os-dev.md'; -/** The final-report key that rule's count is written under (os-dev.md's report shape, ⛔ not restated here). */ -export const LAND_DOGFOOD_REPORT_KEY = 'dogfood_battery'; -/** How many 100-row pages of the card's thread the gate reads; a thread still full on the last one is TRUNCATED. */ -export const LAND_COMMENT_PAGE_CAP = 30; -/** How many merge-of-base commits the first-parent walk from the head steps over before it stops and refuses. */ -export const LAND_MERGE_HOP_CAP = 20; /** * The repositories that carry the dogfood battery and its merge-queue shards (header: `repo`), matched * case-insensitively. A pull in any other `owner/name` is not judged; ⛔ never add one that has no battery. @@ -1729,11 +1718,7 @@ export const LAND_MERGE_HOP_CAP = 20; export const LAND_DOGFOOD_BATTERY_REPOS = Object.freeze(['objectstack-ai/objectstack']); /** How much of the title a refusal quotes, at `clause2-line.mjs`'s `quoteLine` cap. */ export const LAND_TITLE_QUOTE_CAP = 160; -/** The compare statuses that put a commit on the base branch: the base is ahead of it, or it IS the base's tip. */ -const ON_BASE_STATUSES = Object.freeze(['ahead', 'identical']); const FULL_SHA = /^[0-9a-f]{40}$/u; -// A `dogfood_battery` that ran opens with the sha it ran on (os-dev.md: ` · VERDICT · …`), optionally quoted. -const BATTERY_SHA_SHAPE = /^[`'"]?([0-9a-f]{7,40})(?![0-9a-z])/iu; /** * Does `repo` carry the dogfood battery? `false` only for an `owner/name` outside `LAND_DOGFOOD_BATTERY_REPOS`; a @@ -1777,228 +1762,44 @@ export function landDogfoodMarkers({ title, body } = {}) { return { markers }; } -/** - * The `dogfood_battery` text an `os-dev-report` comment's payload declares, or `null` when the comment is no report or - * no payload carries the key as a string. WHERE a payload sits is the patrol's reading (`devReportPayloadCandidates`), - * called rather than restated — the shape `check-handover.mjs`'s `reportedStatus` reads `status` with; only the field - * differs. Pure. - */ -export function reportedDogfoodBattery(body) { - return reportedPayloadString(body, LAND_DOGFOOD_REPORT_KEY); -} - -/** One string field of an `os-dev-report` payload, read the way `reportedDogfoodBattery` reads its own. Pure. */ -export function reportedPayloadString(body, key) { - const text = String(body ?? ''); - if (!markerMatches(OS_DEV_REPORT_MARKER, text)) return null; - for (const candidate of devReportPayloadCandidates(text)) { - let doc; - try { - doc = JSON.parse(candidate); - } catch { - continue; - } - if (doc && typeof doc === 'object' && !Array.isArray(doc) && typeof doc[key] === 'string') return doc[key]; - } - return null; -} - -/** - * Which pull a report's `pr` field names, against this one: `'this'`, `'other'`, or `null` when the field is absent or - * names no pull URL (os-dev.md's shape is a URL or null). Only `'other'` moves the gate off the newest report. Pure. - */ -export function reportNamesPull(body, { repo, number } = {}) { - const pr = reportedPayloadString(body, 'pr'); - const m = /github\.com\/([^/\s]+\/[^/\s]+)\/pull\/(\d+)(?![0-9])/u.exec(String(pr ?? '')); - if (!m) return null; - return m[1].toLowerCase() === String(repo ?? '').toLowerCase() && Number(m[2]) === Number(number) ? 'this' : 'other'; -} - -/** - * What a `dogfood_battery` text says ran: `{ ran: false }` for os-dev.md's `n/a — …` arm, `{ ran: true, sha }` when it - * opens with a 7–40 hex sha (lower-cased), `{ ran: null }` when it does neither — UNREADABLE, which the gate refuses. - */ -export function readBatterySha(text) { - const t = String(text ?? '').trim(); - if (/^n\/a(?![a-z0-9])/iu.test(t)) return { ran: false }; - const m = BATTERY_SHA_SHAPE.exec(t); - return m ? { ran: true, sha: m[1].toLowerCase() } : { ran: null }; -} - /** * The gate itself (header): on a `--land` stroke, BEFORE anything is judged or sent. A pull in a repository with no * battery (`repoCarriesDogfoodBattery`) is not judged (`{ judged: false, noBattery: true }`, zero reads); nor is a - * pull with no marker (`{ judged: false }`, zero extra reads). A marked pull lands only when the NEWEST `os-dev-report` on the card - * it delivers — trusted authors only (`recordAuthorTrusted`: the relay's identity and `GOVERNED_APPROVERS`; another - * account's comment is data, ⛔ never a reason to land) — carries a `dogfood_battery` naming a sha that IS the pull's - * current head, or is reached from the head by a first-parent walk over merges of the base branch alone: + * pull with no marker (`{ judged: false }`, zero extra reads). A marked pull lands only when `readDogfoodLane` + * (`land-dogfood-lane.mjs`) answers `ok` on the `GET /pulls/{n}` read: the pull's file list leaves the lane's workflow + * alone, and a completed `success` check run of the lane's name sits on the pull's CURRENT head sha. * - * at the head, step until the battery's sha: the commit must have EXACTLY two parents, its SECOND parent must be on - * the base branch (`GET /compare/{parent2}...{base}` answers `ahead` or `identical`), and the walk steps to its FIRST - * parent. A one-parent commit, a second parent the base does not hold, an unreadable answer, or more than - * `LAND_MERGE_HOP_CAP` hops is a refusal. + * FAIL CLOSED: an unreadable marker, an unreadable pull, a pull that edits the lane, a file list not read whole and a + * head with no such success all refuse — NOT MEASURED is a refusal here, never a pass. A read the platform did not + * answer comes back `unread: true`, which the fold exits 3 on, not 2. ⛔ Nothing an agent typed is read: no report, no + * card thread, no commit walk. * - * FAIL CLOSED: an unreadable marker, no card, an unreadable pull or thread, a thread longer than - * `LAND_COMMENT_PAGE_CAP` pages, no report (or, when the newest names another pull in `pr`, none naming this one), no - * readable `dogfood_battery`, an `n/a` one or one naming no sha all refuse — NOT MEASURED is a refusal here, never a - * pass. A read the platform did not answer comes back `unread: true`, which the fold exits 3 on, not 2. - * - * A TIE (a fold's equal closing keywords, `deliveredCardsAtStrongest`): every tied card's thread is read whole before - * anything is judged — one that does not read is exit 3 and one that cannot be read whole refuses, whatever the other - * cards carry — then each card's report is chosen exactly as above, and the pull lands when the head, or one first-parent - * walk from it, reaches ANY tied card's battery sha. The result then carries `card`, `cleared` and `tied` (each card - * read, its report and battery); a tie refusal carries `tied` with each card's reason. ⛔ Never a choice by number order. - * - * @returns {Promise<{ judged: false, noBattery?: true } | { judged: true, ok: boolean, title: string|null, marker: string, why?: string, clear?: string, report?: number|null, battery?: string|null, hops?: number, unread?: true, card?: number, cleared?: object[], tied?: object[] }>} + * @returns {Promise<{ judged: false, noBattery?: true } | { judged: true, ok: boolean, title: string|null, marker: string, why?: string, clear?: string, head?: string|null, check?: { id: number|null, url: string|null }, seen?: number, tally?: string, selfCertifying?: true, unread?: true }>} */ export async function landDogfoodGate({ repo, issue, card, doCall }) { if (!repoCarriesDogfoodBattery(repo)) return { judged: false, noBattery: true }; const title = typeof card?.title === 'string' ? quoteLine(card.title, LAND_TITLE_QUOTE_CAP) : null; const read = landDogfoodMarkers({ title: card?.title, body: card?.body }); - const rerun = (head) => - `run the full dogfood battery on head ${head ? `\`${head}\`` : '(the pull\'s current head)'} (${LAND_DOGFOOD_RULE_PATH}, Definition of done) and post the card an \`os-dev-report\` whose \`${LAND_DOGFOOD_REPORT_KEY}\` opens with that sha, then land again`; if (read.unreadable) { - return { judged: true, ok: false, title, marker: 'UNREAD', why: `whether this pull is breaking or narrowing cannot be read: ${read.unreadable}`, clear: read.clear, report: null, battery: null }; + return { judged: true, ok: false, title, marker: 'UNREAD', why: `whether this pull is breaking or narrowing cannot be read: ${read.unreadable}`, clear: read.clear, head: null }; } if (read.markers.length === 0) return { judged: false }; const marker = read.markers.join(' and '); - let report = null; - let battery = null; - const refuse = (why, clear) => ({ judged: true, ok: false, title, marker, why, clear, report, battery }); - // A read the platform did not answer is PREREQUISITE (exit 3), never a judged refusal (header: that gate). - const unread = (what, r, clear) => ({ ...refuse(`${what} did not read (${r.call} -> HTTP ${r.status}, ${r.verdict}) — NOT MEASURED`, clear), unread: true }); const pull = await doCall('pull-read', `/repos/${repo}/pulls/${issue}`, {}); - if (pull.verdict !== 'ok') return unread('the pull', pull, 'land again once the pull reads'); - const head = String(pull.json?.head?.sha ?? '').toLowerCase(); - const baseRef = pull.json?.base?.ref; - if (!FULL_SHA.test(head) || typeof baseRef !== 'string' || baseRef === '') return refuse('the pull read carries no full head sha or no base branch', 'land again once the pull reads whole'); - const delivered = deliveredCardNumber(pull.json); - // A fold delivers one card per closing keyword at equal strength, and `deliveredCardNumber` reports that tie - // (`card: null`) rather than break it. The gate then reads EVERY tied card (`deliveredCardsAtStrongest`, the - // same enumeration) and judges over all of them; a body naming no card still refuses here. - const tie = delivered.card === null ? deliveredCardsAtStrongest(pull.json) : null; - if (delivered.card === null && tie.cards.length < 2) return refuse(`no card: ${delivered.reason}`, `declare the card on the body (\`Fixes #N\` or \`Part of #N\`), then ${rerun(head)}`); - const cards = tie === null ? [delivered.card] : tie.cards; - - const trusted = recordTrustedAuthors(RELAY_COMMENT_AUTHOR); - // One card's thread, read whole, and the report the gate judges on it: `{ blocked }` when the thread cannot be read - // whole (the gate's verdict, as on one card), else `{ card, report, battery, sha }` or `{ card, report, battery, why }`. - const readCard = async (number) => { - const rows = []; - for (let page = 1; ; page += 1) { - if (page > LAND_COMMENT_PAGE_CAP) { - return { - blocked: refuse( - `card #${number}'s thread is still full after ${LAND_COMMENT_PAGE_CAP} pages of 100 — a TRUNCATED listing, so its newest report is unknown`, - 'report it to the maintainer: this gate cannot read the newest report on a thread that long, and it lands nothing it has not read', - ), - }; - } - const listed = await doCall('comments-list', `/repos/${repo}/issues/${number}/comments?per_page=100&page=${page}`, {}); - if (listed.verdict !== 'ok') { - // A 404 is as likely the pull delivering the wrong card (its body or its branch) as the platform failing to answer. - return { blocked: unread(`card #${number}'s thread`, listed, `land again once the card reads${listed.status === 404 ? `, or correct the card this pull delivers (#${number})` : ''}`) }; - } - if (!Array.isArray(listed.json)) return { blocked: refuse(`card #${number}'s thread answered no list on page ${page}`, 'land again once the card reads') }; - rows.push(...listed.json); - if (listed.json.length < 100) break; - } - const kept = rows.filter((row) => recordAuthorTrusted(row, trusted)); - const newest = latestMarkedComment(kept, OS_DEV_REPORT_MARKER); - if (newest === null) return { card: number, report: null, battery: null, why: `card #${number} carries no \`os-dev-report\` by ${trusted.join(' / ')} (${rows.length} comment(s) read)` }; - let row = kept[newest.index]; - // Sibling pulls on one card: the newest report may be another pull's. Then the newest naming THIS pull, or none. - if (reportNamesPull(row?.body, { repo, number: issue }) === 'other') { - const own = kept.filter((r) => reportNamesPull(r?.body, { repo, number: issue }) === 'this'); - const mine = latestMarkedComment(own, OS_DEV_REPORT_MARKER); - if (mine === null) { - return { card: number, report: row?.id ?? null, battery: reportedDogfoodBattery(row?.body), why: `card #${number}'s newest trusted report names another pull in \`pr\`, and no trusted report names this one` }; - } - row = own[mine.index]; - } - const found = { card: number, report: row?.id ?? null, battery: reportedDogfoodBattery(row?.body) }; - if (found.battery === null) return { ...found, why: `the newest report carries no readable \`${LAND_DOGFOOD_REPORT_KEY}\` string` }; - const ran = readBatterySha(found.battery); - if (ran.ran === false) return { ...found, why: 'the battery was not run (`n/a`)' }; - if (ran.ran === null) return { ...found, why: `\`${LAND_DOGFOOD_REPORT_KEY}\` names no sha it ran on` }; - return { ...found, sha: ran.sha }; - }; - const outcomes = []; - for (const number of cards) { - const one = await readCard(number); - if (one.blocked) return tie === null ? one.blocked : { ...one.blocked, tied: outcomes.map(tiedRow) }; - outcomes.push(one); - } - const judgeable = outcomes.filter((one) => one.sha !== undefined); - // On a tie the refusal names every card read and why each failed; on one card it is that card's reason, as before. - const tieRefuse = (walkWhy) => { - const rows = outcomes.map((one) => ({ ...tiedRow(one), why: one.why ?? walkWhy })); - return { - ...refuse( - `it delivers ${cards.length} cards at the same strength (${cards.map((n) => `#${n}`).join(', ')}, ${tie.evidence}), each card's thread was read, and none carries a report that clears this pull — ${rows.map((r) => `card #${r.card}: ${r.why}`).join('; ')}`, - rerun(head), - ), - tied: rows, - }; - }; - if (tie === null) { - report = outcomes[0].report; - battery = outcomes[0].battery; - if (outcomes[0].why !== undefined) return refuse(outcomes[0].why, rerun(head)); - } else if (judgeable.length === 0) { - return tieRefuse(null); + if (pull.verdict !== 'ok') { + // A read the platform did not answer is PREREQUISITE (exit 3), never a judged refusal (header: that gate). + return { judged: true, ok: false, title, marker, head: null, why: `the pull did not read (${pull.call} -> HTTP ${pull.status}, ${pull.verdict}) — NOT MEASURED`, clear: 'land again once the pull reads', unread: true }; } - const shaWords = judgeable.length === 1 ? `the battery's \`${judgeable[0].sha}\`` : `the tied cards' batteries (${[...new Set(judgeable.map((one) => one.sha))].map((sha) => `\`${sha}\``).join(', ')})`; - // A pass names the report(s) whose sha the head reaches first; on a tie every card read rides along in `tied`. - const pass = (at, hops) => { - const clearing = judgeable.filter((one) => at.startsWith(one.sha)); - if (clearing.length === 0) return null; - report = clearing[0].report; - battery = clearing[0].battery; - return { judged: true, ok: true, title, marker, report, battery, hops, ...(tie === null ? {} : { card: clearing[0].card, cleared: clearing.map(tiedRow), tied: outcomes.map(tiedRow) }) }; - }; - const walkRefuse = (why) => (tie === null ? refuse(why, rerun(head)) : tieRefuse(why)); - const walkUnread = (what, r) => (tie === null ? unread(what, r, rerun(head)) : { ...unread(what, r, rerun(head)), tied: outcomes.map(tiedRow) }); - const passedOnHead = pass(head, 0); - if (passedOnHead) return passedOnHead; - - let at = head; - for (let hop = 1; hop <= LAND_MERGE_HOP_CAP; hop += 1) { - const commit = await doCall('commit-read', `/repos/${repo}/commits/${at}`, {}); - if (commit.verdict !== 'ok') return walkUnread(`commit \`${at}\`, on the walk to ${shaWords},`, commit); - const parents = (Array.isArray(commit.json?.parents) ? commit.json.parents : []).map((p) => String(p?.sha ?? '').toLowerCase()); - if (parents.length !== 2 || !parents.every((p) => FULL_SHA.test(p))) { - return walkRefuse(`commit \`${at}\` lies after ${shaWords} and is not a merge (${parents.length} parent(s)) — the battery did not run on this code`); - } - const compared = await doCall('compare-read', `/repos/${repo}/compare/${parents[1]}...${enc(baseRef)}`, {}); - if (compared.verdict !== 'ok') return walkUnread(`whether merge \`${at}\`'s second parent \`${parents[1]}\` is on \`${baseRef}\``, compared); - if (!ON_BASE_STATUSES.includes(compared.json?.status)) { - return walkRefuse(`merge \`${at}\` brings in \`${parents[1]}\`, which \`${baseRef}\` does not hold (compare status ${JSON.stringify(compared.json?.status ?? null)}) — not a merge of the base`); - } - at = parents[0]; - const passed = pass(at, hop); - if (passed) return passed; - } - return walkRefuse(`${shaWords} ${judgeable.length === 1 ? 'is' : 'are'} not reached within ${LAND_MERGE_HOP_CAP} merges of \`${baseRef}\` on the head's first-parent line`); -} - -/** One tied card's row on a tie verdict: the card, its judged report comment (or null) and that report's battery text. Pure. */ -function tiedRow(one) { - return { card: one.card, report: one.report ?? null, battery: one.battery ?? null }; + const lane = await readDogfoodLane({ repo, issue, pull: pull.json, doCall }); + return { judged: true, title, marker, head: null, ...lane }; } -/** The refusal line a failed gate prints: the title, the marker, the report comment and its `dogfood_battery` text, why, and what clears it. */ +/** The refusal line a failed gate prints: the title, the marker, the head the lane was read on, why, and what clears it. */ export function landDogfoodRefusal(gate) { - const reportWords = (r) => `${r.report === null || r.report === undefined ? 'none' : `comment ${r.report}`}`; - const batteryWords = (r) => `${r.battery === null || r.battery === undefined ? 'none' : JSON.stringify(r.battery)}`; - // A tie names every tied card read, each with its report and battery; one card prints as it always has. - const reportPart = Array.isArray(gate.tied) - ? `reports: ${gate.tied.length === 0 ? 'none read' : gate.tied.map((r) => `card #${r.card} ${reportWords(r)}, ${LAND_DOGFOOD_REPORT_KEY} ${batteryWords(r)}`).join('; ')}` - : `report: ${reportWords(gate)} · ${LAND_DOGFOOD_REPORT_KEY}: ${batteryWords(gate)}`; return ( `--land REFUSED by the dogfood battery gate (${LAND_DOGFOOD_RULE_PATH}) — title: ${gate.title === null || gate.title === undefined ? 'none read' : JSON.stringify(gate.title)} · marker: ${gate.marker} · ` + - `${reportPart} · why: ${gate.why} · to clear: ${gate.clear}.` + `head: ${gate.head ? `\`${gate.head}\`` : 'none read'} · why: ${gate.why} · to clear: ${gate.clear}.` ); } @@ -2326,7 +2127,7 @@ async function foldStroke(c) { if (gate.judged && !gate.ok) return refuse(landDogfoodRefusal(gate), { gate }); record( gate.judged - ? `[${stamp()}] ② dogfood gate ✓ — marker: ${gate.marker} · report comment ${gate.report} · ${LAND_DOGFOOD_REPORT_KEY} ${JSON.stringify(gate.battery)} · sha judged only · ${gate.hops === 0 ? 'ran on the head' : `ran ${gate.hops} merge(s) of the base below the head`}${Array.isArray(gate.tied) ? ` · a tie of ${gate.tied.length} cards (${gate.tied.map((r) => `#${r.card}`).join(', ')}), every thread read, cleared by ${gate.cleared.map((r) => `card #${r.card} comment ${r.report}`).join(', ')}` : ''}` + ? `[${stamp()}] ② dogfood gate ✓ — marker: ${gate.marker} · \`${DOGFOOD_LANE_CHECK}\` concluded success on head \`${gate.head}\` (check run ${gate.check.id ?? 'id not read'}; ${gate.seen} run(s) of that name on the head: ${gate.tally}) · the pull's file list leaves \`${DOGFOOD_LANE_WORKFLOW}\` alone` : gate.noBattery ? `[${stamp()}] ② dogfood gate ✓ — not judged: ${repo} has no dogfood battery (only ${LAND_DOGFOOD_BATTERY_REPOS.join(', ')} carries one)` : `[${stamp()}] ② dogfood gate — not judged: no \`!\` in the title and no \`(narrowing)\` arm`, @@ -2795,8 +2596,9 @@ export function classifyOp(method, path) { if (/\/pulls(\?|$)/.test(path)) return 'pulls-list'; if (/\/pulls\/\d+$/.test(path)) return 'pull-read'; if (/\/pulls\/\d+\/reviews(\?|$)/.test(path)) return 'reviews-list'; + if (/\/pulls\/\d+\/files(\?|$)/.test(path)) return 'pull-files-list'; + if (/\/commits\/[0-9a-f]+\/check-runs(\?|$)/.test(path)) return 'check-runs-list'; if (/\/commits\/[0-9a-f]+$/.test(path)) return 'commit-read'; - if (/\/compare\/[^/]+$/.test(path)) return 'compare-read'; if (/\/contents\//.test(path)) return 'contents-read'; if (/\/labels\/[^/]+$/.test(path) && method === 'DELETE') return 'label-delete'; if (/\/labels$/.test(path)) return 'label-add'; @@ -2840,8 +2642,10 @@ export function fakeBoard(initial = {}) { draft: initial.draft ?? true, autoMerge: initial.autoMerge ?? null, // What step ① and `GET /pulls/{n}` answer for a pull's text, and what the `--land` dogfood gate reads beside it: - // the head and base, OTHER cards' threads (`cards`: number → comments), each commit's parents (`commits`: sha → - // parent shas) and the shas the base branch holds (`onBase`), which `GET /compare/{sha}...{base}` answers from. + // the head, the pull's changed files (`pullFiles`, as `GET /pulls/{n}/files` rows; `changedFiles` is the count + // `GET /pulls/{n}` declares, the listing's length unless a fixture says otherwise) and the check runs on each + // commit (`checkRuns`: sha → rows, as `GET /commits/{sha}/check-runs` lists them). `--handoff` reads OTHER cards' + // threads (`cards`: number → comments) and each commit's parents (`commits`: sha → parent shas). title: initial.title ?? ((initial.kind ?? 'issue') === 'pull' ? 'fix(pm): a fixture pull' : 'A fixture card'), body: initial.body ?? null, head: { ...(initial.head ?? { sha: 'f'.repeat(40), ref: 'claude/issue-8-fixture' }) }, @@ -2850,7 +2654,9 @@ export function fakeBoard(initial = {}) { baseSha: initial.baseSha ?? null, cards: { ...(initial.cards ?? {}) }, commits: { ...(initial.commits ?? {}) }, - onBase: new Set(initial.onBase ?? []), + pullFiles: [...(initial.pullFiles ?? [{ filename: 'scripts/pm/fixture.mjs', status: 'modified' }])], + changedFiles: initial.changedFiles ?? null, + checkRuns: { ...(initial.checkRuns ?? {}) }, // `--handoff`'s reads: the pull's author, its pending review requests, its submitted reviews, and each commit's // committer date (`commitDates`: sha → ISO), which `GET /commits/{sha}` answers beside the parents. author: initial.author ?? 'objectstack-fleet[bot]', @@ -2923,10 +2729,16 @@ export function fakeBoard(initial = {}) { if (board.kind !== 'pull') return wrap(404, { message: 'Not Found' }); return wrap(200, board.reviews); } - if (op === 'compare-read') { - const [from, to] = decodeURIComponent(path.slice(path.lastIndexOf('/') + 1)).split('...'); - if (to !== board.baseRef) return wrap(404, { message: 'Not Found' }); - return wrap(200, { status: board.onBase.has(from) ? 'ahead' : 'diverged' }); + if (op === 'pull-files-list' || op === 'check-runs-list') { + if (board.kind !== 'pull') return wrap(404, { message: 'Not Found' }); + const query = new URLSearchParams(path.slice(path.indexOf('?') + 1)); + const size = Number(query.get('per_page') ?? 30); + const page = Number(query.get('page') ?? 1); + if (op === 'pull-files-list') return wrap(200, board.pullFiles.slice((page - 1) * size, page * size)); + // As GitHub lists them: the rows on THAT commit carrying the asked name, a page at a time, under a total. + const sha = /\/commits\/([0-9a-f]+)\/check-runs/.exec(path)[1]; + const named = (board.checkRuns[sha] ?? []).filter((r) => r.name === query.get('check_name')); + return wrap(200, { total_count: named.length, check_runs: named.slice((page - 1) * size, page * size) }); } if (op === 'comments-list') { const query = new URLSearchParams(path.slice(path.indexOf('?') + 1)); @@ -2958,6 +2770,7 @@ export function fakeBoard(initial = {}) { body: board.body, head: board.head, base: { ref: board.baseRef, ...(board.baseSha === null ? {} : { sha: board.baseSha }) }, + ...(board.changedFiles === false ? {} : { changed_files: board.changedFiles ?? board.pullFiles.length }), user: { login: board.author }, requested_reviewers: board.requested.map((login) => ({ login })), labels: board.labels.map((name) => ({ name })), @@ -3197,7 +3010,7 @@ export async function relayMissProbe({ route, send }) { const FOLD_BATTERY = "the fold: a claim (comment + labels + assignee) and a verdict (comment + pr_ready + automerge_enable) as ONE relay stroke, the comment judged on post-stamped's path, every part read back on its own line, a part that fails read-back exit 4 and never repaired, RELAY-ONLY"; const REAL_TRANSPORT_BATTERY = "the real transport: a comment-bearing stroke (a fold, a release) through fleet-write's own sendFleetWrite — fake fetch, real dispatch, real read-back — settles, exit 0, every ④ line printed"; const KIND_BATTERY = 'the kind rule: no pm state added to a pull request, no `pm:awaiting-merge` added to an issue, a removal never refused, an unreadable kind refused — on both write paths, before the transport'; -const LAND_DOGFOOD_BATTERY = "the --land dogfood gate: a `!` title or a `(narrowing)` arm lands only on a trusted newest os-dev-report whose dogfood_battery names the head or a first-parent ancestor reached over merges of the base alone; every NOT MEASURED refuses before any send; an unmarked pull, or one in a repository with no battery, is not judged"; +const LAND_DOGFOOD_BATTERY = "the --land dogfood gate: a `!` title or a `(narrowing)` arm lands only on a completed `success` check run named `Dogfood battery (opt-in)` on the pull's head sha — any such run on that sha, never the newest of that name — and only when the pull's own file list leaves the lane's workflow alone; nothing an agent typed is read; every NOT MEASURED refuses before any send; an unmarked pull, or one in a repository with no battery, is not judged"; const STATELESS_BATTERY = 'the stateless write: an OPEN card never loses its last pm state unless the same write adds a state or needs-user-decision or closes it, a parked card never keeps an assignee a state or assignee move left there, a release stays legal — before the transport, zero writes'; const HAND_SET_BATTERY = "the hand-set grade: a `priority:*` whose newest `labeled` event is not the fleet's (no app, no bot actor), or is the fleet's with its own `Ruling-ref: ` fold beside it, is never changed — refused at step ② with zero writes unless the folded comment's `Ruling-ref:` names the grade it writes"; const HANDOFF_BATTERY = "--handoff: the Tier H hand-off — request comment, pm:awaiting-merge, the author-approver assigned and the rest requested — as ONE relay stroke, refused with zero writes off Tier H, the size limb or a declared narrowing (the narrowed leg), or without a seat ACCEPT newer than the head and a same-head trusted PASS on the PR or its card at the tier its face owes, read back with the H43 and H48 rows themselves on a slice that carries the size limb; idempotent only with the brief on the thread, never the seat's own account; --dry-run the per-round reading, exit 7 while owed"; @@ -3218,9 +3031,10 @@ const SELF_TEST_BATTERIES = Object.freeze({ [FOLD_BATTERY]: 28, [REAL_TRANSPORT_BATTERY]: 5, [STATELESS_BATTERY]: 19, - // Raised 50 → 65 with the fold's tie: two `Fixes` lines read on every tied card, passing and refusing, and the structural pin. - // Raised 65 → 70 with the battery repositories: the pure predicate, the zero-read gate, cloud `(narrowing)` and `!` landing, objectstack still refusing. - [LAND_DOGFOOD_BATTERY]: 70, + // Re-pinned 70 → 64 by maintainer ruling 7269391948 (letter D): the door reads the opt-in lane's check run on the head + // and nothing an agent typed, so the report, sibling-pull, tie and commit-walk cases left with the code they drove + // (each flip is pre-registered in its case's name: "FLIPPED by ruling D (was …)"); the lane's own cases joined. + [LAND_DOGFOOD_BATTERY]: 64, [HAND_SET_BATTERY]: 42, // Raised 59 → 68 with the carried PASS: the git reader and base ref handed to the guard's `regenCarry`, both directions. [HANDOFF_BATTERY]: 68, @@ -3872,17 +3686,22 @@ export async function selfTest() { const HEAD = `abcdef1${'0'.repeat(33)}`; const BELOW = 'b'.repeat(40); const MAIN_SIDE = 'c'.repeat(40); - const STRAY = 'd'.repeat(40); const FLEET = 'objectstack-fleet[bot]'; - const report = (dogfood, { id = 501, at: when = '2026-11-08T14:00:00Z', login = FLEET, raw = null, pr = 'https://github.com/objectstack-ai/objectstack/pull/7' } = {}) => ({ + // The typed proof the door used to read: a trusted os-dev-report on the delivered card. It stays in these + // fixtures ONLY to show the door no longer reads it, in either direction. + const report = (dogfood, { id = 501 } = {}) => ({ id, - created_at: when, - user: { login }, - body: raw ?? `${SIG}\nos-dev-report\n\n\`\`\`json\n${JSON.stringify({ issue: 8, status: 'done', pr, dogfood_battery: dogfood })}\n\`\`\`\n`, + created_at: '2026-11-08T14:00:00Z', + user: { login: FLEET }, + body: `${SIG}\nos-dev-report\n\n\`\`\`json\n${JSON.stringify({ issue: 8, status: 'done', pr: 'https://github.com/objectstack-ai/objectstack/pull/7', dogfood_battery: dogfood })}\n\`\`\`\n`, }); const RAN_HEAD = `${HEAD} · VERDICT command-exit 0 · Test Files 212/212 · Tests 1904/1904 · no failures`; - const RAN_BELOW = `${BELOW} · VERDICT command-exit 0 · Test Files 212/212 · Tests 1904/1904 · no failures`; const NA = 'n/a — no `!` in the PR title and no (narrowing) arm'; + // One check run row, as `GET /commits/{sha}/check-runs` lists it. + const run = (conclusion, { id = 9001, sha = HEAD, status = 'completed', name = DOGFOOD_LANE_CHECK, app = DOGFOOD_LANE_APP } = {}) => ({ id, name, head_sha: sha, status, conclusion, app: { slug: app }, html_url: `https://github.com/objectstack-ai/objectstack/runs/${id}` }); + const SUCCESS = run('success'); + const SKIPPED = (id) => run('skipped', { id }); + const LANE_FILE = { filename: DOGFOOD_LANE_WORKFLOW, status: 'modified' }; const pull = (o = {}) => ({ kind: 'pull', labels: ['domain:skills'], @@ -3890,74 +3709,122 @@ export async function selfTest() { title: o.title ?? 'fix(pm)!: a breaking fixture', body: o.body ?? 'Fixes #8\n\nClause-②: no\nMetadata-protocol: none\n', head: { sha: o.head ?? HEAD, ref: o.ref ?? 'claude/issue-8-fixture' }, - cards: o.cards ?? { 8: [report(RAN_HEAD)] }, + cards: o.cards ?? {}, commits: o.commits ?? {}, - onBase: o.onBase ?? [], + checkRuns: o.runs ?? { [HEAD]: [SUCCESS] }, + ...(o.files === undefined ? {} : { pullFiles: o.files }), + ...(o.changedFiles === undefined ? {} : { changedFiles: o.changedFiles }), }); const land = (board, extra = {}) => driveOffline(landArgv, board, { route, relay: 'success', files, now: NOW, ...extra }); - const writesOf = (run) => run.fake.calls.filter((c) => c.method !== 'GET').map((c) => `${c.method} ${c.path}`); - const refused = (run) => [run.exit, run.sent.length, writesOf(run), run.text.includes('--land REFUSED by the dogfood battery gate')]; + const writesOf = (r) => r.fake.calls.filter((c) => c.method !== 'GET').map((c) => `${c.method} ${c.path}`); + const refused = (r) => [r.exit, r.sent.length, writesOf(r), r.text.includes('--land REFUSED by the dogfood battery gate')]; const REFUSED = [EXIT_USAGE, 0, [], true]; + const LANDED = ['comment', 'pr_ready', 'automerge_enable']; + const opsOf = (r) => r.fake.calls.map((c) => c.op); + const CLEAR = `to clear: add the label \`${DOGFOOD_LANE_LABEL}\` to the pull, wait for the check run \`${DOGFOOD_LANE_CHECK}\` to conclude \`success\` on head \`${HEAD}\`, then land again`; // The pure readers. t('the title marker: `!` as the last character before the first colon, with or without a scope; none in prose or after the colon; an empty title unreadable', ['feat!: x', 'fix(pm)!: x', 'fix(pm) !: x', 'fix(pm): x!', 'fix(pm): a!: b', 'Bump x', '', null].map(titleBreakingMarker), [true, true, true, false, false, false, null, null]); - t('the battery text: `n/a — …` did not run, a leading sha (quoted or bare, 7–40 hex) ran on that sha, anything else is unreadable', - [NA, `\`${HEAD.slice(0, 7)}\` · VERDICT`, RAN_HEAD, 'ran it · VERDICT command-exit 0', 'abcdef · too short', 'abcdef1x · not a sha'].map((x) => readBatterySha(x)), - [{ ran: false }, { ran: true, sha: HEAD.slice(0, 7) }, { ran: true, sha: HEAD }, { ran: null }, { ran: null }, { ran: null }]); - t('the report field: read through the patrol\'s payload candidates, fenced or bare; no report and no string are null', - [reportedDogfoodBattery(report(NA).body), reportedDogfoodBattery(`os-dev-report\n{"dogfood_battery": "${HEAD}"}`), reportedDogfoodBattery('A comment quoting `os-dev-report`.\n```json\n{"dogfood_battery":"x"}\n```'), reportedDogfoodBattery('os-dev-report\n```json\n{"dogfood_battery": 5}\n```')], - [NA, HEAD, null, null]); t('the markers: the title\'s `!`, a `(narrowing)` arm on the body\'s Clause-② line (either value), neither, and a malformed line UNREADABLE', [landDogfoodMarkers({ title: 'fix!: x', body: 'Clause-②: no' }).markers.length, landDogfoodMarkers({ title: 'fix: x', body: 'Clause-②: yes (narrowing)' }).markers.length, landDogfoodMarkers({ title: 'fix: x', body: 'Clause-②: no (narrowing)' }).markers.length, landDogfoodMarkers({ title: 'fix!: x', body: 'Clause-②: no (narrowing)' }).markers.length, landDogfoodMarkers({ title: 'fix: x', body: 'Clause-②: yes (widening)' }).markers.length, typeof landDogfoodMarkers({ title: 'fix: x', body: 'Clause-②: maybe' }).unreadable, typeof landDogfoodMarkers({ title: 'fix: x', body: 'Clause-2: no (narrowing)' }).unreadable, landDogfoodMarkers({ title: 'fix: x', body: 'No declaration here.' }).markers.length], [1, 1, 1, 2, 0, 'string', 'string', 0]); - - // ⭐ The card's both-ways rows. - const na = await land(pull({ cards: { 8: [report(NA)] } })); - t('⭐ REFUSED: a `!` title whose newest report says `n/a` — exit 2, ZERO sends, no pr_ready, nothing written', refused(na), REFUSED, na.text.slice(-600)); - t('…and the refusal quotes the title and names the marker, the report comment id, its dogfood_battery text, why, and what clears it', ['title: "fix(pm)!: a breaking fixture"', '`!` before the colon of the title', 'report: comment 501', JSON.stringify(NA), 'why: the battery was not run', 'to clear: run the full dogfood battery on head', HEAD].map((w) => na.text.includes(w)), [true, true, true, true, true, true, true]); - const longTitle = await land(pull({ title: `fix(pm)!: ${'x'.repeat(400)}`, cards: { 8: [report(NA)] } })); - t('…a long title is quoted capped at quoteLine\'s cap, with its ellipsis', [longTitle.exit, longTitle.text.includes(`title: "fix(pm)!: ${'x'.repeat(LAND_TITLE_QUOTE_CAP - 10)}…"`), longTitle.text.includes('x'.repeat(LAND_TITLE_QUOTE_CAP))], [EXIT_USAGE, true, false]); - const onHead = await land(pull()); - t('⭐ PASSES: a `!` title whose newest report ran on the head — ONE dispatch, comment → pr_ready → automerge_enable, ready and armed, exit 0', [onHead.exit, onHead.sent[0]?.actions.map((a) => a.op), onHead.fake.board.draft, onHead.text.includes('② dogfood gate ✓'), onHead.text.includes('sha judged only · ran on the head')], [EXIT_OK, ['comment', 'pr_ready', 'automerge_enable'], false, true, true], onHead.text.slice(-600)); - t('…from the pull and the card thread alone — no commit walk when the battery names the head', onHead.fake.calls.map((c) => c.op), ['card-read', 'pull-read', 'comments-list', 'card-read', 'comments-list', 'pull-read']); - const short = await land(pull({ cards: { 8: [report(`\`${HEAD.slice(0, 7)}\` · VERDICT command-exit 0`)] } })); - t('…an abbreviated sha (7 hex) naming the head passes the same way', short.exit, EXIT_OK); - const olderCode = await land(pull({ title: 'fix(pm): narrowing fixture', body: 'Fixes #8\n\nClause-②: no (narrowing)\nMetadata-protocol: narrowed\n', cards: { 8: [report(RAN_BELOW)] }, commits: { [HEAD]: [BELOW] } })); - t('⭐ REFUSED: a `(narrowing)` arm whose battery ran on an older NON-MERGE ancestor — the head\'s own commit is new code', [...refused(olderCode), olderCode.text.includes('is not a merge (1 parent(s))'), olderCode.text.includes('`(narrowing)` arm')], [...REFUSED, true, true], olderCode.text.slice(-600)); - const mergedMain = await land(pull({ cards: { 8: [report(RAN_BELOW)] }, commits: { [HEAD]: [BELOW, MAIN_SIDE] }, onBase: [MAIN_SIDE] })); - t('⭐ PASSES: a `!` title whose battery ran one merge of main below the head — the walk reads the merge and the compare, exit 0', [mergedMain.exit, mergedMain.text.includes('ran 1 merge(s) of the base below the head'), mergedMain.fake.calls.filter((c) => c.op === 'commit-read' || c.op === 'compare-read').map((c) => c.path)], [EXIT_OK, true, [`/repos/objectstack-ai/objectstack/commits/${HEAD}`, `/repos/objectstack-ai/objectstack/compare/${MAIN_SIDE}...main`]], mergedMain.text.slice(-600)); - const twoMerges = await land(pull({ cards: { 8: [report(RAN_BELOW)] }, commits: { [HEAD]: [STRAY, MAIN_SIDE], [STRAY]: [BELOW, MAIN_SIDE] }, onBase: [MAIN_SIDE] })); - t('…and over TWO merges of main, each judged', [twoMerges.exit, twoMerges.text.includes('ran 2 merge(s)')], [EXIT_OK, true]); - const notMain = await land(pull({ cards: { 8: [report(RAN_BELOW)] }, commits: { [HEAD]: [BELOW, STRAY] }, onBase: [MAIN_SIDE] })); - t('⛔ REFUSED: a merge whose second parent the base does not hold — a merge of another branch is new code', [...refused(notMain), notMain.text.includes('which `main` does not hold')], [...REFUSED, true]); - const plain = await land(pull({ title: 'fix(pm): an ordinary fixture', cards: { 8: [report(NA)] } })); - t('⭐ NOT JUDGED: no `!` and no `(narrowing)` arm lands as today — even over an `n/a` report — with no gate read at all', [plain.exit, plain.text.includes('not judged'), plain.fake.calls.map((c) => c.op)], [EXIT_OK, true, ['card-read', 'card-read', 'comments-list', 'pull-read']]); - const widening = await land(pull({ title: 'feat(pm): a widening fixture', body: 'Fixes #8\n\nClause-②: yes (widening)\n', cards: {} })); + t('the lane literals are the lane\'s contract: the label, the aggregate check (⛔ not a shard, not the required gate), the workflow file, the app', + [DOGFOOD_LANE_LABEL, DOGFOOD_LANE_CHECK, DOGFOOD_LANE_WORKFLOW, DOGFOOD_LANE_APP, DOGFOOD_LANE_CHECK.includes('shard'), DOGFOOD_LANE_CHECK.startsWith('Dogfood Regression Gate')], + ['needs:dogfood-battery', 'Dogfood battery (opt-in)', '.github/workflows/dogfood-optin.yml', 'github-actions', false, false]); + const cv = (rows) => { const v = dogfoodLaneCheckVerdict(rows, HEAD); return [v.success?.id ?? null, v.seen, v.tally]; }; + t('⭐ the check verdict asks "is there a success of this name on this head", never "what does the newest say": skipped, skipped, success passes wherever the success sits', + [cv([SKIPPED(1), SKIPPED(2), SUCCESS]), cv([SUCCESS, SKIPPED(1), SKIPPED(2)]), cv([SKIPPED(1), SUCCESS, SKIPPED(2)])].map((v) => v.slice(0, 2)), [[9001, 3], [9001, 3], [9001, 3]]); + t('…only skipped, a failure, a cancelled run and no run at all are no success, each tallied in words', + [cv([SKIPPED(1), SKIPPED(2)]), cv([run('failure'), SKIPPED(1)]), cv([run('cancelled')]), cv([]), cv(null)], + [[null, 2, 'skipped ×2'], [null, 2, 'failure ×1, skipped ×1'], [null, 1, 'cancelled ×1'], [null, 0, ''], [null, 0, '']]); + t('⛔ …a run still in progress is no success, whatever its conclusion field holds: `completed` is required', + [cv([run(null, { status: 'in_progress' })]), cv([run('success', { status: 'queued' })])], [[null, 1, 'in_progress ×1'], [null, 1, 'queued ×1']]); + t('⛔ …a success on ANOTHER sha, under a SHARD\'s name, under the required gate\'s name, or by another app is not the lane\'s on this head: not counted at all', + [cv([run('success', { sha: BELOW })]), cv([run('success', { name: 'Dogfood battery shard (1/3, opt-in)' })]), cv([run('success', { name: 'Dogfood Regression Gate' })]), cv([run('success', { app: 'some-other-app' })]), cv([{ ...SUCCESS, app: null }])], + [[null, 0, ''], [null, 0, ''], [null, 0, ''], [null, 0, ''], [null, 0, '']]); + t('…the head is matched whatever its case, and a row with no numeric id still passes with a null id', [cv([{ ...SUCCESS, head_sha: HEAD.toUpperCase() }]).slice(0, 2), dogfoodLaneCheckVerdict([{ ...SUCCESS, id: 'x', html_url: null }], HEAD).success], [[9001, 1], { id: null, url: null }]); + t('the file verdict: the lane\'s workflow by its current name or its PREVIOUS one (a rename away is a change); another workflow, a look-alike path and no list are not', + [dogfoodLaneFilesVerdict([LANE_FILE]), dogfoodLaneFilesVerdict([{ filename: '.github/workflows/renamed.yml', previous_filename: DOGFOOD_LANE_WORKFLOW, status: 'renamed' }]).rows, dogfoodLaneFilesVerdict([{ filename: '.github/workflows/ci.yml', status: 'modified' }, { filename: `docs/${DOGFOOD_LANE_WORKFLOW}`, status: 'added' }]).touched, dogfoodLaneFilesVerdict(null).touched], + [{ touched: true, rows: [{ filename: DOGFOOD_LANE_WORKFLOW, status: 'modified' }] }, [{ filename: '.github/workflows/renamed.yml', status: 'renamed' }], false, false]); + + // ⭐ The ruling's flip, both ways: the lane's check on the head decides, and the typed report decides nothing. + const typedOnly = await land(pull({ cards: { 8: [report(RAN_HEAD)] }, runs: {} })); + t('⭐ FLIPPED by ruling D (was PASSES: "a `!` title whose newest report ran on the head"): the SAME head-pinned typed report with NO lane check on the head now REFUSES — exit 2, ZERO sends, no pr_ready, nothing written', refused(typedOnly), REFUSED, typedOnly.text.slice(-700)); + t('…and the refusal quotes the title, names the marker and the head, says no check run of the lane\'s name is on it, and says to add the label and wait for the run', ['title: "fix(pm)!: a breaking fixture"', '`!` before the colon of the title', `head: \`${HEAD}\``, `why: no check run named \`${DOGFOOD_LANE_CHECK}\` by ${DOGFOOD_LANE_APP} is on head`, CLEAR].map((w) => typedOnly.text.includes(w)), [true, true, true, true, true], typedOnly.text.slice(-700)); + const laneOnly = await land(pull({ cards: { 8: [report(NA)] } })); + t('⭐ FLIPPED by ruling D (was REFUSED: "a `!` title whose newest report says `n/a`"): the SAME `n/a` report over a lane success on the head now PASSES — ONE dispatch, comment → pr_ready → automerge_enable, ready and armed, exit 0', [laneOnly.exit, laneOnly.sent[0]?.actions.map((a) => a.op), laneOnly.fake.board.draft, laneOnly.text.includes('② dogfood gate ✓'), laneOnly.text.includes(`\`${DOGFOOD_LANE_CHECK}\` concluded success on head \`${HEAD}\` (check run 9001; 1 run(s) of that name on the head: success ×1)`)], [EXIT_OK, LANDED, false, true, true], laneOnly.text.slice(-700)); + t('⭐ FLIPPED by ruling D (was: "from the pull and the card thread alone"): the gate reads the pull, its file list and the head\'s check runs — ⛔ no card thread, no commit, nothing an agent typed', [opsOf(laneOnly), laneOnly.fake.calls.filter((c) => /\/issues\/8\//u.test(c.path)).length], [['card-read', 'pull-read', 'pull-files-list', 'check-runs-list', 'card-read', 'comments-list', 'pull-read'], 0]); + t('…the check runs are asked by name, on the head sha, with every attempt listed (`filter=all`)', laneOnly.fake.calls.find((c) => c.op === 'check-runs-list')?.path, `/repos/objectstack-ai/objectstack/commits/${HEAD}/check-runs?check_name=Dogfood%20battery%20(opt-in)&filter=all&per_page=100&page=1`); + const noCard = await land(pull({ body: 'A body naming nothing.\n\nClause-②: no\n', ref: 'feature/x' })); + t('FLIPPED by ruling D (was FAIL CLOSED: "NO CARD — no closing keyword, no `Part of`, no dev branch"): the door reads no card, so a marked pull naming none lands on the lane\'s success', [noCard.exit, noCard.text.includes('② dogfood gate ✓')], [EXIT_OK, true], noCard.text.slice(-500)); + const fold = await land(pull({ body: 'Fixes #8\nFixes #9\n\nClause-②: no\nMetadata-protocol: none\n' })); + t('FLIPPED by ruling D (was: a fold\'s tie read on every tied card): a `!` fold with two `Fixes` lines is judged on its ONE head like any pull — no thread of either card is read', [fold.exit, fold.fake.calls.filter((c) => /\/issues\/[89]\//u.test(c.path)).length], [EXIT_OK, 0], fold.text.slice(-500)); + + // ⭐ Seat order 1: a success ON THE HEAD, any such run, never the newest of the name. + const skippedThenSuccess = await land(pull({ runs: { [HEAD]: [SKIPPED(1), SKIPPED(2), SUCCESS] } })); + const successThenSkipped = await land(pull({ runs: { [HEAD]: [SUCCESS, SKIPPED(1), SKIPPED(2)] } })); + t('⭐ PASSES: skipped, skipped, then success on ONE sha — unrelated label events published the skips; the success is the proof, wherever it sits in the listing', [skippedThenSuccess.exit, successThenSkipped.exit, skippedThenSuccess.text.includes('3 run(s) of that name on the head: skipped ×2, success ×1'), successThenSkipped.sent[0]?.actions.map((a) => a.op)], [EXIT_OK, EXIT_OK, true, LANDED], skippedThenSuccess.text.slice(-600)); + const olderSha = await land(pull({ runs: { [BELOW]: [SUCCESS, run('success', { id: 9002, sha: BELOW })] }, commits: { [HEAD]: [BELOW] } })); + t('⭐ REFUSED: a success only on an OLDER sha — the head carries none, and the check runs of another commit are never read', [...refused(olderSha), olderSha.text.includes('why: no check run named'), olderSha.text.includes(CLEAR), olderSha.fake.calls.filter((c) => c.op === 'check-runs-list').map((c) => c.path.includes(`/commits/${HEAD}/`))], [...REFUSED, true, true, [true]], olderSha.text.slice(-600)); + const mergedMain = await land(pull({ runs: { [BELOW]: [run('success', { sha: BELOW })] }, commits: { [HEAD]: [BELOW, MAIN_SIDE] } })); + t('⭐ FLIPPED by ruling D (was PASSES: "a `!` title whose battery ran one merge of main below the head"): a success one merge of main BELOW the head now REFUSES — the lane proves a head, and a push owes a new run; no commit is walked', [...refused(mergedMain), opsOf(mergedMain).includes('commit-read')], [...REFUSED, false], mergedMain.text.slice(-600)); + const onlySkipped = await land(pull({ runs: { [HEAD]: [SKIPPED(1), SKIPPED(2)] } })); + t('⭐ REFUSED: only `skipped` runs on the head (the label was never on it) — the refusal counts them and says to add the label and wait', [...refused(onlySkipped), onlySkipped.text.includes(`none of the 2 check run(s) named \`${DOGFOOD_LANE_CHECK}\` on head \`${HEAD}\` concluded \`success\` (skipped ×2)`), onlySkipped.text.includes(CLEAR)], [...REFUSED, true, true], onlySkipped.text.slice(-600)); + for (const [name, rows, tally] of [['a FAILED run', [run('failure')], 'failure ×1'], ['a CANCELLED run (a newer push superseded it)', [run('cancelled')], 'cancelled ×1'], ['a run still IN PROGRESS', [run(null, { status: 'in_progress' })], 'in_progress ×1'], ['a failure NEWER than a skip', [run('failure'), SKIPPED(1)], 'failure ×1, skipped ×1']]) { + const r = await land(pull({ runs: { [HEAD]: rows } })); + t(`⛔ REFUSED: ${name} on the head is not a proof — exit 2, zero sends, its tally printed`, [...refused(r), r.text.includes(`(${tally})`)], [...REFUSED, true], r.text.slice(-500)); + } + const rerun = await land(pull({ runs: { [HEAD]: [run('failure', { id: 9003 }), SUCCESS] } })); + t('…while a failed attempt beside a success on the same head passes: any success on the head is the proof (a re-run of the red shards)', [rerun.exit, rerun.text.includes('failure ×1, success ×1')], [EXIT_OK, true], rerun.text.slice(-500)); + const narrowLane = await land(pull({ title: 'fix(pm): narrowing fixture', body: 'Fixes #8\n\nClause-②: no (narrowing)\nMetadata-protocol: narrowed\n' })); + const narrowNone = await land(pull({ title: 'fix(pm): narrowing fixture', body: 'Fixes #8\n\nClause-②: no (narrowing)\nMetadata-protocol: narrowed\n', runs: {} })); + t('a `(narrowing)` arm is judged the same way, both ways: a lane success on the head lands it, none refuses it and names the arm', [narrowLane.exit, ...refused(narrowNone), narrowNone.text.includes('`(narrowing)` arm')], [EXIT_OK, ...REFUSED, true], narrowNone.text.slice(-600)); + + // ⭐ Seat order 2: a pull may not certify itself with a lane it edits. + const selfCert = await land(pull({ files: [{ filename: 'scripts/pm/fixture.mjs', status: 'modified' }, LANE_FILE] })); + t('⭐ REFUSED: a marked pull whose file list changes the lane\'s workflow, EVEN WITH a success on its head — exit 2, zero sends; the refusal names the file and says the lane change lands on its own', [...refused(selfCert), selfCert.text.includes(`why: this pull changes \`${DOGFOOD_LANE_WORKFLOW}\` (modified: \`${DOGFOOD_LANE_WORKFLOW}\`)`), selfCert.text.includes('a pull may not certify itself with a lane it edits'), selfCert.text.includes(`to clear: land the change to \`${DOGFOOD_LANE_WORKFLOW}\` on its own`)], [...REFUSED, true, true, true], selfCert.text.slice(-800)); + t('…and it is refused BEFORE the check runs are read: a run of its own edit is not asked for', opsOf(selfCert), ['card-read', 'pull-read', 'pull-files-list']); + const renamedAway = await land(pull({ files: [{ filename: '.github/workflows/renamed.yml', previous_filename: DOGFOOD_LANE_WORKFLOW, status: 'renamed' }] })); + const added = await land(pull({ files: [{ filename: DOGFOOD_LANE_WORKFLOW, status: 'added' }] })); + const removed = await land(pull({ files: [{ filename: DOGFOOD_LANE_WORKFLOW, status: 'removed' }] })); + t('⛔ …renaming the workflow away, adding it and removing it are changes too, each named by its status', [renamedAway, added, removed].map((r) => [r.exit, r.sent.length]).concat([[renamedAway.text.includes('renamed: `.github/workflows/renamed.yml`'), added.text.includes(`added: \`${DOGFOOD_LANE_WORKFLOW}\``), removed.text.includes(`removed: \`${DOGFOOD_LANE_WORKFLOW}\``)]]), [[EXIT_USAGE, 0], [EXIT_USAGE, 0], [EXIT_USAGE, 0], [true, true, true]], renamedAway.text.slice(-500)); + const pageTwo = await land(pull({ files: [...Array.from({ length: 120 }, (_, i) => ({ filename: `packages/x/src/f${i}.ts`, status: 'modified' })), LANE_FILE] })); + t('⭐ …the lane\'s workflow on the SECOND page of a long file list is still seen: two pages read, refused', [...refused(pageTwo), pageTwo.fake.calls.filter((c) => c.op === 'pull-files-list').length, pageTwo.text.includes('a pull may not certify itself')], [...REFUSED, 2, true], pageTwo.text.slice(-500)); + const otherWorkflow = await land(pull({ files: [{ filename: '.github/workflows/ci.yml', status: 'modified' }] })); + t('…a marked pull editing ANOTHER workflow is not self-certifying: it lands on the lane\'s success (its tier is the queue guard\'s question, not this gate\'s)', otherWorkflow.exit, EXIT_OK, otherWorkflow.text.slice(-500)); + const laneOwnPull = await land(pull({ title: 'ci: a lane fixture', files: [LANE_FILE], runs: {} })); + t('⭐ NOT JUDGED: an UNMARKED pull that edits the lane is the "lands on its own" pull — no gate read at all, so the lane can still be changed', [laneOwnPull.exit, laneOwnPull.text.includes('not judged'), opsOf(laneOwnPull)], [EXIT_OK, true, ['card-read', 'card-read', 'comments-list', 'pull-read']], laneOwnPull.text.slice(-500)); + + // Not judged: no marker, or a repository with no battery. + const plain = await land(pull({ title: 'fix(pm): an ordinary fixture', runs: {} })); + t('⭐ NOT JUDGED: no `!` and no `(narrowing)` arm lands as before — with no lane check anywhere — and no gate read at all', [plain.exit, plain.text.includes('not judged'), opsOf(plain)], [EXIT_OK, true, ['card-read', 'card-read', 'comments-list', 'pull-read']]); + const widening = await land(pull({ title: 'feat(pm): a widening fixture', body: 'Fixes #8\n\nClause-②: yes (widening)\n', runs: {} })); t('…a `(widening)` arm is not a marker either', [widening.exit, widening.text.includes('not judged')], [EXIT_OK, true]); - - // The battery repositories: a pull in a repository with no dogfood battery is not judged; objectstack stays fail-closed. + const absent = await land(pull({ title: 'fix(pm): no declaration', body: 'Fixes #8\n\nNo declaration line at all.\n', runs: {} })); + t('an ABSENT `Clause-②:` line on an unmarked title is not judged — as Check Changeset reads it', [absent.exit, absent.text.includes('not judged')], [EXIT_OK, true]); t('the battery repositories: objectstack (any case) carries one; cloud, hotcrm and gallery do not; a value that is no `owner/name` is judged — fail-closed', ['objectstack-ai/objectstack', ' ObjectStack-AI/ObjectStack ', 'objectstack-ai/cloud', 'objectstack-ai/hotcrm', 'objectstack-ai/gallery', '', null, undefined, 'objectstack', 'a/b/c', 'a /b'].map(repoCarriesDogfoodBattery), [true, true, false, false, false, true, true, true, true, true, true]); const gateCalls = []; const cloudGate = await landDogfoodGate({ repo: 'objectstack-ai/cloud', issue: 7, card: { title: 'fix(svc)!: x', body: 'Clause-②: no (narrowing)' }, doCall: async (...a) => { gateCalls.push(a); return { verdict: 'failed', status: 500, call: a[0] }; } }); t('⭐ the gate on a cloud pull carrying both markers: not judged, `noBattery`, and ZERO reads', [cloudGate, gateCalls.length], [{ judged: false, noBattery: true }, 0]); - const NARROW_NA = { title: 'fix(service-cloud): a narrowing fixture', body: 'Fixes #8\n\nClause-②: no (narrowing)\nMetadata-protocol: none\n', cards: { 8: [report(NA)] } }; + const NARROW = { title: 'fix(service-cloud): a narrowing fixture', body: 'Fixes #8\n\nClause-②: no (narrowing)\nMetadata-protocol: none\n', runs: {} }; const cloudArgv = ['--repo', 'objectstack-ai/cloud', ...landArgv.slice(2)]; - const CLOUD_NA = { ...NARROW_NA, cards: { 8: [report(NA, { pr: 'https://github.com/objectstack-ai/cloud/pull/7' })] } }; - const cloud = await driveOffline(cloudArgv, pull(CLOUD_NA), { route, relay: 'success', files, now: NOW }); - t('⭐ NOT JUDGED: a cloud pull with a `(narrowing)` arm over an `n/a` report lands — ONE dispatch, comment → pr_ready → automerge_enable, exit 0, no gate read, and the ✓ line names the repository', - [cloud.exit, cloud.sent[0]?.actions.map((a) => a.op), cloud.fake.board.draft, cloud.text.includes('② dogfood gate ✓ — not judged: objectstack-ai/cloud has no dogfood battery (only objectstack-ai/objectstack carries one)'), cloud.text.includes('REFUSED'), cloud.fake.calls.map((c) => c.op)], - [EXIT_OK, ['comment', 'pr_ready', 'automerge_enable'], false, true, false, ['card-read', 'card-read', 'comments-list', 'pull-read']], cloud.text.slice(-700)); - const cloudBang = await driveOffline(cloudArgv, pull({ ...CLOUD_NA, title: 'fix(service-cloud)!: a breaking fixture' }), { route, relay: 'success', files, now: NOW }); + const cloud = await driveOffline(cloudArgv, pull(NARROW), { route, relay: 'success', files, now: NOW }); + t('⭐ NOT JUDGED: a cloud pull with a `(narrowing)` arm and no lane check lands — ONE dispatch, comment → pr_ready → automerge_enable, exit 0, no gate read, and the ✓ line names the repository', + [cloud.exit, cloud.sent[0]?.actions.map((a) => a.op), cloud.fake.board.draft, cloud.text.includes('② dogfood gate ✓ — not judged: objectstack-ai/cloud has no dogfood battery (only objectstack-ai/objectstack carries one)'), cloud.text.includes('REFUSED'), opsOf(cloud)], + [EXIT_OK, LANDED, false, true, false, ['card-read', 'card-read', 'comments-list', 'pull-read']], cloud.text.slice(-700)); + const cloudBang = await driveOffline(cloudArgv, pull({ ...NARROW, title: 'fix(service-cloud)!: a breaking fixture' }), { route, relay: 'success', files, now: NOW }); t('…and a cloud `!` title with the same arm lands the same way', [cloudBang.exit, cloudBang.text.includes('not judged: objectstack-ai/cloud has no dogfood battery')], [EXIT_OK, true], cloudBang.text.slice(-600)); - const osNarrow = await land(pull(NARROW_NA)); - t('⭐ REFUSED: the SAME `(narrowing)` pull over an `n/a` report in objectstack still refuses — exit 2, zero sends, nothing written', [...refused(osNarrow), osNarrow.text.includes('why: the battery was not run'), osNarrow.text.includes('has no dogfood battery')], [...REFUSED, true, false], osNarrow.text.slice(-600)); + const osNarrow = await land(pull(NARROW)); + t('⭐ REFUSED: the SAME `(narrowing)` pull with no lane check in objectstack still refuses — exit 2, zero sends, nothing written', [...refused(osNarrow), osNarrow.text.includes('why: no check run named'), osNarrow.text.includes('has no dogfood battery')], [...REFUSED, true, false], osNarrow.text.slice(-600)); // FAIL CLOSED — every case NOT MEASURED is a refusal. // Each case: its board, and the fragment of the `why` only its own branch prints — so a branch ablated away - // cannot hide behind a later refusal that happens to fire too. + // cannot hide behind a later refusal that happens to fire too. Every board here CARRIES a success on its head, + // so none of these refusals is the missing-proof one. + const full = (n, make) => Array.from({ length: n }, (_, i) => make(i)); const cases = { 'an UNREADABLE title': [pull({ title: '' }), 'its title did not read'], 'a MALFORMED `Clause-②:` line on an unmarked title': [pull({ title: 'fix: x', body: 'Fixes #8\n\nClause-②: maybe\n' }), 'reads malformed'], @@ -3965,114 +3832,52 @@ export async function selfTest() { 'an INLINE-KEY `Clause-②:` near miss on an unmarked title': [pull({ title: 'fix: x', body: 'Fixes #8\n\nThe claim says Clause-②: no (narrowing) here.\n' }), 'reads as a near miss (inline-key)'], 'a pull that does not read': [{ ...pull(), hooks: { 'pull-read': [{ status: 404 }] } }, 'the pull did not read', EXIT_PREREQUISITE], 'a pull read with no full head sha': [pull({ head: 'abc' }), 'no full head sha'], - 'NO CARD — no closing keyword, no `Part of`, no dev branch': [pull({ body: 'A body naming nothing.\n', ref: 'feature/x' }), 'why: no card'], - 'a card thread that does not read': [pull({ cards: {} }), "card #8's thread did not read", EXIT_PREREQUISITE], - 'a card thread page that answers no list': [{ ...pull(), hooks: { 'comments-list': [{ status: 200, json: { message: 'not a list' } }] } }, 'answered no list on page 1'], - 'a RATE-LIMITED card thread read': [{ ...pull(), hooks: { 'comments-list': [{ status: 403, rateRemaining: 0, json: { message: 'API rate limit exceeded' } }] } }, 'ratelimit) — NOT MEASURED', EXIT_PREREQUISITE], - 'NO REPORT on the card': [pull({ cards: { 8: [{ id: 9, created_at: '2026-11-08T14:00:00Z', user: { login: FLEET }, body: 'Claim: PM loop round 1' }] } }), 'carries no `os-dev-report` by'], - 'an UNPARSABLE report': [pull({ cards: { 8: [report(null, { raw: `${SIG}\nos-dev-report\n\n\`\`\`json\n{ "dogfood_battery": \n\`\`\`\n` })] } }), 'no readable `dogfood_battery`'], - 'a report with no `dogfood_battery`': [pull({ cards: { 8: [report(null, { raw: `${SIG}\nos-dev-report\n\n\`\`\`json\n{"issue": 8, "status": "done"}\n\`\`\`\n` })] } }), 'no readable `dogfood_battery`'], - 'a battery naming NO sha': [pull({ cards: { 8: [report('ran the battery · VERDICT command-exit 0')] } }), 'names no sha it ran on'], - 'a TRUNCATED listing': [pull({ cards: { 8: [...Array.from({ length: LAND_COMMENT_PAGE_CAP * 100 }, (_, i) => ({ id: 1000 + i, created_at: '2026-11-08T10:00:00Z', user: { login: FLEET }, body: 'note' }))] } }), 'TRUNCATED listing'], - 'a walk commit that does not read': [pull({ cards: { 8: [report(RAN_BELOW)] } }), 'on the walk to the battery', EXIT_PREREQUISITE], - 'a compare that does not read': [pull({ cards: { 8: [report(RAN_BELOW)] }, commits: { [HEAD]: [BELOW, MAIN_SIDE] }, onBase: [MAIN_SIDE] }), 'is on `main` did not read (GET', EXIT_PREREQUISITE], - 'a newest report naming ANOTHER pull, with none naming this one': [pull({ cards: { 8: [report(RAN_HEAD, { pr: 'https://github.com/objectstack-ai/objectstack/pull/9' })] } }), 'names another pull in `pr`'], - [`a battery more than ${LAND_MERGE_HOP_CAP} merges below the head`]: [ - pull({ - head: 'f'.repeat(40), - cards: { 8: [report(RAN_BELOW)] }, - commits: Object.fromEntries(Array.from({ length: LAND_MERGE_HOP_CAP + 1 }, (_, i) => [(i === 0 ? 'f'.repeat(40) : i.toString(16).padStart(2, '0').repeat(20)), [i === LAND_MERGE_HOP_CAP ? BELOW : (i + 1).toString(16).padStart(2, '0').repeat(20), MAIN_SIDE]])), - onBase: [MAIN_SIDE], - }), - `is not reached within ${LAND_MERGE_HOP_CAP} merges`, - ], + 'a pull read with no `changed_files` count': [pull({ changedFiles: false }), 'carries no `changed_files` count'], + 'a file list that does not read': [{ ...pull(), hooks: { 'pull-files-list': [{ status: 502 }] } }, "the pull's file list did not read", EXIT_PREREQUISITE], + 'a file list page that answers no list': [{ ...pull(), hooks: { 'pull-files-list': [{ status: 200, json: { message: 'not a list' } }] } }, "the pull's file list answered no list on page 1"], + 'a TRUNCATED file list (the pull declares more files than the listing holds)': [pull({ changedFiles: 3001 }), "the pull's file list read 1 of its 3001 changed file(s) — a TRUNCATED listing"], + 'check runs that do not read': [{ ...pull(), hooks: { 'check-runs-list': [{ status: 502 }] } }, `the check runs on head \`${HEAD}\` did not read`, EXIT_PREREQUISITE], + 'a RATE-LIMITED check-runs read': [{ ...pull(), hooks: { 'check-runs-list': [{ status: 403, rateRemaining: 0, json: { message: 'API rate limit exceeded' } }] } }, 'ratelimit) — NOT MEASURED', EXIT_PREREQUISITE], + 'a check-runs page that answers no list': [{ ...pull(), hooks: { 'check-runs-list': [{ status: 200, json: { message: 'not a list' } }] } }, 'answered no list on page 1'], + 'a TRUNCATED check-run listing with no success in what was read': [pull({ runs: { [HEAD]: [...full(DOGFOOD_LANE_CHECK_PAGE_CAP * 100, (i) => SKIPPED(i + 1)), SUCCESS] } }), `still full after ${DOGFOOD_LANE_CHECK_PAGE_CAP} pages of 100 (TRUNCATED)`], }; - cases['a compare that does not read'][0].hooks = { 'compare-read': [{ status: 404 }] }; for (const [name, [board, why, exit = EXIT_USAGE]] of Object.entries(cases)) { - const run = await land(board); - t(`⛔ FAIL CLOSED: ${name} refuses — exit ${exit} (${exit === EXIT_USAGE ? 'judged' : 'a read the platform did not answer'}), zero sends, nothing written, its own reason printed`, [...refused(run), run.text.includes(why)], [exit, 0, [], true, true], run.text.slice(-400)); + const r = await land(board); + t(`⛔ FAIL CLOSED: ${name} refuses — exit ${exit} (${exit === EXIT_USAGE ? 'judged' : 'a read the platform did not answer'}), zero sends, nothing written, its own reason printed`, [...refused(r), r.text.includes(why)], [exit, 0, [], true, true], r.text.slice(-500)); } - const atCap = cases[`a battery more than ${LAND_MERGE_HOP_CAP} merges below the head`][0]; - const oneShorter = await land({ ...atCap, commits: { ...atCap.commits, [(LAND_MERGE_HOP_CAP).toString(16).padStart(2, '0').repeat(20)]: undefined, [(LAND_MERGE_HOP_CAP - 1).toString(16).padStart(2, '0').repeat(20)]: [BELOW, MAIN_SIDE] } }); - t(`…while a battery exactly ${LAND_MERGE_HOP_CAP} merges below the head passes — the cap is the hop count, not one short of it`, [oneShorter.exit, oneShorter.text.includes(`ran ${LAND_MERGE_HOP_CAP} merge(s)`)], [EXIT_OK, true], oneShorter.text.slice(-400)); - const pageCount = (await land(cases['a TRUNCATED listing'][0])).fake.calls.filter((c) => c.op === 'comments-list').length; - const card404 = await land(cases['a card thread that does not read'][0]); - const cardLimited = await land(cases['a RATE-LIMITED card thread read'][0]); - t('…a card thread answering 404 also names the body\'s card as the thing to correct; a rate-limited read does not', [card404.text.includes('HTTP 404'), card404.text.includes('or correct the card this pull delivers (#8)'), cardLimited.text.includes('or correct the card this pull delivers')], [true, true, false], card404.text.slice(-400)); - t('…the truncated listing read exactly the page cap and stopped', pageCount, LAND_COMMENT_PAGE_CAP); - - // Whose report, and which one. - const foreign = await land(pull({ cards: { 8: [report(NA, { id: 600, at: '2026-11-08T13:00:00Z' }), report(RAN_HEAD, { id: 601, login: 'someone-else' })] } })); - t('⛔ a NEWER report by an untrusted account is data, never a reason to land: the newest TRUSTED report (n/a) decides', [...refused(foreign), foreign.text.includes('comment 600')], [...REFUSED, true]); - const onlyForeign = await land(pull({ cards: { 8: [report(RAN_HEAD, { login: 'someone-else' })] } })); - t('⛔ …and a thread whose only report is untrusted carries NO report', [...refused(onlyForeign), onlyForeign.text.includes('carries no `os-dev-report` by')], [...REFUSED, true]); - const newerNa = await land(pull({ cards: { 8: [report(RAN_HEAD, { id: 700, at: '2026-11-08T12:00:00Z' }), report(NA, { id: 701, at: '2026-11-08T13:00:00Z' })] } })); - const newerRan = await land(pull({ cards: { 8: [report(NA, { id: 700, at: '2026-11-08T12:00:00Z' }), report(RAN_HEAD, { id: 701, at: '2026-11-08T13:00:00Z' })] } })); - t('the NEWEST trusted report decides, both ways: a later `n/a` refuses over an earlier run, a later run passes over an earlier `n/a`', [newerNa.exit, newerNa.text.includes('comment 701'), newerRan.exit], [EXIT_USAGE, true, EXIT_OK]); - const sibling = await land(pull({ cards: { 8: [report(RAN_HEAD, { id: 800, at: '2026-11-08T12:00:00Z' }), report(NA, { id: 801, at: '2026-11-08T13:00:00Z', pr: 'https://github.com/objectstack-ai/objectstack/pull/9' })] } })); - t('sibling pulls on one card: a newer report whose `pr` names ANOTHER pull is passed over for the newest naming THIS pull', [sibling.exit, sibling.text.includes('report comment 800')], [EXIT_OK, true], sibling.text.slice(-400)); - const noPr = await land(pull({ cards: { 8: [report(RAN_HEAD, { id: 810, at: '2026-11-08T12:00:00Z', pr: 'https://github.com/objectstack-ai/objectstack/pull/9' }), report(NA, { id: 811, at: '2026-11-08T13:00:00Z', pr: null })] } })); - t('…while a newest report whose `pr` is null stays the newest — only a report naming another pull moves the gate', [noPr.exit, noPr.text.includes('comment 811')], [EXIT_USAGE, true]); - const nullFallback = await land(pull({ cards: { 8: [report(RAN_HEAD, { id: 820, at: '2026-11-08T12:00:00Z', pr: null }), report(NA, { id: 821, at: '2026-11-08T13:00:00Z', pr: 'https://github.com/objectstack-ai/objectstack/pull/9' })] } })); - t('⛔ …and in the sibling fallback a null-`pr` report is NOT this pull\'s: under a newest naming another pull, an older null-`pr` run on the head refuses', [...refused(nullFallback), nullFallback.text.includes('no trusted report names this one'), nullFallback.text.includes('comment 821')], [...REFUSED, true, true], nullFallback.text.slice(-400)); - t('the `pr` reading: this pull, another pull (number or repo), and null for no URL', [reportNamesPull(report(NA).body, { repo: 'objectstack-ai/objectstack', number: 7 }), reportNamesPull(report(NA, { pr: 'https://github.com/objectstack-ai/objectstack/pull/70' }).body, { repo: 'objectstack-ai/objectstack', number: 7 }), reportNamesPull(report(NA, { pr: 'https://github.com/objectstack-ai/cloud/pull/7' }).body, { repo: 'objectstack-ai/objectstack', number: 7 }), reportNamesPull(report(NA, { pr: null }).body, { repo: 'objectstack-ai/objectstack', number: 7 })], ['this', 'other', 'other', null]); - const absent = await land(pull({ title: 'fix(pm): no declaration', body: 'Fixes #8\n\nNo declaration line at all.\n', cards: {} })); - t('an ABSENT `Clause-②:` line on an unmarked title is not judged — as Check Changeset reads it', [absent.exit, absent.text.includes('not judged')], [EXIT_OK, true]); - const approver = await land(pull({ cards: { 8: [report(RAN_HEAD, { login: GOVERNED_APPROVERS[0] })] } })); - t('…a report written by a governed approver is trusted, as the record leg trusts it', approver.exit, EXIT_OK); + const capRun = await land(cases['a TRUNCATED check-run listing with no success in what was read'][0]); + t('…the truncated check-run listing read exactly the page cap and stopped', capRun.fake.calls.filter((c) => c.op === 'check-runs-list').length, DOGFOOD_LANE_CHECK_PAGE_CAP); + const secondPage = await land(pull({ runs: { [HEAD]: [...full(100, (i) => SKIPPED(i + 1)), SUCCESS] } })); + t('⭐ …while a success on the SECOND page, behind a hundred skipped runs, passes: the listing is read until a success or its end', [secondPage.exit, secondPage.fake.calls.filter((c) => c.op === 'check-runs-list').length, secondPage.text.includes('skipped ×100, success ×1')], [EXIT_OK, 2, true], secondPage.text.slice(-500)); + const firstPage = await land(pull({ runs: { [HEAD]: [SUCCESS, ...full(150, (i) => SKIPPED(i + 1))] } })); + t('…and a success on the first full page stops the read there: the later pages cannot take it back', [firstPage.exit, firstPage.fake.calls.filter((c) => c.op === 'check-runs-list').length], [EXIT_OK, 1]); + const unreadClear = await land(cases['check runs that do not read'][0]); + t('…a read the platform did not answer still names what clears a missing proof, so exit 3 is not a dead end', [unreadClear.exit, unreadClear.text.includes('② PREREQUISITE NOT MET'), unreadClear.text.includes(`add the label \`${DOGFOOD_LANE_LABEL}\``)], [EXIT_PREREQUISITE, true, true], unreadClear.text.slice(-500)); + const longTitle = await land(pull({ title: `fix(pm)!: ${'x'.repeat(400)}`, runs: {} })); + t('…a long title is quoted capped at quoteLine\'s cap, with its ellipsis', [longTitle.exit, longTitle.text.includes(`title: "fix(pm)!: ${'x'.repeat(LAND_TITLE_QUOTE_CAP - 10)}…"`), longTitle.text.includes('x'.repeat(LAND_TITLE_QUOTE_CAP))], [EXIT_USAGE, true, false]); + // ↔ the rules text names this gate where `--land` is taught, and the gate's rule path is still the file that holds the rule. const landingText = readFileSync(new URL('.claude/skills/pm-dispatch/references/landing-operations.md', REPO_ROOT), 'utf8'); const gateLine = landingText.split('\n').find((l) => l.includes('`--land`') && l.includes('`(narrowing)`')) ?? ''; - const ruleLine = readFileSync(new URL(LAND_DOGFOOD_RULE_PATH, REPO_ROOT), 'utf8').split('\n').find((l) => l.includes('dogfood') && l.includes('`!`') && l.includes('`(narrowing)`')) ?? ''; - t('↔ both ends name the same rule, one line each: landing-operations.md\'s `--land` line carries `!`, `(narrowing)`, dogfood and `os-dev.md`, and the gate\'s rule path (os-dev.md) has ONE line carrying dogfood, `!` and `(narrowing)` together', - [gateLine.includes('`!`'), gateLine.includes('dogfood'), gateLine.includes('`os-dev.md`'), LAND_DOGFOOD_RULE_PATH, ruleLine !== ''], - [true, true, true, '.claude/agents/os-dev.md', true], `rule line: ${JSON.stringify(ruleLine)}`); - - // A FOLD: one closing keyword per card, at equal strength. `deliveredCardNumber` reports the tie (no card), and - // the gate reads EVERY tied card's thread, judging over all of them -- never one picked by number order. - const FOLD = 'Fixes #8\nFixes #9\n\nClause-②: no\nMetadata-protocol: none\n'; - const threadsRead = (run) => run.fake.calls.filter((c) => c.op === 'comments-list').map((c) => Number(/\/issues\/(\d+)\/comments/u.exec(c.path)?.[1])); - const foldHead = await land(pull({ body: FOLD, cards: { 8: [report(RAN_HEAD)], 9: [] } })); - t('⭐ PASSES: a `!` fold whose body carries TWO `Fixes` lines and a dogfood report on the chain-head card — exit 0, ready and armed, both threads read', [foldHead.exit, foldHead.sent[0]?.actions.map((a) => a.op), threadsRead(foldHead).filter((n) => n !== 7), foldHead.text.includes('a tie of 2 cards (#8, #9), every thread read, cleared by card #8 comment 501')], [EXIT_OK, ['comment', 'pr_ready', 'automerge_enable'], [8, 9], true], foldHead.text.slice(-700)); - const foldReversed = await land(pull({ body: 'Fixes #9\nFixes #8\n\nClause-②: no\n', cards: { 8: [report(RAN_HEAD)], 9: [] } })); - t('…the verdict does not follow number or body order: the same fold with its lines swapped passes on the same card', [foldReversed.exit, foldReversed.text.includes('cleared by card #8 comment 501'), threadsRead(foldReversed).filter((n) => n !== 7)], [EXIT_OK, true, [9, 8]], foldReversed.text.slice(-500)); - const foldSecond = await land(pull({ body: FOLD, cards: { 8: [], 9: [report(RAN_HEAD, { id: 901 })] } })); - t('…and a report on the SECOND-named card clears it the same way', [foldSecond.exit, foldSecond.text.includes('cleared by card #9 comment 901')], [EXIT_OK, true], foldSecond.text.slice(-500)); - const foldPartOf = await land(pull({ body: 'Part of #8\nPart of #9\n\nClause-②: no\n', cards: { 8: [report(RAN_HEAD)], 9: [] } })); - t('…a tie of two `Part of` declarations is read the same way', foldPartOf.exit, EXIT_OK, foldPartOf.text.slice(-500)); - const foldNone = await land(pull({ body: FOLD, cards: { 8: [], 9: [] } })); - t('⭐ REFUSED: a fold on which NO delivered card carries a report — exit 2, zero sends, and the refusal names every tied card read and why each failed', [...refused(foldNone), ['it delivers 2 cards at the same strength (#8, #9, closing-keyword)', 'card #8: card #8 carries no `os-dev-report` by', 'card #9: card #9 carries no `os-dev-report` by', 'reports: card #8 none, dogfood_battery none; card #9 none'].map((w) => foldNone.text.includes(w))], [...REFUSED, [true, true, true, true]], foldNone.text.slice(-700)); - const foldNa = await land(pull({ body: FOLD, cards: { 8: [report(NA)], 9: [report(RAN_BELOW, { id: 902 })] }, commits: { [HEAD]: [BELOW] } })); - t('⛔ REFUSED: an `n/a` on one tied card and a battery the head does not reach on the other — each card\'s own reason, the walk\'s on the one it judged', [...refused(foldNa), ['card #8: the battery was not run (`n/a`)', 'card #9: commit `', 'lies after the battery\'s `bbbb', 'card #8 comment 501, dogfood_battery "n/a', 'card #9 comment 902'].map((w) => foldNa.text.includes(w))], [...REFUSED, [true, true, true, true, true]], foldNa.text.slice(-700)); - const foldMerged = await land(pull({ body: FOLD, cards: { 8: [report(NA)], 9: [report(RAN_BELOW, { id: 903 })] }, commits: { [HEAD]: [BELOW, MAIN_SIDE] }, onBase: [MAIN_SIDE] })); - t('…while a tied card whose battery ran one merge of main below the head passes, over an `n/a` on the other', [foldMerged.exit, foldMerged.text.includes('ran 1 merge(s) of the base below the head'), foldMerged.text.includes('cleared by card #9 comment 903')], [EXIT_OK, true, true], foldMerged.text.slice(-500)); - const foldBoth = await land(pull({ body: FOLD, cards: { 8: [report(RAN_BELOW)], 9: [report(RAN_BELOW, { id: 904 })] }, commits: { [HEAD]: [BELOW, STRAY] }, onBase: [MAIN_SIDE] })); - t('⛔ …and when the shared walk refuses, every judged card carries the walk\'s reason', [...refused(foldBoth), foldBoth.text.includes('card #8: merge `'), foldBoth.text.includes('card #9: merge `'), (foldBoth.text.match(/which `main` does not hold/gu) ?? []).length], [...REFUSED, true, true, 2], foldBoth.text.slice(-700)); - const foldLinear = await land(pull({ body: FOLD, cards: { 8: [report(RAN_BELOW)], 9: [report(`${STRAY} · VERDICT command-exit 0`, { id: 906 })] }, commits: { [HEAD]: [BELOW] } })); - t('…the walk names every battery it looked for, once each, when it stops on new code', [...refused(foldLinear), foldLinear.text.includes(`lies after the tied cards' batteries (\`${BELOW}\`, \`${STRAY}\`) and is not a merge`)], [...REFUSED, true], foldLinear.text.slice(-700)); - const foldUnread = await land(pull({ body: FOLD, cards: { 8: [report(RAN_HEAD)] } })); - t('⛔ FAIL CLOSED: a tied card whose thread does not read is NOT MEASURED — exit 3 and zero sends, even with the other card clearing', [foldUnread.exit, foldUnread.sent.length, writesOf(foldUnread), foldUnread.text.includes("card #9's thread did not read"), foldUnread.text.includes('reports: card #8 comment 501')], [EXIT_PREREQUISITE, 0, [], true, true], foldUnread.text.slice(-600)); - const foldNoList = await land({ ...pull({ body: FOLD, cards: { 8: [report(RAN_HEAD)], 9: [] } }), hooks: { 'comments-list': [{ status: 200, json: { message: 'not a list' } }] } }); - t('⛔ …and a tied card\'s thread answering no list refuses before the next card is read, saying none was read whole', [...refused(foldNoList), foldNoList.text.includes("card #8's thread answered no list on page 1"), foldNoList.text.includes('reports: none read')], [...REFUSED, true, true], foldNoList.text.slice(-500)); - const foldWalkUnread = await land(pull({ body: FOLD, cards: { 8: [report(RAN_BELOW)], 9: [report(NA, { id: 907 })] } })); - t('⛔ …and a walk commit that does not read on a tie is NOT MEASURED too, naming every tied card\'s report', [foldWalkUnread.exit, foldWalkUnread.sent.length, foldWalkUnread.text.includes('on the walk to the battery\'s `bbbb'), foldWalkUnread.text.includes('reports: card #8 comment 501'), foldWalkUnread.text.includes('card #9 comment 907')], [EXIT_PREREQUISITE, 0, true, true, true], foldWalkUnread.text.slice(-600)); - const foldSibling = await land(pull({ body: FOLD, cards: { 8: [report(RAN_HEAD, { pr: 'https://github.com/objectstack-ai/objectstack/pull/9' })], 9: [report(RAN_HEAD, { id: 905 })] } })); - t('the sibling-pull rule holds per tied card: a card whose newest report names another pull is passed over, the other card clears', [foldSibling.exit, foldSibling.text.includes('cleared by card #9 comment 905')], [EXIT_OK, true], foldSibling.text.slice(-500)); - const foldForeign = await land(pull({ body: FOLD, cards: { 8: [report(RAN_HEAD, { login: 'someone-else' })], 9: [] } })); - t('⛔ …and the trusted-author filter too: an untrusted report on a tied card is data, never a reason to land', [...refused(foldForeign), foldForeign.text.includes('card #8: card #8 carries no `os-dev-report` by')], [...REFUSED, true], foldForeign.text.slice(-500)); + const ruleText = readFileSync(new URL(LAND_DOGFOOD_RULE_PATH, REPO_ROOT), 'utf8'); + const ruleLine = ruleText.split('\n').find((l) => l.includes('dogfood') && l.includes('`!`') && l.includes('`(narrowing)`')) ?? ''; + const TYPED_KEY = ['dogfood', 'battery'].join('_'); + t('↔ both ends name the same rule, one line each: landing-operations.md\'s `--land` line carries `!`, `(narrowing)`, dogfood and the lane\'s label, and the gate\'s rule path (os-dev.md) has ONE line carrying dogfood, `!`, `(narrowing)` and that label together', + [gateLine.includes('`!`'), gateLine.includes('dogfood'), gateLine.includes(`\`${DOGFOOD_LANE_LABEL}\``), LAND_DOGFOOD_RULE_PATH, ruleLine.includes(`\`${DOGFOOD_LANE_LABEL}\``)], + [true, true, true, '.claude/agents/os-dev.md', true], `rule line: ${JSON.stringify(ruleLine)} · gate line: ${JSON.stringify(gateLine)}`); + t('⭐ FLIPPED by ruling D (was: the report template carries the typed key the door reads): os-dev.md carries the typed key NOWHERE — neither in its rules nor in its report template — and no `pnpm --filter @objectstack/dogfood test` order to a dev', + [ruleText.includes(TYPED_KEY), ruleText.includes('pnpm --filter @objectstack/dogfood test')], [false, false]); + t('↔ the label a refusal tells a seat to add is one `ensure-pm-labels.sh` creates', readFileSync(new URL('scripts/pm/ensure-pm-labels.sh', REPO_ROOT), 'utf8').includes(`gh label create ${DOGFOOD_LANE_LABEL} `), true); // Ordering and shape. - const early = await land(pull({ cards: { 8: [report(NA)] } })); + const early = await land(pull({ runs: {} })); t('the gate refuses BEFORE the comment is judged and before any send — the comment file is never even read', [early.exit, early.sent.length, early.text.includes('② comment —')], [EXIT_USAGE, 0, false]); const own = readFileSync(SELF_PATH, 'utf8'); const foldSource = own.slice(own.indexOf('async function foldStroke('), own.indexOf('export async function runRelease(')); const gateSource = own.slice(own.indexOf('export async function landDogfoodGate('), own.indexOf('export function landDogfoodRefusal(')); - t('structural: in the fold the gate runs before judgeBody; ⛔ no second report parser — the marker, the payload candidates, the newest-of and the card are the owners\' readers', - [foldSource.indexOf('landDogfoodGate(') > 0 && foldSource.indexOf('landDogfoodGate(') < foldSource.indexOf('judgeBody('), /latestMarkedComment\(kept, OS_DEV_REPORT_MARKER\)/u.test(gateSource), /deliveredCardNumber\(pull\.json\)/u.test(gateSource), /recordAuthorTrusted\(row, trusted\)/u.test(gateSource), /\bOS_DEV_REPORT_MARKER\s*=/u.test(own)], - [true, true, true, true, false]); - t('structural: a tie is read through the owner\'s tie relation, ⛔ never a second enumeration of the body, and nothing in the gate ranks cards by number', - [/deliveredCardsAtStrongest\(pull\.json\)/u.test(gateSource), /closingKeywordTargets|partOfTargets|deliveryEvidence\(/u.test(gateSource), /\.sort\(|Math\.(?:min|max)\(/u.test(gateSource)], - [true, false, false]); + t('structural: in the fold the gate runs before judgeBody, and it CALLS the lane\'s reader — ⛔ no report, comment thread or commit is read in the gate', + [foldSource.indexOf('landDogfoodGate(') > 0 && foldSource.indexOf('landDogfoodGate(') < foldSource.indexOf('judgeBody('), /readDogfoodLane\(\{ repo, issue, pull: pull\.json, doCall \}\)/u.test(gateSource), /comments-list|commit-read|os-dev-report|latestMarkedComment/u.test(gateSource)], + [true, true, false]); } // ── the real transport ─────────────────────────────────────────────────── diff --git a/scripts/pm/land-dogfood-lane.mjs b/scripts/pm/land-dogfood-lane.mjs new file mode 100644 index 00000000000..f3a15b5127f --- /dev/null +++ b/scripts/pm/land-dogfood-lane.mjs @@ -0,0 +1,157 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * land-dogfood-lane — what `label-write.mjs --land` reads to judge a breaking or narrowing pull: the conclusion of the + * opt-in dogfood lane on the pull's head, and whether the pull edits that lane. Nothing else lives here; the markers + * that put a pull under the gate, the gate's place in the fold and its refusal line stay in `label-write.mjs` + * (`landDogfoodGate`), which calls this file. It has no CLI: `node scripts/pm/label-write.mjs --self-test` drives every + * function below against its fake board. + * + * ## The contract it reads (maintainer ruling 7269391948, letter D, 「云端流水线代跑」) + * + * A breaking change, once labelled, has the real-app regression run by a CI runner, and the landing door reads that + * result. The runner is `.github/workflows/dogfood-optin.yml`, whose header is the authority on the lane; the three + * literals below are that header's "What the door reads" table, and a rename there is a rename here, in one pull: + * + * label `needs:dogfood-battery` — the owning seat hangs it by hand on the head it means to land. + * check `Dogfood battery (opt-in)` — the lane's aggregate job. `success` means all three shards ran on this head + * and each one attested that every step was green. + * + * ## Two questions, both fail-closed + * + * edits does the pull's own file list change the lane's workflow? A `pull_request` run takes its workflow from the + * pull's own merge commit, so a pull that edits the lane publishes whatever that edit says under the lane's + * name: it cannot certify itself. Asked FIRST, of every page of `GET /pulls/{n}/files`, by `filename` and + * by `previous_filename` (a rename away is a change). A listing shorter than the pull's own `changed_files` + * is TRUNCATED and refuses: a file the door has not seen is not known to be another file. + * success is there a COMPLETED check run of that name, by GitHub Actions, with conclusion `success`, on the head + * sha? ⛔ Never "what does the newest run say": every `pull_request` event starts a run, and a run whose + * label guard says no (an unrelated label added later) publishes the same name as `skipped` on the same + * head. Any success on the head is the proof; no success on it — none at all, only skipped, a failure, a + * cancelled run, one still in progress, a success on an OLDER head — is a refusal that says to add the + * label and wait. `filter=all` is asked for, so a re-run's earlier attempts are listed too. + * + * A read the platform did not answer (`doCall`'s verdict other than `ok`) comes back `unread: true`: the fold exits 3 + * on it (PREREQUISITE, NOT MEASURED), never 2. Every other miss is a judged refusal. + */ + +/** The label that starts the lane on a pull (the workflow's two-limb guard reads this literal). */ +export const DOGFOOD_LANE_LABEL = 'needs:dogfood-battery'; +/** The aggregate check run the door reads, by name, on the head sha. ⛔ Not a shard's name, and not the required `Dogfood Regression Gate`. */ +export const DOGFOOD_LANE_CHECK = 'Dogfood battery (opt-in)'; +/** The lane's workflow file: a pull whose file list changes it may not be certified by it. */ +export const DOGFOOD_LANE_WORKFLOW = '.github/workflows/dogfood-optin.yml'; +/** The app whose check runs are the lane's (measured on the lane's first labelled run: `app.slug`). */ +export const DOGFOOD_LANE_APP = 'github-actions'; +/** How many 100-row pages of check runs of that name the door reads on one head before it calls the listing TRUNCATED. */ +export const DOGFOOD_LANE_CHECK_PAGE_CAP = 10; +/** How many 100-row pages of the pull's files the door reads: GitHub lists at most 3000 files of a pull. */ +export const DOGFOOD_LANE_FILES_PAGE_CAP = 30; + +/** What clears a missing proof, as the refusal prints it. Pure. */ +export function dogfoodLaneClear(head) { + return `add the label \`${DOGFOOD_LANE_LABEL}\` to the pull, wait for the check run \`${DOGFOOD_LANE_CHECK}\` to conclude \`success\` on head ${head ? `\`${head}\`` : '(the pull\'s current head)'}, then land again`; +} + +/** + * The file-list question, over rows shaped as `GET /pulls/{n}/files` answers them: the rows that change the lane's + * workflow, by its current or its previous name. Pure. + * + * @returns {{ touched: boolean, rows: { filename: string, status: string|null }[] }} + */ +export function dogfoodLaneFilesVerdict(files) { + const rows = (Array.isArray(files) ? files : []) + .filter((f) => f?.filename === DOGFOOD_LANE_WORKFLOW || f?.previous_filename === DOGFOOD_LANE_WORKFLOW) + .map((f) => ({ filename: String(f.filename), status: typeof f.status === 'string' ? f.status : null })); + return { touched: rows.length > 0, rows }; +} + +/** + * The check-run question, over rows shaped as `GET /commits/{sha}/check-runs` answers them: the FIRST row that is the + * lane's own success on `head`, or none, with the conclusions of every row of that name on the head counted for the + * refusal. A row on another sha, under another name or by another app is not the lane's and is not counted. Pure. + * + * @returns {{ success: { id: number|null, url: string|null }|null, seen: number, tally: string }} + */ +export function dogfoodLaneCheckVerdict(runs, head) { + const sha = String(head ?? '').toLowerCase(); + const own = (Array.isArray(runs) ? runs : []).filter( + (r) => r?.name === DOGFOOD_LANE_CHECK && String(r?.head_sha ?? '').toLowerCase() === sha && r?.app?.slug === DOGFOOD_LANE_APP, + ); + const hit = own.find((r) => r.status === 'completed' && r.conclusion === 'success') ?? null; + const counts = new Map(); + for (const r of own) { + const word = r.status === 'completed' ? String(r.conclusion ?? 'no conclusion') : String(r.status ?? 'no status'); + counts.set(word, (counts.get(word) ?? 0) + 1); + } + return { + success: hit === null ? null : { id: typeof hit.id === 'number' ? hit.id : null, url: typeof hit.html_url === 'string' ? hit.html_url : null }, + seen: own.length, + tally: [...counts].map(([word, n]) => `${word} ×${n}`).join(', '), + }; +} + +/** + * Both questions, asked of the platform through the caller's `doCall` (`label-write.mjs`' counted, classified read). + * `pull` is the `GET /pulls/{n}` answer the caller already holds: its `head.sha` and `changed_files` are read, nothing + * is fetched twice. + * + * @returns {Promise<{ ok: true, head: string, check: { id: number|null, url: string|null }, seen: number, tally: string } | { ok: false, why: string, clear: string, head?: string, seen?: number, tally?: string, selfCertifying?: true, unread?: true }>} + */ +export async function readDogfoodLane({ repo, issue, pull, doCall }) { + const head = String(pull?.head?.sha ?? '').toLowerCase(); + if (!/^[0-9a-f]{40}$/u.test(head)) return { ok: false, why: 'the pull read carries no full head sha', clear: 'land again once the pull reads whole' }; + const unread = (what, r) => ({ ok: false, head, why: `${what} did not read (${r.call} -> HTTP ${r.status}, ${r.verdict}) — NOT MEASURED`, clear: `land again once it reads; a missing proof is cleared this way: ${dogfoodLaneClear(head)}`, unread: true }); + + // ── edits: the pull's own file list ────────────────────────────────────── + const declared = Number.isInteger(pull?.changed_files) ? pull.changed_files : null; + if (declared === null) return { ok: false, head, why: 'the pull read carries no `changed_files` count, so its file list cannot be known whole', clear: 'land again once the pull reads whole' }; + const files = []; + for (let page = 1; page <= DOGFOOD_LANE_FILES_PAGE_CAP; page += 1) { + const listed = await doCall('pull-files-list', `/repos/${repo}/pulls/${issue}/files?per_page=100&page=${page}`, {}); + if (listed.verdict !== 'ok') return unread('the pull\'s file list', listed); + if (!Array.isArray(listed.json)) return { ok: false, head, why: `the pull's file list answered no list on page ${page}`, clear: 'land again once the pull\'s files read' }; + files.push(...listed.json); + if (listed.json.length < 100) break; + } + const edits = dogfoodLaneFilesVerdict(files); + if (edits.touched) { + return { + ok: false, + head, + selfCertifying: true, + why: `this pull changes \`${DOGFOOD_LANE_WORKFLOW}\` (${edits.rows.map((r) => `${r.status ?? 'changed'}: \`${r.filename}\``).join(', ')}), the workflow that publishes \`${DOGFOOD_LANE_CHECK}\`, so a run on its head is a run of its own edit and proves nothing about the battery — a pull may not certify itself with a lane it edits`, + clear: `land the change to \`${DOGFOOD_LANE_WORKFLOW}\` on its own, in a pull that is neither breaking nor narrowing, then bring this pull's head up to it and ${dogfoodLaneClear(null)}`, + }; + } + if (files.length < declared) { + return { ok: false, head, why: `the pull's file list read ${files.length} of its ${declared} changed file(s) — a TRUNCATED listing, so whether it changes \`${DOGFOOD_LANE_WORKFLOW}\` is unknown`, clear: 'report it to the maintainer: this gate lands nothing whose file list it has not read whole' }; + } + + // ── success: a check run of the lane's name on the head ────────────────── + const runs = []; + let truncated = false; + for (let page = 1; ; page += 1) { + if (page > DOGFOOD_LANE_CHECK_PAGE_CAP) { + truncated = true; + break; + } + const listed = await doCall('check-runs-list', `/repos/${repo}/commits/${head}/check-runs?check_name=${encodeURIComponent(DOGFOOD_LANE_CHECK)}&filter=all&per_page=100&page=${page}`, {}); + if (listed.verdict !== 'ok') return unread(`the check runs on head \`${head}\``, listed); + if (!Array.isArray(listed.json?.check_runs)) return { ok: false, head, why: `the check runs on head \`${head}\` answered no list on page ${page}`, clear: 'land again once the check runs read' }; + runs.push(...listed.json.check_runs); + // Any success on the head is the proof: the later pages cannot take it back. + if (dogfoodLaneCheckVerdict(runs, head).success !== null || listed.json.check_runs.length < 100) break; + } + const verdict = dogfoodLaneCheckVerdict(runs, head); + if (verdict.success !== null) return { ok: true, head, check: verdict.success, seen: verdict.seen, tally: verdict.tally }; + const found = verdict.seen === 0 ? `no check run named \`${DOGFOOD_LANE_CHECK}\` by ${DOGFOOD_LANE_APP} is on head \`${head}\`` : `none of the ${verdict.seen} check run(s) named \`${DOGFOOD_LANE_CHECK}\` on head \`${head}\` concluded \`success\` (${verdict.tally})`; + return { + ok: false, + head, + seen: verdict.seen, + tally: verdict.tally, + why: `${found}${truncated ? `, and the listing is still full after ${DOGFOOD_LANE_CHECK_PAGE_CAP} pages of 100 (TRUNCATED)` : ''} — the battery is not proven on this head; a success on an older head, a skipped run and a run still in progress are not a proof`, + clear: dogfoodLaneClear(head), + }; +}