* Build a synthetic issue body shaped like the real bundlers produce — * a few small sections followed by a giant `## Log (last N lines, * sanitized)` fenced block. We make the log section large enough to * exceed the requested budget.
(opts: { logLineCount: number; lineSize?: number })
| 95 | * exceed the requested budget. |
| 96 | */ |
| 97 | function makeBody(opts: { logLineCount: number; lineSize?: number }): string { |
| 98 | const lineSize = opts.lineSize ?? 80; |
| 99 | const logLines: string[] = []; |
| 100 | for (let i = 0; i < opts.logLineCount; i += 1) { |
| 101 | // Each line is prefixed with its index so we can verify which |
| 102 | // ones get dropped vs kept after truncation. |
| 103 | const prefix = `LINE${String(i).padStart(6, "0")}: `; |
| 104 | const padding = "x".repeat(Math.max(0, lineSize - prefix.length)); |
| 105 | logLines.push(prefix + padding); |
| 106 | } |
| 107 | |
| 108 | return [ |
| 109 | "## Description", |
| 110 | "Test description for the cap helper.", |
| 111 | "", |
| 112 | "## Environment", |
| 113 | "- Plugin: v0.21.5", |
| 114 | "", |
| 115 | "## Recent errors (last 20, sanitized)", |
| 116 | "```", |
| 117 | "transform failed: critical error 1", |
| 118 | "transform failed: critical error 2", |
| 119 | "```", |
| 120 | "", |
| 121 | "## Log (last 400 lines, sanitized)", |
| 122 | "```", |
| 123 | logLines.join("\n"), |
| 124 | "```", |
| 125 | ].join("\n"); |
| 126 | } |
| 127 | |
| 128 | it("returns body unchanged when already within budget", () => { |
| 129 | const body = makeBody({ logLineCount: 20 }); |