Skip to content

Commit 3645d92

Browse files
cliffhallclaude
andcommitted
fix(sdk-watch): refresh an open issue's rows and scope labels for the same target
While the registry target stays put, a server can upgrade on its own, be added, or move between SDK groups, and the open issue kept its original rows and server-<name> labels. The sweep now re-renders an OPEN issue for the current target and edits it when the body differs (a ticked checklist box alone is not a difference). Scope labels move only by the delta between the old body's rows and the new ones, so labels triage or a maintainer applied or removed are kept. A closed issue is left alone. The sweep writer's edit gains --add-label / --remove-label, applied one by one so it never replaces the label set. Closes modelcontextprotocol#5067 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 82acf2a commit 3645d92

4 files changed

Lines changed: 347 additions & 23 deletions

File tree

‎scripts/lib/sweep.mjs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,31 @@ export function issueWriter({
386386
return { url, number };
387387
},
388388
/**
389+
* Labels are changed one by one, never replaced as a set, so a label
390+
* someone else applied survives an edit that does not name it.
391+
*
389392
* @param {number} number
390-
* @param {{title?: string, body: string}} change
393+
* @param {{title?: string, body: string, addLabels?: string[], removeLabels?: string[]}} change
391394
*/
392-
edit(number, { title, body }) {
395+
edit(number, { title, body, addLabels = [], removeLabels = [] }) {
393396
if (dryRun) {
394-
show(`edit #${number}`, { title }, body);
397+
show(
398+
`edit #${number}`,
399+
{
400+
title,
401+
"add labels": addLabels.length ? addLabels.join(", ") : undefined,
402+
"remove labels": removeLabels.length
403+
? removeLabels.join(", ")
404+
: undefined,
405+
},
406+
body,
407+
);
395408
return;
396409
}
397410
const args = ["issue", "edit", String(number), "--repo", repo];
398411
if (title !== undefined) args.push("--title", title);
412+
for (const label of addLabels) args.push("--add-label", label);
413+
for (const label of removeLabels) args.push("--remove-label", label);
399414
args.push("--body-file", "-");
400415
run(args, body, "gh issue edit");
401416
},

‎scripts/lib/sweep.test.mjs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,42 @@ test("issueWriter writes through gh with bodies on stdin", () => {
299299
assert.equal(calls[3].input, "C");
300300
});
301301

302+
test("issueWriter edits labels one by one, never as a set", () => {
303+
const { spawn, calls } = fakeSpawn(() => ({ status: 0 }));
304+
const writer = issueWriter({ repo: "o/r", spawn, sweep: "s", log: () => {} });
305+
writer.edit(7, {
306+
body: "B",
307+
addLabels: ["server-git"],
308+
removeLabels: ["server-time", "server-fetch"],
309+
});
310+
assert.deepEqual(calls[0].args, [
311+
"issue",
312+
"edit",
313+
"7",
314+
"--repo",
315+
"o/r",
316+
"--add-label",
317+
"server-git",
318+
"--remove-label",
319+
"server-time",
320+
"--remove-label",
321+
"server-fetch",
322+
"--body-file",
323+
"-",
324+
]);
325+
assert.ok(!calls[0].args.includes("--label"));
326+
327+
const lines = [];
328+
issueWriter({
329+
repo: "o/r",
330+
spawn: () => assert.fail("a dry run must not spawn"),
331+
dryRun: true,
332+
sweep: "s",
333+
log: (line) => lines.push(line),
334+
}).edit(7, { body: "B", addLabels: ["a"], removeLabels: ["b"] });
335+
assert.match(lines.join("\n"), /add labels: a\nremove labels: b/);
336+
});
337+
302338
test("issueWriter create without a milestone omits the flag", () => {
303339
const { spawn, calls } = fakeSpawn(() => ({
304340
status: 0,

‎scripts/sdk-watch.mjs‎

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
// FURTHER release files a new issue and leaves a supersession comment on the
4848
// older open one; it never closes it.
4949
//
50+
// An OPEN issue for the current target is kept current (#5067): while the
51+
// target stays put, a server can upgrade on its own, be added, or move
52+
// between groups (the v1 -> v2 migration), and the issue would otherwise
53+
// keep pointing at servers with no work left. Its body is re-rendered and
54+
// rewritten when it differs, as the monthly refresh does, except that a
55+
// ticked checklist box alone is not a difference. Its scope labels move by
56+
// the DELTA between what the old body's rows called for and what the new
57+
// rows do, so a label triage or a maintainer applied, or removed, stays as
58+
// they left it. A closed issue is left alone.
59+
//
5060
// "An issue exists" and "it was analyzed" are different claims. The workflow
5161
// stamps `ANALYSIS_MARKER` on its comment, and an OPEN issue for the current
5262
// target with no such comment from the automation is handed to the analysis
@@ -270,6 +280,20 @@ export function buildIssueTitle(state) {
270280
return `chore(deps): upgrade the ${state.group.label} to ${state.target}`;
271281
}
272282

283+
/**
284+
* The scope labels for the places a copy is behind, or none when that is
285+
* every server (the issue is then repository-wide).
286+
*
287+
* @param {string[]} wheres each behind row's `where`
288+
* @returns {string[]}
289+
*/
290+
function scopesFor(wheres) {
291+
const scopes = [
292+
...new Set(wheres.map((w) => scopeLabel(`${w}/`)).filter(Boolean)),
293+
].sort();
294+
return scopes.length === SERVERS.length ? [] : scopes;
295+
}
296+
273297
/**
274298
* Labels: the sweep's, plus each server with a copy that is BEHIND (a server
275299
* already at the target has no work here), unless that is every server (then
@@ -278,17 +302,55 @@ export function buildIssueTitle(state) {
278302
* @param {NonNullable<ReturnType<typeof groupState>>} state
279303
*/
280304
export function issueLabels(state) {
281-
const scopes = [
282-
...new Set(
283-
state.rows
284-
.filter((r) => r.behind)
285-
.map((r) => scopeLabel(`${r.where}/`))
286-
.filter(Boolean),
287-
),
288-
].sort();
289-
return scopes.length === SERVERS.length
290-
? [...SWEEP_LABELS]
291-
: [...SWEEP_LABELS, ...scopes];
305+
return [
306+
...SWEEP_LABELS,
307+
...scopesFor(state.rows.filter((r) => r.behind).map((r) => r.where)),
308+
];
309+
}
310+
311+
/** A row of the table `buildIssueBody` writes: its `where`, and `Behind`. */
312+
const ROW_RE = /^\| `.*?` \| `([^`]*)` \|.*\| (\*\*yes\*\*|no) \|$/gm;
313+
314+
/**
315+
* The scope labels an issue body's rows called for when the sweep wrote it,
316+
* read back from its table.
317+
*
318+
* @param {string | undefined} body
319+
* @returns {string[]}
320+
*/
321+
export function bodyScopes(body) {
322+
return scopesFor(
323+
[...(body ?? "").matchAll(ROW_RE)]
324+
.filter((m) => m[2] === "**yes**")
325+
.map((m) => m[1]),
326+
);
327+
}
328+
329+
/** A body with every checklist box unticked, so ticking one is not a change. */
330+
const unticked = (body) => (body ?? "").replace(/^- \[[xX]\]/gm, "- [ ]");
331+
332+
/**
333+
* What an OPEN issue for the current target needs to match the current
334+
* state, or `null` when it already does. Labels move only by the delta
335+
* between the old body's rows and the new ones, so labels the sweep did not
336+
* apply (or that someone removed) are left as they are.
337+
*
338+
* @param {{body?: string, labels?: Array<{name?: string}>}} issue
339+
* @param {NonNullable<ReturnType<typeof groupState>>} state
340+
* @returns {{body: string, addLabels: string[], removeLabels: string[]} | null}
341+
*/
342+
export function refreshPlan(issue, state) {
343+
const body = buildIssueBody(state);
344+
// Labels follow the rows, so an unchanged body means unchanged labels.
345+
if (unticked(issue.body) === unticked(body)) return null;
346+
const had = new Set((issue.labels ?? []).map((l) => l?.name));
347+
const before = bodyScopes(issue.body);
348+
const after = bodyScopes(body);
349+
return {
350+
body,
351+
addLabels: after.filter((l) => !before.includes(l) && !had.has(l)),
352+
removeLabels: before.filter((l) => !after.includes(l) && had.has(l)),
353+
};
292354
}
293355

294356
/**
@@ -643,6 +705,19 @@ export function main({
643705
// OPEN only: a closed issue keeps suppressing its target, and must not
644706
// be handed a fresh analysis every night.
645707
if (match && match.state === "OPEN") {
708+
const refresh = refreshPlan(match, state);
709+
if (refresh) {
710+
writer.edit(number, refresh);
711+
log(
712+
`${SWEEP}: refreshed #${number} for what is installed now` +
713+
(refresh.addLabels.length
714+
? `; added ${refresh.addLabels.join(", ")}`
715+
: "") +
716+
(refresh.removeLabels.length
717+
? `; removed ${refresh.removeLabels.join(", ")}`
718+
: ""),
719+
);
720+
}
646721
if (hasAnalysis(issueComments(repo, number, spawn))) {
647722
log(
648723
`${SWEEP}: ${state.group.label} ${state.target} has an issue and an analysis; no-op`,

0 commit comments

Comments
 (0)