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
34 changes: 31 additions & 3 deletions .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,29 @@ jobs:
echo "::error::docker daemon is not reachable on this runner; the sandboxed agent cannot start."
exit 1
fi
# 'Set up Node.js' assumes this pool keeps ~/.npm across jobs;
# log its size so a move to per-job containers is visible.
du -sh "${HOME}/.npm" 2>/dev/null || echo '~/.npm is absent on this runner.'

- name: 'Set up Node.js'
uses: 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e' # v6.4.0
with:
node-version: '22.x'
cache: 'npm'
# No remote npm cache on the persistent pool: one measured
# review-address leg spent 339s in `Set up Node.js` restoring
# 2,654,052,865 bytes (~10 MB/s) to protect an `npm ci` that took
# 29s in the very next step, and those runners keep ~/.npm across
# jobs anyway, so every leg paid the download again — up to ten
# review-address legs per scan. The hosted fallback is ephemeral
# and keeps the cache; the choice keys on the runner fact directly.
# Keep the truthy literal in the MIDDLE of the ternary — GHA's
# &&/|| return operand values and '' is falsy, so
# `== 'self-hosted' && '' || 'npm'` yields 'npm' on BOTH pools
# (the contract tests evaluate the expression for both runner
# facts). package-manager-cache stops a future `packageManager`
# field in package.json from silently re-enabling the cache here.
cache: "${{ runner.environment != 'self-hosted' && 'npm' || '' }}"
package-manager-cache: false
cache-dependency-path: 'package-lock.json'

- name: 'Install tmux'
Expand Down Expand Up @@ -3109,7 +3126,11 @@ jobs:
uses: 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e' # v6.4.0
with:
node-version: '22.x'
cache: 'npm'
# No remote npm cache on the persistent pool — the rationale and
# the ternary's operand-order trap live in issue-autofix's 'Set up
# Node.js' step; the contract tests pin all three copies.
cache: "${{ runner.environment != 'self-hosted' && 'npm' || '' }}"
package-manager-cache: false
cache-dependency-path: 'package-lock.json'

# The npm-ci retry recipe and the 'Prepare Qwen Code CLI' shim below
Expand Down Expand Up @@ -3454,12 +3475,19 @@ jobs:
echo "::error::docker daemon is not reachable on this runner; the sandboxed agent cannot start."
exit 1
fi
# 'Set up Node.js' assumes this pool keeps ~/.npm across jobs;
# log its size so a move to per-job containers is visible.
du -sh "${HOME}/.npm" 2>/dev/null || echo '~/.npm is absent on this runner.'

- name: 'Set up Node.js'
uses: 'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e' # v6.4.0
with:
node-version: '22.x'
cache: 'npm'
# No remote npm cache on the persistent pool — the rationale and
# the ternary's operand-order trap live in issue-autofix's 'Set up
# Node.js' step; the contract tests pin all three copies.
cache: "${{ runner.environment != 'self-hosted' && 'npm' || '' }}"
package-manager-cache: false
cache-dependency-path: 'package-lock.json'

