diff --git a/.claude/skills/pm-dispatch/references/landing-operations.md b/.claude/skills/pm-dispatch/references/landing-operations.md index 839aa336889..2b361ef0e85 100644 --- a/.claude/skills/pm-dispatch/references/landing-operations.md +++ b/.claude/skills/pm-dispatch/references/landing-operations.md @@ -10,7 +10,7 @@ - 声明肢 = 认领评论声明 `Clause-②: yes`,与路径无关;错误的 `no` 是可审计的假申报。 - 子代理起不来 ⇒ 复核缺席,PR 带 `needs:contract-review` 留 draft 队列外;旁路仅维护者逐次亲审 - PASS ⇒ Tier S ready、auto-merge;Tier H 经 SKILL.md ③ 交棒;FAIL ⇒ 撤挂,补丁轮;⛔ 免复核不放行。 -- 落地后才见欠复核 ⇒ 按 `contract-review.md` 复审落地 head、发现立新卡,⛔ 不修已关 PR。 +- 落地后见欠复核 ⇒ 按 `contract-review.md` 复审落地 head、发现照立卡门入卡,⛔ 不修已关 PR。 - DELIBERATE CORRECTION 红(`check-empty-changeset`)⛔ 不等维护者;确认件皆须点名每个被改 note: - diff 只改 release 文字或注释者:派发席 ACCEPT 确认,逐句引改前与改后,免第二次同 head 复核。 - 其余(含改代码)照全套:同 head 达档复核 PASS 记录即确认,记录逐句判改写句。 @@ -34,7 +34,11 @@ - (a) 它带着正把**他人** PR 踢出队列的签名之修复;(b) 它是他车道 PR/卡具名前置 (`Blocked-by`/串行行),该线经维护者或账户主人定为最高优先;(c) 账户主人点名要它插队。 - 送出前先在 PR 贴审计评论点名字母与依据;一笔一 PR,同仓同时至多一个插队者在队。 -- 中继另拒 draft、head 已移与 AGENTS.md §7 三类;读回非队首即 FAILED,⛔ 不重发,报维护者。 +- 中继另拒 draft、head 已移、受管面与发版 PR;读回非队首即 FAILED,⛔ 不重发,报维护者。 +- 逾 3,000 行须授权批准在现 head,或维护者非席位签名评论点名现 head 承接(`approval_comment`)。 +- 出队(中继 `pr_dequeue`)限三因:(a) 与基座冲突;(b) 自身改动致队列构建红,三事实判非 flake; + (c) PR 正文签名尾行之席以签名评论自请。审计评论在先,回读离队且仍开未合才落地。 +- 谁入队谁看护:冲突或自因被踢 ⇒ 一轮巡查内出队修复再入队;他人 flake 照四分支重投。 - PR 侧红(非队列)同在本窗口处置:义务与三步只住 `platform-readings.md`「红检查先读日志」。 - 挂 auto-merge/入队前读 K = `git rev-list --count --first-parent PRBASE..origin/main`。 - PRBASE = 末次绿 PR 跑 Test Core 所印 `Affected-set diff base`,⛔ 不取该跑起始时刻。 diff --git a/.claude/skills/pm-dispatch/references/lanes/queue.md b/.claude/skills/pm-dispatch/references/lanes/queue.md index 26626c0e295..a7bf5743fb0 100644 --- a/.claude/skills/pm-dispatch/references/lanes/queue.md +++ b/.claude/skills/pm-dispatch/references/lanes/queue.md @@ -17,13 +17,15 @@ - 例外:该 flake 在 `main` 上也红 ⇒ 照 main-red 约定①立 p0 锚卡, 敲分诊 `Request: main-red`、锚卡车道 `Notify: main-red`(project-forms.md 立锚卡者行)。 - flake 受害者(head 未变):照 landing-operations.md 四分支与三事实重投一次,同签名再弹即停。 -- 插队只用中继 `pr_enqueue_front`:ACCEPT 后、≤3,000 行、无受管面,照该文三因与一插队者规则。 +- 插队只用中继 `pr_enqueue_front`:ACCEPT 后、无受管面,照该文三因与一插队者规则。 +- 逾 3,000 行者另须授权批准在现 head,或维护者非席位签名评论点名现 head 承接。 - 插队前在 PR 留审计评论点名字母与依据;读回非队首即 FAILED,⛔ 不重发,报维护者。 +- 出队只用中继 `pr_dequeue`:落地席离线时本席代办 (a)(b);(c) 中继只认正文签名尾行之席。 +- 中继自贴审计评论并回读,仍在队或已合即 FAILED,⛔ 不重发,报维护者;落地席经订阅得知。 -## 归维护者(至中继出队操作落地) +## 归维护者 -- 出队:中继尚无此操作;冲突或自因被踢的 PR 由维护者移出,原因只写进该 PR 的审计评论。 -- 逾 3,000 行 PR 的插队与批准、受管面 PR、Version Packages 合并、队列配置与 App 权限。 +- 逾 3,000 行 PR 的批准、受管面 PR、Version Packages 合并、队列配置与 App 权限。 ## 边界 diff --git a/scripts/pm/check-skill-line-ratchet.mjs b/scripts/pm/check-skill-line-ratchet.mjs index 03981d91f5e..234556389ea 100644 --- a/scripts/pm/check-skill-line-ratchet.mjs +++ b/scripts/pm/check-skill-line-ratchet.mjs @@ -1270,7 +1270,15 @@ export const CEILINGS = new Map([ // on triage's five proposals; quoted in the body of card #33484, claim comment 6885221965). // The `Part of` close-out pair became three lines: the remainder's state for its lane, the three // legal states, and the comment plus the write door's refusal. Measured delta +1; headroom 0. - ['.claude/skills/pm-dispatch/references/landing-operations.md', 108], + // Raised 108 → 112 by the merge-queue stewardship card — an ORDINARY raise on the same destination, + // recorded under that entry's `ruledRaises` below, ⛔ not a second move. The text is the relay's two new + // queue doors and the landing seat's queue duty: the jump's over-3,000-line lift (an authorised approval + // on the head, or carried by the maintainer's comment), `pr_dequeue`'s three causes with its audit + // comment and read-back, and "who queued it watches it". The jump's former §7 line folded into its + // refusal line at zero lines. Ruling of record: the queue card (#33647, filing gate ③, maintainer-directed + // in the triage seat's session), maintainer verbatim and untranslated: 「建议有专人来跟进队列吗?这种操作不应该等我」; + // its items 1–3 order this text. Measured delta +4 (108 → 112); landed count, headroom 0. + ['.claude/skills/pm-dispatch/references/landing-operations.md', 112], // Release-aftercare duties — what a lane PM still owes AFTER a tagged release // rolls to production, which the landing window (ends at MERGED) never // covered: post-roll placement/latency reading with the waker-bias re-draw @@ -1817,7 +1825,16 @@ export const CEILINGS = new Map([ // first PR. A NEW file, so this is an added row and no other row moves; set // at the landed line count (headroom 0, same convention as every lane // charter above). - ['.claude/skills/pm-dispatch/references/lanes/queue.md', 30], + // Raised 30 → 32 by the same card's PR 2 (an ORDINARY ruled raise; no move + // touches this file). The text is the charter widened to the relay's two new + // queue doors: the jump's over-3,000-line lift (an authorised approval on the + // head, or carried by the maintainer's `approval_comment`) and `pr_dequeue`, + // which this seat may use for causes (a)(b) when the landing seat is offline, + // with the relay's own audit comment and read-back. The "maintainer removes + // it" interim section lost one line. Ruling of record: the queue card + // (#33647, filing gate ③), verbatim 「建议有专人来跟进队列吗?这种操作不应该等我」; + // its order names this widening. Measured delta +2; landed count, headroom 0. + ['.claude/skills/pm-dispatch/references/lanes/queue.md', 32], // repo:cloud lane charter: the cloud seats keep first-touch triage of the // cloud repo, run the first-touch sweep before they claim, set grade and // state when they file, and triage's daily reconciliation is the backstop; @@ -2515,6 +2532,15 @@ export const CROSS_FILE_MOVES = new Map([ date: '2026-11-09', delta: 5, }, + { + // Quoted beside this entry's ceiling above. Copied from there, not paraphrased. + ruling: + 'the relay queue doors and the landing seat\'s queue duty on `.claude/skills/pm-dispatch/references/landing-operations.md`' + + ' — the queue card (#33647, filing gate ③, maintainer-directed in the triage seat\'s session),' + + ' maintainer verbatim and untranslated: 「建议有专人来跟进队列吗?这种操作不应该等我」', + date: '2026-11-15', + delta: 4, + }, ], }, ], diff --git a/scripts/pm/fleet-write/execute.mjs b/scripts/pm/fleet-write/execute.mjs index 664cfbf6ec4..0bad3810e94 100644 --- a/scripts/pm/fleet-write/execute.mjs +++ b/scripts/pm/fleet-write/execute.mjs @@ -61,7 +61,8 @@ * token that request spends `actions: write` on reaches that path and the * failed-jobs re-run below, and no other (`ops.mjs`, `REFUSED_PATH_FAMILIES`). * A `run_rerun_failed` is fenced on the run and read back HERE (the section - * of that name below), and a `pr_enqueue_front` on the pull and its queue. + * of that name below), a `pr_enqueue_front` on the pull and its queue, and a + * `pr_dequeue` on the pull, its queue and its cause. * The FIRST failure stops the run — later actions are NOT attempted, and the * summary says which — because a seat that dispatched five related writes * must be able to read exactly where the board was left. A 404 on a directed @@ -184,6 +185,38 @@ * (the entry jumped, nothing ahead). Queued without the jump, or behind * another, is FAILED at once and says the pull IS queued — ⛔ never re-sent. * + * Over the human-merge line the `size` fence asks for the SIZE lift + * (`ops.mjs`, "The SIZE lift"): only then are the pull's reviews read, after + * the queue (`GET …/pulls/{n}/reviews`, one page at the endpoint's maximum, a + * full page read as unreadable) and reduced by the queue guard's + * `authorizedApprovalVerdict`; an approval that is not on the head reads the + * action's `approval_comment` by its own GET. Unread, unauthorised, elsewhere, + * carried by nobody or by a comment opening with a seat signature + * (`readSignatureLine`, passed in), the line holds and the mutation is NOT SENT. + * + * ## The dequeue — `pr_dequeue`, fenced on the PULL, its QUEUE and its CAUSE, audited, and read back + * + * One action, one function (`dequeueAction`): the fences (`DEQUEUE_FENCES` in + * `ops.mjs`) are AUTHORITATIVE here (`dequeuePreflight`), judged on the + * pull's own GET, its base's queue read with each entry's merge-group rollup + * (`DEQUEUE_QUEUE_READ_QUERY`, unpaced) and — for `seat-asks` alone — the + * landing seat its body's signed trailer names (`readPrBodyTrailer`; none + * named is a refusal, the comments unread) and then its comments, every page + * to a cap, a comment counting only when the relay wrote it and its first + * line is a signature naming that seat, its account and the dispatching + * session (`signedByLandingSeat`). A read or fence that fails writes NOTHING, + * exit 5, and so does a pull whose read carries no node id. Then the ONE + * audit comment, a paced POST, whose 201 with an id is required before + * anything else is sent; then the mutation on the node id that same pull + * read answered (no second read between the comment and the mutation); then + * the queue re-read every `DEQUEUE_POLL_MS` for up to `DEQUEUE_WINDOW_MS` + * until it no longer lists the pull, and the pull's own GET read open with + * `merged` false (`dequeuePullAfter`) twice, one `DEQUEUE_POLL_MS` apart. GraphQL errors are FAILED naming the + * grant when the platform says "not accessible by integration"; a pull that + * merged, or closed, inside the window is FAILED naming it; a read-back that + * still lists the pull after the window is FAILED, UNCONFIRMED. Every failure after the comment names the + * comment, which stands: the run's row is the outcome it points to. + * * ## The hierarchy link — `sub_issue_add` / `sub_issue_remove`, fenced on the CARDS and read back * * The fences on the two cards (`SUB_ISSUE_FENCES` in `ops.mjs`: parent, @@ -540,6 +573,7 @@ import { GOVERNED_TIER_H, GOVERNED_TIER_S, governedPathsIn, + HUMAN_MERGE_LINE_THRESHOLD, landingTierOf, LOW_RISK_ARM_RULING, pullCatalogReading, @@ -551,7 +585,8 @@ import { repoIdForSlug, slugFromRemote, } from '../check-governed-merges.mjs'; -import { GOVERNED_APPROVERS } from '../check-governed-queue-guard.mjs'; +import { authorizedApprovalVerdict, GOVERNED_APPROVERS, unreadableApproval } from '../check-governed-queue-guard.mjs'; +import { readSignatureLine } from '../check-half-states.mjs'; import { scrub } from '../fleet-token.mjs'; import { classifyHttp } from '../label-write.mjs'; import { announceBatch, EXIT_WRITE_PACE_REFUSED, fmtDuration, isWriteMethod, noteResponse, paceFilePath, paceWrite, releaseWriteLease, unrecordableText } from '../write-pace.mjs'; @@ -565,6 +600,7 @@ import { parseRelayAdvisoryNoteAnnotation, parseRelayAdvisoryReadAnnotation, parseRelayAnnotation, + readPrBodyTrailer, RELAY_ANNOTATION_PREFIX, relayAdvisoryAnnotationMessage, relayAdvisoryNoteAnnotationMessage, @@ -673,6 +709,18 @@ import { enqueueFrontFenceText, enqueueFrontLandedText, enqueueFrontReadBack, + enqueueFrontSizeLift, + ENQUEUE_FRONT_REVIEWS_PAGE_SIZE, + DEQUEUE_QUEUE_READ_QUERY, + RELAY_COMMENT_AUTHOR, + signedByLandingSeat, + dequeueAuditBody, + dequeueCauseReading, + dequeueFenceFailures, + dequeueFenceText, + dequeueLandedText, + dequeuePullAfter, + dequeueReadBack, mergeQueueOf, failedJobNames, governedReviewRequests, @@ -1226,9 +1274,9 @@ export const ENQUEUE_FRONT_WINDOW_MS = 30_000; export const ENQUEUE_FRONT_POLL_MS = 3_000; /** The base's merge queue, read by GraphQL query — unpaced (`read`). `{ queue }`, or `{ fail }` — the sentence. Never throws. */ -async function readMergeQueue(repo, branch, api, t) { +async function readMergeQueue(repo, branch, api, t, query = MERGE_QUEUE_READ_QUERY) { const [owner, name] = repo.split('/'); - const r = await rest(api, '/graphql', { method: 'POST', body: { query: MERGE_QUEUE_READ_QUERY, variables: { owner, name, branch } }, read: true }, t); + const r = await rest(api, '/graphql', { method: 'POST', body: { query, variables: { owner, name, branch } }, read: true }, t); const errors = Array.isArray(r.json?.errors) && r.json.errors.length ? `: GraphQL ${r.json.errors.map((e) => e?.message ?? 'error').join('; ')}` : ''; const queue = r.status === 200 && !errors ? mergeQueueOf(r.json) : null; if (!queue) return { fail: `POST /graphql mergeQueue(branch: ${branch}) -> HTTP ${r.status}${r.detail ? ` (${r.detail})` : ''}${errors}: the merge queue could not be read` }; @@ -1253,11 +1301,36 @@ export async function enqueueFrontPreflight(req, payload, api, t) { if (base === null) return { fail: `pull #${number}'s base ref could not be read, so its queue was not judged — nothing sent` }; const q = await readMergeQueue(payload.repo, base, api, t); if (q.fail) return { fail: `${q.fail}, so its fences were not judged — nothing sent` }; - const failures = enqueueFrontFenceFailures({ pull: p.json, expectedHeadSha, governed, queue: q.queue }); + // The SIZE lift (header): read only for a pull over the line — its reviews, and the carrying comment when named. + const lines = (p.json.additions ?? 0) + (p.json.deletions ?? 0); + const approval = Number.isInteger(p.json.additions) && Number.isInteger(p.json.deletions) && lines > HUMAN_MERGE_LINE_THRESHOLD ? await readSizeLift(req, payload, p.json, api, t) : null; + const failures = enqueueFrontFenceFailures({ pull: p.json, expectedHeadSha, governed, queue: q.queue, approval }); if (failures.length) return { fail: `REFUSED at the relay's fence on pull #${number}, nothing sent — ${enqueueFrontFenceText(failures)}` }; return { pull: p.json, base, queue: q.queue }; } +/** + * The jump's SIZE lift, read (header: "The front-of-queue enqueue"): the pull's reviews, one page at the endpoint's + * maximum — a full page is a truncated SUBSET, read as unreadable — reduced by the queue guard's + * `authorizedApprovalVerdict`, then the `approval_comment`'s own GET when the action names one and the approval is + * not on the head. Returns `enqueueFrontSizeLift`'s `{ lifts, way, reading }`. Never throws on a status. + */ +async function readSizeLift(req, payload, pull, api, t) { + const number = req.enqueueFront.pull; + const r = await rest(api, `/repos/${payload.repo}/pulls/${number}/reviews?per_page=${ENQUEUE_FRONT_REVIEWS_PAGE_SIZE}`, {}, t); + const verdict = + r.status !== 200 || !Array.isArray(r.json) + ? unreadableApproval(`GET …/pulls/${number}/reviews answered HTTP ${r.status}`) + : r.json.length >= ENQUEUE_FRONT_REVIEWS_PAGE_SIZE + ? unreadableApproval(`a full page of ${r.json.length} reviews is a truncated list`) + : authorizedApprovalVerdict(r.json, pull.head?.sha); + const headSha = pull.head?.sha ?? null; + const onHead = Array.isArray(verdict.approvals) && verdict.approvals.some((a) => typeof headSha === 'string' && a.commitId === headSha.toLowerCase()); + const id = req.enqueueFront.approvalComment; + const comment = !onHead && Number.isInteger(id) ? await rest(api, `/repos/${payload.repo}/issues/comments/${id}`, {}, t) : null; + return enqueueFrontSizeLift({ verdict, headSha, comment, pull: number, approvers: GOVERNED_APPROVERS, signatureOf: readSignatureLine }); +} + /** * Did the jump LAND? Judged by reading the queue back, never by the 200 (header): GraphQL errors are FAILED with * nothing changed; otherwise the queue is re-read until `enqueueFrontReadBack` settles. Returns `{ ok, why, result }`. @@ -1288,6 +1361,117 @@ export async function confirmEnqueueFront(req, answer, pre, payload, api, t, { s return { ok: false, why: `HTTP 200 accepted, but ${last} ${windowMs} ms later — UNCONFIRMED: read the queue before anything else, ⛔ do not re-send` }; } +/** The dequeue's read-back window and poll interval (header): the queue is re-read until the entry is gone. */ +export const DEQUEUE_WINDOW_MS = 30_000; +export const DEQUEUE_POLL_MS = 3_000; +/** The pull's comments the `seat-asks` cause walks, at the endpoint's page maximum, to a cap — past it is a SUBSET. */ +export const DEQUEUE_COMMENTS_PAGE_SIZE = 100; +export const DEQUEUE_COMMENTS_PAGE_CAP = 5; + +/** + * Did the pull's LANDING seat sign a fleet comment on it under the dispatching session? `true`, `false`, or + * `{ fail }` — the sentence — for a page that did not answer 200 with an array or a walk past the cap: an unread + * list is never `false`. A comment counts only when its author is the relay itself (`RELAY_COMMENT_AUTHOR`) and + * its first non-empty line is a seat signature naming `session` and `landing`'s seat and account + * (`signedByLandingSeat`). Never throws. + */ +async function landingSeatSignedOn(repo, pull, landing, session, api, t) { + for (let page = 1; page <= DEQUEUE_COMMENTS_PAGE_CAP; page++) { + const r = await rest(api, `/repos/${repo}/issues/${pull}/comments?per_page=${DEQUEUE_COMMENTS_PAGE_SIZE}&page=${page}`, {}, t); + if (r.status !== 200 || !Array.isArray(r.json)) return { fail: `GET /repos/${repo}/issues/${pull}/comments -> HTTP ${r.status}${r.detail ? ` (${r.detail})` : ''}: #${pull}'s comments could not be read` }; + if (r.json.some((c) => c?.user?.login === RELAY_COMMENT_AUTHOR && signedByLandingSeat(readSignatureLine(c?.body), landing, session))) return true; + if (r.json.length < DEQUEUE_COMMENTS_PAGE_SIZE) return false; + } + return { fail: `#${pull}'s comments ran past the ${DEQUEUE_COMMENTS_PAGE_CAP}-page cap without a comment signed by ${session} — a truncated list is a SUBSET, never read as unsigned` }; +} + +/** + * The dequeue's fences, AUTHORITATIVE (header: "The dequeue"): the pull's own GET, its base's queue with each + * entry's merge-group rollup and — for `seat-asks` alone — its comments, the last reads before anything is written, + * judged against `DEQUEUE_FENCES`. Returns `{ pull, base, ctx }` to proceed, or `{ fail }` — nothing written. + * Never throws on a status. + */ +export async function dequeuePreflight(req, payload, api, t) { + const { pull: number, expectedHeadSha, cause } = req.dequeue; + const p = await rest(api, `/repos/${payload.repo}/pulls/${number}`, {}, t); + if (p.status !== 200 || !p.json || typeof p.json !== 'object') return { fail: `${p.call} -> HTTP ${p.status}${p.detail ? ` (${p.detail})` : ''}: pull #${number} could not be read, so its fences were not judged — nothing written` }; + const base = typeof p.json.base?.ref === 'string' ? p.json.base.ref : null; + if (base === null) return { fail: `pull #${number}'s base ref could not be read, so its queue was not judged — nothing written` }; + const q = await readMergeQueue(payload.repo, base, api, t, DEQUEUE_QUEUE_READ_QUERY); + if (q.fail) return { fail: `${q.fail}, so its fences were not judged — nothing written` }; + let signed = null; + let landing = null; + if (cause === 'seat-asks') { + // The landing seat is the one the pull's own body names in its signed trailer; a body naming none is refused. + landing = readPrBodyTrailer(p.json.body)?.signature ?? null; + if (landing) { + const s = await landingSeatSignedOn(payload.repo, number, landing, payload.session, api, t); + if (s?.fail) return { fail: `${s.fail}, so the seat-asks cause was not judged — nothing written` }; + signed = s; + } + } + const ctx = { number, pull: p.json, expectedHeadSha, queue: q.queue, cause, session: payload.session, landing, signed }; + const failures = dequeueFenceFailures(ctx); + if (failures.length) return { fail: `REFUSED at the relay's fence on pull #${number}, nothing written — ${dequeueFenceText(failures)}` }; + return { pull: p.json, base, ctx }; +} + +/** + * ONE dequeue (header: "The dequeue"): the fences, then the ONE audit comment (paced; a comment that does not answer + * 201 with an id stops the action, the mutation NOT SENT), then the mutation behind the node id the preflight's own + * pull read answered, then the queue read back until the entry is gone and the pull's own GET reads it open and + * unmerged. Returns `{ ok, call, status, result | why }` for the row. Never throws on a status. + */ +export async function dequeueAction(req, { payload, api, t, sleep, now, windowMs = DEQUEUE_WINDOW_MS, pollMs = DEQUEUE_POLL_MS }) { + const { pull, reason, cause } = req.dequeue; + const mutation = 'POST /graphql dequeuePullRequest'; + const pre = await dequeuePreflight(req, payload, api, t); + if (pre.fail) return { ok: false, call: mutation, status: 'not sent', why: pre.fail }; + const nodeId = pre.pull.node_id; + if (typeof nodeId !== 'string' || nodeId === '') return { ok: false, call: mutation, status: 'not sent', why: `pull #${pull}'s node id did not read on its own GET, so the dequeue could not be addressed — nothing written` }; + const reading = dequeueCauseReading(pre.ctx); + const body = dequeueAuditBody({ session: payload.session, requestId: payload.request_id, number: pull, cause, reading, reason }); + const audit = await rest(api, `/repos/${payload.repo}/issues/${pull}/comments`, { method: 'POST', body: { body } }, t); + if (audit.status !== 201 || !Number.isInteger(audit.json?.id)) { + return { ok: false, call: audit.call, status: audit.status, why: `the audit comment did not land (HTTP ${audit.status}${audit.detail ? ` — ${audit.detail}` : ''}), so the dequeue was NOT SENT — a use with no audit comment never leaves` }; + } + const auditId = audit.json.id; + const r = await rest(api, '/graphql', { method: 'POST', body: { query: req.graphql.query, variables: { id: nodeId } } }, t); + if (r.status !== 200 || !r.json || typeof r.json !== 'object') return { ok: false, call: mutation, status: r.status, why: `HTTP ${r.status}${r.detail ? ` — ${r.detail}` : ''}; audit comment ${auditId} stands — read the queue before anything else` }; + if (Array.isArray(r.json.errors) && r.json.errors.length) { + const said = r.json.errors.map((e) => e?.message ?? 'error').join('; '); + const grant = /not accessible by integration/i.test(said) ? ' — the App token lacks the dequeue: the maintainer grants the objectstack-fleet App `Merge queues: write` (and accepts it on the installation)' : ''; + return { ok: false, call: mutation, status: r.status, why: `GraphQL: ${said}${grant}; nothing was dequeued by this answer, audit comment ${auditId} stands — read the queue before anything else` }; + } + const started = now(); + let last = 'nothing was read back'; + for (;;) { + const q = await readMergeQueue(payload.repo, pre.base, api, t, DEQUEUE_QUEUE_READ_QUERY); + if (q.fail) last = q.fail; + else { + const v = dequeueReadBack({ pull, queue: q.queue }); + if (!v.ok) last = v.why; + else { + // Out of the queue is half the landing: the pull's own GET must read it still open and unmerged, TWICE, one + // poll apart — the queue's removal and `merged` arrive seconds apart in either order (header). + const readPull = async () => dequeuePullAfter(await rest(api, `/repos/${payload.repo}/pulls/${pull}`, {}, t)); + const merged = (after) => ({ ok: false, call: mutation, status: r.status, why: `HTTP 200 accepted and the queue no longer lists #${pull}, but ${after.why}; audit comment ${auditId} stands — ⛔ do not re-send, read the pull and report to the maintainer` }); + let after = await readPull(); + if (after.ok) { + await sleep(pollMs); + after = await readPull(); + if (after.ok) return { ok: true, call: mutation, status: r.status, result: dequeueLandedText({ pull, total: q.queue.entries.length, auditId }) }; + } + if (!after.pending) return merged(after); + last = after.why; + } + } + if (now() - started >= windowMs) break; + await sleep(pollMs); + } + return { ok: false, call: mutation, status: r.status, why: `HTTP 200 accepted, but ${last} ${windowMs} ms later — UNCONFIRMED: a 200 is never trusted alone; read the queue before anything else, audit comment ${auditId} stands` }; +} + /** The hierarchy link's read-back window and poll interval (header): the parent's list is re-read until it settles. */ export const SUB_ISSUE_WINDOW_MS = 30_000; export const SUB_ISSUE_POLL_MS = 3_000; @@ -2068,6 +2252,7 @@ export async function executeFleetWrite({ payload: raw, sender, token, api = DEF const rr = { sleep: ub.sleep, now: ub.now, ...(deps.rerunFailed ?? {}) }; const si = { sleep: ub.sleep, now: ub.now, ...(deps.subIssue ?? {}) }; const ef = { sleep: ub.sleep, now: ub.now, ...(deps.enqueueFront ?? {}) }; + const dq = { sleep: ub.sleep, now: ub.now, ...(deps.dequeue ?? {}) }; const judged = validatePayload(raw); if (!judged.ok) { @@ -2142,6 +2327,18 @@ export async function executeFleetWrite({ payload: raw, sender, token, api = DEF break; } const req = filled.req; + // The dequeue (header): its fences, its ONE audit comment, the mutation and the queue read back — one action. + if (req.dequeue) { + const out = await dequeueAction(req, { payload, api, t, ...dq }); + rows.push({ action: i + 1, op: action.op, call: out.call, status: out.status, result: out.ok ? scrub(out.result, [token]) : `FAILED: ${scrub(out.why, [token])}` }); + if (!out.ok) { + stoppedAt = { action: i + 1, op: action.op, why: scrub(out.why, [token]) }; + log(` ✗ action ${i + 1} ${action.op}: ${out.call} -> ${stoppedAt.why}`); + break; + } + log(` ✓ action ${i + 1} ${action.op}: ${out.call} -> HTTP ${out.status} · ${rows[rows.length - 1].result}`); + continue; + } // The failed-jobs re-run and the mailbox branch delete (header): their fences, judged HERE on the reads before the write — refused, NOT SENT. const pre = req.rerunFailed ? await rerunFailedPreflight(req, payload, api, t) @@ -2358,6 +2555,12 @@ const SELF_TEST_BATTERIES = Object.freeze({ // 17 → 21 with the head fence: a stale head, the embedded copy never trusted, a run naming no pull, a pull unread. "the run_rerun_failed: the five fences judged HERE on the run and its pull, read immediately before ONE bodiless POST — the pull's current head by its own GET, never the run's embedded copy, and a run naming no pull refused by name; each refused with the POST not sent and accepted on the measured run; a run, pull, baseline or fence that fails is zero writes; the 201 confirmed only by reading attempt 2 back with its failed jobs queued or in progress, naming their job ids; attempt 2 never seen, a failed job completed, or a job list unread is FAILED; no annotation": 21, "the pr_enqueue_front: the pull's own GET, its whole file list and its base's queue read immediately before ONE enqueuePullRequest mutation with jump true and the expected head — open, ready, its head, not Version Packages, no governed path, at most the human-merge line count, a queue read whole with no jumped entry; each fence refused with the mutation not sent; GraphQL errors FAILED naming the missing grant; the 200 confirmed only by reading the queue back with the pull jumped and nothing ahead; queued without the jump or behind another is FAILED, never re-sent; the queue read unpaced; no annotation": 20, + // 9 → 12 with a carrying comment that opens with a seat signature refused, its other way, and no reader carrying nothing. + "the pr_enqueue_front SIZE lift: a pull over the human-merge line is jumped only on an authorised APPROVED review on its current head, or an earlier one carried to the head by an authorised comment on the pull naming it — the reviews read only over the line, a full page or an unread list lifting nothing, a non-approver, an approval elsewhere, a comment naming another head or pull or opening with a seat signature refused with the mutation not sent": 12, + // 16 → 27 with seat-asks bound to the landing seat (another seat, the relay's own audit, no trailer, the pure match), + // the pull read back open and unmerged (merged, closed, a late read, the pure reading) and the node id from the first read; + // 27 → 28 with the second pull read one interval later, a merge that shows only there refused. + "the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged on two reads one interval apart, a merge or close inside the window FAILED, UNCONFIRMED after the window": 28, "the hierarchy link: sub_issue_add and sub_issue_remove read the parent's and the child's own answers, then the child's parent (add) or the parent's whole list (remove), immediately before ONE write whose body is the child's REST id from its own answer — never its number, never replace_parent; a pull, a transferred or unread card, a child under another parent, one the parent does not list, or a read that is neither answer is zero writes; a child already under this parent is a no-op landed on the list; the answer confirmed only when the parent's list reads the child back (or no longer does) inside the window; a refused write, a list that never settles or never reads whole is FAILED; no annotation, and the rows ride a stroke beside other ops": 20, "the advisory rows: advisory_report and advisory_create are ONE POST of their body each, landed on a 2xx carrying an id — a draft's reading state draft — that the row and a notice annotation name; advisory_collaborators_add, advisory_versions and advisory_state read the advisory first and send ONE PATCH — every existing login kept with the missing ones added, an all-present list a no-op, the versions entries alone, or the one state a legal transition reaches, the reopen and the publish among them — or nothing at all on a fence: an unread, other or wrong-state advisory, an illegal move, a list the versions may not replace or a publish whose versions are not set; each lands only when its answer shows the result, a publish only read back as published with the versions it was sent, and a landed publish alone is annotated with its id; ⛔ the marker in a report's or a draft's summary, description and packages and in every advisory answer's summary, description and vulnerabilities reaches no log line, row, step summary or annotation": 41, "the mailbox branch delete: the pull's own answer, the open pulls on its head and the ref read immediately before ONE DELETE of the ref under the App token — an open, unlabelled, other-headed or forked pull, an open pull on that head, a ref moved off the pull's head, or a read that does not answer is zero writes with every failing fence named; the DELETE lands only when the ref reads back absent, a ref already gone an idempotent landing and one still there FAILED; and mailbox-open's close stroke — comment, close, delete — leaves no branch, while a head outside claude/mailbox-* sends no DELETE": 7, @@ -2369,8 +2572,9 @@ const SELF_TEST_BATTERIES = Object.freeze({ // Raised 17 → 18 with the governed-review follow-up battery, 18 → 19 with the run_rerun_failed battery, 19 → 20 with the // hierarchy link battery, 20 → 21 with the advisory rows' battery, 21 → 22 with advisory_read's, 22 → 23 with the mailbox // branch delete's, 23 → 24 with the private-repository issue body's, 24 → 25 with advisory_list's, 25 → 26 with -// pr_enqueue_front's, 26 → 27 with the cloud staging deploy's, 27 → 28 with advisory_note's: one battery, one row. -const SELF_TEST_BATTERY_FLOOR = 28; +// pr_enqueue_front's, 26 → 27 with the cloud staging deploy's, 27 → 28 with advisory_note's: one battery, one row; +// 28 → 30 with the jump's SIZE lift and pr_dequeue's. +const SELF_TEST_BATTERY_FLOOR = 30; const UNATTRIBUTED_BATTERY = '(unattributed)'; const batteryCases = new Map(); @@ -2581,10 +2785,10 @@ export async function selfTest() { const bare = { verb: 'POST', path: '/graphql', graphql: { mutation: 'enablePullRequestAutoMerge', query: 'q', pull: 21 } }; t('⛔ a pull mutation whose descriptor declares no landed state is never judged landed', requestLanded(bare, { status: 200, json: { data: { enablePullRequestAutoMerge: { pullRequest: { number: 21, autoMergeRequest: { mergeMethod: 'SQUASH' } } } } } }).ok, false); // The table half: every pull mutation the op table can issue carries its entry, and selects every field that entry reads. - const pullRows = Object.keys(OPS).flatMap((op) => OPS[op].requests({ op, pull: 21, issue: 21, comment_id: 1, target_repo: 'x', title: 't', body: 'b', head: 'h', base: 'main', labels: ['l'], assignees: ['u'], reviewers: ['r'], workflow: 'shard-timings-refresh.yml', ref: 'main', summary: 's', description: 'd', ghsa_id: 'GHSA-abcd-2345-wxyz', collaborators: ['u'], advisory_state: 'draft', packages: ['p'], versions: [{ package: 'p', vulnerable_version_range: '< 1.0.0', patched_versions: '1.0.0' }] }, REPO).filter((r) => r.graphql?.pull !== undefined && !r.enqueueFront).map((r) => [op, r.graphql])); + const pullRows = Object.keys(OPS).flatMap((op) => OPS[op].requests({ op, pull: 21, issue: 21, comment_id: 1, target_repo: 'x', title: 't', body: 'b', head: 'h', base: 'main', labels: ['l'], assignees: ['u'], reviewers: ['r'], workflow: 'shard-timings-refresh.yml', ref: 'main', summary: 's', description: 'd', ghsa_id: 'GHSA-abcd-2345-wxyz', collaborators: ['u'], advisory_state: 'draft', packages: ['p'], versions: [{ package: 'p', vulnerable_version_range: '< 1.0.0', patched_versions: '1.0.0' }] }, REPO).filter((r) => r.graphql?.pull !== undefined && !r.enqueueFront && !r.dequeue).map((r) => [op, r.graphql])); // The one pull mutation judged by reading its QUEUE back (header: "The front-of-queue enqueue"): no landed entry. - const queueRows = Object.keys(OPS).flatMap((op) => OPS[op].requests({ op, pull: 21, issue: 21, comment_id: 1, target_repo: 'x', title: 't', body: 'b', head: 'h', base: 'main', labels: ['l'], assignees: ['u'], reviewers: ['r'], workflow: 'shard-timings-refresh.yml', ref: 'main', summary: 's', description: 'd', ghsa_id: 'GHSA-abcd-2345-wxyz', collaborators: ['u'], advisory_state: 'draft', packages: ['p'], versions: [{ package: 'p', vulnerable_version_range: '< 1.0.0', patched_versions: '1.0.0' }], expected_head_sha: 'a'.repeat(40) }, REPO).filter((r) => r.enqueueFront).map((r) => [op, r.graphql.landed ?? null])); - t('…and the one pull mutation judged by its queue read back instead, pr_enqueue_front, carries no PR_LANDED_STATE entry', queueRows, [['pr_enqueue_front', null]]); + const queueRows = Object.keys(OPS).flatMap((op) => OPS[op].requests({ op, pull: 21, issue: 21, comment_id: 1, target_repo: 'x', title: 't', body: 'b', head: 'h', base: 'main', labels: ['l'], assignees: ['u'], reviewers: ['r'], workflow: 'shard-timings-refresh.yml', ref: 'main', summary: 's', description: 'd', ghsa_id: 'GHSA-abcd-2345-wxyz', collaborators: ['u'], advisory_state: 'draft', packages: ['p'], versions: [{ package: 'p', vulnerable_version_range: '< 1.0.0', patched_versions: '1.0.0' }], expected_head_sha: 'a'.repeat(40), cause: 'conflict', reason: 'r' }, REPO).filter((r) => r.enqueueFront || r.dequeue).map((r) => [op, r.graphql.landed ?? null])); + t('…and the two pull mutations judged by their queue read back instead, pr_enqueue_front and pr_dequeue, carry no PR_LANDED_STATE entry', queueRows, [['pr_enqueue_front', null], ['pr_dequeue', null]]); const selects = (query, field) => new RegExp(`\\b${field}\\b`).test(query.slice(query.indexOf('pullRequest {'))); t('every pull mutation in the op table carries its PR_LANDED_STATE entry, and its query selects every field that entry reads', [pullRows.map(([op]) => op).sort(), pullRows.every(([op, g]) => g.landed === PR_LANDED_STATE[op] && g.landed.fields.every((f) => selects(g.query, f)))], [Object.keys(PR_LANDED_STATE).sort(), true]); } @@ -3175,6 +3379,149 @@ export async function selfTest() { t('⛔ the validator is the executor\'s gate too: beside another action, or with a short head, refused with ZERO requests, exit 2', [[beside.exit, beside.seen.length], [short.exit, short.seen.length]], [[EXIT_REFUSED, 0], [EXIT_REFUSED, 0]]); } + // ── the jump's SIZE lift ──────────────────────────────────────────────── + battery("the pr_enqueue_front SIZE lift: a pull over the human-merge line is jumped only on an authorised APPROVED review on its current head, or an earlier one carried to the head by an authorised comment on the pull naming it — the reviews read only over the line, a full page or an unread list lifting nothing, a non-approver, an approval elsewhere, a comment naming another head or pull or opening with a seat signature refused with the mutation not sent"); + { + const PULL = 3227; + const HEAD = '7a1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c'; + const EARLIER = '1b2c3d4e5f60718293a4b5c6d7e8f9a0b1c2d3e4'; + const APPROVER = GOVERNED_APPROVERS[0]; + const PULL_GET = `GET /repos/${REPO}/pulls/${PULL}`; + const FILES = `GET /repos/${REPO}/pulls/${PULL}/files`; + const REVIEWS = `GET /repos/${REPO}/pulls/${PULL}/reviews`; + const COMMENT = `GET /repos/${REPO}/issues/comments/71`; + const GQL = 'POST /graphql'; + const big = { status: 200, json: { number: PULL, node_id: 'PR_kwDObig', state: 'open', draft: false, title: 'feat(ui): large', additions: 3300, deletions: 93, head: { sha: HEAD, ref: 'claude/issue-33181-x' }, base: { ref: 'main' } } }; + const entry = (number, position, jump = false) => ({ position, jump, state: 'AWAITING_CHECKS', pullRequest: { number } }); + const queueOf = (nodes) => ({ status: 200, json: { data: { repository: { mergeQueue: { entries: { totalCount: nodes.length, pageInfo: { hasNextPage: false }, nodes } } } } } }); + const enqueued = { status: 200, json: { data: { enqueuePullRequest: { mergeQueueEntry: entry(PULL, 1, true) } } } }; + const review = (login, commit, state = 'APPROVED') => ({ id: 1, state, commit_id: commit, user: { login } }); + const reviewsOf = (...list) => ({ status: 200, json: list }); + const commentOf = (patch = {}) => ({ status: 200, json: { id: 71, user: { login: APPROVER }, issue_url: `https://api.github.com/repos/${REPO}/issues/${PULL}`, body: `The approval carries to ${HEAD.slice(0, 9)}.`, ...patch } }); + const happy = { ...allowed, [PULL_GET]: big, [FILES]: { status: 200, json: [{ filename: 'ui/src/a.ts' }] }, [REVIEWS]: reviewsOf(review(APPROVER, HEAD)), [GQL]: [queueOf([entry(3730, 1)]), enqueued, queueOf([entry(PULL, 1, true), entry(3730, 2)])] }; + const stroke = (extra = {}) => base([{ op: 'pr_enqueue_front', pull: PULL, expected_head_sha: HEAD, ...extra }]); + let clock = 0; + const timing = { sleep: async (ms) => { clock += ms; }, now: () => clock }; + const sent = (seen) => seen.filter((x) => x.call === GQL && x.body?.query?.startsWith('mutation')).length; + const verdict = async (answers, extra) => { + const r = await run(stroke(extra), { ...happy, ...answers }, timing); + return [r.exit, sent(r.seen), r.rows[0]?.status]; + }; + const landed = [EXIT_OK, 1, 200]; + const refused = [EXIT_ACTION_FAILED, 0, 'not sent']; + const ok = await run(stroke(), happy, timing); + t('⭐ ON THE HEAD: an authorised APPROVED review whose commit is the current head lifts the line — the reviews read after the queue, the jump sent and read back', [ok.exit, ok.seen.map((x) => x.call)], [EXIT_OK, [PERM, PULL_GET, FILES, GQL, REVIEWS, PULL_GET, GQL, GQL]], ok.logs.join(' | ')); + t('⛔ an authorised approval on an EARLIER commit with no approval_comment lifts nothing — refused naming the missing carry', [await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)) }), (await run(stroke(), { ...happy, [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)) })).rows[0]?.result.includes('no `approval_comment` carries it')], [refused, true]); + t('⭐ CARRIED: an earlier authorised approval plus the approver\'s comment on this pull naming the head\'s prefix lifts it; the comment read by its own GET', [await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf() }, { approval_comment: 71 }), (await run(stroke({ approval_comment: 71 }), { ...happy, [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf() }, timing)).seen.some((x) => x.call === COMMENT)], [landed, true]); + t('⛔ CARRIED, refused: a comment by a non-approver, on another pull, naming another head or too short a prefix, or unreadable', [ + await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf({ user: { login: 'os-support-ai' } }) }, { approval_comment: 71 }), + await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf({ issue_url: `https://api.github.com/repos/${REPO}/issues/3228` }) }, { approval_comment: 71 }), + await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf({ body: `carries to ${EARLIER.slice(0, 9)}` }) }, { approval_comment: 71 }), + await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf({ body: `carries to ${HEAD.slice(0, 6)}` }) }, { approval_comment: 71 }), + await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: { status: 404, json: { message: 'Not Found' } } }, { approval_comment: 71 }), + ], [refused, refused, refused, refused, refused]); + const seatSigned = commentOf({ body: `triage#1 · ${APPROVER} · session_01ABCDEFGHJKMNPQRSTVWXYZ\n\nHead-sha: ${HEAD.slice(0, 9)}` }); + t('⛔ CARRIED, refused: the approver\'s comment naming the head but opening with a SEAT signature (an agent-operated account\'s knock or record) carries nothing, the reading naming the seat', [await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: seatSigned }, { approval_comment: 71 }), (await run(stroke({ approval_comment: 71 }), { ...happy, [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: seatSigned })).rows[0]?.result.includes('a seat\'s comment is no carried approval')], [refused, true]); + t('⭐ CARRIED, the other way: the same approver\'s comment with the signature line further down, not first, still carries it', [await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, EARLIER)), [COMMENT]: commentOf({ body: `The approval carries to ${HEAD.slice(0, 9)}.\n\ntriage#1 · ${APPROVER} · session_01ABCDEFGHJKMNPQRSTVWXYZ` }) }, { approval_comment: 71 })], [landed]); + const pastApproval = { state: 'approved', approvals: [{ login: APPROVER, commitId: EARLIER }] }; + t('enqueueFrontSizeLift with no signature reader carries nothing — the opening line unjudged is never a pass', [enqueueFrontSizeLift({ verdict: pastApproval, headSha: HEAD, comment: commentOf(), pull: PULL, approvers: GOVERNED_APPROVERS }).lifts, enqueueFrontSizeLift({ verdict: pastApproval, headSha: HEAD, comment: commentOf(), pull: PULL, approvers: GOVERNED_APPROVERS, signatureOf: () => null }).lifts], [false, true]); + t('⛔ an approval by an account outside GOVERNED_APPROVERS, or one the approver later dismissed, lifts nothing even on the head', [await verdict({ [REVIEWS]: reviewsOf(review('os-support-ai', HEAD)) }), await verdict({ [REVIEWS]: reviewsOf(review(APPROVER, HEAD), review(APPROVER, HEAD, 'DISMISSED')) })], [refused, refused]); + t('⛔ reviews unread, or a full page of them (a truncated list), lift nothing — never a pass', [await verdict({ [REVIEWS]: { status: 502, json: { message: 'Bad Gateway' } } }), await verdict({ [REVIEWS]: { status: 200, json: Array.from({ length: ENQUEUE_FRONT_REVIEWS_PAGE_SIZE }, () => review(APPROVER, HEAD)) } })], [refused, refused]); + const under = await run(stroke(), { ...happy, [PULL_GET]: { ...big, json: { ...big.json, additions: 2000, deletions: 0 } } }, timing); + t('a pull at or under the line reads no reviews at all — the lift is asked only over it', [under.exit, under.seen.some((x) => x.call === REVIEWS)], [EXIT_OK, false]); + t('the governed and one-jump fences are untouched by the lift: an approved large pull touching a governed path, or behind a jumped entry, is still refused', [await verdict({ [FILES]: { status: 200, json: [{ filename: 'AGENTS.md' }] } }), await verdict({ [GQL]: queueOf([entry(3730, 1, true)]) })], [refused, refused]); + t('enqueueFrontSizeLift is pure: no verdict reads unread, an empty approval list lifts nothing', [enqueueFrontSizeLift({}).lifts, enqueueFrontSizeLift({ verdict: { state: 'unapproved', approvals: [] }, headSha: HEAD }).reading], [false, 'no authorised APPROVED review']); + } + + // ── the dequeue ───────────────────────────────────────────────────────── + battery("the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged on two reads one interval apart, a merge or close inside the window FAILED, UNCONFIRMED after the window"); + { + const PULL = 3591; + const HEAD = '5c1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c'; + const MOVED = '0a1b2c3d4e5f60718293a4b5c6d7e8f9a0b1c2d3'; + const SESSION = base([]).session; + const PULL_GET = `GET /repos/${REPO}/pulls/${PULL}`; + const COMMENTS = `GET /repos/${REPO}/issues/${PULL}/comments`; + const AUDIT = `POST /repos/${REPO}/issues/${PULL}/comments`; + const GQL = 'POST /graphql'; + const LANDING = 'domain:server#5 · os-project-manager'; + const prBody = `\nFixes #33590\n\n${LANDING} · ${SESSION}\n\nWhat changes.\n\n\n`; + const pullAt = (patch = {}) => ({ status: 200, json: { number: PULL, node_id: 'PR_kwDOout', state: 'open', merged: false, merged_at: null, draft: false, title: 'fix(server): x', body: prBody, mergeable: false, mergeable_state: 'dirty', additions: 40, deletions: 6, head: { sha: HEAD, ref: 'claude/issue-33591-x' }, base: { ref: 'main' }, ...patch } }); + const entry = (number, position, state = 'AWAITING_CHECKS', rollup = 'PENDING') => ({ position, jump: false, state, pullRequest: { number }, headCommit: rollup === undefined ? null : { statusCheckRollup: rollup === null ? null : { state: rollup } } }); + const queueOf = (nodes, hasNextPage = false) => ({ status: 200, json: { data: { repository: { mergeQueue: { entries: { totalCount: nodes.length, pageInfo: { hasNextPage }, nodes } } } } } }); + const before = queueOf([entry(3730, 1), entry(PULL, 2), entry(3732, 3)]); + const after = queueOf([entry(3730, 1), entry(3732, 2)]); + const dequeued = { status: 200, json: { data: { dequeuePullRequest: { mergeQueueEntry: entry(PULL, 2) } } } }; + const audited = { status: 201, json: { id: 6899 } }; + const stroke = (extra = {}) => base([{ op: 'pr_dequeue', pull: PULL, expected_head_sha: HEAD, cause: 'conflict', reason: 'conflicts with main at the shared changeset', ...extra }]); + const happy = { ...allowed, [PULL_GET]: pullAt(), [AUDIT]: audited, [GQL]: [before, dequeued, after] }; + let clock = 0; + const timing = { sleep: async (ms) => { clock += ms; }, now: () => clock }; + const mutations = (seen) => seen.filter((x) => x.call === GQL && x.body?.query?.startsWith('mutation')); + const audits = (seen) => seen.filter((x) => x.call === AUDIT); + const ok = await run(stroke(), happy, timing); + t('⭐ conflict: the sender gate, the pull, its queue — then ONE audit comment, ONE mutation on the node id the first pull read answered (no second read between the comment and the mutation), the queue read back, the pull read back twice; exit 0', [ok.exit, ok.seen.map((x) => x.call)], [EXIT_OK, [PERM, PULL_GET, GQL, AUDIT, GQL, GQL, PULL_GET, PULL_GET]], ok.logs.join(' | ')); + t('…the queue read selects each entry\'s merge-group rollup, the mutation sends the pull\'s node id to dequeuePullRequest', [ok.seen[2].body.query.includes('statusCheckRollup { state }'), mutations(ok.seen).map((m) => [m.body.query.includes('dequeuePullRequest(input: { id: $id })'), m.body.variables])], [true, [[true, { id: 'PR_kwDOout' }]]]); + const body = audits(ok.seen)[0]?.body?.body ?? ''; + t('…the ONE audit comment names the session, the request, the cause, what the relay read and the seat\'s reason', [SESSION, 'fw-test-1', 'cause `conflict`', 'mergeable_state dirty', 'conflicts with main at the shared changeset'].map((w) => body.includes(w)), [true, true, true, true, true]); + t('…the row lands on the read-back, naming the audit comment; the comment and the mutation were paced as writes, the reads were not', [ok.rows[0]?.call, ok.rows[0]?.result, ok.pace ? readReal(ok.pace.file, 'utf8').trim().split('\n').filter(Boolean).length : null], [`${GQL} dequeuePullRequest`, `#${PULL} out of the merge queue and still open, unmerged · read back 2 entr(ies), none is #${PULL} · audit comment 6899`, 2]); + const fenced = async (answers, extra) => { + const r = await run(stroke(extra), { ...happy, ...answers }); + return [r.exit, mutations(r.seen).length, audits(r.seen).length, r.rows[0]?.status, /REFUSED at the relay's fence/.test(r.rows[0]?.result ?? '')]; + }; + const refused = [EXIT_ACTION_FAILED, 0, 0, 'not sent', true]; + t('⛔ conflict, refused: a pull that is clean, or whose mergeability is not computed yet — nothing written', [await fenced({ [PULL_GET]: pullAt({ mergeable: true, mergeable_state: 'clean' }) }), await fenced({ [PULL_GET]: pullAt({ mergeable: null, mergeable_state: 'unknown' }) })], [refused, refused]); + t('⛔ a pull whose own read carries no node id: nothing written — the audit comment never stands without a mutation it can address', (await fenced({ [PULL_GET]: pullAt({ node_id: null }) })).slice(0, 4), refused.slice(0, 4)); + t('⛔ open, head and release, refused: a closed pull, a head pushed since the seat read the cause, the Version Packages pull', [await fenced({ [PULL_GET]: pullAt({ state: 'closed' }) }), await fenced({ [PULL_GET]: pullAt({ head: { sha: MOVED, ref: 'x' } }) }), await fenced({ [PULL_GET]: pullAt({ head: { sha: HEAD, ref: 'changeset-release/main' } }) })], [refused, refused, refused]); + t('⛔ queue and queued, refused: no queue on the base, a truncated list, a pull the queue does not list', [await fenced({ [GQL]: { status: 200, json: { data: { repository: { mergeQueue: null } } } } }), await fenced({ [GQL]: queueOf([entry(PULL, 1)], true) }), await fenced({ [GQL]: after })], [refused, refused, refused]); + const own = (node) => ({ [PULL_GET]: pullAt({ mergeable: true, mergeable_state: 'blocked' }), [GQL]: [queueOf([entry(3730, 1), node]), dequeued, after] }); + t('own-failure: an entry reading UNMERGEABLE, or a merge-group rollup reading FAILURE or ERROR, holds', [(await run(stroke({ cause: 'own-failure' }), { ...happy, ...own(entry(PULL, 2, 'UNMERGEABLE')) }, timing)).exit, (await run(stroke({ cause: 'own-failure' }), { ...happy, ...own(entry(PULL, 2, 'AWAITING_CHECKS', 'FAILURE')) }, timing)).exit, (await run(stroke({ cause: 'own-failure' }), { ...happy, ...own(entry(PULL, 2, 'AWAITING_CHECKS', 'ERROR')) }, timing)).exit], [EXIT_OK, EXIT_OK, EXIT_OK]); + t('⛔ own-failure, refused: a build still pending, a green one, and a rollup the token could not read — null is never a pass', [await fenced(own(entry(PULL, 2, 'AWAITING_CHECKS', 'PENDING')), { cause: 'own-failure' }), await fenced(own(entry(PULL, 2, 'MERGEABLE', 'SUCCESS')), { cause: 'own-failure' }), await fenced(own(entry(PULL, 2, 'AWAITING_CHECKS', null)), { cause: 'own-failure' })], [refused, refused, refused]); + const signed = (login, session, seat = LANDING) => ({ status: 200, json: [{ id: 1, user: { login }, body: `${seat} · ${session}\n\nLanded.` }] }); + const asks = (comments) => ({ [PULL_GET]: pullAt({ mergeable: true, mergeable_state: 'blocked' }), [COMMENTS]: comments }); + const seat = await run(stroke({ cause: 'seat-asks' }), { ...happy, ...asks(signed(RELAY_COMMENT_AUTHOR, SESSION)) }, timing); + t('seat-asks: a relay comment on the pull signed by the LANDING seat (the seat and account its body\'s signed trailer names) under the dispatching session holds — the comments read only for this cause', [seat.exit, seat.seen.filter((x) => x.call === COMMENTS).length, ok.seen.filter((x) => x.call === COMMENTS).length], [EXIT_OK, 1, 0]); + t('⛔ seat-asks, refused: a signature naming another session, the same signature typed by a non-relay account, no comment at all', [await fenced(asks(signed(RELAY_COMMENT_AUTHOR, 'session_01ZZZZZZZZZZZZZZZZZZZZZZZZ')), { cause: 'seat-asks' }), await fenced(asks(signed('a-stranger', SESSION)), { cause: 'seat-asks' }), await fenced(asks({ status: 200, json: [] }), { cause: 'seat-asks' })], [refused, refused, refused]); + const queueSeatJump = { status: 200, json: [{ id: 2, user: { login: RELAY_COMMENT_AUTHOR }, body: `queue#1 · os-project-manager · ${SESSION}\n\nJump (a): carries the fix for the ejection signature.` }] }; + const ownAudit = { status: 200, json: [{ id: 3, user: { login: RELAY_COMMENT_AUTHOR }, body: dequeueAuditBody({ session: SESSION, requestId: 'fw-earlier', number: PULL, cause: 'conflict', reading: 'mergeable_state dirty', reason: 'x' }) }] }; + t('⛔ seat-asks, refused: ANOTHER seat\'s signed comment under the dispatching session (the queue seat\'s jump comment, a seat of another lane, the landing lane#N under another account), and the relay\'s own earlier audit comment', [await fenced(asks(queueSeatJump), { cause: 'seat-asks' }), await fenced(asks(signed(RELAY_COMMENT_AUTHOR, SESSION, 'review#2 · os-project-manager')), { cause: 'seat-asks' }), await fenced(asks(signed(RELAY_COMMENT_AUTHOR, SESSION, 'domain:server#5 · os-someone-else')), { cause: 'seat-asks' }), await fenced(asks(ownAudit), { cause: 'seat-asks' })], [refused, refused, refused, refused]); + const noTrailer = await run(stroke({ cause: 'seat-asks' }), { ...happy, ...asks(signed(RELAY_COMMENT_AUTHOR, SESSION)), [PULL_GET]: pullAt({ mergeable: true, mergeable_state: 'blocked', body: prBody.replace(//u, '') }) }); + t('⛔ seat-asks, refused: a pull body whose last line is no signed trailer names no landing seat — refused unread, its comments never walked, the sentence naming the trailer', [noTrailer.exit, writes(noTrailer.seen).filter((x) => x.call !== GQL).length, noTrailer.seen.filter((x) => x.call === COMMENTS).length, noTrailer.rows[0]?.result.includes("signed trailer names no seat")], [EXIT_ACTION_FAILED, 0, 0, true]); + t('signedByLandingSeat: one seat, account and session holds; any one of the four parts different, or either reading missing, does not', [signedByLandingSeat({ lane: 'domain:server', seat: 5, account: 'a', session: 's' }, { lane: 'domain:server', seat: 5, account: 'a', session: 'other' }, 's'), ...[{ lane: 'queue' }, { seat: 6 }, { account: 'b' }, { session: 't' }].map((d) => signedByLandingSeat({ lane: 'domain:server', seat: 5, account: 'a', session: 's', ...d }, { lane: 'domain:server', seat: 5, account: 'a' }, 's')), signedByLandingSeat(null, { lane: 'x', seat: 1, account: 'a' }, 's'), signedByLandingSeat({ lane: 'x', seat: 1, account: 'a', session: 's' }, null, 's')], [true, false, false, false, false, false, false]); + const unreadComments = await run(stroke({ cause: 'seat-asks' }), { ...happy, ...asks({ status: 502, json: { message: 'Bad Gateway' } }) }); + t('⛔ seat-asks with the comments unread: nothing written, the read named — an unread list is never unsigned', [unreadComments.exit, writes(unreadComments.seen).filter((x) => x.call !== GQL).length, mutations(unreadComments.seen).length, unreadComments.rows[0]?.result.includes('comments could not be read')], [EXIT_ACTION_FAILED, 0, 0, true]); + const noAudit = await run(stroke(), { ...happy, [AUDIT]: { status: 403, json: { message: 'Resource not accessible by integration' } } }); + t('⛔ an audit comment that does not land stops the action: the mutation NOT SENT, the row says so', [noAudit.exit, mutations(noAudit.seen).length, noAudit.rows[0]?.result.includes('NOT SENT')], [EXIT_ACTION_FAILED, 0, true]); + const denied = await run(stroke(), { ...happy, [GQL]: [before, { status: 200, json: { data: { dequeuePullRequest: null }, errors: [{ message: 'Resource not accessible by integration' }] } }] }); + t('⛔ GraphQL errors on the mutation (the grant missing) are FAILED naming `Merge queues: write`; the audit comment stands and nothing is read back', [denied.exit, denied.rows[0]?.result.includes('Merge queues: write'), denied.rows[0]?.result.includes('audit comment 6899 stands'), denied.seen.filter((x) => x.call === GQL).length], [EXIT_ACTION_FAILED, true, true, 2]); + clock = 0; + const still = await run(stroke(), { ...happy, [GQL]: [before, dequeued, before] }, timing); + t('⛔ a read-back that still lists the pull is FAILED, UNCONFIRMED, after the window — a 200 is never trusted alone', [still.exit, still.rows[0]?.result.includes('UNCONFIRMED'), still.rows[0]?.result.includes('still lists'), clock], [EXIT_ACTION_FAILED, true, true, DEQUEUE_WINDOW_MS]); + clock = 0; + const late = await run(stroke(), { ...happy, [GQL]: [before, dequeued, before, after] }, timing); + t('an entry gone on a later read lands, read again at the interval, then the pull read twice one interval apart', [late.exit, clock], [EXIT_OK, 2 * DEQUEUE_POLL_MS]); + clock = 0; + const merged = await run(stroke({ cause: 'seat-asks' }), { ...happy, ...asks(signed(RELAY_COMMENT_AUTHOR, SESSION)), [PULL_GET]: [pullAt({ mergeable: true, mergeable_state: 'clean' }), pullAt({ state: 'closed', merged: true, merged_at: '2026-11-15T08:40:12Z' })] }, timing); + t('⛔ a pull that MERGES inside the window left the queue by landing: FAILED naming the merge, never a landed dequeue, never UNCONFIRMED or re-read', [merged.exit, merged.rows[0]?.result.includes('MERGED at 2026-11-15T08:40:12Z'), merged.rows[0]?.result.includes('UNCONFIRMED'), clock], [EXIT_ACTION_FAILED, true, false, 0]); + const closed = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt({ state: 'closed' })] }, timing); + t('⛔ a pull read back closed unmerged is FAILED too — out of the queue and not open is no dequeue landing', [closed.exit, closed.rows[0]?.result.includes('state closed')], [EXIT_ACTION_FAILED, true]); + clock = 0; + const pullLate = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), { status: 502, json: { message: 'Bad Gateway' } }, pullAt()] }, timing); + t('a pull read that fails after the queue reads it gone is read again at the interval, and lands when it reads open and unmerged', [pullLate.exit, clock], [EXIT_OK, 2 * DEQUEUE_POLL_MS]); + clock = 0; + const mergedLate = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt(), pullAt({ state: 'closed', merged: true, merged_at: '2026-11-15T08:40:15Z' })] }, timing); + const mergedLateClock = clock; + const mergedAtOnly = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt(), pullAt({ merged: false, merged_at: '2026-11-15T08:40:15Z' })] }, timing); + t('⛔ a merge that shows only on the SECOND pull read, one interval after the first read it open and unmerged, is FAILED naming the merge — the queue\'s removal and `merged` arrive in either order; `merged_at` beside a false `merged` reads as merged too', [mergedLate.exit, mergedLate.rows[0]?.result.includes('MERGED at 2026-11-15T08:40:15Z'), mergedLateClock, mergedAtOnly.exit, mergedAtOnly.rows[0]?.result.includes('MERGED')], [EXIT_ACTION_FAILED, true, DEQUEUE_POLL_MS, EXIT_ACTION_FAILED, true]); + t('dequeuePullAfter: open and merged false lands; merged, closed or an unread merged flag does not', [dequeuePullAfter({ status: 200, json: { state: 'open', merged: false } }).ok, dequeuePullAfter({ status: 200, json: { state: 'closed', merged: true } }).pending, dequeuePullAfter({ status: 200, json: { state: 'closed', merged: false } }).pending, dequeuePullAfter({ status: 200, json: { state: 'open' } }).pending, dequeuePullAfter({ status: 404, json: {} }).pending], [true, false, false, true, true]); + t('dequeueReadBack: a truncated list is pending, a base with no queue lists nothing', [dequeueReadBack({ pull: 1, queue: { present: true, complete: false, entries: [] } }).pending, dequeueReadBack({ pull: 1, queue: { present: false, complete: true, entries: [] } }).ok], [true, true]); + const beside = await run(base([stroke().actions[0], { op: 'comment', issue: 1, body: 'x' }]), happy); + const flake = await run(stroke({ cause: 'flake' }), happy); + t('⛔ the validator is the executor\'s gate too: beside another action, or a cause outside the three, refused with ZERO requests, exit 2', [[beside.exit, beside.seen.length], [flake.exit, flake.seen.length]], [[EXIT_REFUSED, 0], [EXIT_REFUSED, 0]]); + const handover = readReal(fileURLToPath(new URL('../check-handover.mjs', import.meta.url)), 'utf8'); + t('RELAY_COMMENT_AUTHOR is check-handover.mjs\'s FLEET_BOT_LOGIN, spelled once each and held equal here', /export const FLEET_BOT_LOGIN = '([^']+)'/.exec(handover)?.[1], RELAY_COMMENT_AUTHOR); + } + // ── the hierarchy link ────────────────────────────────────────────────── battery("the hierarchy link: sub_issue_add and sub_issue_remove read the parent's and the child's own answers, then the child's parent (add) or the parent's whole list (remove), immediately before ONE write whose body is the child's REST id from its own answer — never its number, never replace_parent; a pull, a transferred or unread card, a child under another parent, one the parent does not list, or a read that is neither answer is zero writes; a child already under this parent is a no-op landed on the list; the answer confirmed only when the parent's list reads the child back (or no longer does) inside the window; a refused write, a list that never settles or never reads whole is FAILED; no annotation, and the rows ride a stroke beside other ops"); { diff --git a/scripts/pm/fleet-write/ops.mjs b/scripts/pm/fleet-write/ops.mjs index 6e65163293a..fa58614467f 100644 --- a/scripts/pm/fleet-write/ops.mjs +++ b/scripts/pm/fleet-write/ops.mjs @@ -195,8 +195,9 @@ * `advisory_state`, below) are `repository-advisories: write`, and the two * that read (`advisory_read` and `advisory_list`, below) spend the same grant * at `read` alone (each row's `grant`), the seven rows spending it; the - * front-of-queue enqueue (`pr_enqueue_front`, below) is `merge-queues: write`, - * the one row spending it — GitHub's GraphQL mutations are outside that ledger, + * front-of-queue enqueue (`pr_enqueue_front`, below) and the dequeue + * (`pr_dequeue`, below) are `merge-queues: write`, the two rows spending it — + * GitHub's GraphQL mutations are outside that ledger, * so this one is the App-permission vocabulary's (`permission-merge-queues` on * `actions/create-github-app-token`), NOT MEASURED until its first stroke; the sender gate's * `GET /repos/{o}/{r}/collaborators/{login}/permission` is `metadata: read`. @@ -301,7 +302,7 @@ * own documentation of the option), and it is an ADDITIONAL repository * permission above write ("Jump to the front of the queue", a custom-role * permission an admin holds by default), so the row is fenced like - * `run_rerun_failed` and spends a grant no other row spends: + * `run_rerun_failed` and spends a grant only it and `pr_dequeue` spend: * * - the GRANT: `merge-queues: write`, minted for that stroke alone through * `STROKE_SCOPED_PERMISSIONS`, as `actions` is; `contents` and @@ -323,7 +324,9 @@ * head or a `chore: version packages` title, AGENTS.md Prime Directive * #15), no governed path in its whole file list (`governedPathsIn`: a * governed pull's place in the queue stays a human's), and at most - * `HUMAN_MERGE_LINE_THRESHOLD` changed lines (AGENTS.md §7's third class); + * `HUMAN_MERGE_LINE_THRESHOLD` changed lines (AGENTS.md §7's third class) + * unless an authorised approval lifts that line (`enqueueFrontSizeLift`, + * below); * - the QUEUE (`MERGE_QUEUE_READ_QUERY`, the pull's base): the base has a * queue, the entry list is read whole, and no entry is already jumped — one * jumped pull per repository at a time, a second refused while the first is @@ -340,6 +343,99 @@ * query, a read: unpaced, like every GET. WHEN a seat may send the stroke is * pm-dispatch's rule (`references/landing-operations.md`), never this table's. * + * The SIZE lift (`enqueueFrontSizeLift`; the queue card's item 2): a pull + * over the line may be jumped only when the approval that lets it land at all + * already stands, read by the executor immediately before the mutation from + * the pull's own reviews (`GET /repos/{repo}/pulls/{n}/reviews`, one page at + * the endpoint's maximum — a full page is a truncated SUBSET and lifts + * nothing) through the queue guard's `authorizedApprovalVerdict` (latest + * decisive review per reviewer, an account in `GOVERNED_APPROVERS`, not + * dismissed). Two ways and no third: + * + * - ON THE HEAD: one such APPROVED review's `commit_id` is the pull's + * current head; + * - CARRIED: such an approval stands on an EARLIER commit, and the action + * names `approval_comment`, a comment on THIS pull whose author is in + * `GOVERNED_APPROVERS` and whose text carries the current head (seven or + * more leading hex characters of it) — the maintainer's confirmation that + * the approval carries to this head. The comment is read by its own GET + * (`/repos/{repo}/issues/comments/{id}`); a comment on another pull, by + * another author, or naming another head lifts nothing. Nor does one whose + * first non-empty line is a seat signature (`LANE#N · ACCOUNT · SESSION`): + * an authorised account is agent-operated too (AGENTS.md Prime Directive + * #14), and a seat's knock or record quoting the head is no confirmation + * by the maintainer's own hand. + * + * The approval stays the maintainer's: the relay reads it and never gives + * one. The governed fence, the one-jump fence and the jump reasons are + * untouched by the lift. + * + * ## The one row that takes a pull OUT of the merge queue — `pr_dequeue` + * + * `dequeuePullRequest(input: { id })` removes a pull's entry from its base's + * merge queue; every group behind it rebuilds. `automerge_disable` does not + * do this (its own section above), so before this row only the maintainer's + * hand could. The queue card (item 1) fences it to three CAUSES, named by the + * action's `cause` and judged by the executor on its own reads immediately + * before anything is written (`DEQUEUE_FENCES`): + * + * - `conflict`: the pull's own GET reads `mergeable_state` `dirty` — the + * entry conflicts with its base (`unknown` or a null `mergeable` is not + * judged: re-read the pull and send again); + * - `own-failure`: the entry's queue build failed — its entry reads + * `UNMERGEABLE`, or its merge-group commit's check rollup reads `FAILURE` + * or `ERROR` (`DEQUEUE_QUEUE_READ_QUERY` reads both); a rollup the token + * cannot read is null, and null is refused, never a pass. WHOSE change + * failed is the three-fact test of `landing-operations.md`, which no read + * here can run: the seat states it in `reason`, and the audit comment + * carries it; + * - `seat-asks`: the pull's LANDING seat asks. The landing seat is the one + * the pull's own body names in its signed trailer (`` on its last non-empty line, `readPrBodyTrailer`); + * a body whose trailer names no seat is refused. The proof is a fleet + * comment on the pull whose first non-empty line is a seat signature + * naming `payload.session` AND that same seat and account. Another seat's + * signed comment — a review record, a triage knock, the queue seat's own + * jump or ejection comment — answers nothing, and the relay's own audit + * comments open with no signature. `payload.session` is still the + * sender's own word: the fence binds it to the seat the pull names, it + * does not prove who typed it. + * + * Beside the cause, the pull is open, its head is `expected_head_sha` (a push + * after the seat's reading may have fixed what it read), it is not the + * Version Packages pull, its base has a queue read whole, and the queue lists + * it. A fence that fails is refused with nothing written, exit 5. + * + * ONE audit comment per use, and before the mutation: once the fences hold, + * the executor posts `dequeueAuditBody` on the pull — the session, the cause, + * what the relay read for it and the seat's `reason` — and sends the mutation + * only when that comment answered 201. A use with no audit comment never + * leaves; a comment whose mutation then fails says so on the run's row. + * + * The grant: `merge-queues: write`, minted for this stroke alone through + * `STROKE_SCOPED_PERMISSIONS`, as for the jump; `contents` and `issues` (the + * audit comment) are its literal `alsoSpends`. Whether `dequeuePullRequest` + * needs the merge-queue grant at all, or what an App token without it + * answers, is NOT MEASURED until the first live stroke — nor is the reading + * that an entry's `headCommit { statusCheckRollup }` is its merge-group + * commit's rollup (the `own-failure` cause's second half; the audit comment + * prints the rollup it read, so the first such stroke measures it): the row mints it so + * that the door works once the maintainer grants it, an installation without + * it fails the mint with zero writes, and GraphQL errors on the mutation are + * a FAILED action naming the grant. Travels alone. + * + * The 200 is an acceptance, not a landing: the executor re-reads the queue + * every `DEQUEUE_POLL_MS` for up to `DEQUEUE_WINDOW_MS` and lands only when + * the pull is no longer listed (`dequeueReadBack`) AND its own GET reads it + * still open with `merged` false (`dequeuePullAfter`) on two reads one poll + * apart — out of the queue and not landed, the two readings + * `platform-readings.md` asks for, whose removal and `merged` arrive seconds + * apart in either order. A pull that + * left by MERGING inside the window is a FAILED action naming the merge; one + * closed unmerged is FAILED too. A read-back that still lists it after the + * window is a FAILED action, UNCONFIRMED — ⛔ a 200 is never trusted alone. WHEN a seat may send it is pm-dispatch's rule + * (`landing-operations.md`), never this table's. + * * ## A workflow's inputs are CLOSED per file — `WORKFLOW_DISPATCH_INPUTS` * * An input picks which of a workflow's lanes the run takes, so the inputs are @@ -1220,7 +1316,14 @@ export function mergeQueueOf(json) { if (!queue) return { present: false, complete: true, entries: [] }; const nodes = Array.isArray(queue.entries?.nodes) ? queue.entries.nodes : null; const complete = nodes !== null && queue.entries?.pageInfo?.hasNextPage === false; - const entries = (nodes ?? []).filter((e) => e && typeof e === 'object').map((e) => ({ number: e.pullRequest?.number ?? null, jump: e.jump === true, position: Number.isInteger(e.position) ? e.position : null, state: e.state ?? null })); + // `rollup` only when the query selected the entry's merge-group commit (`DEQUEUE_QUEUE_READ_QUERY`): null is unread, never a pass. + const entries = (nodes ?? []).filter((e) => e && typeof e === 'object').map((e) => ({ + number: e.pullRequest?.number ?? null, + jump: e.jump === true, + position: Number.isInteger(e.position) ? e.position : null, + state: e.state ?? null, + ...('headCommit' in e ? { rollup: typeof e.headCommit?.statusCheckRollup?.state === 'string' ? e.headCommit.statusCheckRollup.state : null } : {}), + })); return { present: true, complete, entries }; } @@ -1254,9 +1357,9 @@ export const ENQUEUE_FRONT_FENCES = Object.freeze([ }), Object.freeze({ fence: 'size', - wants: `at most ${HUMAN_MERGE_LINE_THRESHOLD} changed lines (additions + deletions) — a larger pull lands the way a Tier H one does`, - reads: (c) => `${(c.pull?.additions ?? 0) + (c.pull?.deletions ?? 0)} changed line(s)`, - holds: (c) => Number.isInteger(c.pull?.additions) && Number.isInteger(c.pull?.deletions) && c.pull.additions + c.pull.deletions <= HUMAN_MERGE_LINE_THRESHOLD, + wants: `at most ${HUMAN_MERGE_LINE_THRESHOLD} changed lines (additions + deletions), or a larger pull whose authorised approval stands on its current head or is carried to it by an authorised comment (\`approval_comment\`) — a larger pull lands the way a Tier H one does`, + reads: (c) => `${(c.pull?.additions ?? 0) + (c.pull?.deletions ?? 0)} changed line(s)${c.approval ? `, ${c.approval.reading}` : ''}`, + holds: (c) => Number.isInteger(c.pull?.additions) && Number.isInteger(c.pull?.deletions) && (c.pull.additions + c.pull.deletions <= HUMAN_MERGE_LINE_THRESHOLD || c.approval?.lifts === true), }), Object.freeze({ fence: 'queue', @@ -1307,6 +1410,209 @@ export function enqueueFrontLandedText(v, total) { return `#${v.entry.number} at the front of the merge queue · position ${v.entry.position} · jump true · ${v.entry.state ?? 'state unread'} · ${total} entr(ies) queued`; } +/** The jump's SIZE lift (header: "The SIZE lift"): one page of reviews at this size; a full page is a truncated SUBSET. */ +export const ENQUEUE_FRONT_REVIEWS_PAGE_SIZE = 100; +/** The fewest leading hex characters of the head a carrying comment must spell (git's own default abbreviation). */ +export const CARRIED_HEAD_MIN_CHARS = 7; + +/** + * The jump's SIZE lift (header: "The SIZE lift"), judged on reads the executor took. `verdict` is the queue guard's + * `authorizedApprovalVerdict` over the pull's reviews (null: not read whole), `headSha` the pull's current head, + * `comment` the `approval_comment`'s own GET answer `{ status, json }` (null: the action names none), `pull` the + * pull's number, `approvers` the authorised logins (`GOVERNED_APPROVERS`) and `signatureOf` the seat-signature + * reader (`readSignatureLine`) — both passed in so this file imports no guard; a reader missing carries nothing. + * Answers `{ lifts, way, reading }`: `way` is `head`, `carried` or null; `reading` is what the size fence's + * sentence quotes. Pure. + */ +export function enqueueFrontSizeLift({ verdict = null, headSha = null, comment = null, pull = null, approvers = [], signatureOf = null } = {}) { + if (!verdict || verdict.state === 'unreadable' || !Array.isArray(verdict.approvals)) return { lifts: false, way: null, reading: `the reviews unread${verdict?.reason ? ` (${verdict.reason})` : ''}` }; + const head = typeof headSha === 'string' ? headSha.toLowerCase() : ''; + const approvals = verdict.approvals.filter((a) => typeof a?.login === 'string' && a.login !== ''); + if (approvals.length === 0) return { lifts: false, way: null, reading: 'no authorised APPROVED review' }; + const onHead = approvals.filter((a) => head !== '' && a.commitId === head); + if (onHead.length) return { lifts: true, way: 'head', reading: `authorised approval by ${onHead.map((a) => a.login).join(', ')} on the current head` }; + const earlier = `authorised approval by ${approvals.map((a) => `${a.login} on ${shortHead(a.commitId) || 'an unread commit'}`).join(', ')}, not on the current head ${shortHead(head)}`; + if (comment === null) return { lifts: false, way: null, reading: `${earlier}, and no \`approval_comment\` carries it` }; + const c = comment.json; + if (comment.status !== 200 || !isObject(c)) return { lifts: false, way: null, reading: `${earlier}; the approval_comment could not be read (HTTP ${comment.status ?? 'none'})` }; + const author = c.user?.login ?? null; + if (!approvers.includes(author)) return { lifts: false, way: null, reading: `${earlier}; the approval_comment's author ${author ?? 'unread'} is not an authorised approver` }; + if (!new RegExp(`/issues/${pull}$`).test(String(c.issue_url ?? ''))) return { lifts: false, way: null, reading: `${earlier}; the approval_comment is not on #${pull}` }; + if (typeof signatureOf !== 'function') return { lifts: false, way: null, reading: `${earlier}; the approval_comment's opening line was not judged` }; + const seat = signatureOf(c.body); + if (seat) return { lifts: false, way: null, reading: `${earlier}; the approval_comment by ${author} opens with the seat signature ${seat.lane}#${seat.seat} · ${seat.account} — a seat's comment is no carried approval` }; + const tokens = String(c.body ?? '').match(/\b[0-9a-f]{7,40}\b/giu) ?? []; + const carries = head !== '' && tokens.some((tok) => tok.length >= CARRIED_HEAD_MIN_CHARS && head.startsWith(tok.toLowerCase())); + if (!carries) return { lifts: false, way: null, reading: `${earlier}; the approval_comment by ${author} names no prefix of the current head` }; + return { lifts: true, way: 'carried', reading: `authorised approval by ${approvals.map((a) => a.login).join(', ')} carried to the current head by ${author}'s comment ${c.id ?? ''}`.trimEnd() }; +} + +/** + * The dequeue (header: "The one row that takes a pull OUT of the merge queue"). The mutation sends the pull's node + * id; the queue read is the jump's plus each entry's merge-group commit rollup, the `own-failure` cause's reading. + */ +export const DEQUEUE_MUTATION = 'mutation($id: ID!) { dequeuePullRequest(input: { id: $id }) { mergeQueueEntry { position state pullRequest { number } } } }'; +export const DEQUEUE_QUEUE_READ_QUERY = `query($owner: String!, $name: String!, $branch: String!) { repository(owner: $owner, name: $name) { mergeQueue(branch: $branch) { entries(first: ${MERGE_QUEUE_PAGE_SIZE}) { totalCount pageInfo { hasNextPage } nodes { position jump state pullRequest { number } headCommit { statusCheckRollup { state } } } } } } }`; +/** + * The relay's own comment author — the only author whose signed comment answers the `seat-asks` cause, since any + * account may comment on a public pull. `check-handover.mjs`'s `FLEET_BOT_LOGIN`, spelled here so the relay imports + * no seat tool; `execute.mjs --self-test` holds the two equal. + */ +export const RELAY_COMMENT_AUTHOR = 'objectstack-fleet[bot]'; +/** The three causes the queue card fences the dequeue to (header) — `cause`, a closed enum. */ +export const DEQUEUE_CAUSES = Object.freeze(['conflict', 'own-failure', 'seat-asks']); +/** The `own-failure` readings: the entry's own state, or its merge-group commit's rollup. */ +export const DEQUEUE_FAILED_ENTRY_STATES = Object.freeze(['UNMERGEABLE']); +export const DEQUEUE_FAILED_ROLLUPS = Object.freeze(['FAILURE', 'ERROR']); +/** The seat's `reason`, carried into the audit comment — bounded: it is the cause's evidence, not a report. */ +export const MAX_DEQUEUE_REASON_BYTES = 1000; + +const entryOf = (c) => (c.queue?.entries ?? []).find((e) => e.number === c.number) ?? null; +const seatOf = (sig) => `${sig.lane}#${sig.seat} · ${sig.account}`; + +/** + * Is `signature` (a `readSignatureLine` reading) the pull's landing seat — the same lane, seat number and account + * as `landing`, the reading of the pull body's signed trailer — under `session`? The `seat-asks` proof (header). Pure. + */ +export function signedByLandingSeat(signature, landing, session) { + return Boolean(signature && landing) && signature.session === session && signature.lane === landing.lane && signature.seat === landing.seat && signature.account === landing.account; +} + +/** What each cause reads and whether it holds — the `cause` fence's two halves, keyed by cause. Pure. */ +const DEQUEUE_CAUSE_JUDGES = Object.freeze({ + conflict: Object.freeze({ + wants: 'a pull whose mergeable_state reads dirty — its entry conflicts with its base', + reads: (c) => `mergeable_state ${c.pull?.mergeable_state ?? null}, mergeable ${c.pull?.mergeable ?? null}`, + holds: (c) => c.pull?.mergeable_state === 'dirty', + }), + 'own-failure': Object.freeze({ + wants: `an entry whose queue build failed — its state ${DEQUEUE_FAILED_ENTRY_STATES.join('/')} or its merge-group rollup ${DEQUEUE_FAILED_ROLLUPS.join('/')}`, + reads: (c) => { + const e = entryOf(c); + return e ? `entry state ${e.state ?? null}, merge-group rollup ${e.rollup ?? null}` : 'no entry read'; + }, + holds: (c) => { + const e = entryOf(c); + return Boolean(e) && (DEQUEUE_FAILED_ENTRY_STATES.includes(e.state) || DEQUEUE_FAILED_ROLLUPS.includes(e.rollup)); + }, + }), + 'seat-asks': Object.freeze({ + wants: "a pull whose body's signed trailer names its landing seat, carrying a fleet comment signed by that seat and account under the dispatching session — its landing seat asks", + reads: (c) => { + if (!c.landing) return "the pull body's signed trailer names no seat"; + const seat = seatOf(c.landing); + return c.signed === true ? `landing seat ${seat}, signed by ${seat} · ${c.session}` : c.signed === false ? `landing seat ${seat}, no fleet comment on it signed by ${seat} · ${c.session}` : `landing seat ${seat}, its comments unread`; + }, + holds: (c) => Boolean(c.landing) && c.signed === true, + }), +}); + +/** + * The fences on the PULL, its QUEUE and the CAUSE (header). Each takes one context + * `{ number, pull, expectedHeadSha, queue, cause, session, landing, signed }`: `pull` the pull's own GET, `queue` + * `mergeQueueOf`'s reading of `DEQUEUE_QUEUE_READ_QUERY`, `landing` the seat the pull body's signed trailer names + * (a `readSignatureLine` reading, or null), `signed` whether that seat signed a fleet comment on it under the + * dispatching session (null: not read — read only for `seat-asks`, and only when `landing` is read). Alone in its stroke and the grant are the validator's. + */ +export const DEQUEUE_FENCES = Object.freeze([ + Object.freeze({ fence: 'open', wants: 'an open pull', reads: (c) => `state ${c.pull?.state ?? null}`, holds: (c) => c.pull?.state === 'open' }), + Object.freeze({ + fence: 'head', + wants: 'a pull whose current head is expected_head_sha, the head the seat read its cause on', + reads: (c) => `head ${shortHead(c.pull?.head?.sha)}, expected ${shortHead(c.expectedHeadSha)}`, + holds: (c) => typeof c.pull?.head?.sha === 'string' && c.pull.head.sha === c.expectedHeadSha, + }), + Object.freeze({ + fence: 'release', + wants: `a pull that is not the Version Packages pull (head ${VERSION_PACKAGES_HEAD_PREFIX}*, or a "chore: version packages" title) — its queue place is the maintainer's`, + reads: (c) => `head ref ${c.pull?.head?.ref ?? null}, title ${JSON.stringify(c.pull?.title ?? null)}`, + holds: (c) => typeof c.pull?.head?.ref === 'string' && !c.pull.head.ref.startsWith(VERSION_PACKAGES_HEAD_PREFIX) && !VERSION_PACKAGES_TITLE.test(c.pull?.title ?? ''), + }), + Object.freeze({ + fence: 'queue', + wants: 'a base with a merge queue whose entry list was read whole', + reads: (c) => (!c.queue ? 'the queue unread' : !c.queue.present ? 'no merge queue on the base' : `${c.queue.entries.length} entr(ies), ${c.queue.complete ? 'read whole' : 'a truncated list'}`), + holds: (c) => Boolean(c.queue?.present && c.queue.complete), + }), + Object.freeze({ + fence: 'queued', + wants: 'a pull the queue lists', + reads: (c) => (entryOf(c) ? `listed at position ${entryOf(c).position}` : `#${c.number} not listed`), + holds: (c) => entryOf(c) !== null, + }), + Object.freeze({ + fence: 'cause', + wants: `one of ${DEQUEUE_CAUSES.join(', ')}, holding on what the relay reads`, + reads: (c) => (DEQUEUE_CAUSE_JUDGES[c.cause] ? `cause ${c.cause}: ${DEQUEUE_CAUSE_JUDGES[c.cause].reads(c)}` : `cause ${JSON.stringify(c.cause ?? null)}`), + holds: (c) => Boolean(DEQUEUE_CAUSE_JUDGES[c.cause]?.holds(c)), + }), +]); + +/** The fences a context fails: `[{ fence, wants, got }]`, in `DEQUEUE_FENCES` order; `[]` when all hold. Pure. */ +export function dequeueFenceFailures(ctx) { + return DEQUEUE_FENCES.filter((f) => !f.holds(ctx)).map((f) => ({ fence: f.fence, wants: f.fence === 'cause' && DEQUEUE_CAUSE_JUDGES[ctx.cause] ? DEQUEUE_CAUSE_JUDGES[ctx.cause].wants : f.wants, got: f.reads(ctx) ?? null })); +} + +/** The sentence a fence refusal prints. Pure. */ +export function dequeueFenceText(failures) { + return failures.map((f) => `fence \`${f.fence}\`: the relay read ${JSON.stringify(f.got)}, and it dequeues only ${f.wants}`).join('; '); +} + +/** What the relay read for the cause, as the audit comment and the landed row quote it. Pure. */ +export function dequeueCauseReading(ctx) { + return DEQUEUE_CAUSE_JUDGES[ctx.cause]?.reads(ctx) ?? 'unread'; +} + +/** + * The ONE audit comment a dequeue leaves on the pull, before the mutation (header). It opens with the dispatching + * session and the request, names the cause, what the relay read for it and the seat's reason. Pure. + */ +export function dequeueAuditBody({ session, requestId, number, cause, reading, reason }) { + return [ + `Relay \`pr_dequeue\` · ${session} · request \`${requestId}\``, + '', + `**Merge-queue dequeue of #${number} — cause \`${cause}\`.**`, + '', + `- Relay read: ${reading}.`, + `- Seat's reason: ${String(reason ?? '').trim()}`, + '', + 'The relay sends `dequeuePullRequest` after this comment and confirms the removal by reading the queue back; the run row of this request carries the outcome. Re-queue once the cause is fixed (`landing-operations.md`, the landing seat\'s queue duty).', + ].join('\n'); +} + +/** + * What LANDED means for a `pr_dequeue` (header): the queue read back no longer lists the pull. Answers + * `{ ok, pending, why }`: `pending` the entry still listed, or the list not read whole (the executor re-reads inside + * its window). A base that reads no merge queue lists nothing — the pull is out of it. Pure. + */ +export function dequeueReadBack({ pull, queue } = {}) { + if (!queue) return { ok: false, pending: true, why: 'the queue was not read back' }; + if (!queue.present) return { ok: true, pending: false, why: '' }; + if (!queue.complete) return { ok: false, pending: true, why: 'the queue read back is a truncated list, which cannot show the entry gone' }; + const entry = queue.entries.find((e) => e.number === pull) ?? null; + if (entry) return { ok: false, pending: true, why: `the queue read back still lists #${pull} at position ${entry.position}` }; + return { ok: true, pending: false, why: '' }; +} + +/** + * The second half of a dequeue's landing (header): the pull's own GET once the queue no longer lists it — still open + * and `merged` false, so it left the queue without landing. `{ ok, pending, why }`: a read that is not a 200 object + * is `pending` (read again inside the window); a merged pull, or one closed unmerged, is a terminal failure. Pure. + */ +export function dequeuePullAfter(answer) { + const p = answer?.json; + if (answer?.status !== 200 || !isObject(p)) return { ok: false, pending: true, why: `the pull's own read answered HTTP ${answer?.status ?? 'none'}, so "not landed" was not read` }; + if (p.merged === true || p.merged_at) return { ok: false, pending: false, why: `the pull MERGED${p.merged_at ? ` at ${p.merged_at}` : ''} — it left the queue by landing, not by this dequeue` }; + if (p.state !== 'open') return { ok: false, pending: false, why: `the pull reads state ${p.state ?? null}, not open — it left the queue closed, not by this dequeue alone` }; + if (p.merged !== false) return { ok: false, pending: true, why: `the pull's merged reads ${p.merged ?? null}, not false` }; + return { ok: true, pending: false, why: '' }; +} + +/** The read-back line a landing prints. Pure. */ +export function dequeueLandedText({ pull, total, auditId }) { + return `#${pull} out of the merge queue and still open, unmerged · read back ${total} entr(ies), none is #${pull} · audit comment ${auditId}`; +} + /** The two modes of the hierarchy rows (header: "The two rows that write an issue's hierarchy") — the descriptor's `subIssue.mode`. */ export const SUB_ISSUE_MODES = Object.freeze(['add', 'remove']); @@ -2672,6 +2978,11 @@ export const FIELDS = Object.freeze({ public_key: Object.freeze({ kind: 'x25519' }), // A note sealed to the relay's committed key (header: "The one row that APPENDS to an advisory") — its own kind, ciphertext alone. sealed_note: Object.freeze({ kind: 'sealed' }), + // The dequeue's cause and the seat's evidence for it (header: "The one row that takes a pull OUT of the merge queue"). + cause: Object.freeze({ kind: 'enum', values: DEQUEUE_CAUSES }), + reason: Object.freeze({ kind: 'str', max: MAX_DEQUEUE_REASON_BYTES }), + // The comment that carries an earlier authorised approval to the head (header: "The SIZE lift"), by its id. + approval_comment: Object.freeze({ kind: 'int' }), }); /** @@ -2690,9 +3001,10 @@ export const FIELDS = Object.freeze({ * write alone, and minted only for a stroke carrying one of them, the same * way; `advisory_read` and `advisory_list` spend that grant at `read` (each * row's `grant`), so a read's stroke is minted the lower level and never write. - * `merge-queues: write` is spent by the `pr_enqueue_front` row alone, and - * minted only for its stroke, the same way (header: "The one row that - * reorders the merge queue"). + * `merge-queues: write` is spent by the `pr_enqueue_front` and `pr_dequeue` + * rows alone, and minted only for a stroke carrying one of them, the same way + * (header: "The one row that reorders the merge queue", "The one row that + * takes a pull OUT of the merge queue"). */ export const PERMISSIONS = Object.freeze({ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write', 'repository-advisories': 'write', 'merge-queues': 'write' }); @@ -2700,7 +3012,7 @@ export const PERMISSIONS = Object.freeze({ issues: 'write', 'pull-requests': 'wr * The permissions minted ONLY for a stroke carrying an op that spends them — * `actions: write`, the `workflow_dispatch` and `run_rerun_failed` rows' * alone, `repository-advisories`, the eight advisory rows' alone, and - * `merge-queues`, the `pr_enqueue_front` row's alone — at + * `merge-queues`, the `pr_enqueue_front` and `pr_dequeue` rows' alone — at * write, or at the row's `grant` (`advisory_read`'s and `advisory_list`'s `read`); each of those * rows travels alone in its stroke. `validate.mjs` * computes a stroke's permission set (`tokenPermissionsOf`) and writes each of @@ -2822,8 +3134,8 @@ export function transferRemedy(source, target) { * one action — `workflow_dispatch`'s and `run_rerun_failed`'s, * the two rows spending `actions: write`, and * the eight advisory rows', the ones spending - * `repository-advisories`, and `pr_enqueue_front`'s, the one - * spending `merge-queues` (header above); + * `repository-advisories`, and `pr_enqueue_front`'s and + * `pr_dequeue`'s, the two spending `merge-queues` (header above); * `closedInputs` (optional) the per-repository, per-workflow closed inputs — * `WORKFLOW_DISPATCH_BY_REPO`, `workflow_dispatch`'s alone: the * stroke's repository must list the action's `workflow`, and the @@ -2897,7 +3209,11 @@ export function transferRemedy(source, target) { * judges the queue read back against * (`enqueueFrontPreflight` / `confirmEnqueueFront`, * execute.mjs) — its graphql descriptor carries no `landed`, - * since the answer is a queue entry, not a pull. + * since the answer is a queue entry, not a pull; a `dequeue` + * descriptor carries the pull, the expected head, the cause and + * the reason the executor fences, writes into the ONE audit + * comment before the mutation, and judges the queue read back + * against (`dequeueAction`, execute.mjs) — no `landed` either. */ export const OPS = Object.freeze({ comment: Object.freeze({ @@ -3042,8 +3358,19 @@ export const OPS = Object.freeze({ alsoSpends: Object.freeze(['contents', 'workflows']), alone: true, required: Object.freeze(['pull', 'expected_head_sha']), + optional: Object.freeze(['approval_comment']), + requests: (a) => [{ verb: 'POST', path: '/graphql', graphql: { mutation: 'enqueuePullRequest', query: ENQUEUE_FRONT_MUTATION, pull: a.pull }, enqueueFront: { pull: a.pull, expectedHeadSha: a.expected_head_sha, approvalComment: a.approval_comment ?? null } }], + }), + // The one row that takes a pull out of the merge queue — see the header. `merge-queues` is minted for its stroke + // alone; `contents` as the two auto-merge rows spend it, `issues` for the ONE audit comment. The fences on the pull, + // its queue and the cause are the executor's, on its own reads before the comment; the queue is read back. + pr_dequeue: Object.freeze({ + permission: 'merge-queues', + alsoSpends: Object.freeze(['contents', 'issues']), + alone: true, + required: Object.freeze(['pull', 'expected_head_sha', 'cause', 'reason']), optional: Object.freeze([]), - requests: (a) => [{ verb: 'POST', path: '/graphql', graphql: { mutation: 'enqueuePullRequest', query: ENQUEUE_FRONT_MUTATION, pull: a.pull }, enqueueFront: { pull: a.pull, expectedHeadSha: a.expected_head_sha } }], + requests: (a) => [{ verb: 'POST', path: '/graphql', graphql: { mutation: 'dequeuePullRequest', query: DEQUEUE_MUTATION, pull: a.pull }, dequeue: { pull: a.pull, expectedHeadSha: a.expected_head_sha, cause: a.cause, reason: a.reason } }], }), // The one row that deletes a ref — see the header. `branch` is held to `MAILBOX_BRANCH_SHAPE` before the dispatch; // the pull's fences are the executor's, on its own answers immediately before the DELETE; the ref is read back absent. @@ -3292,4 +3619,4 @@ export const REFUSED_PATH_FAMILIES = Object.freeze([ ]); /** The GraphQL mutations the table may name — anything else in a `graphql` descriptor is a bug this pins. */ -export const ALLOWED_MUTATIONS = Object.freeze(['markPullRequestReadyForReview', 'convertPullRequestToDraft', 'enablePullRequestAutoMerge', 'disablePullRequestAutoMerge', 'enqueuePullRequest', 'transferIssue']); +export const ALLOWED_MUTATIONS = Object.freeze(['markPullRequestReadyForReview', 'convertPullRequestToDraft', 'enablePullRequestAutoMerge', 'disablePullRequestAutoMerge', 'enqueuePullRequest', 'dequeuePullRequest', 'transferIssue']); diff --git a/scripts/pm/fleet-write/validate.mjs b/scripts/pm/fleet-write/validate.mjs index 100ecadfe68..954b592ca25 100644 --- a/scripts/pm/fleet-write/validate.mjs +++ b/scripts/pm/fleet-write/validate.mjs @@ -188,6 +188,10 @@ import { RERUN_FAILED_PATH_SHAPE, ENQUEUE_FRONT_FENCES, ENQUEUE_FRONT_MUTATION, + DEQUEUE_CAUSES, + DEQUEUE_FENCES, + DEQUEUE_MUTATION, + MAX_DEQUEUE_REASON_BYTES, RERUN_FAILED_RERUN_STATES, RERUN_FAILED_STATUS, RERUN_FAILED_WORKFLOWS, @@ -1116,6 +1120,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ "the workflow table keyed by repository: cloud's deploy-staging.yml dispatchable on cloud alone with apps affected alone, on main alone; a file judged against the stroke's own repository, so a name one repository lists is refused on every other and a repository with no entry starts nothing; the token minted for that ONE repository; and this repository's entries unchanged": 18, "the run_rerun_failed row: run_id alone, a positive integer, nothing that widens it; one bodiless POST to the run's rerun-failed-jobs; a stroke of exactly that one action; actions write minted for that stroke and EMPTY for every other, through the workflow's existing input; the five fences on the run and its pull, each accepted and refused — the head by the pull's own answer, never the run's embedded copy, and a run naming no pull refused by name; the read-back's judgment; and every other actions path still refused": 36, "the pr_enqueue_front row: pull and expected_head_sha, a full sha, and nothing that widens them; ONE enqueuePullRequest mutation with jump true and the expected head, the pull's node id read first; a stroke of exactly that one action; merge-queues write minted for that stroke and EMPTY for every other, through the workflow's own input; contents and workflows its literal alsoSpends; the fences on the pull and its queue named and left to the executor": 10, + "the pr_dequeue row: pull, expected_head_sha, a cause from the closed three and a bounded reason, and nothing that widens them; ONE dequeuePullRequest mutation behind the pull's node id; a stroke of exactly that one action; merge-queues write minted for that stroke, EMPTY for every other; contents and issues its literal alsoSpends; the fences on the pull, its queue and the cause named and left to the executor": 11, "the hierarchy rows: sub_issue_add and sub_issue_remove name a parent and a child by NUMBER — two different positive integers and nothing that widens them; one POST to the parent's sub_issues and one DELETE to its sub_issue, the body left to the executor; issues write, riding any stroke on the literal grants; the fences on the two cards, each accepted and refused — an issue on the repository, never a pull or a transferred card, the child free of any other parent or listed by this one; and the read-back's judgment by the child's id": 23, "the event file: the workflow carries client_payload in no step's env, and the payload is read from GITHUB_EVENT_PATH": 6, "the advisory rows: advisory_report, advisory_create, advisory_collaborators_add, advisory_versions and advisory_state — closed keys, a malformed id, package or versions entry refused before any request, a refusal that names the key and the byte count and never echoes a value, published reached by advisory_state alone, from draft alone and through the versions fence; one request each, the draft's and the versions' bodies naming no state and the two other PATCH bodies left to the executor; each a stroke of its own, repository-advisories write minted for it and EMPTY for every other; the bare collection reached by the draft's POST alone and every other security-advisories path refused; the fences, the transitions, the merge and the five read-backs, printing nothing of an answer but the id, the state, the logins and counts": 77, @@ -1126,8 +1131,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ // Raised 11 → 12 with the run_rerun_failed battery, 12 → 13 with the hierarchy rows' battery, 13 → 15 with the event // file's battery and the advisory rows' battery, 15 → 16 with advisory_read's, 16 → 17 with mailbox_branch_delete's, // 17 → 18 with advisory_list's, 18 → 19 with pr_enqueue_front's: one battery, one row; 19 → 20 with the workflow -// table's repository key; 20 → 21 with advisory_note's. -const SELF_TEST_BATTERY_FLOOR = 21; +// table's repository key; 20 → 21 with advisory_note's; 21 → 22 with pr_dequeue's. +const SELF_TEST_BATTERY_FLOOR = 22; const UNATTRIBUTED_BATTERY = '(unattributed)'; const batteryCases = new Map(); @@ -1276,7 +1281,7 @@ export async function selfTest() { pr_draft: { pull: 1 }, automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, - pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, + pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, sub_issue_add: { issue: 1, sub_issue: 2 }, @@ -1346,7 +1351,7 @@ export async function selfTest() { t('…and neither is the FIRST request of its action — the answer they read exists before either is sent', OP_NAMES.filter((op) => { const a = { op }; for (const k of [...OPS[op].required, ...OPS[op].optional]) a[k] = sample[k]; return OPS[op].requests(a, 'o/r')[0].fromAnswer !== undefined; }), []); t('…every such leg is a POST to the one additive issue endpoint for its list — never a PATCH or PUT, the whole-set replaces', legs.map((r) => [r.verb, /\/(assignees|labels)$/.test(r.path)]), [['POST', true], ['POST', true]]); t('…their placeholder is the one spelling the executor fills, spelled once, and no path without fromAnswer carries a brace', [answerPlaceholder('number'), everyRequest.filter((r) => r.fromAnswer === undefined && /[{}]/.test(r.path)).map((r) => `${r.op} ${r.path}`)], ['{number}', []]); - t('every grant a row ALSO spends is a literal mint input of PERMISSIONS, never a stroke-scoped one — so the mint widens nothing for it; pr_create\'s issues write (its assignees and labels legs), pr_ready\'s (the governed-review assignee fallback), automerge_enable\'s workflows write and pr_enqueue_front\'s contents and workflows write (the two literal grants an enqueue spends) are the four such rows', [OP_NAMES.flatMap((op) => OPS[op].alsoSpends ?? []).every((name) => name in PERMISSIONS && !STROKE_SCOPED_PERMISSIONS.includes(name)), OP_NAMES.filter((op) => OPS[op].alsoSpends).map((op) => [op, [...OPS[op].alsoSpends]])], [true, [['pr_create', ['issues']], ['pr_ready', ['issues']], ['automerge_enable', ['workflows']], ['pr_enqueue_front', ['contents', 'workflows']]]]); + t('every grant a row ALSO spends is a literal mint input of PERMISSIONS, never a stroke-scoped one — so the mint widens nothing for it; pr_create\'s issues write (its assignees and labels legs), pr_ready\'s (the governed-review assignee fallback), automerge_enable\'s workflows write, pr_enqueue_front\'s contents and workflows write (the two literal grants an enqueue spends) and pr_dequeue\'s contents and issues write (the auto-merge rows\' grant and its ONE audit comment) are the five such rows', [OP_NAMES.flatMap((op) => OPS[op].alsoSpends ?? []).every((name) => name in PERMISSIONS && !STROKE_SCOPED_PERMISSIONS.includes(name)), OP_NAMES.filter((op) => OPS[op].alsoSpends).map((op) => [op, [...OPS[op].alsoSpends]])], [true, [['pr_create', ['issues']], ['pr_ready', ['issues']], ['automerge_enable', ['workflows']], ['pr_enqueue_front', ['contents', 'workflows']], ['pr_dequeue', ['contents', 'issues']]]]); t('pr_create without assignees or labels is the one create request it always was — no later leg', OPS.pr_create.requests({ op: 'pr_create', title: 't', head: 'h', base: 'b' }, 'o/r').length, 1); t('…with labels alone, the create then the labels leg; with assignees alone, the create then the assignees leg', [OPS.pr_create.requests({ op: 'pr_create', title: 't', head: 'h', base: 'b', labels: ['skip-changeset'] }, 'o/r').map((r) => r.labelled ?? r.assigned ?? 'create'), OPS.pr_create.requests({ op: 'pr_create', title: 't', head: 'h', base: 'b', assignees: ['u'] }, 'o/r').map((r) => r.labelled ?? r.assigned ?? 'create')], [['create', ['skip-changeset']], ['create', ['u']]]); t('labels_remove is one directed DELETE per name, URL-encoded, idempotent on 404', OPS.labels_remove.requests({ op: 'labels_remove', issue: 1, labels: ['a b', 'c'] }, 'o/r').map((r) => [r.verb, r.path, r.idempotent404]), [['DELETE', '/repos/o/r/issues/1/labels/a%20b', true], ['DELETE', '/repos/o/r/issues/1/labels/c', true]]); @@ -1479,7 +1484,7 @@ export async function selfTest() { comment: { issue: 1, body: 'b' }, comment_edit: { comment_id: 1, body: 'b' }, labels_add: { issue: 1, labels: ['a'] }, labels_remove: { issue: 1, labels: ['a'] }, assign: { issue: 1, assignees: ['u'] }, unassign: { issue: 1, assignees: ['u'] }, issue_patch: { issue: 1, state: 'closed' }, issue_create: { title: 't', body: 'b' }, pr_create: { title: 't', head: 'h', base: 'main' }, pr_request_reviewers: { pull: 1, reviewers: ['u'] }, pr_update_branch: { pull: 1, expected_head_sha: SHA }, pr_ready: { pull: 1 }, pr_draft: { pull: 1 }, - automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, workflow_dispatch: { workflow: WORKFLOW_DISPATCH_ALLOWLIST[0], ref: WORKFLOW_DISPATCH_REF }, + automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, workflow_dispatch: { workflow: WORKFLOW_DISPATCH_ALLOWLIST[0], ref: WORKFLOW_DISPATCH_REF }, run_rerun_failed: { run_id: 1 }, sub_issue_add: { issue: 1, sub_issue: 2 }, sub_issue_remove: { issue: 1, sub_issue: 2 }, advisory_report: { summary: 's', description: 'd' }, advisory_create: { summary: 's', description: 'd', packages: ['p'] }, advisory_collaborators_add: { ghsa_id: GHSA, collaborators: ['u'] }, advisory_versions: { ghsa_id: GHSA, versions: [VERSION] }, advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, @@ -1527,7 +1532,7 @@ export async function selfTest() { t('an inputs key on a file whose entry is null is refused BY NAME — the relay sends none there', refuses(one(start({ inputs: { reason: true } })), `actions[0].inputs: ${FILE} declares no inputs`)); t('⛔ a workflow_dispatch beside any other op is refused — the stroke carries that one action alone', refuses(fixturePayload({ actions: [start(), { op: 'comment', issue: 7, body: 'x' }] }), 'actions[1] is `comment` in a stroke that carries a `workflow_dispatch`')); t('⛔ two workflow_dispatch in one stroke are refused too', refuses(fixturePayload({ actions: [start(), start()] }), 'a stroke carries exactly ONE `workflow_dispatch` and nothing else')); - t('the only rows that travel alone or widen the token: pr_enqueue_front, workflow_dispatch, run_rerun_failed and the eight advisory rows (alone) and transfer (second repository)', [OP_NAMES.filter((op) => OPS[op].alone), OP_NAMES.filter((op) => OPS[op].secondRepo)], [['pr_enqueue_front', 'workflow_dispatch', 'run_rerun_failed', 'advisory_report', 'advisory_create', 'advisory_collaborators_add', 'advisory_versions', 'advisory_state', 'advisory_read', 'advisory_list', 'advisory_note'], ['transfer']]); + t('the only rows that travel alone or widen the token: pr_enqueue_front, pr_dequeue, workflow_dispatch, run_rerun_failed and the eight advisory rows (alone) and transfer (second repository)', [OP_NAMES.filter((op) => OPS[op].alone), OP_NAMES.filter((op) => OPS[op].secondRepo)], [['pr_enqueue_front', 'pr_dequeue', 'workflow_dispatch', 'run_rerun_failed', 'advisory_report', 'advisory_create', 'advisory_collaborators_add', 'advisory_versions', 'advisory_state', 'advisory_read', 'advisory_list', 'advisory_note'], ['transfer']]); t('…and actions is spent by the workflow_dispatch and run_rerun_failed rows and NOTHING else — each of them alone in its stroke', [OP_NAMES.filter((op) => OPS[op].permission === 'actions'), OP_NAMES.filter((op) => OPS[op].permission === 'actions').every((op) => OPS[op].alone === true)], [['workflow_dispatch', 'run_rerun_failed'], true]); const plain = validatePayload(fixturePayload()).payload; const run = validatePayload(one(start())).payload; @@ -1686,7 +1691,7 @@ export async function selfTest() { comment: { issue: 1, body: 'b' }, comment_edit: { comment_id: 1, body: 'b' }, labels_add: { issue: 1, labels: ['a'] }, labels_remove: { issue: 1, labels: ['a'] }, assign: { issue: 1, assignees: ['u'] }, unassign: { issue: 1, assignees: ['u'] }, issue_patch: { issue: 1, state: 'closed' }, issue_create: { title: 't', body: 'b' }, pr_create: { title: 't', head: 'h', base: 'main' }, pr_request_reviewers: { pull: 1, reviewers: ['u'] }, pr_update_branch: { pull: 1, expected_head_sha: SHA }, pr_ready: { pull: 1 }, pr_draft: { pull: 1 }, - automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, + automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, sub_issue_add: { issue: 1, sub_issue: 2 }, sub_issue_remove: { issue: 1, sub_issue: 2 }, advisory_report: { summary: 's', description: 'd' }, advisory_create: { summary: 's', description: 'd', packages: ['p'] }, advisory_collaborators_add: { ghsa_id: GHSA, collaborators: ['u'] }, advisory_versions: { ghsa_id: GHSA, versions: [VERSION] }, advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, @@ -1780,9 +1785,9 @@ export async function selfTest() { const spec = OPS.pr_enqueue_front; const jump = (extra = {}) => ({ op: 'pr_enqueue_front', pull: 3686, expected_head_sha: SHA, ...extra }); const one = (action) => fixturePayload({ actions: [action] }); - t('the row: pull and expected_head_sha required, nothing optional, spending merge-queues, contents and workflows its alsoSpends, travelling alone, reaching no second repository', [spec.required, spec.optional, spec.permission, spec.alsoSpends, spec.alone, spec.secondRepo ?? null], [['pull', 'expected_head_sha'], [], 'merge-queues', ['contents', 'workflows'], true, null]); + t('the row: pull and expected_head_sha required, approval_comment the one optional key (the SIZE lift\'s carried approval), spending merge-queues, contents and workflows its alsoSpends, travelling alone, reaching no second repository', [spec.required, spec.optional, spec.permission, spec.alsoSpends, spec.alone, spec.secondRepo ?? null], [['pull', 'expected_head_sha'], ['approval_comment'], 'merge-queues', ['contents', 'workflows'], true, null]); const req = spec.requests(jump(), REPO); - t('its one request is the enqueuePullRequest mutation with jump true and expectedHeadOid, behind the pull\'s node id, carrying the pull and head the executor fences and reads back — and no landed state, since the answer is a queue entry', [req.length, req[0].verb, req[0].path, req[0].graphql.mutation, req[0].graphql.query === ENQUEUE_FRONT_MUTATION, ENQUEUE_FRONT_MUTATION.includes('jump: true'), ENQUEUE_FRONT_MUTATION.includes('expectedHeadOid: $head'), req[0].graphql.pull, req[0].graphql.landed ?? null, req[0].enqueueFront], [1, 'POST', '/graphql', 'enqueuePullRequest', true, true, true, 3686, null, { pull: 3686, expectedHeadSha: SHA }]); + t('its one request is the enqueuePullRequest mutation with jump true and expectedHeadOid, behind the pull\'s node id, carrying the pull and head the executor fences and reads back — and no landed state, since the answer is a queue entry', [req.length, req[0].verb, req[0].path, req[0].graphql.mutation, req[0].graphql.query === ENQUEUE_FRONT_MUTATION, ENQUEUE_FRONT_MUTATION.includes('jump: true'), ENQUEUE_FRONT_MUTATION.includes('expectedHeadOid: $head'), req[0].graphql.pull, req[0].graphql.landed ?? null, req[0].enqueueFront, spec.requests(jump({ approval_comment: 77 }), REPO)[0].enqueueFront.approvalComment], [1, 'POST', '/graphql', 'enqueuePullRequest', true, true, true, 3686, null, { pull: 3686, expectedHeadSha: SHA, approvalComment: null }, 77]); const ok = validatePayload(one(jump())); t('accepted: the minimal stroke, whose normalised action is op, pull and expected_head_sha alone', [ok.ok, ok.payload?.actions[0]], [true, { op: 'pr_enqueue_front', pull: 3686, expected_head_sha: SHA }], ok.errors.join(' | ')); t('⛔ refused: a missing expected_head_sha or pull — the head the seat accepted is named on every request, never defaulted', [refuses(one({ op: 'pr_enqueue_front', pull: 1 }), 'actions[0].expected_head_sha is required by `pr_enqueue_front`'), refuses(one({ op: 'pr_enqueue_front', expected_head_sha: SHA }), 'actions[0].pull is required by `pr_enqueue_front`')], [true, true]); @@ -1797,13 +1802,40 @@ export async function selfTest() { t('fence grant, accepted side: its stroke mints the five literal grants plus merge-queues write, for ONE repository, and the GitHub output says so', stroke ? [tokenPermissionsOf(stroke), tokenRepositoriesOf(stroke), outputLine(stroke, 'permission_merge_queues'), outputLine(stroke, 'permission_actions')] : 'refused', [{ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', 'merge-queues': 'write' }, [REPO], 'permission_merge_queues=write', 'permission_actions=']); const plain = validatePayload(fixturePayload()).payload; const landing = validatePayload(fixturePayload({ actions: [{ op: 'pr_ready', pull: 1 }, { op: 'automerge_enable', pull: 1 }] })).payload; - t('⛔ fence grant, refused side: a comment stroke and the back-of-queue landing pair write an EMPTY permission_merge_queues — the grant is this row\'s alone', [outputLine(plain, 'permission_merge_queues'), outputLine(landing, 'permission_merge_queues'), OP_NAMES.filter((op) => OPS[op].permission === 'merge-queues')], ['permission_merge_queues=', 'permission_merge_queues=', ['pr_enqueue_front']]); + t('⛔ fence grant, refused side: a comment stroke and the back-of-queue landing pair write an EMPTY permission_merge_queues — the grant is this row\'s and the dequeue\'s alone', [outputLine(plain, 'permission_merge_queues'), outputLine(landing, 'permission_merge_queues'), OP_NAMES.filter((op) => OPS[op].permission === 'merge-queues')], ['permission_merge_queues=', 'permission_merge_queues=', ['pr_enqueue_front', 'pr_dequeue']]); const repoRoot = resolve(SELF_PATH, '../../../..'); const workflowText = readFileSync(resolve(repoRoot, '.github/workflows/fleet-write.yml'), 'utf8'); t('fleet-write.yml mints permission-merge-queues from the validator\'s permission_merge_queues output, once, and never as a literal', [[...workflowText.matchAll(/^\s+permission-merge-queues:\s*\$\{\{\s*steps\.validate\.outputs\.permission_merge_queues\s*\}\}\s*$/gm)].length, /^\s+permission-merge-queues:\s*write\s*$/m.test(workflowText)], [1, false]); t('the fences this file cannot see are the executor\'s, named once in the op table: open, ready, head, release, governed, size, queue, one-jump', ENQUEUE_FRONT_FENCES.map((f) => f.fence), ['open', 'ready', 'head', 'release', 'governed', 'size', 'queue', 'one-jump']); } + // ── the pr_dequeue row ──────────────────────────────────────────────────── + battery("the pr_dequeue row: pull, expected_head_sha, a cause from the closed three and a bounded reason, and nothing that widens them; ONE dequeuePullRequest mutation behind the pull's node id; a stroke of exactly that one action; merge-queues write minted for that stroke, EMPTY for every other; contents and issues its literal alsoSpends; the fences on the pull, its queue and the cause named and left to the executor"); + { + const REPO = `${TARGET_OWNER}/objectstack`; + const spec = OPS.pr_dequeue; + const out = (extra = {}) => ({ op: 'pr_dequeue', pull: 3591, expected_head_sha: SHA, cause: 'conflict', reason: 'conflicts with main at the shared changeset', ...extra }); + const one = (action) => fixturePayload({ actions: [action] }); + t('the row: pull, expected_head_sha, cause and reason required, nothing optional, spending merge-queues, contents and issues its alsoSpends, travelling alone, reaching no second repository', [spec.required, spec.optional, spec.permission, spec.alsoSpends, spec.alone, spec.secondRepo ?? null], [['pull', 'expected_head_sha', 'cause', 'reason'], [], 'merge-queues', ['contents', 'issues'], true, null]); + const req = spec.requests(out(), REPO); + t('its one request is the dequeuePullRequest mutation behind the pull\'s node id, carrying the pull, head, cause and reason the executor fences, writes into the audit comment and reads back — no landed state, the answer is a queue entry', [req.length, req[0].verb, req[0].path, req[0].graphql.mutation, req[0].graphql.query === DEQUEUE_MUTATION, DEQUEUE_MUTATION.includes('dequeuePullRequest(input: { id: $id })'), req[0].graphql.pull, req[0].graphql.landed ?? null, req[0].dequeue], [1, 'POST', '/graphql', 'dequeuePullRequest', true, true, 3591, null, { pull: 3591, expectedHeadSha: SHA, cause: 'conflict', reason: 'conflicts with main at the shared changeset' }]); + const ok = validatePayload(one(out())); + t('accepted: each of the three causes, the normalised action carrying exactly the four keys', [...DEQUEUE_CAUSES.map((cause) => validatePayload(one(out({ cause }))).ok), Object.keys(ok.payload?.actions[0] ?? {})], [true, true, true, ['op', 'pull', 'expected_head_sha', 'cause', 'reason']], ok.errors.join(' | ')); + t('the causes are the queue card\'s three, closed', [...DEQUEUE_CAUSES], ['conflict', 'own-failure', 'seat-asks']); + t('⛔ refused: a cause outside the three — a flake, a speed-up or a free word never dequeues', ['flake', 'faster', 'other', ''].map((cause) => refuses(one(out({ cause })), 'actions[0].cause')), [true, true, true, true]); + t('⛔ refused: a missing cause, reason, head or pull — each named', ['cause', 'reason', 'expected_head_sha', 'pull'].map((key) => { const a = out(); delete a[key]; return refuses(one(a), `actions[0].${key} is required by \`pr_dequeue\``); }), [true, true, true, true]); + t('⛔ refused: a reason over its bound, a short head', [refuses(one(out({ reason: 'x'.repeat(MAX_DEQUEUE_REASON_BYTES + 1) })), 'actions[0].reason'), refuses(one(out({ expected_head_sha: SHA.slice(0, 7) })), 'actions[0].expected_head_sha')], [true, true]); + t('⛔ refused BY NAME: jump, branch, body or a second pull — no request-time key widens the fences', ['jump', 'branch', 'body', 'pulls'].map((key) => refuses(one(out({ [key]: 1 })), `actions[0].${key} is not a key \`pr_dequeue\` takes`)), [true, true, true, true]); + t('⛔ alone, refused: beside a comment, beside the jump and two of them', [ + refuses(fixturePayload({ actions: [{ op: 'comment', issue: 3591, body: 'x' }, out()] }), 'actions[0] is `comment` in a stroke that carries a `pr_dequeue`'), + refuses(fixturePayload({ actions: [out(), { op: 'pr_enqueue_front', pull: 3591, expected_head_sha: SHA }] }), 'pr_enqueue_front'), + refuses(fixturePayload({ actions: [out(), out({ pull: 3592 })] }), 'a stroke carries exactly ONE `pr_dequeue` and nothing else'), + ], [true, true, true]); + const stroke = ok.payload; + t('grant, accepted side: its stroke mints the five literal grants plus merge-queues write, for ONE repository', stroke ? [tokenPermissionsOf(stroke), tokenRepositoriesOf(stroke), outputLine(stroke, 'permission_merge_queues')] : 'refused', [{ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', 'merge-queues': 'write' }, [REPO], 'permission_merge_queues=write']); + t('the fences this file cannot see are the executor\'s, named once in the op table: open, head, release, queue, queued, cause', DEQUEUE_FENCES.map((f) => f.fence), ['open', 'head', 'release', 'queue', 'queued', 'cause']); + } + // ── the hierarchy rows ──────────────────────────────────────────────────── battery("the hierarchy rows: sub_issue_add and sub_issue_remove name a parent and a child by NUMBER — two different positive integers and nothing that widens them; one POST to the parent's sub_issues and one DELETE to its sub_issue, the body left to the executor; issues write, riding any stroke on the literal grants; the fences on the two cards, each accepted and refused — an issue on the repository, never a pull or a transferred card, the child free of any other parent or listed by this one; and the read-back's judgment by the child's id"); { @@ -2006,7 +2038,7 @@ export async function selfTest() { comment: { issue: 1, body: 'b' }, comment_edit: { comment_id: 1, body: 'b' }, labels_add: { issue: 1, labels: ['a'] }, labels_remove: { issue: 1, labels: ['a'] }, assign: { issue: 1, assignees: ['u'] }, unassign: { issue: 1, assignees: ['u'] }, issue_patch: { issue: 1, state: 'closed' }, issue_create: { title: 't', body: 'b' }, pr_create: { title: 't', head: 'h', base: 'main' }, pr_request_reviewers: { pull: 1, reviewers: ['u'] }, pr_update_branch: { pull: 1, expected_head_sha: SHA }, pr_ready: { pull: 1 }, pr_draft: { pull: 1 }, - automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, + automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, sub_issue_add: { issue: 1, sub_issue: 2 }, sub_issue_remove: { issue: 1, sub_issue: 2 }, workflow_dispatch: { workflow: WORKFLOW_DISPATCH_ALLOWLIST[0], ref: WORKFLOW_DISPATCH_REF }, run_rerun_failed: { run_id: 1 }, };