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
199 changes: 199 additions & 0 deletions .github/scripts/ci-runner-routing.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// Runner-routing regression guards for ci.yml and serve-ab.yml.
//
// classify_pr carries the routing logic TWICE — the `runs-on` expression
// (which selects the classify job's own runner) and the `pick_runner` shell
// step (which publishes `ubuntu_runner` for every downstream Linux job). If
// they drift, classify and the Test job land on different pools. These tests
// evaluate BOTH against the same event matrix — including the negative
// associations that must stay hosted — and assert they agree.
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import { parse } from 'yaml';

const workflowsDir = join(
dirname(fileURLToPath(import.meta.url)),
'..',
'workflows',
);
const ciDoc = parse(readFileSync(join(workflowsDir, 'ci.yml'), 'utf8'));
const serveAbDoc = parse(
readFileSync(join(workflowsDir, 'serve-ab.yml'), 'utf8'),
);

const TRUSTED = ['OWNER', 'MEMBER', 'COLLABORATOR'];
const ECS = '["self-hosted", "linux", "x64", "ecs-qwen"]';
const HOSTED = '["ubuntu-latest"]';

const classifyRunsOn = String(ciDoc.jobs.classify_pr['runs-on']);
const pickRunner = ciDoc.jobs.classify_pr.steps.find(
(s) => s.id === 'pick_runner',
);

// GitHub expression semantics for the classify runs-on, restricted to the
// routing-relevant inputs: contains(list, '') is false, a missing
// pull_request (merge_group / dispatch) yields '' for both head.repo and
// author_association.
function simulateRunsOn({ ecsDisabled, sameRepo, assoc, mergeGroup }) {
const trusted = TRUSTED.includes(assoc);
const ecs =
!ecsDisabled && (sameRepo || trusted || mergeGroup);
return ecs ? ECS : HOSTED;
}

// Executes the real pick_runner shell with the same inputs and returns the
// selected runner exactly as CI would publish it.
function runPickRunner({ ecsDisabled, sameRepo, assoc, eventName, dispatch }) {
const tmp = mkdtempSync(join(tmpdir(), 'pick-runner-'));
const outputFile = join(tmp, 'github_output');
const result = spawnSync('bash', ['-c', pickRunner.run], {
env: {
SAME_REPO: sameRepo ? 'true' : 'false',
AUTHOR_ASSOCIATION: assoc,
ECS_DISABLED: ecsDisabled ? 'true' : '',
EVENT_NAME: eventName,
DISPATCH_LINUX_RUNNER: dispatch ?? '',
GITHUB_OUTPUT: outputFile,
},
encoding: 'utf8',
});
rmSync(tmp, { recursive: true, force: true });
assert.equal(result.status, 0, `pick_runner failed: ${result.stderr}`);
const line = result.stdout
.split('\n')
.find((l) => l.startsWith('Selected Linux runner: '));
assert.ok(line, `no selection in pick_runner output: ${result.stdout}`);
return line.slice('Selected Linux runner: '.length);
}

describe('ci.yml classify_pr runner routing', () => {
it('the expression and the shell step agree on every association', () => {
const associations = [
...TRUSTED,
'CONTRIBUTOR',
'FIRST_TIME_CONTRIBUTOR',
'FIRST_TIMER',
'NONE',
'',
];
for (const sameRepo of [true, false]) {
for (const assoc of associations) {
const expected = simulateRunsOn({
ecsDisabled: false,
sameRepo,
assoc,
mergeGroup: false,
});
const actual = runPickRunner({
ecsDisabled: false,
sameRepo,
assoc,
eventName: 'pull_request',
});
assert.equal(
actual,
expected,
`drift for sameRepo=${sameRepo} assoc='${assoc}'`,
);
}
}
});

it('only write-access associations leave the hosted pool', () => {
for (const assoc of ['CONTRIBUTOR', 'FIRST_TIME_CONTRIBUTOR', 'NONE', '']) {
assert.equal(
runPickRunner({
ecsDisabled: false,
sameRepo: false,
assoc,
eventName: 'pull_request',
}),
HOSTED,
`assoc '${assoc}' must stay hosted`,
);
}
for (const assoc of TRUSTED) {
assert.equal(
runPickRunner({
ecsDisabled: false,
sameRepo: false,
assoc,
eventName: 'pull_request',
}),
ECS,
`assoc '${assoc}' must route to ECS`,
);
}
});

it('merge queue and explicit dispatch still reach ECS; the kill-switch wins', () => {
assert.equal(
runPickRunner({
ecsDisabled: false,
sameRepo: false,
assoc: '',
eventName: 'merge_group',
}),
ECS,
);
assert.equal(
runPickRunner({
ecsDisabled: false,
sameRepo: false,
assoc: '',
eventName: 'workflow_dispatch',
dispatch: 'self-hosted',
}),
ECS,
);
assert.equal(
runPickRunner({
ecsDisabled: true,
sameRepo: true,
assoc: 'OWNER',
eventName: 'pull_request',
}),
HOSTED,
'kill-switch must revert even trusted runs to hosted',
);
});

it('the runs-on expression keeps the trusted clause and kill-switch', () => {
// Structural pins for the expression half of the drift guard — the
// simulation above re-implements it, so pin the real text too.
assert.match(
classifyRunsOn,
/contains\(fromJSON\('\["OWNER","MEMBER","COLLABORATOR"\]'\), github\.event\.pull_request\.author_association\)/,
);
assert.match(classifyRunsOn, /vars\.MAINTAINER_ECS_RUNNER_DISABLED != 'true'/);
assert.match(classifyRunsOn, /github\.event_name == 'merge_group'/);
});
});

