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
20 changes: 14 additions & 6 deletions .github/workflows/qwen-autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1777,9 +1777,17 @@ jobs:
# The agent step runs AFTER prepare checks out the PR branch, so
# invoking the runner from the working tree would execute
# branch-controlled code on the host with the model key in env
# (takeover targets human-authored branches). Stage it from the
# trusted base and invoke the staged copy.
cp .qwen/skills/autofix/scripts/run-agent.mjs "${RUNNER_TEMP}/run-agent.mjs"
# (takeover targets human-authored branches). Stage the runner AND
# its SKILL from the trusted base, MIRRORING the skill's on-disk
# layout (autofix/{SKILL.md,scripts/run-agent.mjs}) — run-agent.mjs
# resolves the skill as `<its dir>/../SKILL.md`, so a flat stage
# (RUNNER_TEMP/run-agent.mjs) points ../SKILL.md at RUNNER_TEMP/..
# and the agent crashes with ENOENT before reading any feedback.
# The mirror also means the model's instructions come from the
# trusted base, never the PR branch.
mkdir -p "${RUNNER_TEMP}/autofix-skill/scripts"
cp .qwen/skills/autofix/SKILL.md "${RUNNER_TEMP}/autofix-skill/SKILL.md"
cp .qwen/skills/autofix/scripts/run-agent.mjs "${RUNNER_TEMP}/autofix-skill/scripts/run-agent.mjs"

- name: 'Check runner environment'
env:
Expand Down Expand Up @@ -2175,9 +2183,9 @@ jobs:
# write-capable collaborators); keep AUTOFIX_OPENAI_API_KEY a
# low-privilege, quota-bounded, rotatable key.
git config core.hooksPath .husky
# Trusted staged copy — never the PR branch's version (see the
# staging step).
node "${RUNNER_TEMP}/run-agent.mjs" \
# Trusted staged copy in the mirrored layout — resolves
# ../SKILL.md to the trusted staged SKILL, never the PR branch's.
node "${RUNNER_TEMP}/autofix-skill/scripts/run-agent.mjs" \
--mode address-review \
--pr "${PR}" \
--issue "${ISSUE}" \
Expand Down
28 changes: 24 additions & 4 deletions scripts/tests/qwen-autofix-workflow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ describe('qwen-autofix workflow', () => {
// repo copy; the review address step runs AFTER the PR branch is
// checked out and must invoke the TRUSTED STAGED copy instead.
expect(step).toMatch(
/node (?:"\$\{RUNNER_TEMP\}\/run-agent\.mjs"|\.qwen\/skills\/autofix\/scripts\/run-agent\.mjs)/,
/node (?:"\$\{RUNNER_TEMP\}\/autofix-skill\/scripts\/run-agent\.mjs"|\.qwen\/skills\/autofix\/scripts\/run-agent\.mjs)/,
);
expect(step).not.toContain('qwen --yolo --prompt "${PROMPT}"');
expect(step).not.toContain('AUTOFIX_INVOCATION:');
Expand Down Expand Up @@ -2061,11 +2061,31 @@ describe('qwen-autofix workflow', () => {
'run-agent.mjs \\\n --mode develop-issue',
);
expect(triageAndAddressStep).toContain(
'node "${RUNNER_TEMP}/run-agent.mjs" \\\n --mode address-review',
'node "${RUNNER_TEMP}/autofix-skill/scripts/run-agent.mjs" \\\n --mode address-review',
);
// Staging must MIRROR the skill layout: run-agent.mjs resolves its
// SKILL as `<own dir>/../SKILL.md`, so the staged runner and a staged
// SKILL.md must sit in autofix-skill/{scripts/run-agent.mjs,SKILL.md}.
// A flat stage crashes the agent with ENOENT before it reads feedback
// (regression: #7165 staged run-agent.mjs alone → ../SKILL.md pointed
// one dir above RUNNER_TEMP). Derive the invariant from the invocation
// rather than hard-coding the path, so any future relocation stays
// self-consistent.
const stagedRunner = triageAndAddressStep.match(
/node "(\$\{RUNNER_TEMP\}\/\S+\/run-agent\.mjs)"/,
)?.[1];
expect(stagedRunner).toBeTruthy();
// `<dir>/../SKILL.md` where dir = dirname(dirname(stagedRunner)).
const stagedSkillDir = stagedRunner
.replace(/\/scripts\/run-agent\.mjs$/, '')
.trim();
expect(workflow).toContain(
`cp .qwen/skills/autofix/scripts/run-agent.mjs "${stagedRunner}"`,
);
expect(workflow).toContain(
`cp .qwen/skills/autofix/scripts/run-agent.mjs "\${RUNNER_TEMP}/run-agent.mjs"`,
`cp .qwen/skills/autofix/SKILL.md "${stagedSkillDir}/SKILL.md"`,
);
expect(workflow).toContain(`mkdir -p "${stagedSkillDir}/scripts"`);
expect(workflow).not.toContain('.github/scripts/build-autofix-prompt.mjs');

for (const step of [
Expand Down Expand Up @@ -2285,7 +2305,7 @@ describe('qwen-autofix workflow', () => {
/git config core\.hooksPath \/dev\/null\n\s+git checkout -B "\$\{BRANCH\}"/,
);
expect(workflow).toMatch(
/git config core\.hooksPath \.husky\n[\s\S]{0,200}node "\$\{RUNNER_TEMP\}\/run-agent\.mjs"/,
/git config core\.hooksPath \.husky\n[\s\S]{0,200}node "\$\{RUNNER_TEMP\}\/autofix-skill\/scripts\/run-agent\.mjs"/,
);
});

Expand Down
Loading