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
24 changes: 24 additions & 0 deletions actions/setup/js/log_parser_shared.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,16 @@ function formatSafeOutputsPreview(safeOutputsContent, options = {}) {
const bodyPreview = truncateString(bodyStr.replace(/\n/g, " "), 80);
preview.push(` Body: ${bodyPreview}`);
}
// noop, missing_tool, and missing_data carry their primary content in
// "message"/"reason" rather than title/body — surface those too.
if (entry.message) {
const messageStr = typeof entry.message === "string" ? entry.message : String(entry.message);
preview.push(` Message: ${truncateString(messageStr.replace(/\n/g, " "), 80)}`);
}
if (entry.reason) {
const reasonStr = typeof entry.reason === "string" ? entry.reason : String(entry.reason);
preview.push(` Reason: ${truncateString(reasonStr.replace(/\n/g, " "), 80)}`);
}
}

if (hasMore) {
Expand Down Expand Up @@ -1353,6 +1363,20 @@ function formatSafeOutputsPreview(safeOutputsContent, options = {}) {
preview.push("");
}

// noop, missing_tool, and missing_data carry their primary content in
// "message"/"reason" rather than title/body — surface those too.
if (entry.message) {
const messageStr = typeof entry.message === "string" ? entry.message : String(entry.message);
preview.push(`**Message:** ${truncateString(messageStr, 200)}`);
preview.push("");
}

if (entry.reason) {
const reasonStr = typeof entry.reason === "string" ? entry.reason : String(entry.reason);
preview.push(`**Reason:** ${truncateString(reasonStr, 200)}`);
preview.push("");
}

if (entry.data !== undefined) {
const dataString = truncateString(JSON.stringify(entry.data, null, 2), 400);
preview.push("**Data:**");
Expand Down
31 changes: 31 additions & 0 deletions actions/setup/js/log_parser_shared.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,37 @@ describe("log_parser_shared.cjs", () => {
expect(result).not.toContain("Body:");
});

it("should surface the message field for noop entries in plain text mode", async () => {
const { formatSafeOutputsPreview } = await import("./log_parser_shared.cjs");

const safeOutputs = JSON.stringify({ type: "noop", message: "Nothing to do here" });
const result = formatSafeOutputsPreview(safeOutputs, { isPlainText: true });

expect(result).toContain("[1] noop");
expect(result).toContain("Message: Nothing to do here");
});

it("should surface the message field for noop entries in markdown mode", async () => {
const { formatSafeOutputsPreview } = await import("./log_parser_shared.cjs");

const safeOutputs = JSON.stringify({ type: "noop", message: "Nothing to do here" });
const result = formatSafeOutputsPreview(safeOutputs, { isPlainText: false });

expect(result).toContain("**1. noop**");
expect(result).toContain("**Message:** Nothing to do here");
});

it("should surface the reason field for missing_tool/missing_data entries", async () => {
const { formatSafeOutputsPreview } = await import("./log_parser_shared.cjs");

const safeOutputs = JSON.stringify({ type: "missing_tool", tool: "docker", reason: "Docker is not available" });
const plain = formatSafeOutputsPreview(safeOutputs, { isPlainText: true });
const markdown = formatSafeOutputsPreview(safeOutputs, { isPlainText: false });

expect(plain).toContain("Reason: Docker is not available");
expect(markdown).toContain("**Reason:** Docker is not available");
});

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] Test name promises missing_tool/missing_data coverage but only exercises missing_toolmissing_data has a different schema (data_type, context, alternatives) and its reason rendering is untested.

💡 Suggested addition
it('should surface the reason field for missing_data entries', async () => {
  const { formatSafeOutputsPreview } = await import('./log_parser_shared.cjs');

  const safeOutputs = JSON.stringify({ type: 'missing_data', data_type: 'pr_number', reason: 'PR number not found in context' });
  const plain = formatSafeOutputsPreview(safeOutputs, { isPlainText: true });
  const markdown = formatSafeOutputsPreview(safeOutputs, { isPlainText: false });

  expect(plain).toContain('Reason: PR number not found in context');
  expect(markdown).toContain('**Reason:** PR number not found in context');
});

@copilot please address this.

it("should skip invalid JSON lines", async () => {
const { formatSafeOutputsPreview } = await import("./log_parser_shared.cjs");

Expand Down
Loading