Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 15 additions & 2 deletions .github/workflows/pr-self-report-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,31 @@ jobs:
HAS_LABEL="$(gh pr view "${PR}" --repo "${REPO}" --json labels \
--jq "[.labels[].name] | index(\"${LABEL}\") != null" 2> /dev/null || echo 'false')"

# Label mutations go through REST, NOT `gh pr edit`: that command's
# GraphQL lookup requests repository.pullRequest.projectCards, and
# GitHub answers the Projects (classic) deprecation as an ERROR on
# the gh builds that still send that query — this job's runner
# image does, so `gh pr edit` exits 1 before mutating anything.
# Every add/remove path of this job failed that way from
# 2026-08-04 on (43 runs); the green runs were all the no-change
# arm. REST never touches that query.
if [[ "${SELF}" == 'true' && "${HAS_LABEL}" != 'true' ]]; then
# Create the label on first use (idempotent), then apply it.
gh label create "${LABEL}" --repo "${REPO}" --color 'BFD4F2' \
--description 'The linked issue was opened by the PR author (self-reported)' \
2> /dev/null || true
gh pr edit "${PR}" --repo "${REPO}" --add-label "${LABEL}"
gh api -X POST "repos/${REPO}/issues/${PR}/labels" -f "labels[]=${LABEL}" > /dev/null
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo "🏷️ #${PR}: added ${LABEL} — a closed issue was opened by ${PR_AUTHOR}"
elif [[ "${SELF}" != 'true' && "${HAS_LABEL}" == 'true' && "${API_OK}" == 'true' ]]; then
# The link was removed or re-pointed to someone else's issue — clear
# the now-stale label so it never lies. Only when the query itself
# succeeded: an API failure must not look like "no self-reported link".
gh pr edit "${PR}" --repo "${REPO}" --remove-label "${LABEL}"
# The label name is a PATH SEGMENT here, and it contains a slash —
# unencoded, the request hits …/labels/review/self-reported (404).
# `|| true`: the presence check above is not atomic with this
# DELETE — if the label was removed in the gap, the 404 only says
# the desired end state already holds and must not fail the step.
gh api -X DELETE "repos/${REPO}/issues/${PR}/labels/$(jq -rn --arg l "${LABEL}" '$l|@uri')" > /dev/null || true
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo "🏷️ #${PR}: removed ${LABEL} — no self-reported linked issue"
else
echo "#${PR}: no change (self=${SELF}, labeled=${HAS_LABEL}, api=${API_OK})"
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,14 @@ jobs:
gh pr comment "${PR}" --repo "${REPO}" --body "$(printf '🔄 Takeover re-armed: the round counter starts a fresh window (previous rounds no longer count toward the cap); management continues.\n\n<details>\n<summary>中文说明</summary>\n\n🔄 已重新武装:轮次计数开启新窗口(此前轮次不再计入上限),托管继续。\n\n</details>\n\n<!-- takeover-ack engaged -->')"
echo "🔄 re-armed ${TAKEOVER_LABEL} window on #${PR}"
else
gh pr edit "${PR}" --repo "${REPO}" --add-label "${TAKEOVER_LABEL}"
# REST for consistency and runner-version independence: `gh pr
# edit`'s GraphQL lookup requests
# repository.pullRequest.projectCards, which GitHub rejects on
# the gh builds that still send that query (demonstrated on the
# ECS pool — see pr-self-report-label.yml). This job runs on
# ubuntu-latest, where the command still worked; REST behaves
# the same on every runner image.
gh api -X POST "repos/${REPO}/issues/${PR}/labels" -f "labels[]=${TAKEOVER_LABEL}" > /dev/null
Comment thread
wenshao marked this conversation as resolved.
Resolved
echo "🏷️ applied ${TAKEOVER_LABEL} to #${PR}"
# Ack HERE, not via the pull_request:labeled round-trip: that
# event has been observed to simply not fire (#7999 — the
Expand All @@ -1759,7 +1766,12 @@ jobs:
if [[ "${HAS}" != 'true' ]]; then
echo "ℹ️ #${PR} does not carry ${TAKEOVER_LABEL} — nothing to do"
else
gh pr edit "${PR}" --repo "${REPO}" --remove-label "${TAKEOVER_LABEL}"
# REST for the same reason as the add above; the label name is a
# path segment and contains a slash, so it must be URI-encoded.
# `|| true`: a concurrent removal between the presence check
# and this DELETE already reached the end state — the 404 must
# not abort the step and drop the release ack below.
gh api -X DELETE "repos/${REPO}/issues/${PR}/labels/$(jq -rn --arg l "${TAKEOVER_LABEL}" '$l|@uri')" > /dev/null || true
echo "🏷️ removed ${TAKEOVER_LABEL} from #${PR}"
# Release ack, direct from the command — the exact mirror of
# the engage side above, for the same reason: the unlabeled
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/repo-hygiene.yml
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,21 @@ jobs:

