|
7 | 7 | isWrongAncestry, |
8 | 8 | authorHasPushPermission, |
9 | 9 | assessPrDescription, |
| 10 | + hasGuiCue, |
| 11 | + hasScreenshotEvidence, |
10 | 12 | collectPrQualityFailures, |
11 | 13 | } = require("./pr-quality.cjs"); |
12 | 14 |
|
@@ -81,6 +83,7 @@ describe("assessPrDescription", () => { |
81 | 83 | "## Verification", |
82 | 84 | "", |
83 | 85 | "- List the commands or checks you ran.", |
| 86 | + "- If this PR changes the GUI, include a screenshot of the UI change in the description.", |
84 | 87 | "", |
85 | 88 | "## Checklist", |
86 | 89 | "", |
@@ -114,9 +117,115 @@ describe("assessPrDescription", () => { |
114 | 117 | }); |
115 | 118 | }); |
116 | 119 |
|
| 120 | +describe("hasGuiCue", () => { |
| 121 | + it("matches gui as a whole word, case-insensitively, in title or body", () => { |
| 122 | + assert.equal(hasGuiCue("Fix GUI spacing", ""), true); |
| 123 | + assert.equal(hasGuiCue("fix gui spacing", ""), true); |
| 124 | + assert.equal(hasGuiCue("", "This changes gui/src/App.tsx"), true); |
| 125 | + assert.equal( |
| 126 | + hasGuiCue("", "## Summary\nGUI button is misaligned in the dashboard"), |
| 127 | + true, |
| 128 | + ); |
| 129 | + }); |
| 130 | + |
| 131 | + it("does not match gui inside other words", () => { |
| 132 | + assert.equal(hasGuiCue("Add contributor guidance", ""), false); |
| 133 | + assert.equal(hasGuiCue("", "Fix the guild invitation bug"), false); |
| 134 | + assert.equal(hasGuiCue("", "Remove guillotine dead code"), false); |
| 135 | + }); |
| 136 | + |
| 137 | + it("does not match missing or non-string inputs", () => { |
| 138 | + assert.equal(hasGuiCue(undefined, undefined), false); |
| 139 | + assert.equal(hasGuiCue(null, null), false); |
| 140 | + }); |
| 141 | +}); |
| 142 | + |
| 143 | +describe("hasScreenshotEvidence", () => { |
| 144 | + it("accepts embedded markdown images", () => { |
| 145 | + assert.equal( |
| 146 | + hasScreenshotEvidence(""), |
| 147 | + true, |
| 148 | + ); |
| 149 | + assert.equal( |
| 150 | + hasScreenshotEvidence( |
| 151 | + "Before:\n\n", |
| 152 | + ), |
| 153 | + true, |
| 154 | + ); |
| 155 | + }); |
| 156 | + |
| 157 | + it("accepts HTML img tags", () => { |
| 158 | + assert.equal( |
| 159 | + hasScreenshotEvidence('<img src="https://example.com/ui.png" width="600">'), |
| 160 | + true, |
| 161 | + ); |
| 162 | + }); |
| 163 | + |
| 164 | + it("accepts reference-style images with a matching definition", () => { |
| 165 | + assert.equal( |
| 166 | + hasScreenshotEvidence( |
| 167 | + "After:\n\n![after][shot]\n\n[shot]: https://example.com/after.png", |
| 168 | + ), |
| 169 | + true, |
| 170 | + ); |
| 171 | + assert.equal( |
| 172 | + hasScreenshotEvidence( |
| 173 | + "![after][]\n\n[after]: https://example.com/after.png", |
| 174 | + ), |
| 175 | + true, |
| 176 | + ); |
| 177 | + }); |
| 178 | + |
| 179 | + it("rejects image syntax inside fenced code and HTML comments", () => { |
| 180 | + assert.equal( |
| 181 | + hasScreenshotEvidence('```\n\n```'), |
| 182 | + false, |
| 183 | + ); |
| 184 | + assert.equal( |
| 185 | + hasScreenshotEvidence('```\n<img src="https://example.com/ui.png">\n```'), |
| 186 | + false, |
| 187 | + ); |
| 188 | + assert.equal( |
| 189 | + hasScreenshotEvidence("<!--  -->"), |
| 190 | + false, |
| 191 | + ); |
| 192 | + assert.equal( |
| 193 | + hasScreenshotEvidence('<!-- <img src="https://example.com/ui.png"> -->'), |
| 194 | + false, |
| 195 | + ); |
| 196 | + }); |
| 197 | + |
| 198 | + it("rejects img tags without a renderable src and references without a definition", () => { |
| 199 | + assert.equal(hasScreenshotEvidence("<img>"), false); |
| 200 | + assert.equal(hasScreenshotEvidence('<img src="">'), false); |
| 201 | + assert.equal( |
| 202 | + hasScreenshotEvidence("![after][shot]"), |
| 203 | + false, |
| 204 | + ); |
| 205 | + }); |
| 206 | + |
| 207 | + it("rejects plain links, bare image URLs, and text-only bodies", () => { |
| 208 | + assert.equal( |
| 209 | + hasScreenshotEvidence("[Screenshot](https://example.com/ui.png)"), |
| 210 | + false, |
| 211 | + ); |
| 212 | + assert.equal(hasScreenshotEvidence("https://example.com/ui.png"), false); |
| 213 | + assert.equal(hasScreenshotEvidence("No screenshot here."), false); |
| 214 | + assert.equal(hasScreenshotEvidence(undefined), false); |
| 215 | + }); |
| 216 | +}); |
| 217 | + |
117 | 218 | describe("collectPrQualityFailures", () => { |
118 | 219 | const allowed = ["dev"]; |
119 | 220 |
|
| 221 | + const richBody = [ |
| 222 | + "## Summary", |
| 223 | + "This change fixes the provider list spacing in the dashboard.", |
| 224 | + "", |
| 225 | + "## Test plan", |
| 226 | + "- Ran bun test tests/ci-workflows.test.ts", |
| 227 | + ].join("\n"); |
| 228 | + |
120 | 229 | it("reports wrong_base without requiring ancestry inputs", () => { |
121 | 230 | const failures = collectPrQualityFailures({ |
122 | 231 | baseRef: "main", |
@@ -277,4 +386,128 @@ describe("collectPrQualityFailures", () => { |
277 | 386 | }); |
278 | 387 | assert.ok(failures.some((f) => f.code === "wrong_base")); |
279 | 388 | }); |
| 389 | + |
| 390 | + it("flags a gui title without a screenshot", () => { |
| 391 | + const failures = collectPrQualityFailures({ |
| 392 | + baseRef: "dev", |
| 393 | + allowedBases: allowed, |
| 394 | + title: "GUI: fix provider list spacing", |
| 395 | + body: richBody, |
| 396 | + behindMain: 0, |
| 397 | + behindBase: 0, |
| 398 | + authorPermission: "read", |
| 399 | + }); |
| 400 | + assert.ok(failures.some((f) => f.code === "missing_ui_screenshot")); |
| 401 | + }); |
| 402 | + |
| 403 | + it("flags a gui mention in the body without a screenshot", () => { |
| 404 | + const failures = collectPrQualityFailures({ |
| 405 | + baseRef: "dev", |
| 406 | + allowedBases: allowed, |
| 407 | + title: "Fix dashboard spacing", |
| 408 | + body: [ |
| 409 | + "## Summary", |
| 410 | + "This change adjusts gui/ spacing tokens used by the dashboard.", |
| 411 | + "", |
| 412 | + "## Test plan", |
| 413 | + "- Ran bun test tests/ci-workflows.test.ts", |
| 414 | + ].join("\n"), |
| 415 | + behindMain: 0, |
| 416 | + behindBase: 0, |
| 417 | + authorPermission: "read", |
| 418 | + }); |
| 419 | + assert.ok(failures.some((f) => f.code === "missing_ui_screenshot")); |
| 420 | + }); |
| 421 | + |
| 422 | + it("accepts a gui title when a screenshot image is embedded", () => { |
| 423 | + const failures = collectPrQualityFailures({ |
| 424 | + baseRef: "dev", |
| 425 | + allowedBases: allowed, |
| 426 | + title: "GUI: fix provider list spacing", |
| 427 | + body: [ |
| 428 | + "## Summary", |
| 429 | + "This change fixes the provider list spacing in the dashboard.", |
| 430 | + "", |
| 431 | + "", |
| 432 | + "", |
| 433 | + "## Test plan", |
| 434 | + "- Ran bun test tests/ci-workflows.test.ts", |
| 435 | + ].join("\n"), |
| 436 | + behindMain: 0, |
| 437 | + behindBase: 0, |
| 438 | + authorPermission: "read", |
| 439 | + }); |
| 440 | + assert.ok(!failures.some((f) => f.code === "missing_ui_screenshot")); |
| 441 | + }); |
| 442 | + |
| 443 | + it("accepts a gui title when the screenshot uses reference-style markdown", () => { |
| 444 | + const failures = collectPrQualityFailures({ |
| 445 | + baseRef: "dev", |
| 446 | + allowedBases: allowed, |
| 447 | + title: "GUI: fix provider list spacing", |
| 448 | + body: [ |
| 449 | + "## Summary", |
| 450 | + "This change fixes the provider list spacing in the dashboard.", |
| 451 | + "", |
| 452 | + "![after][shot]", |
| 453 | + "", |
| 454 | + "[shot]: https://example.com/after.png", |
| 455 | + "", |
| 456 | + "## Test plan", |
| 457 | + "- Ran bun test tests/ci-workflows.test.ts", |
| 458 | + ].join("\n"), |
| 459 | + behindMain: 0, |
| 460 | + behindBase: 0, |
| 461 | + authorPermission: "read", |
| 462 | + }); |
| 463 | + assert.ok(!failures.some((f) => f.code === "missing_ui_screenshot")); |
| 464 | + }); |
| 465 | + |
| 466 | + it("still flags a gui title when image syntax is only inside a code fence", () => { |
| 467 | + const failures = collectPrQualityFailures({ |
| 468 | + baseRef: "dev", |
| 469 | + allowedBases: allowed, |
| 470 | + title: "GUI: fix provider list spacing", |
| 471 | + body: [ |
| 472 | + "## Summary", |
| 473 | + "This change fixes the provider list spacing in the dashboard.", |
| 474 | + "", |
| 475 | + "```", |
| 476 | + "", |
| 477 | + "```", |
| 478 | + "", |
| 479 | + "## Test plan", |
| 480 | + "- Ran bun test tests/ci-workflows.test.ts", |
| 481 | + ].join("\n"), |
| 482 | + behindMain: 0, |
| 483 | + behindBase: 0, |
| 484 | + authorPermission: "read", |
| 485 | + }); |
| 486 | + assert.ok(failures.some((f) => f.code === "missing_ui_screenshot")); |
| 487 | + }); |
| 488 | + |
| 489 | + it("ignores the template's own gui/screenshot instruction", () => { |
| 490 | + const failures = collectPrQualityFailures({ |
| 491 | + baseRef: "dev", |
| 492 | + allowedBases: allowed, |
| 493 | + title: "Add a thing", |
| 494 | + body: [ |
| 495 | + "## Summary", |
| 496 | + "This change touches the proxy only; no UI surface changed.", |
| 497 | + "", |
| 498 | + "## Verification", |
| 499 | + "- List the commands or checks you ran.", |
| 500 | + "- If this PR changes the GUI, include a screenshot of the UI change in the description.", |
| 501 | + "", |
| 502 | + "## Checklist", |
| 503 | + "- [ ] Scope stays focused and avoids unrelated cleanup.", |
| 504 | + "- [ ] Docs or release notes were updated when needed.", |
| 505 | + "- [ ] Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.", |
| 506 | + ].join("\n"), |
| 507 | + behindMain: 0, |
| 508 | + behindBase: 0, |
| 509 | + authorPermission: "read", |
| 510 | + }); |
| 511 | + assert.ok(!failures.some((f) => f.code === "missing_ui_screenshot")); |
| 512 | + }); |
280 | 513 | }); |
0 commit comments