-
Notifications
You must be signed in to change notification settings - Fork 431
fix: apply_samples derivePrHeadRef uses target-repo config for siderepo PR lookups #41295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -543,6 +543,61 @@ describe("apply_samples.cjs preStagePatch (create_pull_request / push_to_pull_re | |
| } | ||
| }); | ||
|
|
||
| it("derives push_to_pull_request_branch branch using target-repo from safe-outputs config (issue #41292 siderepo workflow_dispatch)", async () => { | ||
| // Reproduces the siderepo failure: a workflow_dispatch provides | ||
| // `pull_request_number` but no `repo` override in the sample arguments. | ||
| // The safe-outputs config carries `target-repo: "githubnext/gh-aw-side-repo"`, | ||
| // which derivePrHeadRef must use when building the PR fetch URL. | ||
| const workspace = makeTempDir("gh-aw-prestage-push-siderepo-"); | ||
| initRepo(workspace, "main"); | ||
|
|
||
| const headRef = "feat/siderepo-pr-branch"; | ||
| const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce({ | ||
| ok: true, | ||
| status: 200, | ||
| json: async () => ({ head: { ref: headRef } }), | ||
| }); | ||
|
|
||
| const configPath = path.join(workspace, "config.json"); | ||
| fs.writeFileSync( | ||
| configPath, | ||
| JSON.stringify({ | ||
| push_to_pull_request_branch: { "target-repo": "githubnext/gh-aw-side-repo" }, | ||
| }) | ||
| ); | ||
|
|
||
| const prevBase = process.env.GH_AW_CUSTOM_BASE_BRANCH; | ||
| const prevEvent = process.env.GITHUB_EVENT_PATH; | ||
| const prevRepo = process.env.GITHUB_REPOSITORY; | ||
| const prevConfig = process.env.GH_AW_SAFE_OUTPUTS_CONFIG_PATH; | ||
| delete process.env.GITHUB_EVENT_PATH; // no event; rely on config | ||
| process.env.GH_AW_CUSTOM_BASE_BRANCH = "main"; | ||
| process.env.GITHUB_REPOSITORY = "githubnext/gh-aw-test"; // host repo (wrong repo) | ||
| process.env.GH_AW_SAFE_OUTPUTS_CONFIG_PATH = configPath; | ||
| try { | ||
| const entry = { | ||
| tool: "push_to_pull_request_branch", | ||
| // No `repo` override — agent emits only pull_request_number. | ||
| arguments: { message: "Multi-commit test push from Copilot in side repo", pull_request_number: 447 }, | ||
| sidecars: { patch: newFileDiff("src/siderepo-feature.py", "# side repo\n") }, | ||
| }; | ||
| await preStagePatch(entry, 0, workspace); | ||
| expect(git(["rev-parse", "--abbrev-ref", "HEAD"], workspace).trim()).toBe(headRef); | ||
| // Must fetch from the side repo, NOT the host repo. | ||
| expect(fetchSpy).toHaveBeenCalledWith(expect.stringContaining("/repos/githubnext/gh-aw-side-repo/pulls/447"), expect.anything()); | ||
| expect(fetchSpy).not.toHaveBeenCalledWith(expect.stringContaining("/repos/githubnext/gh-aw-test/pulls/447"), expect.anything()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test exercises path 3 of 💡 Suggested complementary testAdd a second The current test already does the heavy lifting; this would be a near-copy with a different event payload wired in. |
||
| } finally { | ||
| fetchSpy.mockRestore(); | ||
| if (prevBase === undefined) delete process.env.GH_AW_CUSTOM_BASE_BRANCH; | ||
| else process.env.GH_AW_CUSTOM_BASE_BRANCH = prevBase; | ||
| if (prevEvent !== undefined) process.env.GITHUB_EVENT_PATH = prevEvent; | ||
| if (prevRepo === undefined) delete process.env.GITHUB_REPOSITORY; | ||
| else process.env.GITHUB_REPOSITORY = prevRepo; | ||
| if (prevConfig === undefined) delete process.env.GH_AW_SAFE_OUTPUTS_CONFIG_PATH; | ||
| else process.env.GH_AW_SAFE_OUTPUTS_CONFIG_PATH = prevConfig; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Missing edge-case: The new test correctly covers tier-2 (config → side repo). But there is no assertion that tier-1 ( 💡 Suggested complementary testit("entry.arguments.repo takes precedence over target-repo in safe-outputs config", async () => {
// setup: write config with target-repo, but also set entry.arguments.repo
const entry = {
tool: "push_to_pull_request_branch",
arguments: { repo: "explicit/override-repo", pull_request_number: 123 },
sidecars: { patch: newFileDiff("src/file.py", "# content\n") },
};
await preStagePatch(entry, 0, workspace);
// tier-1 explicit repo must win over config target-repo
expect(fetchSpy).toHaveBeenCalledWith(
expect.stringContaining("/repos/explicit/override-repo/pulls/123"),
expect.anything()
);
expect(fetchSpy).not.toHaveBeenCalledWith(
expect.stringContaining("/repos/githubnext/gh-aw-side-repo/pulls/123"),
expect.anything()
);
}); |
||
| }); | ||
|
|
||
| it("is a no-op when the sample tool isn't in the patch-sidecar set", async () => { | ||
| // We assert this at the driver level (PATCH_SIDECAR_TOOLS gate in main()), | ||
| // but preStagePatch itself should also be a no-op when called with an | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/zoom-out] The single-line
||chain is harder to scan than the equivalentif/elseblock used inresolvePatchWorkspace(lines 308–312).Keeping the two functions stylistically consistent would lower cognitive load when future contributors need to modify the resolution order.
💡 Suggested style alignment with resolvePatchWorkspace
This matches the three-tier structure that is already documented in the comment block above.