# Label requested by issue #7383. Non-fatal: never create labels,
# and a repo without it should not fail the run.
gh pr edit "${PR_URL}" --add-label 'autofix/repo-hygiene' \
|| echo '⚠️ Could not add label autofix/repo-hygiene (missing in this repo?)'
# REST, not `gh pr edit`: its GraphQL lookup requests
# repository.pullRequest.projectCards, which GitHub rejects on the
# gh builds that still send that query (see
# pr-self-report-label.yml). The label autofix/repo-hygiene has
# never been created in this repo, and the existence probe
# preserves the no-create promise: the REST add alone would create
# a missing label. The probe cannot tell a 404 from any other API
# failure, so the skip message claims neither.
if gh api "repos/${GITHUB_REPOSITORY}/labels/autofix%2Frepo-hygiene" > /dev/null 2>&1; then
Comment thread
wenshao marked this conversation as resolved.
Resolved
gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR_URL##*/}/labels" \
Comment thread
wenshao marked this conversation as resolved.
Resolved
-f 'labels[]=autofix/repo-hygiene' > /dev/null \
|| echo '⚠️ Could not add label autofix/repo-hygiene'
else
echo '⚠️ Could not verify label autofix/repo-hygiene; skipping'
fi

if [[ -s "${WORKDIR}/report-only.md" ]]; then
{
Expand Down
72 changes: 70 additions & 2 deletions scripts/tests/pr-self-report-label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
existsSync,
mkdirSync,
mkdtempSync,
readdirSync,
readFileSync,
rmSync,
writeFileSync,
Expand Down Expand Up @@ -38,6 +39,24 @@ const GH_STUB = [
'exit 0',
].join('\n');

// The replayed DELETE URI-encodes the slashed label with a REAL jq — stub it
// on PATH like gh so the suite never depends on the host having jq (a fresh
// macOS has none, and the %2F assertion would fail opaquely). Supports only
// the one form the workflow executes: jq -rn --arg NAME VALUE '$NAME|@uri'.
const JQ_STUB = [
'#!/usr/bin/env bash',
'value=""',
'while [[ $# -gt 0 ]]; do',
' if [[ "$1" == "--arg" ]]; then value="$3"; shift 3; else shift; fi',
Comment thread
wenshao marked this conversation as resolved.
Resolved
'done',
'out=""',
'for ((i = 0; i < ${#value}; i++)); do',
' c="${value:i:1}"',
' if [[ "$c" =~ [A-Za-z0-9._~-] ]]; then out+="$c"; else printf -v hex \'%02X\' "\'$c"; out+="%$hex"; fi',
'done',
'printf \'%s\' "$out"',
].join('\n');

describe('pr-self-report-label', () => {
const run = ({
prAuthor = 'alice',
Expand All @@ -51,6 +70,8 @@ describe('pr-self-report-label', () => {
const callsLog = join(dir, 'calls.log');
writeFileSync(join(bin, 'gh'), GH_STUB);
chmodSync(join(bin, 'gh'), 0o755);
writeFileSync(join(bin, 'jq'), JQ_STUB);
chmodSync(join(bin, 'jq'), 0o755);
const out = execFileSync('bash', ['-c', runBlock], {
env: {
...process.env,
Expand All @@ -69,8 +90,21 @@ describe('pr-self-report-label', () => {
const calls = existsSync(callsLog) ? readFileSync(callsLog, 'utf8') : '';
rmSync(dir, { recursive: true, force: true });
return {
added: /add-label/.test(calls),
removed: /remove-label/.test(calls),
// Label mutations are REST — `gh pr edit`'s GraphQL lookup requests
// repository.pullRequest.projectCards, which GitHub rejects on the gh
// builds that still send it (this job's runner image does), so it
// exits 1 before mutating (43 straight CI failures of the add/remove
// arms, 2026-08-04..08). The full method + path is asserted,
// including the %2F: the label is a PATH SEGMENT in the DELETE and
// contains a slash, so an unencoded call 404s.
added:
/api -X POST repos\/o\/r\/issues\/1\/labels -f labels\[\]=review\/self-reported/.test(
calls,
),
Comment thread
wenshao marked this conversation as resolved.
Resolved
removed:
/api -X DELETE repos\/o\/r\/issues\/1\/labels\/review%2Fself-reported/.test(
Comment thread
wenshao marked this conversation as resolved.
Resolved
calls,
),
labelCreated: /label create/.test(calls),
out: out.trim(),
};
Expand Down Expand Up @@ -130,3 +164,37 @@ describe('pr-self-report-label', () => {
expect(runBlock).not.toMatch(/\$\{\{/);
});
});

describe('gh pr edit label mutations are banned in workflow files', () => {
// `gh pr edit` label mutations fail wherever the gh build still requests
// repository.pullRequest.projectCards: GitHub answers the Projects
// (classic) deprecation as an error and the command exits 1 before
// applying the change. Three workflows carried label mutations through it
// and every such arm failed silently-green (the runs only passed when
// there was nothing to do) or warned with a misdiagnosis. Labels go
// through the REST issues/labels endpoints, which never touch that query.
// Scope is workflow YAML: .github/scripts/classify-release-notes.mjs still
// toggles skip-changelog-auto through `gh pr edit` on the release path and
// needs its own conversion.
it('no workflow mutates labels through gh pr edit', () => {
const dir = '.github/workflows';
const files = readdirSync(dir).filter((f) => /\.ya?ml$/.test(f));
expect(files.length).toBeGreaterThan(0);
const offenders = [];
for (const file of files) {
// Join backslash continuations first: `.` does not span newlines, so a
// wrapped `gh pr edit … \` with the label flag on the next line would
// otherwise slip past the per-line scan.
const text = readFileSync(join(dir, file), 'utf8').replace(
/\\\n\s*/g,
' ',
);
Comment thread
wenshao marked this conversation as resolved.
Resolved
for (const [i, line] of text.split('\n').entries()) {
Comment thread
wenshao marked this conversation as resolved.
Resolved
if (/gh pr edit .*(--add-label|--remove-label)/.test(line)) {
Comment thread
wenshao marked this conversation as resolved.
Resolved
offenders.push(`${file}:${i + 1}`);
}
}
}
expect(offenders).toEqual([]);
});
});
45 changes: 29 additions & 16 deletions scripts/tests/qwen-autofix-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3276,7 +3276,7 @@ describe('qwen-autofix workflow', () => {
// no-op, a skip-labeled add refuses, and a fork refuses — neither posts
// a toggle.
const toggle = workflow.match(
/(if ! PR_INFO="\$\(gh pr view[\s\S]*?— nothing to do"\n {12}else\n {14}gh pr edit "\$\{PR\}" --repo "\$\{REPO\}" --remove-label "\$\{TAKEOVER_LABEL\}"\n[\s\S]*?\n {10}fi)/,
/(if ! PR_INFO="\$\(gh pr view[\s\S]*?— nothing to do"\n {12}else\n[\s\S]*?gh api -X DELETE "repos\/\$\{REPO\}\/issues\/\$\{PR\}\/labels\/[\s\S]*?\n {10}fi)/,
)?.[1];
expect(toggle).toBeTruthy();
const runToggle = ({
Expand Down Expand Up @@ -3305,7 +3305,9 @@ describe('qwen-autofix workflow', () => {
'#!/bin/bash',
`if [[ "$1" == "api" && "$2" == */collaborators/*/permission ]]; then printf '%s' '${authorPerm}';`,
`elif [[ "$1" == "pr" && "$2" == "view" ]]; then printf '%s' '${prJson}';`,
`elif [[ "$1" == "pr" && "$2" == "edit" ]]; then echo "EDIT $*" >> '${join(dir, 'writes.log')}';`,
// Label mutations are REST gh api calls (gh pr edit's
// projectCards lookup errors on older gh builds); record them.
`elif [[ "$1" == "api" ]]; then echo "API $*" >> '${join(dir, 'writes.log')}';`,
Comment thread
wenshao marked this conversation as resolved.
Resolved
`elif [[ "$1" == "pr" && "$2" == "comment" ]]; then echo "COMMENT $*" >> '${join(dir, 'writes.log')}';`,
'fi',
].join('\n'),
Expand Down Expand Up @@ -3345,22 +3347,27 @@ describe('qwen-autofix workflow', () => {
// (#7999, #8002), so the user-visible ack cannot depend on that
// round-trip. In-repo PRs get no fork note.
const addAbsent = runToggle({ cmd: 'add' });
expect(addAbsent.writes).toContain('EDIT pr edit 7165');
expect(addAbsent.writes).toContain('--add-label');
expect(addAbsent.writes).toContain(
'API api -X POST repos/QwenLM/qwen-code/issues/7165/labels',
);
expect(addAbsent.writes).toContain('labels[]=autofix/takeover');
expect(addAbsent.writes).toContain('<!-- takeover-ack engaged -->');
expect(addAbsent.writes).not.toContain('next scheduled scan');
expect(addAbsent.writes).not.toContain('定时扫描');
// add + present → re-arm ack, label untouched.
const rearm = runToggle({ cmd: 'add', labels: ['autofix/takeover'] });
expect(rearm.writes).toContain('COMMENT');
expect(rearm.writes).not.toContain('EDIT');
expect(rearm.writes).not.toContain('API');
expect(rearm.log).toContain('re-armed');
// remove + present → label removed.
// remove + present → label removed, through the URI-encoded path segment
// (real jq runs in the substitution, so the %2F is the executed truth).
const removePresent = runToggle({
cmd: 'remove',
labels: ['autofix/takeover'],
});
expect(removePresent.writes).toContain('--remove-label');
expect(removePresent.writes).toContain(
'API api -X DELETE repos/QwenLM/qwen-code/issues/7165/labels/autofix%2Ftakeover',
);
// Release acks directly too — the exact mirror of the engage side: a
// loud add next to a mute stop re-creates the lost-event ambiguity on
// the release side (and fork/non-main releases have no other ack path
Expand Down Expand Up @@ -3390,14 +3397,14 @@ describe('qwen-autofix workflow', () => {
// skip present vetoes engagement — refusal comment, never a toggle.
const skipBlocked = runToggle({ cmd: 'add', labels: ['autofix/skip'] });
expect(skipBlocked.writes).toContain('COMMENT');
expect(skipBlocked.writes).not.toContain('EDIT');
expect(skipBlocked.writes).not.toContain('API');
// Fork WITHOUT allow-edits refuses with the actionable ask, never
// toggling; fork WITH allow-edits is fully manageable and toggles.
const forkRefused = runToggle({ cmd: 'add', fork: true, canModify: false });
expect(forkRefused.writes).toContain('COMMENT');
expect(forkRefused.writes).not.toContain('EDIT');
expect(forkRefused.writes).not.toContain('API');
const forkManaged = runToggle({ cmd: 'add', fork: true });
expect(forkManaged.writes).toContain('--add-label');
expect(forkManaged.writes).toContain('labels[]=autofix/takeover');
// Fork label events carry no secrets, so no other job could ever ack a
// fork engage — the command's own ack is the ONLY one, and it sets the
// expectation that the first round comes from the next scheduled scan.
Expand All @@ -3417,7 +3424,7 @@ describe('qwen-autofix workflow', () => {
// nothing ever manages it) — the command refuses with the adoption ask.
const forkGhost = runToggle({ cmd: 'add', fork: true, authorPerm: 'read' });
expect(forkGhost.writes).toContain('COMMENT');
expect(forkGhost.writes).not.toContain('EDIT');
expect(forkGhost.writes).not.toContain('API');
expect(forkGhost.log).toContain('below write');
// Release is NEVER blocked by engage-side fork requirements: stop on an
// allow-edits-revoked fork still removes the label.
Expand All @@ -3427,7 +3434,9 @@ describe('qwen-autofix workflow', () => {
canModify: false,
labels: ['autofix/takeover'],
});
expect(forkStop.writes).toContain('--remove-label');
expect(forkStop.writes).toContain(
'API api -X DELETE repos/QwenLM/qwen-code/issues/7165/labels/autofix%2Ftakeover',
);
// Fork unlabeled events carry no secrets, so this is the ONLY possible
// release ack for a fork — it must post here.
expect(forkStop.writes).toContain('<!-- takeover-ack released -->');
Expand All @@ -3436,7 +3445,7 @@ describe('qwen-autofix workflow', () => {
const stacked = runToggle({ cmd: 'add', base: 'feat/base-pr' });
expect(stacked.writes).toContain('<!-- takeover-ack base-refused -->');
expect(stacked.writes).toContain('`feat/base-pr`');
expect(stacked.writes).not.toContain('EDIT');
expect(stacked.writes).not.toContain('API');
// …but a stop on a non-main PR PROCEEDS: removing a stuck label is
// harmless and matches the latest intent (previously dropped, leaving a
// manually-applied label with no command able to remove it).
Expand All @@ -3445,7 +3454,9 @@ describe('qwen-autofix workflow', () => {
base: 'feat/base-pr',
labels: ['autofix/takeover'],
});
expect(stackedStop.writes).toContain('--remove-label');
expect(stackedStop.writes).toContain(
'API api -X DELETE repos/QwenLM/qwen-code/issues/7165/labels/autofix%2Ftakeover',
);
// A non-main release never reaches the ack job (route ignores it), so
// the command's own ack is the only voice here too.
expect(stackedStop.writes).toContain('<!-- takeover-ack released -->');
Expand Down Expand Up @@ -4428,9 +4439,11 @@ exit 1
expect(cmdBranch).toBeTruthy();
expect(cmdBranch).not.toContain('DO_REVIEW=true');
expect(cmdBranch).toContain('TAKEOVER_CMD="${CMD}"');
// The toggle job is presence-aware and PAT-verified.
// The toggle job is presence-aware and PAT-verified. Label mutations
// are REST — on older gh builds `gh pr edit` exits 1 on its projectCards
// lookup.
expect(workflow).toMatch(
/takeover-command:[\s\S]*?CI_DEV_BOT_PAT identity[\s\S]*?--add-label "\$\{TAKEOVER_LABEL\}"[\s\S]*?--remove-label "\$\{TAKEOVER_LABEL\}"/,
/takeover-command:[\s\S]*?CI_DEV_BOT_PAT identity[\s\S]*?-f "labels\[\]=\$\{TAKEOVER_LABEL\}"[\s\S]*?gh api -X DELETE "repos\/\$\{REPO\}\/issues\/\$\{PR\}\/labels\//,
);
// No other command surface exists.
expect(workflow).not.toContain('pull_request_review_comment');
Expand Down
Loading
Loading