Resolve SideRepoOps safe-outputs base branch from the checked-out target branch#32659
Conversation
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
| // re-anchors the checkout to a non-default release branch before generating the patch. | ||
| if (options?.preferCheckedOutBranch && options.cwd) { | ||
| try { | ||
| const checkedOutBranch = execSync("git rev-parse --abbrev-ref HEAD", { |
There was a problem hiding this comment.
Addressed in 13875d7 by switching get_base_branch.cjs to the shared execGitSync() helper instead of calling git inline.
Co-authored-by: pelikhan <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes safe-outputs patch baseline selection for SideRepoOps (and other configured target-repo workflows) so patches are generated against the branch actually checked out in the target repository, instead of always using the target repo’s default branch.
Changes:
- Extend
getBaseBranch()to optionally prefer the checked-out git branch (opt-in via options). - Update safe-outputs handlers to resolve the target repo checkout first, then derive
base_branchwith a preference for the checked-out branch when operating in a side-repo/target-repo checkout. - Add a regression test fixture ensuring create-PR patches on a checked-out release branch exclude pre-existing default↔release divergence.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/safe_outputs_handlers.cjs | Resolve repo checkout before base branch selection; prefer checked-out branch for side-repo patch baselines. |
| actions/setup/js/get_base_branch.cjs | Add optional “prefer checked-out branch” resolution step via git when requested. |
| actions/setup/js/safe_outputs_handlers.test.cjs | Add regression test for side-repo release branch patch generation baseline. |
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
| * 7. Fallback to DEFAULT_BRANCH env var or "main" | ||
| * | ||
| * @param {{owner: string, repo: string}|null} [targetRepo] - Optional target repository. | ||
| * If provided, API calls (steps 4 and 5) use this instead of context.repo, |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnose and /tdd — this is a targeted bug fix with regression coverage.
Key Themes
- Root cause properly addressed: The reordering of
repoCwdresolution beforegetBaseBranchin both handlers is the correct fix. The original code resolved the base branch before knowing which directory was checked out, so it could not prefer the checked-out branch even in principle. - Test coverage gap:
pushToPullRequestBranchHandlerreceived the same base-branch fix but has no corresponding regression test (see inline comment). - Test clarity: The test's
branchvalue deliberately equals the resolvedbase_branchto trigger the git fallback — worth a short clarifying comment (see inline comment).
Positive Highlights
- ✅ Clean opt-in API:
preferCheckedOutBranch/cwdoptions keepgetBaseBranchbackward-compatible — callers that don't pass options get the existing behaviour unchanged. - ✅
Boolean(repoCwd)guard correctly avoids the git lookup when no checkout was found, so the fallback chain still applies in the normal case. - ✅ The
execGitSyncrefactor (addressing the existing review thread) is a good use of the shared helper. - ✅ Regression test for
createPullRequestHandleris thorough: it sets up a realistic diverged repo, assertsbase_branch, and verifies the patch contains only the local commit.
Verdict
Minor suggestions only — commenting rather than blocking.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 4.5M
| }); | ||
| }); | ||
|
|
||
| describe("pushToPullRequestBranchHandler", () => { |
There was a problem hiding this comment.
[/tdd] pushToPullRequestBranchHandler received the same base-branch fix in this PR but has no parallel regression test. The createPullRequestHandler test added here verifies the new behaviour precisely — a matching test for the push handler would guard against the same class of regression on that code path.
Consider adding a sibling test in the pushToPullRequestBranchHandler describe block that reuses createSideRepoOnReleaseBranchWithLocalCommit and asserts base_branch: "release-1.12.x" in the appended entry.
| body: "Prepare release branch fix", | ||
| }); | ||
|
|
||
| expect(result.isError).toBeUndefined(); |
There was a problem hiding this comment.
[/tdd] The test passes branch: "release-1.12.x" which equals the resolved base_branch, triggering the fallback logic that replaces it with the current git branch. That's the correct path to exercise, but the test comment doesn't explain it — a reader might think the branch value is arbitrary. A short inline comment would make the intent explicit:
// branch intentionally equals base_branch to exercise the git-fallback path
branch: "release-1.12.x",
🧪 Test Quality Sentinel ReportTest Quality Score: 92/100✅ Excellent test quality
Test Classification DetailsView test classification table (5 tests)
Key Strengths
The Minor Observations
Flagged Tests — NoneNo tests require remediation. Language SupportTests analyzed:
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: §25968749492
|
|
@copilot review all review comments |
Co-authored-by: pelikhan <[email protected]>
|
|
Safe outputs were generating create-PR patches against the target repo’s default branch, even when a SideRepoOps workflow had re-anchored the checkout to a non-default release branch. In that case the patch could include all default→release divergence and trigger E003 instead of containing only the agent’s actual change.
Base branch resolution
Side-repo handler behavior
base_branchincreate_pull_requestandpush_to_pull_request_branch.target-repois configured, not only whenrepois passed in the tool call.Regression coverage
mainas default branchrelease-1.12.xdiverged frommainThis keeps safe-outputs aligned with the branch the agent is actually working on, so SideRepoOps PR creation against non-default branches does not require a custom
DEFAULT_BRANCHoverride.