Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions actions/setup/js/update_pr_description_helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The detectionCaution truthy branch — ${detectionCaution}\n\n${sanitizedNewContent} — has no test coverage. The PR adds tests for findIsland and buildAIFooter, but the code path that was actually changed (updateBody's caution injection) is never exercised with a non-empty detectionCaution.

💡 Suggested test scaffold

To cover this branch you would need to mock assembleMarkdownBodyParts to return a non-empty detectionCaution, then assert the output starts with the caution block followed by the sanitized content:

it('should prepend detectionCaution before content when threat is detected', () => {
  // mock markdown_body_helpers to return detectionCaution = '>  [!CAUTION]\n> ...'
  const result = updateBody({ ...baseParams, operation: 'replace' });
  expect(result.indexOf(caution)).toBeLessThan(result.indexOf('New content'));
});

Without this test the template-literal on this line is validated only by visual inspection.


if (operation === "replace") {
// Replace: use new content with optional AI footer
Expand Down
40 changes: 40 additions & 0 deletions actions/setup/js/update_pr_description_helpers.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant test: this it block adds no regression protection beyond what adjacent tests already provide.

💡 Details

Every other buildAIFooter test (e.g. line 22, which asserts toContain("Test Workflow") and toContain(runUrl)) already implicitly proves the function returns a non-empty string. If buildAIFooter broke and returned undefined or "", those tests would fail first.

The expect(typeof footer).toBe("string") assertion is a no-op: TypeScript enforces this at compile time, and if it somehow weren't a string at runtime, footer.length would throw or return undefined, failing toBeGreaterThan(0) on its own.

Consider replacing this with a more targeted assertion — for example verifying the footer contains the <!-- gh-aw-agentic-workflow: ... --> XML marker or the Generated by prefix — so this slot in the suite actually catches a novel failure mode.

const footer = buildAIFooter("Test Workflow", "https://github.com/owner/repo/actions/runs/123");
expect(typeof footer).toBe("string");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The typeof footer === 'string' assertion is redundant — earlier tests already imply the return type via .toContain(), and the JSDoc @returns {string} documents the contract.

💡 Consider a behavioural assertion instead

A more valuable spec would verify something the other tests don't cover, for example that a footer produced with no optional args still contains the mandatory attribution marker. The current check reads as a type-level sanity probe rather than a specification.

expect(footer.length).toBeGreaterThan(0);
});
});

describe("buildIslandStartMarker", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down
Loading