describe('serve-ab.yml runner routing', () => {
const runsOn = String(serveAbDoc.jobs.ab['runs-on']);

it('admits same-repo and write-access fork PRs, guarded by the kill-switch', () => {
assert.match(runsOn, /head\.repo\.full_name == github\.repository/);
assert.match(
runsOn,
/contains\(fromJSON\('\["OWNER","MEMBER","COLLABORATOR"\]'\), github\.event\.pull_request\.author_association\)/,
);
assert.match(runsOn, /vars\.MAINTAINER_ECS_RUNNER_DISABLED != 'true'/);
assert.match(runsOn, /ecs-qwen/);
assert.match(runsOn, /ubuntu-latest/);
});

it('wipes the reused workspace before checking out PR code', () => {
const wipe = serveAbDoc.jobs.ab.steps.find(
(s) => s.name === 'Wipe stale workspace before checkout',
);
assert.ok(wipe, 'self-hosted reuse must not bleed one PR into the next');
assert.equal(wipe.if, "${{ runner.environment == 'self-hosted' }}");
assert.match(wipe.run, /find "\$GITHUB_WORKSPACE" -mindepth 1 -maxdepth 1 -exec rm -rf/);
});
});
39 changes: 38 additions & 1 deletion .github/scripts/qwen-triage-workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,49 @@ describe('qwen-triage: agent tool/permission settings', () => {

describe('qwen-triage: fork-PR runner routing', () => {
const runsOn = String(triageJob['runs-on']);
const authorizeJob = doc.jobs.authorize;
const authorizeRunsOn = String(authorizeJob['runs-on']);

it('gates the persistent ECS pool on same-repo (fork code never persists)', () => {
it('routes the ECS pool on same-repo or a REAL write-permission check', () => {
assert.match(runsOn, /head\.repo\.full_name == github\.repository/);
// The boundary is the collaborator-permission lookup authorize computes,
// NOT the coarse author_association: MEMBER admits any org member and
// COLLABORATOR admits read-only invitees — neither implies write access
// on this repo, and this job's agent loads bot PATs and a model key.
assert.match(
runsOn,
/needs\.authorize\.outputs\.author_can_write == 'true'/,
);
assert.doesNotMatch(runsOn, /author_association/);
assert.match(runsOn, /ecs-qwen/);
});

it('keeps the authorize gate itself on the same-repo guard', () => {
// authorize IS the permission check (and loads CI_BOT_PAT); it cannot
// route on its own output and must not widen to association-based trust.
assert.match(authorizeRunsOn, /head\.repo\.full_name == github\.repository/);
assert.doesNotMatch(authorizeRunsOn, /author_association/);
assert.doesNotMatch(authorizeRunsOn, /needs\./);
});

it('computes author_can_write from the collaborator-permission API', () => {
assert.equal(
authorizeJob.outputs.author_can_write,
'${{ steps.perm.outputs.author_can_write }}',
);
const perm = authorizeJob.steps.find((s) => s.id === 'perm');
assert.ok(
String(perm.env.PR_AUTHOR).includes(
'github.event.pull_request.user.login',
),
);
assert.match(perm.run, /collaborators\/\$\{PR_AUTHOR\}\/permission/);
assert.match(
perm.run,
/admin\|maintain\|write\) echo "author_can_write=true"/,
);
});

it('falls back to an ephemeral hosted runner', () => {
assert.match(runsOn, /ubuntu-latest/);
});
Expand Down
27 changes: 18 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ env:
# BOTH the github_ci_only helper step and the full-profile Test step, so a
# new helper test can't be added to one path and silently dropped from the
# other.
HELPER_TESTS: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/classify-release-notes.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/resolve-sandbox-image.test.mjs .github/scripts/web-shell-visuals-publish.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/qwen-triage-workflow.test.mjs .github/scripts/auto-minimize-spam.test.mjs'
HELPER_TESTS: '.github/scripts/pr-safety-precheck.test.mjs .github/scripts/cap-release-notes.test.mjs .github/scripts/ci/classify-profile.test.mjs .github/scripts/ci/main-failure-signature.test.mjs .github/scripts/classify-release-notes.test.mjs .github/scripts/dsw-swe-verified/make-manifest.test.mjs .github/scripts/resolve-sandbox-image.test.mjs .github/scripts/web-shell-visuals-publish.test.mjs .github/scripts/web-shell-visuals-compose.test.mjs .github/scripts/serve-ab-diff.test.mjs .github/scripts/qwen-triage-workflow.test.mjs .github/scripts/auto-minimize-spam.test.mjs .github/scripts/ci-runner-routing.test.mjs'

jobs:
classify_pr:
name: 'Classify PR'
if: "${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}"
# Gate runs on ECS for in-repo PRs and for the merge queue (which runs in the
# base-repo context), else a busy hosted pool delays it and blocks the
# ECS-bound jobs. The kill-switch is read here, so flipping it reverts
# everything to hosted.
runs-on: '${{ (vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'' && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == ''merge_group'')) && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
# Gate runs on ECS for in-repo PRs, fork PRs whose author has write access
# (OWNER/MEMBER/COLLABORATOR association — a write-access author is as
# trusted as an in-repo branch), and the merge queue (base-repo context),
# else a busy hosted pool delays it and blocks the ECS-bound jobs. The
# kill-switch is read here, so flipping it reverts everything to hosted.
# This runs-on and the pick_runner step below are the canonical home of
# the association routing; sdk-java.yml and serve-ab.yml mirror it.
runs-on: '${{ (vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'' && (github.event.pull_request.head.repo.full_name == github.repository || contains(fromJSON(''["OWNER","MEMBER","COLLABORATOR"]''), github.event.pull_request.author_association) || github.event_name == ''merge_group'')) && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
continue-on-error: true
outputs:
skip_ci: '${{ steps.release_sync.outputs.skip_ci }}'
Expand Down Expand Up @@ -102,23 +105,29 @@ jobs:
echo "skip_ci=${skip_ci}" >> "${GITHUB_OUTPUT}"
echo "skip_ci=${skip_ci}"

# In-repo PR (head branch in this repo => author has write access) and the
# merge queue (base-repo context) run the Linux jobs on ECS; fork PRs stay
# In-repo PRs, fork PRs whose author has write access
# (OWNER/MEMBER/COLLABORATOR association), and the merge queue
# (base-repo context) run the Linux jobs on ECS; other fork PRs stay
# hosted. Disable via repo var MAINTAINER_ECS_RUNNER_DISABLED=true.
- name: 'Select Linux runner'
id: 'pick_runner'
env:
SAME_REPO: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
AUTHOR_ASSOCIATION: '${{ github.event.pull_request.author_association }}'
ECS_DISABLED: '${{ vars.MAINTAINER_ECS_RUNNER_DISABLED }}'
EVENT_NAME: '${{ github.event_name }}'
DISPATCH_LINUX_RUNNER: '${{ github.event.inputs.linux_runner }}'
run: |-
ubuntu_runner='["ubuntu-latest"]'
trusted_author=false
case "${AUTHOR_ASSOCIATION}" in
OWNER|MEMBER|COLLABORATOR) trusted_author=true ;;
esac
if [[ "${EVENT_NAME}" == "workflow_dispatch" ]]; then
if [[ "${ECS_DISABLED}" != "true" && "${DISPATCH_LINUX_RUNNER}" == "self-hosted" ]]; then
ubuntu_runner='["self-hosted", "linux", "x64", "ecs-qwen"]'
fi
elif [[ "${ECS_DISABLED}" != "true" && ( "${SAME_REPO}" == "true" || "${EVENT_NAME}" == "merge_group" ) ]]; then
elif [[ "${ECS_DISABLED}" != "true" && ( "${SAME_REPO}" == "true" || "${trusted_author}" == "true" || "${EVENT_NAME}" == "merge_group" ) ]]; then
ubuntu_runner='["self-hosted", "linux", "x64", "ecs-qwen"]'
fi
echo "ubuntu_runner=${ubuntu_runner}" >> "${GITHUB_OUTPUT}"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/comment-attachment-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ jobs:
github.event.comment.author_association ||
github.event.review.author_association
)
runs-on: 'ubuntu-latest'
# Checks out nothing and runs no repository code (comment/review events
# use base-repo YAML), so the persistent ECS pool is safe and skips the
# saturated hosted queue. Kill-switch: MAINTAINER_ECS_RUNNER_DISABLED.
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
steps:
- name: 'Remove suspicious attachment comments'
uses: 'actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3' # v9.0.0
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/docs-page-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ jobs:
environment:
name: 'github-pages'
url: '${{ steps.deployment.outputs.page_url }}'
runs-on: 'ubuntu-latest'
# Checks out nothing and runs no repository code (push/dispatch use
# base-repo YAML), so the persistent ECS pool is safe.
# Kill-switch: MAINTAINER_ECS_RUNNER_DISABLED.
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
# One API deploy; a hang must not pin a persistent pool machine for the
# 360-minute default.
timeout-minutes: 5
needs: 'build'
steps:
- name: 'Deploy to GitHub Pages'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main-ci-failure-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ jobs:
file_issue:
name: 'Create autofix issue'
needs: 'analyze'
# Deliberately hosted, NOT the ECS pool: this job reports that CI broke,
# and the pool being the REASON CI broke would queue the report behind
# the very failure it documents.
runs-on: 'ubuntu-latest'
timeout-minutes: 5
permissions:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr-force-push-reminder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
timeout-minutes: 5
if: |-
${{ github.repository == 'QwenLM/qwen-code' }}
runs-on: 'ubuntu-latest'
# Checks out nothing and runs no repository code (pull_request_target
# events use base-repo YAML), so the persistent ECS pool is safe and
# skips the saturated hosted queue. Kill-switch: MAINTAINER_ECS_RUNNER_DISABLED.
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
steps:
- name: 'Detect force-push and post reminder'
uses: 'actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3' # v9.0.0
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr-self-report-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
label:
if: |-
${{ github.repository == 'QwenLM/qwen-code' }}
runs-on: 'ubuntu-latest'
# Checks out nothing and runs no repository code (pull_request_target
# events use base-repo YAML), so the persistent ECS pool is safe and
# skips the saturated hosted queue. Kill-switch: MAINTAINER_ECS_RUNNER_DISABLED.
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'') && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
timeout-minutes: 5
steps:
- name: 'Label a self-reported PR'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/qwen-code-pr-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ jobs:
startsWith(github.event.review.body, '@qwen-code /review')))
# Canonical same-repo guard: this job loads CI_BOT_PAT, so fork-triggered
# runs stay on hosted (ephemeral); only in-repo PR events on QwenLM/qwen-code
# use the persistent ECS runner.
# use the persistent ECS runner. The job IS the write-permission check, so
# it cannot route on its own output; downstream jobs already route on the
# repository guard alone.
runs-on: '${{ (github.repository == ''QwenLM/qwen-code'' && vars.MAINTAINER_ECS_RUNNER_DISABLED != ''true'' && github.event.pull_request && github.event.pull_request.head.repo.full_name == github.repository) && fromJSON(''["self-hosted", "linux", "x64", "ecs-qwen"]'') || fromJSON(''["ubuntu-latest"]'') }}'
timeout-minutes: 5
permissions:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/qwen-fleet-shepherd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ jobs:
shepherd:
if: |-
${{ github.repository == 'QwenLM/qwen-code' && vars.FLEET_SHEPHERD_DISABLED != 'true' }}
# Deliberately hosted, NOT the ECS pool: the shepherd is the watchdog FOR
# that pool. When the pool is wedged, drained, or offline — exactly when
# the shepherd is needed — a pool-routed shepherd would queue behind the
# failure it exists to fix, and recovery would need the manual kill-switch
# flip the shepherd exists to avoid. One 15-minute hosted job per tick is
# a negligible queue cost for that independence.
runs-on: 'ubuntu-latest'
timeout-minutes: 15
steps:
Expand Down
Loading
Loading