-
Notifications
You must be signed in to change notification settings - Fork 494
Deduplicate safe-output body attribution handling #51648
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ const mockCore = { | |
| global.core = mockCore; | ||
|
|
||
| // Import the module | ||
| const { buildAIFooter, buildIslandStartMarker, buildIslandEndMarker, findIsland, updateBody } = await import("./update_pr_description_helpers.cjs"); | ||
| const { buildAIFooter, buildUpdatedBody, buildIslandStartMarker, buildIslandEndMarker, findIsland, updateBody } = await import("./update_pr_description_helpers.cjs"); | ||
|
|
||
| describe("update_pr_description_helpers.cjs", () => { | ||
| beforeEach(() => { | ||
|
|
@@ -45,6 +45,29 @@ describe("update_pr_description_helpers.cjs", () => { | |
| }); | ||
| }); | ||
|
|
||
| describe("buildUpdatedBody", () => { | ||
| it("uses the workflow repository for attribution and target repository for history", () => { | ||
| process.env.GH_AW_CALLER_WORKFLOW_ID = "caller-workflow"; | ||
| const result = buildUpdatedBody({ | ||
| context: { | ||
| repo: { owner: "target", repo: "repository" }, | ||
| serverUrl: "https://github.example", | ||
| runId: 123, | ||
| }, | ||
| currentBody: "Existing body", | ||
| newContent: "New body", | ||
| operation: "append", | ||
| includeFooter: true, | ||
| workflowRepo: { owner: "workflow", repo: "repository" }, | ||
| itemType: "issue", | ||
| }); | ||
|
|
||
| expect(result).toContain("https://github.example/workflow/repository/actions/runs/123"); | ||
|
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] 💡 Use afterEach to guarantee cleanupMove env setup/teardown to describe('buildUpdatedBody', () => {
const originalCallerId = process.env.GH_AW_CALLER_WORKFLOW_ID;
afterEach(() => {
if (originalCallerId === undefined) delete process.env.GH_AW_CALLER_WORKFLOW_ID;
else process.env.GH_AW_CALLER_WORKFLOW_ID = originalCallerId;
});
// ...
});This guarantees cleanup even if assertions throw. @copilot please address this. |
||
| expect(result).toContain("repo%3Atarget%2Frepository"); | ||
| delete process.env.GH_AW_CALLER_WORKFLOW_ID; | ||
| }); | ||
| }); | ||
|
|
||
| describe("buildIslandStartMarker", () => { | ||
| it("should build island start marker with workflow ID", () => { | ||
| const marker = buildIslandStartMarker("test-workflow"); | ||
|
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] No test for the 💡 Suggested testit('falls back to context.repo when workflowRepo is omitted', () => {
const result = buildUpdatedBody({
context: { repo: { owner: 'myorg', repo: 'myrepo' }, serverUrl: 'https://github.com', runId: 1 },
currentBody: '',
newContent: 'Body',
operation: 'append',
includeFooter: true,
itemType: 'issue',
// workflowRepo intentionally omitted
});
// run URL should use context.repo
expect(result).toContain('https://github.com/myorg/myrepo/actions/runs/1');
});This guards against a regression in @copilot please address this. |
||
|
|
||
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.
[/codebase-design] The critical cross-repo invariant — "use
workflowRepofor the run URL, butcontext.repofor the history link" — was documented in both callers but is absent frombuildUpdatedBody. Callers can no longer see this distinction; it should live here.💡 Suggested JSDoc addition
Add to the function's JSDoc (above
@param params):@copilot please address this.