- name: 'Install tmux'
Expand Down
139 changes: 133 additions & 6 deletions scripts/tests/qwen-autofix-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,80 @@ const nodeSetupSteps =
workflow.match(/- name: 'Set up Node.js'[\s\S]*?(?=\n[ ]{6}- name: ')/g) ??
[];

// GitHub Actions expressions return operand VALUES from &&/||, not
// booleans: && yields the first falsy operand (else the last operand), ||
// the first truthy (else the last), '' is falsy, and && binds tighter
// than ||. A ternary can therefore read right and evaluate wrong, which
// text pins cannot see — so the cache choice is also pinned semantically
// with this minimal evaluator.
function evalGhaExpression(expression, facts) {
let pos = 0;
const truthy = (value) =>
value !== false && value !== null && value !== 0 && value !== '';
const skipSpace = () => {
while (/\s/.test(expression[pos] ?? '')) {
pos += 1;
}
};
const parsePrimary = () => {
skipSpace();
if (expression[pos] === "'") {
const end = expression.indexOf("'", pos + 1);
const value = expression.slice(pos + 1, end);
pos = end + 1;
return value;
}
const name = /^[A-Za-z_][A-Za-z0-9_.]*/.exec(expression.slice(pos))[0];
pos += name.length;
if (name === 'true') {
return true;
}
if (name === 'false') {
return false;
}
if (name === 'null') {
return null;
}
return facts[name];
};
const parseComparison = () => {
const left = parsePrimary();
skipSpace();
const op = expression.slice(pos, pos + 2);
if (op !== '==' && op !== '!=') {
return left;
}
pos += 2;
const right = parsePrimary();
return op === '==' ? left === right : left !== right;
};
const parseAnd = () => {
let left = parseComparison();
for (;;) {
skipSpace();
if (expression.slice(pos, pos + 2) !== '&&') {
return left;
}
pos += 2;
const right = parseComparison();
left = truthy(left) ? right : left;
}
};
const parseOr = () => {
let left = parseAnd();
for (;;) {
skipSpace();
if (expression.slice(pos, pos + 2) !== '||') {
return left;
}
pos += 2;
const right = parseAnd();
left = truthy(left) ? left : right;
}
};
return parseOr();
}

function readAutofixSkill() {
return readFileSync('.qwen/skills/autofix/SKILL.md', 'utf8');
}
Expand Down Expand Up @@ -6130,7 +6204,19 @@ exit 1
expect(workflow).not.toContain(
'["self-hosted", "linux", "x64", "autofix"]',
);
expect(workflow).not.toContain("runner.environment == 'self-hosted'");
// What this line guarded is the STEP the dedicated-runner design added —
// a `command -v node` check gated on `runner.environment == 'self-hosted'`
// that duplicated setup-node and was removed in #6261. That step is
// pinned out by name on the next line, so guarding the bare expression as
// a substring only forbids the `runner` context by accident: this same
// test requires `RUNNER_ENVIRONMENT: '${{ runner.environment }}'` below,
// and the npm-cache choice reads the same fact. Guard the shape that was
// actually reverted — an `if:` that tests that fact — in every spelling:
// single-line or block scalar, wrapped `${{ }}`, extra conjuncts, either
// operand order, arbitrary spacing.
expect(workflow).not.toMatch(
/if:\s*(?:\|-\s*)?\$\{\{[^}]*(?:runner\.environment\s*==\s*'self-hosted'|'self-hosted'\s*==\s*runner\.environment)/,
);
expect(workflow).not.toContain('Use pre-installed Node.js (self-hosted)');
expect(workflow).not.toContain('AUTOFIX_ECS_RUNNER_DISABLED');
expect(workflow).toContain(
Expand Down Expand Up @@ -6259,15 +6345,22 @@ exit 1
// Node bump applied to two of the three jobs) must not ship green.
expect(nodeSetupSteps).toHaveLength(3);
for (const step of nodeSetupSteps) {
// Unconditional: re-adding the hosted-only `if` skips setup-node on
// every ECS-routed run and leaves the job on whatever Node the pool
// image happens to ship, while every recipe assertion stays green.
expect(step).not.toContain("runner.environment == 'github-hosted'");
// Unconditional: any `if:` skips setup-node on one of the pools and
// leaves that job on whatever Node its image happens to ship, while
// every recipe assertion stays green.
expect(step).not.toMatch(/^\s*if:/m);
expect(step).toContain(
'actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e',
);
expect(step).toContain("node-version: '22.x'");
expect(step).toContain("cache: 'npm'");
// The cache is the one input that is NOT the same on both pools — see
// 'does not restore the remote npm cache on the persistent pool'. The
// inputs are still identical across the three steps, which is what
// this test is for.
expect(step).toContain(
`cache: "\${{ runner.environment != 'self-hosted' && 'npm' || '' }}"`,
);
expect(step).toContain('package-manager-cache: false');
expect(step).toContain("cache-dependency-path: 'package-lock.json'");
}
});
Expand Down Expand Up @@ -7021,6 +7114,40 @@ exit 1
}
});

it('does not restore the remote npm cache on the persistent pool', () => {
// Measured on one review-address leg: `Set up Node.js` took 339s, of
// which Node itself was free (already in the runner tool cache) and
// 2,654,052,865 bytes at ~10 MB/s were the npm cache restore — guarding
// an `npm ci` that took 29s in the very next step. Every leg pays it,
// up to ten per scan, plus build-cli and issue-autofix.
// All three consumers, so a fourth job with a hardcoded cache fails
// here rather than quietly paying 2.65 GB per run — counted by step
// name, so no choice of inputs can dodge the capture.
expect(nodeSetupSteps).toHaveLength(3);
for (const step of nodeSetupSteps) {
expect(step).toContain(
`cache: "\${{ runner.environment != 'self-hosted' && 'npm' || '' }}"`,
);
}
// Text pins cannot tell a ternary that works from one that GHA's
// operand-value &&/|| semantics defeat — this PR's first attempt read
// correctly and still restored the cache on BOTH pools. Evaluate the
// pinned expression the way Actions does: '' on the persistent pool,
// 'npm' on the ephemeral hosted fallback.
const cacheExpression =
nodeSetupSteps[0].match(/cache: "\$\{\{ ([^}]+) \}\}"/)?.[1] ?? '';
for (const [environment, expected] of [
['self-hosted', ''],
['github-hosted', 'npm'],
]) {
expect(
evalGhaExpression(cacheExpression, {
'runner.environment': environment,
}),
).toBe(expected);
}
});

it('passes model credentials directly to qwen subprocesses', () => {
const qwenSteps = [
assessCandidatesStep,
Expand Down
Loading