diff --git a/actions/setup/js/update_pr_description_helpers.cjs b/actions/setup/js/update_pr_description_helpers.cjs index f5bed7ecbd4..09791c6f08c 100644 --- a/actions/setup/js/update_pr_description_helpers.cjs +++ b/actions/setup/js/update_pr_description_helpers.cjs @@ -103,12 +103,12 @@ function updateBody(params) { const sanitizedNewContent = sanitizeContent(newContent); // Inject CAUTION at top of new content if threat detection warning was raised - const detectionCaution = assembleMarkdownBodyParts({ + const { detectionCaution } = assembleMarkdownBodyParts({ includeFooter: false, workflowName, runUrl, - }).detectionCaution; - const contentWithCaution = detectionCaution ? detectionCaution + "\n\n" + sanitizedNewContent : sanitizedNewContent; + }); + const contentWithCaution = detectionCaution ? `${detectionCaution}\n\n${sanitizedNewContent}` : sanitizedNewContent; if (operation === "replace") { // Replace: use new content with optional AI footer diff --git a/actions/setup/js/update_pr_description_helpers.test.cjs b/actions/setup/js/update_pr_description_helpers.test.cjs index d29b8644a41..ff54c39136e 100644 --- a/actions/setup/js/update_pr_description_helpers.test.cjs +++ b/actions/setup/js/update_pr_description_helpers.test.cjs @@ -31,6 +31,18 @@ describe("update_pr_description_helpers.cjs", () => { const footer = buildAIFooter("Test & Workflow", "https://github.com/owner/repo/actions/runs/123"); expect(footer).toContain("Test & Workflow"); }); + + it("should include historyUrl in footer when provided", () => { + const historyUrl = "https://github.com/search?q=repo%3Aowner%2Frepo"; + const footer = buildAIFooter("Test Workflow", "https://github.com/owner/repo/actions/runs/123", historyUrl); + expect(footer).toContain(historyUrl); + }); + + it("should return a non-empty footer string", () => { + const footer = buildAIFooter("Test Workflow", "https://github.com/owner/repo/actions/runs/123"); + expect(typeof footer).toBe("string"); + expect(footer.length).toBeGreaterThan(0); + }); }); describe("buildIslandStartMarker", () => { @@ -96,6 +108,34 @@ describe("update_pr_description_helpers.cjs", () => { expect(result2.found).toBe(true); expect(result1.startIndex).toBeLessThan(result2.startIndex); }); + + it("should return exact startIndex=0 and endIndex=body.length when island spans entire body", () => { + const startMarker = buildIslandStartMarker("wf"); + const endMarker = buildIslandEndMarker("wf"); + const body = `${startMarker}inner${endMarker}`; + const result = findIsland(body, "wf"); + expect(result.found).toBe(true); + expect(result.startIndex).toBe(0); + expect(result.endIndex).toBe(body.length); + }); + + it("should not find island in empty body", () => { + const result = findIsland("", "test-workflow"); + expect(result.found).toBe(false); + expect(result.startIndex).toBe(-1); + expect(result.endIndex).toBe(-1); + }); + + it("should find island with prefix content and return correct startIndex", () => { + const prefix = "prefix content\n"; + const startMarker = buildIslandStartMarker("wf"); + const endMarker = buildIslandEndMarker("wf"); + const body = `${prefix}${startMarker}inner${endMarker}`; + const result = findIsland(body, "wf"); + expect(result.found).toBe(true); + expect(result.startIndex).toBe(prefix.length); + expect(result.endIndex).toBe(body.length); + }); }); describe("updateBody - replace operation", () => {