fix(autofix): unconditionally restore tracked files before branch checkout (#6281) - #6286
Conversation
…ckout (#6281) git diff --quiet exits 0 when only CRLF normalization differs (content is identical after filter), so the conditional git restore was skipped even though the working tree was dirty. This caused git checkout -B to fail on NOTICES.txt. Remove the conditional guard so restore always runs.
E2E Report — Issue #6281Bug Reproduction (Before Fix)Baseline state on Linux CI: Key finding: Fix AppliedRemoved the conditional guard around Before: if ! git diff --quiet || ! git diff --cached --quiet; then
echo 'Restoring tracked build output before switching to the PR branch.'
git status --short
git restore --source=HEAD --staged --worktree .
fi
git checkout -B "${BRANCH}" "origin/${BRANCH}"After: echo 'Restoring tracked build output before switching to the PR branch.'
git status --short
git restore --source=HEAD --staged --worktree .
git checkout -B "${BRANCH}" "origin/${BRANCH}"Test ChangesAdded assertion in expect(prepareBranchAndFeedbackStep).not.toContain('git diff --quiet');This assertion fails on the old code (which had the conditional guard) and passes on the new code. Verification CommandsThe workflow verification gate should run: # 1. Run the workflow test
cd scripts && npx vitest run tests/qwen-autofix-workflow.test.js
# 2. Verify the workflow YAML is valid
# (the workflow runs on CI, so validation happens at action-parse time)
# 3. Confirm the fix resolves the CRLF issue:
# On a Linux runner with NOTICES.txt showing CRLF dirty state:
git status --short packages/vscode-ide-companion/NOTICES.txt
# Expected: M packages/vscode-ide-companion/NOTICES.txt
git restore --source=HEAD --staged --worktree .
git status --short packages/vscode-ide-companion/NOTICES.txt
# Expected: (empty — clean working tree)
git checkout -B test-branch origin/main
# Expected: succeeds without error |
|
Thanks for the fix! Template looks good ✓ Problem: This is an observed bug with solid evidence. Issue #6281 documents the failure — the autofix review-address job aborts at Direction: Straightforward CI bugfix — the prior conditional guard was too clever and missed the CRLF edge case. Removing it and making Approach: Minimal and focused — two files, +4/-5 lines, exactly the scope the fix needs. The test assertion preventing regression of the conditional guard is a nice touch. Moving on to code review and testing. 🔍 中文说明感谢修复! 模板完整 ✓ 问题:这是一个有明确证据的已观测 bug。Issue #6281 记录了 autofix review-address 任务在 方向:直接的 CI bugfix——之前的条件判断过于"聪明",没有覆盖 CRLF 边界情况。移除条件判断,无条件执行 方案:最小且聚焦——两个文件,+4/-5 行,恰好是修复所需的范围。防止条件判断回归的测试断言是个好细节。 进入代码审查和测试 🔍 — Qwen Code · qwen3.7-max |
Code ReviewThe diff is clean and minimal — exactly two changes:
No correctness issues, no scope creep, no unused code left behind. The implementation matches exactly what I would have done independently. Test ResultsRan the workflow test suite on the PR branch — all 14 tests pass, including the new assertion: Real-Scenario TestingNot applicable — this is a CI workflow change, not user-facing CLI behavior. The unit tests and the linked failed workflow run are the appropriate verification. — Qwen Code · qwen3.7-max |
|
This is a textbook minimal fix. The problem is real (linked workflow failure, clear root cause in CRLF normalization defeating The independent proposal I wrote before reading the diff was identical — remove the Confident this is correct and safe to ship. ✅ 中文说明这是一个教科书般的最小修复。问题是真实的(有链接的 workflow 失败记录,CRLF 规范化导致 我在读 diff 之前写的独立方案完全一致——移除 确信正确且安全,可以合入。✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
yiliang114
left a comment
There was a problem hiding this comment.
Reviewed the workflow change and the regression test. The unconditional restore now runs before branch checkout, which directly addresses the CRLF-dirty working tree failure while staying a no-op on clean trees.
Local verification: the focused workflow test passed (14/14), actionlint and yamllint passed, and shellcheck completed with pre-existing warnings outside this diff. Approved from code review; the pending GitHub checks should still finish before merge.
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
No issues found. LGTM! ✅
The unconditional git restore is a clean, minimal fix for the CRLF line-ending issue — it's a no-op on clean trees and guarantees checkout succeeds regardless of line-ending state. Tests (14/14) pass.
Downgraded from Approve to Comment: CI still running (30 checks pending).
— qwen3.7-max via Qwen Code /review
What this PR does
The autofix review-address job's "Prepare branch and feedback" step conditionally restores tracked working-tree changes before switching to a PR branch. The condition uses
git diff --quietto decide whether a restore is needed. However,git diff --quietexits 0 when the only difference is CRLF→LF line-ending normalization — the content is identical after Git's filter, so it reports no change. The restore is skipped, butgit checkout -Bstill sees the working tree as dirty and aborts. This PR removes the conditional guard sogit restore --source=HEAD --staged --worktree .runs unconditionally before every branch switch.Why it's needed
After
npm ci && npm run build && npm run bundleon Linux CI,packages/vscode-ide-companion/NOTICES.txtpicks up CRLF working-copy state. The conditionalgit diff --quietexits 0 (content matches after normalization), so the restore is skipped. The subsequentgit checkout -Bthen fails with "Your local changes to the following files would be overwritten by checkout" and the entire review-address job aborts — even though the fix logic was never reached. Making the restore unconditional is a safe, zero-cost operation when the tree is already clean, and guarantees the checkout succeeds regardless of line-ending state.Reviewer Test Plan
How to verify
npm ci && npm run build && npm run bundle, confirmgit status --shortshowsM packages/vscode-ide-companion/NOTICES.txtbutgit diff --quietexits 0 with a CRLF warning.git restore --source=HEAD --staged --worktree .cleans the working tree (emptygit status --shortoutput).git checkout -Bthen succeeds without error.cd scripts && npx vitest run tests/qwen-autofix-workflow.test.js— the "clears tracked build output" test should pass, including the new assertion that the step does not containgit diff --quiet.Evidence (Before & After)
Before: review-address job fails at
git checkout -Bwith "Your local changes to the following files would be overwritten by checkout: packages/vscode-ide-companion/NOTICES.txt". Workflow run: https://github.com/QwenLM/qwen-code/actions/runs/28672328479/job/85038229491After:
git restoreruns unconditionally, cleaning all tracked working-tree changes (including CRLF-only differences) before checkout. Branch switch succeeds.Tested on
Environment (optional)
Linux CI runner (GitHub Actions). Verified baseline behavior via
git diff --quietandgit status --shorton the working copy.Risk & Scope
git restore --source=HEAD --staged --worktree .is a no-op when the tree is already clean, so the unconditional call adds negligible overhead..gitattributesandcore.autocrlfinteractions).Linked Issues
Fixes #6281
中文说明
此 PR 的作用
autofix review-address 任务的"Prepare branch and feedback"步骤在切换到 PR 分支前,原本通过
git diff --quiet条件判断是否需要恢复被构建产物修改的 tracked 文件。然而git diff --quiet在仅有 CRLF→LF 行尾规范化差异时返回 0(经过 Git filter 后内容一致),导致恢复逻辑被跳过,但git checkout -B仍然检测到工作树脏并中止。本 PR 移除了条件判断,使git restore --source=HEAD --staged --worktree .在每次分支切换前无条件执行。为什么需要
在 Linux CI 上执行
npm ci && npm run build && npm run bundle后,packages/vscode-ide-companion/NOTICES.txt会因 CRLF 行尾状态变化而被标记为已修改。条件判断git diff --quiet返回 0(内容经规范化后一致),导致恢复被跳过。随后的git checkout -B因"Your local changes to the following files would be overwritten by checkout"失败,整个 review-address 任务中止——甚至还没进入 agent 修复阶段。无条件执行恢复在工作树已经干净时是零开销的空操作,且能保证无论行尾状态如何,checkout 都能成功。审阅者测试计划
npm ci && npm run build && npm run bundle后,确认git status --short显示M packages/vscode-ide-companion/NOTICES.txt,但git diff --quiet以 CRLF 警告退出 0。git restore --source=HEAD --staged --worktree .可清理工作树(git status --short输出为空)。git checkout -B随后成功执行。cd scripts && npx vitest run tests/qwen-autofix-workflow.test.js——"clears tracked build output" 测试应通过,包括新增的断言(步骤不包含git diff --quiet)。风险与范围
git restore是空操作。Fixes #6281