Fix safe output bundle fetch for checked-out PR branches#32070
Conversation
Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
|
Hey However, this PR was opened directly by a coding agent on behalf of an external contributor, which doesn't match the contribution model for this project. Direct PRs from non-core team members are not accepted — even well-crafted ones from agents. Here's what to do instead:
If you'd like to prepare a ready-to-use plan for the issue, your agent can generate it with this prompt:
|
|
@copilot add integration test |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes bundle application for create-pull-request flows where the target branch may already be checked out.
Changes:
- Adds
applyBundleToBranchto fetch bundles into a temporary ref before updating/checking out the target branch. - Updates bundle transport unit assertions for temporary refs and
update-ref. - Adds a real-git integration test for checked-out branch bundle application.
Show a summary per file
| File | Description |
|---|---|
actions/setup/js/create_pull_request.cjs |
Refactors bundle application through a temporary ref and updates fallback instructions. |
actions/setup/js/create_pull_request.test.cjs |
Updates bundle fetch expectations and adds branch-with-slash regression coverage. |
actions/setup/js/create_pull_request_bundle_integration.test.cjs |
Adds integration coverage for applying bundles when the target branch is checked out. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
|
|
||
| # Fetch the bundle into a local branch | ||
| git fetch /tmp/agent-${runId}/${artifactFileName} ${bundleBranchRef}:refs/heads/${branchName} | ||
| git fetch /tmp/agent-${runId}/${artifactFileName} refs/heads/${originalAgentBranch || branchName}:refs/heads/${branchName} |
There was a problem hiding this comment.
Updated in 5513624 to use the temporary-ref/update-ref/reset flow in the fallback issue instructions instead of fetching directly into the branch ref.
🧪 Test Quality Sentinel ReportTest Quality Score: 100/100✅ Excellent test quality
Test Classification DetailsView all 5 tests
Flagged Tests — Requires ReviewNone. All tests are well-formed with behavioral assertions. HighlightsNew integration test is a standout. Mocking is appropriate. Unit tests spy on Test inflation check. The integration file adds 115 lines vs 59 lines added to the production file — a ratio of 1.95:1, just under the 2:1 threshold. Given the setup boilerplate required for real git repos, this is expected and acceptable. Language Support
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators. References:
|
There was a problem hiding this comment.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 6.2M
| async function applyBundleToBranch(bundleFilePath, branchName, originalAgentBranch, execApi) { | ||
| let bundleBranchRef = `refs/heads/${originalAgentBranch || branchName}`; | ||
| const bundleTargetRef = `refs/heads/${branchName}`; | ||
| const bundleTempRef = `refs/bundles/create-pr-${branchName.replace(/[^a-zA-Z0-9-]/g, "-")}`; |
There was a problem hiding this comment.
[/diagnose] The temp ref name sanitises / → -, so branches foo/bar and foo-bar both map to refs/bundles/create-pr-foo-bar. If two concurrent workflow runs target these two branches on the same runner they will overwrite each other's temp ref mid-flight.
Consider including a short random or timestamp suffix to make the ref unique per invocation:
const bundleTempRef = `refs/bundles/create-pr-${branchName.replace(/[^a-zA-Z0-9-]/g, "-")}-${Date.now()}`;| await execApi.exec("git", ["update-ref", bundleTargetRef, bundleTempRef]); | ||
| core.info(`Created local branch ${branchName} from bundle`); | ||
| await execApi.exec("git", ["checkout", branchName]); | ||
| await execApi.exec("git", ["reset", "--hard"]); |
There was a problem hiding this comment.
[/diagnose] git reset --hard (without a ref) discards any staged/unstaged changes on the currently checked-out branch. After git checkout <branch> has already updated the working tree to the new HEAD, the reset is a no-op in the clean CI case — but if for some reason the branch had local uncommitted changes before applyBundleToBranch was called, this silently destroys them.
A comment explaining the intent would help:
// Ensure the working tree matches the new HEAD in case checkout left any index/worktree drift
await execApi.exec("git", ["reset", "--hard"]);If the goal is strictly to update the working tree to match the new ref, consider git reset --hard HEAD (explicit) or git read-tree -u -m HEAD so the intent is unambiguous.
|
|
||
| fs.writeFileSync(path.join(targetRepo, "file.txt"), "checked out branch before bundle\n"); | ||
| execGit(["add", "file.txt"], { cwd: targetRepo }); | ||
| execGit(["commit", "-m", "old branch state"], { cwd: targetRepo }); |
There was a problem hiding this comment.
[/tdd] The integration test covers the happy path well (temp ref cleaned up, HEAD at expected commit, file contents correct). The error path — what happens when applyBundleToBranch throws mid-way (e.g. update-ref fails after the fetch) — isn't exercised. The finally cleanup block is the most likely place for a latent ref leak.
Consider adding a test that injects a failure after the fetch step and asserts:
- The
refs/bundles/...ref is deleted - The target branch ref is not left in a partial state
it("cleans up the temp ref when update-ref fails", async () => {
// inject error on update-ref, then assert temp ref is gone
});|
@copilot review all review comments |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Bug Fix
What was the bug?
safe_outputscould fail duringcreate_pull_requestwhen the bundle target branch was already checked out. Git rejects direct fetches into the checked-out branch ref:How did you fix it?
Bundle application
refs/bundles/...git update-refRegression coverage
refs/heads/<branch>autoloop/perf-comparison