Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Fixed

- The issue lane's in-slot re-check (`check-blockers.mjs` with `RECHECK=true`) now reads the issue before its blocked_by list, so a session-owned, container or wayfind label, or a `provenance: untrusted` label, added while the run waited for its slot stops the run as admission does. Before, an empty blocked_by list let the run proceed without looking at the issue's labels.
21 changes: 12 additions & 9 deletions .github/scripts/work-resolve-issue/check-blockers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
//
// With RECHECK=true it is the read runner's in-slot re-check
// (pr-run-activity-read.yml check-broker), after admission passed and the run
// waited for its slot: one read of the blocked_by list decides when the list
// is empty (proceed) or names an open blocker (blocked, as above). A list of
// closed blockers alone takes the full check, since only it judges who
// closed them.
// waited for its slot. It reads the issue first: a map or untrusted label on
// it, added while the run waited, takes the full check, as admission does
// (https://github.com/melodic-software/claude-code-plugins/issues/18061).
// Otherwise one read of the blocked_by list decides when the list is empty
// (proceed) or names an open blocker (blocked, as above). A list of closed
// blockers alone takes the full check, since only it judges who closed them.
//
// Environment:
// GH_TOKEN the job's GITHUB_TOKEN (issues: read)
Expand Down Expand Up @@ -114,22 +116,23 @@ export async function main({ env = process.env, github, log = console.log, write
const { humans } = loadTrustedList(env.TRUSTED_ACTORS_PATH);
const client = github ?? createGitHub({ token: env.GH_TOKEN, apiUrl: env.GITHUB_API_URL || undefined });
const base = `/repos/${repository}/issues/${number}`;
if (env.RECHECK === "true") {
const issue = await client("GET", base);
const routing = readRouting(join(env.BASE_PATH || ".base", "docs/conventions/work-items.yaml"), { who: "check-blockers", log });
const labels = (issue?.labels ?? []).map((label) => String(label?.name ?? label));
const isApp = (actor) => actor?.id === appId;
if (env.RECHECK === "true" && !routingLabel(labels, routing) && !untrustedHold({ labels: issue?.labels, events: [], humans, isApp })) {
const blockers = await blockersOf(client, base);
pending = await stillBlocking(blockers, repository, async () => true, async () => true);
rechecked = blockers.length === 0 || pending.length > 0;
subs = [];
}
if (!rechecked) {
const issue = await client("GET", base);
const routing = readRouting(join(env.BASE_PATH || ".base", "docs/conventions/work-items.yaml"), { who: "check-blockers", log });
const trust = await authorTrust(client, repository, issue, humans, appId);
outsider = trust === null;
drift = trust === "drift";
const events = outsider ? [] : await statusReader({ env, github: client, repository, log }).events(Number(number));
const isApp = (actor) => actor?.id === appId;
held = !outsider && untrustedHold({ labels: issue?.labels, events, humans, isApp });
routed = outsider || held ? null : routingLabel((issue?.labels ?? []).map((label) => String(label?.name ?? label)), routing);
routed = outsider || held ? null : routingLabel(labels, routing);
if (!outsider && !held && !routed) {
// The same close admission counts (admit.mjs closedByTrusted), so a split
// parent the lanes App closed does not hold an issue admission let through.
Expand Down
30 changes: 22 additions & 8 deletions .github/scripts/work-resolve-issue/check-blockers.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import assert from "node:assert/strict";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { after, describe, test } from "node:test";

import { renderSplitRecord, SIZE_SPLIT_MARKER } from "../intake-triage/admit.mjs";
Expand All @@ -17,7 +18,7 @@ after(() => rmSync(dir, { recursive: true, force: true }));
const TRUSTED = join(dir, "trusted-actors.json");
writeFileSync(TRUSTED, JSON.stringify({ version: 1, actors: [{ kind: "human", id: HUMAN.id, login: HUMAN.login }] }));
// BASE_PATH: the checkout whose models.issue-status the field read takes.
const ENV = { GITHUB_REPOSITORY: "o/r", ISSUE_NUMBER: "42", TRUSTED_ACTORS_PATH: TRUSTED, LANES_APP_ID: String(APP.id), BASE_PATH: new URL("../../..", import.meta.url).pathname };
const ENV = { GITHUB_REPOSITORY: "o/r", ISSUE_NUMBER: "42", TRUSTED_ACTORS_PATH: TRUSTED, LANES_APP_ID: String(APP.id), BASE_PATH: fileURLToPath(new URL("../../..", import.meta.url)) };

const issue = (number, state, { repo = "o/r", reason = state === "closed" ? "completed" : null, closer = HUMAN } = {}) => ({
number,
Expand Down Expand Up @@ -437,26 +438,28 @@ test("a blocker someone other than the lanes App closed blocks even with an olde
});

// The read runner's in-slot re-check (RECHECK=true): a blocker added while
// the run waited for its slot stops it as admission's blocker gate does, on
// one blocked_by read; a list of closed blockers takes the full check.
// the run waited for its slot stops it as admission's blocker gate does; a
// map or untrusted label added in that wait, or a list of closed blockers,
// takes the full check (https://github.com/melodic-software/claude-code-plugins/issues/18061).
describe("the in-slot re-check", () => {
const RECHECK = { ...ENV, RECHECK: "true" };
const RECHECK_RUN = { proceed: "true", untrusted: "false" };
const TWO_READS = ["GET /repos/o/r/issues/42", "GET /repos/o/r/issues/42/dependencies/blocked_by?per_page=100&page=1"];

test("no blocker proceeds on the one blocked_by read", async () => {
test("no blocker proceeds on the issue read and the one blocked_by read", async () => {
const { code, calls, outputs } = await run([], { env: RECHECK });
assert.equal(code, 0);
assert.deepEqual(outputs, RECHECK_RUN);
assert.deepEqual(calls, ["GET /repos/o/r/issues/42/dependencies/blocked_by?per_page=100&page=1"]);
assert.deepEqual(calls, TWO_READS);
});

test("an open blocker added since admission stops the run as admission does, on the one read, with the same notice", async () => {
test("an open blocker added since admission stops the run as admission does, on the two reads, with the same notice", async () => {
const admitted = await run([issue(7, "open")]);
const { code, calls, lines, outputs } = await run([issue(7, "open"), issue(8, "closed")], { env: RECHECK });
assert.equal(code, 0);
assert.deepEqual(outputs, SKIP);
assert.deepEqual(outputs, admitted.outputs);
assert.deepEqual(calls, ["GET /repos/o/r/issues/42/dependencies/blocked_by?per_page=100&page=1"]);
assert.deepEqual(calls, TWO_READS);
const notice = lines.find((line) => line.startsWith("::notice"));
assert.match(notice, /^::notice title=blocked::/);
assert.match(notice, /#7/);
Expand All @@ -466,7 +469,18 @@ describe("the in-slot re-check", () => {
assert.deepEqual((await run([issue(8, "closed")], { env: RECHECK })).outputs, RUN);
const stranger = await run([issue(7, "closed", { closer: STRANGER })], { env: RECHECK });
assert.deepEqual(stranger.outputs, SKIP);
assert.ok(stranger.calls.includes("GET /repos/o/r/issues/42"), "the full check reads the issue");
assert.ok(stranger.calls.some((call) => call.startsWith("GET /repos/o/r/issues/42/events")), "the full check reads the events");
});

test("a session-owned label added while the run waited skips it as admission does, before any blocker read", async () => {
const { calls, lines, outputs } = await run([], { env: RECHECK, subject: { labels: ["agent-ready", "session-owned"] } });
assert.deepEqual(outputs, SKIP);
assert.ok(!calls.some((call) => call.includes("/dependencies/")), calls.join("\n"));
assert.match(lines.find((line) => line.startsWith("::notice")), /^::notice title=map issue::the run is skipped: the issue carries 'session-owned'/);
});

test("an untrusted label added while the run waited stops it for good", async () => {
assert.deepEqual((await run([], { env: RECHECK, subject: { labels: ["agent-ready", UNTRUSTED] } })).outputs, FINAL);
});

test("a blocked_by read that fails stops the run with a warning, not for good", async () => {
Expand Down
Loading