mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-19 06:34:43 +01:00
Open pull requests with three plain lines and land each one as a single commit (GST-2737) (#4438)
* WIP plain PR bodies and squash messages Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Fold PR bodies to three plain lines and land every PR as one plainly titled commit Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Expect the plain commit body in the train land tests Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Count the new policy keys in the floor tests and record the ship size change Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Let older, generated and Dependabot PRs pass the body check, and keep comments posting The opening check now follows the same date and branch exemption as the rest of the body check, Dependabot branches are exempt, the exemption only counts for branches in this repository, a merge that cannot read the PR waits instead of refusing, and a broken policy file no longer stops comments. Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/specialist-batched#2 reader=testing Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/red-team#2 reader=red-team Review-Finding: p1/red-team#4 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Stop re-posted PR bodies from duplicating sections, and let file names through the word check Posting an already-folded body now replaces each section once instead of keeping the old copy beside it, and listed words inside file paths or file names, such as a test file in the Tests section, no longer count as prose. Review-Finding: v2/outside-voice#3 reader=outside-voice Review-Finding: v2/adversarial-native#2 reader=adversarial-native Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Describe the folded three-line PR body in the skills guide and the prose lint help Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
aeb74eb00b
commit
c53b15c48d
47 files changed
+1182
-208
No files matched your search
+125
-29
@@ -13,6 +13,7 @@ import * as path from "node:path";
|
||||
import { EXIT, attributionCallout, mergeBodySections, runPost, type PostEnv } from "../lib/gstack-post";
|
||||
import { extractReceipt, orderReceipt, placeReceipt, receiptRuns } from "../lib/ship-receipt";
|
||||
import type { ShipReceipt } from "../lib/headless-artifacts";
|
||||
import { foldSections, unfoldSections } from "../lib/pr-body-shape";
|
||||
|
||||
interface Call { cmd: string; args: string[]; input?: string }
|
||||
|
||||
@@ -348,7 +349,7 @@ describe("gstack-post owns the redaction scan", () => {
|
||||
);
|
||||
for (const [name, text, needle] of holds) {
|
||||
const { code, phones, f } = post(text);
|
||||
expect([name, phones, code]).toEqual([name, [`RULE: pii.phone.e164 LINE: ${lineOf(text, needle)} PART: body`], EXIT.confirm]);
|
||||
expect([name, phones, code]).toEqual([name, [`RULE: pii.phone.e164 LINE: ${lineOf(foldSections(text), needle)} PART: body`], EXIT.confirm]);
|
||||
expect(f.posts()).toEqual([]);
|
||||
}
|
||||
});
|
||||
@@ -494,23 +495,33 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
test("a first-section-only body keeps the other sections and the receipt; a same-titled section is replaced in place; new sections are appended", () => {
|
||||
const f = withBody(CURRENT, { "/b": "## What Changed\n\n- the new summary\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], f)).toBe(EXIT.posted);
|
||||
expect(sent(f).input).toBe(RECEIPT("aaaa") + "\n## What Changed\n\n- the new summary\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: do it\n");
|
||||
expect(sent(f).input).toBe(foldSections(RECEIPT("aaaa") + "\n## What Changed\n\n- the new summary\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: do it\n"));
|
||||
expect(f.stderr()).toBe("gstack-post: pr-body merged by section: replaced What changed; kept ship receipt, Why, Approvals; added none\n");
|
||||
expect(f.calls.find(c => c.cmd === "gh" && c.args[1] === "view")!.args).toEqual(["pr", "view", "5", "--json", "body", "--jq", ".body"]);
|
||||
|
||||
const receipt = withBody(CURRENT, { "/b": RECEIPT("bbbb") });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], receipt)).toBe(EXIT.posted);
|
||||
expect(sent(receipt).input).toBe(CURRENT.replace(RECEIPT("aaaa"), RECEIPT("bbbb")));
|
||||
expect(sent(receipt).input).toBe(foldSections(CURRENT.replace(RECEIPT("aaaa"), RECEIPT("bbbb"))));
|
||||
expect(receipt.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt; kept What changed, Why, Approvals; added none\n");
|
||||
|
||||
const added = withBody(CURRENT, { "/b": "## Why\n\nStill because.\n\n## Tests\n\n- one\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], added)).toBe(EXIT.posted);
|
||||
expect(sent(added).input).toBe(RECEIPT("aaaa") + "\n## What changed\n\n- the old summary\n\n## Why\n\nStill because.\n\n## Approvals\n\n- owner: do it\n\n## Tests\n\n- one\n");
|
||||
expect(sent(added).input).toBe(foldSections(RECEIPT("aaaa") + "\n## What changed\n\n- the old summary\n\n## Why\n\nStill because.\n\n## Approvals\n\n- owner: do it\n\n## Tests\n\n- one\n"));
|
||||
expect(added.stderr()).toBe("gstack-post: pr-body merged by section: replaced Why; kept ship receipt, What changed, Approvals; added Tests\n");
|
||||
|
||||
const fenced = withBody("## Notes\n\n```md\n## not a heading\n```\n\n## Why\n\nold\n", { "/b": "## Why\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], fenced)).toBe(EXIT.posted);
|
||||
expect(sent(fenced).input).toBe("## Notes\n\n```md\n## not a heading\n```\n\n## Why\n\nnew\n");
|
||||
expect(sent(fenced).input).toBe(foldSections("## Notes\n\n```md\n## not a heading\n```\n\n## Why\n\nnew\n"));
|
||||
});
|
||||
|
||||
// Value: protects=re-posting an already-folded body (the live body, or gstack-post fold output) replaces each section once instead of keeping the
|
||||
// old sections beside it; fails_when=the incoming folds are read as leading text and every section ends up twice; why_new=GST-2737 review (granted fix-check)
|
||||
test("a folded incoming body replaces the folded sections it names; nothing is duplicated", () => {
|
||||
const current = foldSections("Opening.\n\n## Tests\n\nOld\n\n## Why\n\nBecause.\n");
|
||||
const f = withBody(current, { "/b": foldSections("Opening.\n\n## Tests\n\nNew\n") });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], f)).toBe(EXIT.posted);
|
||||
expect(sent(f).input).toBe(foldSections("Opening.\n\n## Tests\n\nNew\n\n## Why\n\nBecause.\n"));
|
||||
expect(f.stderr()).toContain("replaced leading text, Tests; kept Why");
|
||||
});
|
||||
|
||||
// Value: protects=a fence closes only on a run of its own character at least as long as the opener with nothing after it, so a ``` line inside a
|
||||
@@ -522,31 +533,31 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
const long = "## Notes\n\n````md\n```\n## Tests\nfake\n```\n````\n\n## Tests\n\nold\n";
|
||||
const four = withBody(long, { "/b": "## Tests\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], four)).toBe(EXIT.posted);
|
||||
expect(sent(four).input).toBe("## Notes\n\n````md\n```\n## Tests\nfake\n```\n````\n\n## Tests\n\nnew\n");
|
||||
expect(sent(four).input).toBe(foldSections("## Notes\n\n````md\n```\n## Tests\nfake\n```\n````\n\n## Tests\n\nnew\n"));
|
||||
expect(four.stderr()).toBe("gstack-post: pr-body merged by section: replaced Tests; kept Notes; added none\n");
|
||||
|
||||
const info = withBody("## Notes\n\n```sh\n```js\n## Tests\n~~~\n```\n\n## Tests\n\nold\n", { "/b": "## Tests\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], info)).toBe(EXIT.posted);
|
||||
expect(sent(info).input).toBe("## Notes\n\n```sh\n```js\n## Tests\n~~~\n```\n\n## Tests\n\nnew\n");
|
||||
expect(sent(info).input).toBe(foldSections("## Notes\n\n```sh\n```js\n## Tests\n~~~\n```\n\n## Tests\n\nnew\n"));
|
||||
|
||||
const unclosed = "```gstack-ship-receipt\nSHIP_RECEIPT: pr=5 head=aaaa\n\n## Summary\n\nold\n\n## Approvals\n\n- owner: do it\n";
|
||||
const open = withBody(unclosed, { "/b": RECEIPT("bbbb") + "\n## Summary\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], open)).toBe(EXIT.posted);
|
||||
expect(sent(open).input).toBe(RECEIPT("bbbb") + "\n" + unclosed + "\n## Summary\n\nnew\n");
|
||||
expect(sent(open).input).toBe(foldSections(RECEIPT("bbbb") + "\n" + unclosed + "\n## Summary\n\nnew\n"));
|
||||
expect(open.stderr()).toBe("gstack-post: pr-body merged by section: replaced none; kept unclosed receipt fence; added ship receipt, Summary\n");
|
||||
|
||||
const prose = withBody(unclosed, { "/b": "Updated introduction\n\n## Summary\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], prose)).toBe(EXIT.posted);
|
||||
expect(sent(prose).input).toBe("Updated introduction\n\n" + unclosed + "\n## Summary\n\nnew\n");
|
||||
expect(sent(prose).input).toBe(foldSections("Updated introduction\n\n" + unclosed + "\n## Summary\n\nnew\n"));
|
||||
|
||||
const inside = withBody("Intro\n\n## Notes\n\n" + unclosed, { "/b": "New intro\n\n## Notes\n\nnew notes\n\n## Approvals\n\n- owner: still\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], inside)).toBe(EXIT.posted);
|
||||
expect(sent(inside).input).toBe("New intro\n\n## Notes\n\nnew notes\n\n" + unclosed + "\n## Approvals\n\n- owner: still\n");
|
||||
expect(sent(inside).input).toBe(foldSections("New intro\n\n## Notes\n\nnew notes\n\n" + unclosed + "\n## Approvals\n\n- owner: still\n"));
|
||||
expect(inside.stderr()).toBe("gstack-post: pr-body merged by section: replaced leading text, Notes; kept unclosed receipt fence; added Approvals\n");
|
||||
|
||||
const after = withBody(RECEIPT("aaaa") + "\n## Why\n\nold\n\n" + unclosed, { "/b": RECEIPT("bbbb") + "\n## Why\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], after)).toBe(EXIT.posted);
|
||||
expect(sent(after).input).toBe(RECEIPT("bbbb") + "\n## Why\n\nnew\n\n" + unclosed);
|
||||
expect(sent(after).input).toBe(foldSections(RECEIPT("bbbb") + "\n## Why\n\nnew\n\n" + unclosed));
|
||||
expect(after.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt, Why; kept unclosed receipt fence; added none\n");
|
||||
});
|
||||
|
||||
@@ -560,18 +571,18 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
const intro = "Draft intro from gh pr create, long enough to need truncation in the summary line\nsecond line\n\n";
|
||||
const stale = withBody(intro + CURRENT, { "/b": RECEIPT("bbbb") + "\n## What changed\n\n- new\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], stale)).toBe(EXIT.posted);
|
||||
expect(sent(stale).input).toBe(intro + RECEIPT("bbbb") + "\n## What changed\n\n- new\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: do it\n");
|
||||
expect(sent(stale).input).toBe(foldSections(intro + RECEIPT("bbbb") + "\n## What changed\n\n- new\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: do it\n"));
|
||||
expect(stale.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt, What changed; kept leading text, Why, Approvals; added none\n");
|
||||
|
||||
const between = withBody(RECEIPT("aaaa") + "Old note under the receipt\n\n## What changed\n\n- old\n", { "/b": RECEIPT("bbbb") + "## What changed\n\n- new\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], between)).toBe(EXIT.posted);
|
||||
expect(sent(between).input).toBe(RECEIPT("bbbb") + "\n## What changed\n\n- new\n");
|
||||
expect(sent(between).input).toBe(foldSections(RECEIPT("bbbb") + "\n## What changed\n\n- new\n"));
|
||||
expect(between.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt, What changed; kept none; added none; dropped trailing text (\"Old note under the receipt\")\n");
|
||||
|
||||
const own = withBody("Stale intro\n\n" + RECEIPT("aaaa") + "Stale note\n\n## Why\n\nold\n", { "/b": "Fresh intro\n\n" + RECEIPT("bbbb") + "Fresh note\n\n## Why\n\nnew\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], own)).toBe(EXIT.posted);
|
||||
expect(sent(own).input).toBe("Fresh intro\n\n" + RECEIPT("bbbb") + "\nFresh note\n\n## Why\n\nnew\n");
|
||||
expect(mergeBodySections(sent(own).input!, "Fresh intro\n\n" + RECEIPT("bbbb") + "Fresh note\n\n## Why\n\nnew\n").body).toBe(sent(own).input!);
|
||||
expect(sent(own).input).toBe(foldSections("Fresh intro\n\n" + RECEIPT("bbbb") + "\nFresh note\n\n## Why\n\nnew\n"));
|
||||
expect(foldSections(mergeBodySections(unfoldSections(sent(own).input!), "Fresh intro\n\n" + RECEIPT("bbbb") + "Fresh note\n\n## Why\n\nnew\n").body)).toBe(sent(own).input!);
|
||||
expect(own.stderr()).toBe("gstack-post: pr-body merged by section: replaced leading text, ship receipt, trailing text, Why; kept none; added none\n");
|
||||
});
|
||||
|
||||
@@ -585,17 +596,17 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
const PREAMBLE = BADGE + "\nThis PR stops the login retry from looping.\n\n";
|
||||
const first = withBody(PREAMBLE + "## What changed\n\n- the old summary\n\n## Why\n\nBecause.\n", { "/b": RECEIPT("bbbb") + "\n## What changed\n\n- new\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], first)).toBe(EXIT.posted);
|
||||
expect(sent(first).input).toBe(PREAMBLE + RECEIPT("bbbb") + "\n## What changed\n\n- new\n\n## Why\n\nBecause.\n");
|
||||
expect(sent(first).input).toBe(foldSections(PREAMBLE + RECEIPT("bbbb") + "\n## What changed\n\n- new\n\n## Why\n\nBecause.\n"));
|
||||
expect(first.stderr()).toBe("gstack-post: pr-body merged by section: replaced What changed; kept leading text, Why; added ship receipt\n");
|
||||
|
||||
const again = withBody(sent(first).input!, { "/b": RECEIPT("cccc") + "\n## What changed\n\n- newer\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], again)).toBe(EXIT.posted);
|
||||
expect(sent(again).input).toBe(PREAMBLE + RECEIPT("cccc") + "\n## What changed\n\n- newer\n\n## Why\n\nBecause.\n");
|
||||
expect(sent(again).input).toBe(foldSections(PREAMBLE + RECEIPT("cccc") + "\n## What changed\n\n- newer\n\n## Why\n\nBecause.\n"));
|
||||
expect(again.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt, What changed; kept leading text, Why; added none\n");
|
||||
|
||||
const trailing = withBody(CURRENT + "\n" + BADGE, { "/b": RECEIPT("bbbb") + "\n## Approvals\n\n- owner: ship it\n\n## Tests\n\n- one\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], trailing)).toBe(EXIT.posted);
|
||||
expect(sent(trailing).input).toBe(RECEIPT("bbbb") + "\n## What changed\n\n- the old summary\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: ship it\n\n## Tests\n\n- one\n\n" + BADGE);
|
||||
expect(sent(trailing).input).toBe(foldSections(RECEIPT("bbbb") + "\n## What changed\n\n- the old summary\n\n## Why\n\nBecause.\n\n## Approvals\n\n- owner: ship it\n\n## Tests\n\n- one\n\n" + BADGE));
|
||||
expect(trailing.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt, Approvals; kept What changed, Why, capy-badge block; added Tests\n");
|
||||
});
|
||||
|
||||
@@ -655,7 +666,7 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
test("a partial post keeps the current intro and the note under the receipt", () => {
|
||||
const partial = withBody("Human intro\n\n" + RECEIPT("aaaa") + "Review-loop exception: accepted by owner\n\n## What changed\n\n- old\n", { "/b": "## Screenshots\n\n\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], partial)).toBe(EXIT.posted);
|
||||
expect(sent(partial).input).toBe("Human intro\n\n" + RECEIPT("aaaa") + "Review-loop exception: accepted by owner\n\n## What changed\n\n- old\n\n## Screenshots\n\n\n");
|
||||
expect(sent(partial).input).toBe(foldSections("Human intro\n\n" + RECEIPT("aaaa") + "Review-loop exception: accepted by owner\n\n## What changed\n\n- old\n\n## Screenshots\n\n\n"));
|
||||
expect(partial.stderr()).toBe("gstack-post: pr-body merged by section: replaced none; kept leading text, ship receipt, trailing text, What changed; added Screenshots\n");
|
||||
|
||||
for (const file of ["Screenshots below.\n\n## Screenshots\n\n\n", "## Screenshots\n\n\n\n" + RECEIPT("bbbb")]) {
|
||||
@@ -678,12 +689,12 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
const lead = "Human intro\n\n" + CURRENT;
|
||||
const receiptOnly = withBody(lead, { "/b": RECEIPT("bbbb") });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], receiptOnly)).toBe(EXIT.posted);
|
||||
expect(sent(receiptOnly).input).toBe(lead.replace(RECEIPT("aaaa"), RECEIPT("bbbb")));
|
||||
expect(sent(receiptOnly).input).toBe(foldSections(lead.replace(RECEIPT("aaaa"), RECEIPT("bbbb"))));
|
||||
expect(receiptOnly.stderr()).toBe("gstack-post: pr-body merged by section: replaced ship receipt; kept leading text, What changed, Why, Approvals; added none\n");
|
||||
|
||||
const textOnly = withBody(RECEIPT("aaaa") + "Old note\n\n## Why\n\nx\n", { "/b": "New intro\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], textOnly)).toBe(EXIT.posted);
|
||||
expect(sent(textOnly).input).toBe("New intro\n\n" + RECEIPT("aaaa") + "Old note\n\n## Why\n\nx\n");
|
||||
expect(sent(textOnly).input).toBe(foldSections("New intro\n\n" + RECEIPT("aaaa") + "Old note\n\n## Why\n\nx\n"));
|
||||
expect(textOnly.stderr()).toBe("gstack-post: pr-body merged by section: replaced none; kept ship receipt, trailing text, Why; added leading text\n");
|
||||
|
||||
const composed = "Intro\n\n" + RECEIPT("bbbb") + "\n## Summary\n\nnew\n\n## Test plan\n\n- [x] bun test\n";
|
||||
@@ -707,22 +718,22 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
test("--replace overwrites; a body without H2 headings is kept above a new receipt by any file; the merged bytes are what is scanned; a failed read refuses", () => {
|
||||
const replaced = withBody(CURRENT, { "/b": "## What changed\n\nonly this\n" });
|
||||
expect(run(["pr-body", "5", "--replace", "--body-file", "/b"], replaced)).toBe(EXIT.posted);
|
||||
expect(sent(replaced).input).toBe("## What changed\n\nonly this\n");
|
||||
expect(sent(replaced).input).toBe(foldSections("## What changed\n\nonly this\n"));
|
||||
expect(replaced.stderr()).toBe("");
|
||||
expect(replaced.calls.some(c => c.cmd === "gh" && c.args[1] === "view")).toBe(false);
|
||||
|
||||
const plain = withBody("Just a paragraph.\nAnother line.", { "/b": RECEIPT("bbbb") + "\n## Tests\n\n- one\n" });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], plain)).toBe(EXIT.posted);
|
||||
expect(sent(plain).input).toBe("Just a paragraph.\nAnother line.\n\n" + RECEIPT("bbbb") + "\n## Tests\n\n- one\n");
|
||||
expect(sent(plain).input).toBe(foldSections("Just a paragraph.\nAnother line.\n\n" + RECEIPT("bbbb") + "\n## Tests\n\n- one\n"));
|
||||
expect(plain.stderr()).toBe("gstack-post: pr-body merged by section: replaced none; kept leading text; added ship receipt, Tests\n");
|
||||
const plainText = withBody("Just a paragraph.\nAnother line.", { "/b": RECEIPT("bbbb") });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], plainText)).toBe(EXIT.posted);
|
||||
expect(sent(plainText).input).toBe("Just a paragraph.\nAnother line.\n\n" + RECEIPT("bbbb"));
|
||||
expect(sent(plainText).input).toBe(foldSections("Just a paragraph.\nAnother line.\n\n" + RECEIPT("bbbb")));
|
||||
expect(plainText.stderr()).toBe("gstack-post: pr-body merged by section: replaced none; kept leading text; added ship receipt\n");
|
||||
|
||||
const empty = withBody("", { "/b": "new body" });
|
||||
expect(run(["pr-body", "6", "--body-file", "/b"], empty)).toBe(EXIT.posted);
|
||||
expect(sent(empty).input).toBe("new body");
|
||||
expect(sent(empty).input).toBe(foldSections("new body"));
|
||||
|
||||
const secret = fakeEnv({ files: { "/b": "## What changed\n\nclean\n" }, respond: c => (c.cmd === "gh" && c.args[1] === "view" ? { status: 0, stdout: "## Keys\n\n" + AWS + "\n" } : undefined) });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b"], secret)).toBe(EXIT.refused);
|
||||
@@ -747,15 +758,15 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
const merged = fakeEnv({ remote, files: { "/b": "## Why\n\nnew\n" }, respond: view(JSON.stringify({ iid: 8, description: "## What changed\n\n- old\n\n## Why\n\nold\n" }) + "\n") });
|
||||
expect(run(["pr-body", "8", "--body-file", "/b"], merged)).toBe(EXIT.posted);
|
||||
expect(merged.calls.find(c => c.cmd === "glab" && c.args[1] === "view")!.args).toEqual(["mr", "view", "8", "--output", "json"]);
|
||||
expect(merged.posts()).toEqual([{ cmd: "glab", args: ["mr", "update", "8", "--description=## What changed\n\n- old\n\n## Why\n\nnew\n"], input: undefined }]);
|
||||
expect(merged.posts()).toEqual([{ cmd: "glab", args: ["mr", "update", "8", "--description=" + foldSections("## What changed\n\n- old\n\n## Why\n\nnew\n")], input: undefined }]);
|
||||
expect(merged.stderr()).toBe("gstack-post: pr-body merged by section: replaced Why; kept What changed; added none\n");
|
||||
|
||||
const empty = fakeEnv({ remote, files: { "/b": "## Why\n\nnew\n" }, respond: view("") });
|
||||
expect(run(["pr-body", "8", "--body-file", "/b"], empty)).toBe(EXIT.posted);
|
||||
expect(empty.posts()[0]!.args).toEqual(["mr", "update", "8", "--description=## Why\n\nnew\n"]);
|
||||
expect(empty.posts()[0]!.args).toEqual(["mr", "update", "8", "--description=" + foldSections("## Why\n\nnew\n")]);
|
||||
const nullDescription = fakeEnv({ remote, files: { "/b": "## Why\n\nnew\n" }, respond: view('{"iid":8,"description":null}\n') });
|
||||
expect(run(["pr-body", "8", "--body-file", "/b"], nullDescription)).toBe(EXIT.posted);
|
||||
expect(nullDescription.posts()[0]!.args).toEqual(["mr", "update", "8", "--description=## Why\n\nnew\n"]);
|
||||
expect(nullDescription.posts()[0]!.args).toEqual(["mr", "update", "8", "--description=" + foldSections("## Why\n\nnew\n")]);
|
||||
|
||||
const garbled = fakeEnv({ remote, files: { "/b": "## Why\n\nnew\n" }, respond: view("<html>502</html>\n") });
|
||||
expect(run(["pr-body", "8", "--body-file", "/b"], garbled)).toBe(EXIT.cliFailed);
|
||||
@@ -809,7 +820,7 @@ describe("gstack-post pr-body merges the PR body by section", () => {
|
||||
|
||||
const replaced = withBody(current, { "/b": fresh });
|
||||
expect(run(["pr-body", "5", "--body-file", "/b", "--replace"], replaced)).toBe(EXIT.posted);
|
||||
expect(sent(replaced).input).toBe(fresh);
|
||||
expect(sent(replaced).input).toBe(foldSections(fresh));
|
||||
});
|
||||
|
||||
// Value: protects=a current body holding two ship-receipt blocks (an old receipt pasted below) refuses like a doubled title, so the stale
|
||||
@@ -984,6 +995,18 @@ describe("gstack-post refuses a title that is not in plain words (exit 4)", () =
|
||||
} finally { fs.rmSync(none, { recursive: true, force: true }); fs.rmSync(broken, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
// Value: protects=a comment is never held back by a broken policy file, which it never needed before the body check;
|
||||
// fails_when=an invalid policy stops pr-comment, issue-comment and reply; why_new=comments now read the policy for warnings (GST-2737 review)
|
||||
test("an invalid policy file warns and still posts a comment", () => {
|
||||
const broken = repoWith("{ not json");
|
||||
try {
|
||||
const c = fakeEnv({ root: broken, files: { "/b": "The pregate passed.\n" } });
|
||||
expect(run(["pr-comment", "7", "--body-file", "/b"], c)).toBe(EXIT.posted);
|
||||
expect(c.posts()).toHaveLength(1);
|
||||
expect(c.stderr()).toContain("(PLAIN_POLICY_INVALID); the comment is posted unchecked");
|
||||
} finally { fs.rmSync(broken, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test("the help names exit 4", () => {
|
||||
const f = fakeEnv();
|
||||
expect(run(["--help"], f)).toBe(EXIT.posted);
|
||||
@@ -991,3 +1014,76 @@ describe("gstack-post refuses a title that is not in plain words (exit 4)", () =
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("gstack-post refuses a PR body that breaks the plain shape (exit 4)", () => {
|
||||
const repoWith = (policy: string | null) => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "gstack-post-body-"));
|
||||
if (policy !== null) { fs.mkdirSync(path.join(root, ".gstack")); fs.writeFileSync(path.join(root, ".gstack", "plain-titles.json"), policy); }
|
||||
return root;
|
||||
};
|
||||
const POLICY = JSON.stringify({ codes: ["\\bGST-\\d+\\b"], terms: ["pregate"], allow: [], since: "2026-11-08", body_since: "2026-11-17", exempt_branch_prefixes: [], replace_default_terms: true });
|
||||
const TITLE = "Stop gstack from hitting GitHub's rate limit (GST-1713)";
|
||||
const LONG = "One.\n\nTwo.\n\nThree.\n\nFour, and the pregate said so.\n\n## Tests\n\n- one\n";
|
||||
const created = (at: string) => (c: Call) => (c.cmd === "gh" && c.args[1] === "view" && c.args.includes("createdAt") ? { status: 0, stdout: at + "\n" } : undefined);
|
||||
|
||||
// Value: protects=a body with more than three visible lines or a listed word above the Agent notes fold posts nothing under a policy,
|
||||
// with title and body findings printed in one pass; fails_when=the body is checked after posting, unfolded, or not at all;
|
||||
// why_new=R76 as amended 2026-11-15; seam=a real policy file under the fake root; no_claim=real gh
|
||||
test("a body with four visible lines and a listed word posts nothing; title and body findings print in one pass", () => {
|
||||
const root = repoWith(POLICY);
|
||||
try {
|
||||
const f = fakeEnv({ root, files: { "/t": "Make the pregate quieter", "/b": LONG } });
|
||||
expect(run(["pr-create", "--base", "main", "--title-file", "/t", "--body-file", "/b"], f)).toBe(EXIT.plainTitle);
|
||||
expect(f.calls.filter(c => c.cmd === "gh" || c.cmd === "glab")).toEqual([]);
|
||||
expect(f.stdout()).toContain("PLAIN_TITLE: refused=1\n");
|
||||
expect(f.stdout()).toContain('PLAIN_BODY: PLAIN_BODY_REFUSED visible-lines "4 lines');
|
||||
expect(f.stdout()).toContain('PLAIN_BODY: PLAIN_BODY_REFUSED term "pregate"');
|
||||
expect(f.stdout()).toContain("PLAIN_BODY: refused=2\n");
|
||||
expect(f.stderr()).toContain("the body does not have the plain shape; nothing was posted");
|
||||
const edit = fakeEnv({ root, files: { "/b": LONG }, respond: created("2026-11-18T00:00:00Z") });
|
||||
expect(run(["pr-body", "7", "--body-file", "/b", "--replace"], edit)).toBe(EXIT.plainTitle);
|
||||
expect(edit.posts()).toEqual([]);
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
// Value: protects=PRs opened before body_since, repositories without a policy and comments only warn, and still post;
|
||||
// fails_when=old PRs or other repositories start refusing; why_new=A1 (refusals need a policy) and J1 (comments warn);
|
||||
// seam=a real policy file and a fake createdAt; no_claim=real gh
|
||||
test("an older PR, a repository without the policy and a comment get warnings and still post", () => {
|
||||
const root = repoWith(POLICY);
|
||||
const none = repoWith(null);
|
||||
try {
|
||||
const old = fakeEnv({ root, files: { "/b": LONG }, respond: created("2026-11-10T00:00:00Z") });
|
||||
expect(run(["pr-body", "7", "--body-file", "/b", "--replace"], old)).toBe(EXIT.posted);
|
||||
expect(old.stdout()).toContain("(warning only)");
|
||||
expect(old.stdout()).toContain("PLAIN_BODY: warned=2\n");
|
||||
const free = fakeEnv({ root: none, files: { "/t": TITLE, "/b": LONG } });
|
||||
expect(run(["pr-create", "--base", "main", "--title-file", "/t", "--body-file", "/b"], free)).toBe(EXIT.posted);
|
||||
expect(free.stdout()).toContain("PLAIN_BODY: warned=1\n");
|
||||
const comment = fakeEnv({ root, files: { "/b": "One.\nTwo.\nThree.\nFour: the pregate passed.\n" } });
|
||||
expect(run(["pr-comment", "7", "--body-file", "/b"], comment)).toBe(EXIT.posted);
|
||||
expect(comment.stdout()).toContain('PLAIN_BODY: PLAIN_BODY_REFUSED term "pregate"');
|
||||
expect(comment.stdout()).not.toContain("visible-lines");
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); fs.rmSync(none, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
// Value: protects=bodies go out folded, a ## section replaces the same-titled fold already on the PR, and fold posts nothing;
|
||||
// fails_when=a body is posted with open sections or the merge duplicates a folded section; why_new=E1; seam=the fake gh pr view body; no_claim=real gh
|
||||
test("a body is posted folded, a ## Tests section replaces the Tests fold, and fold prints without posting", () => {
|
||||
const root = repoWith(POLICY);
|
||||
try {
|
||||
const current = "What changed for a user.\n\n<details><summary>Tests</summary>\n\n- old\n\n</details>\n";
|
||||
const f = fakeEnv({ root, files: { "/b": "## Tests\n\n- new\n" }, respond: c => (c.cmd === "gh" && c.args[1] === "view" && c.args.includes("body") ? { status: 0, stdout: current } : undefined) });
|
||||
expect(run(["pr-body", "7", "--body-file", "/b"], f)).toBe(EXIT.posted);
|
||||
expect(f.posts().find(c => c.args[1] === "edit")!.input).toBe("What changed for a user.\n\n<details><summary>Tests</summary>\n\n- new\n\n</details>\n");
|
||||
const fold = fakeEnv({ root, files: { "/b": "Opening.\n\n## Tests\n\n- one\n" } });
|
||||
expect(run(["fold", "--body-file", "/b"], fold)).toBe(EXIT.posted);
|
||||
expect(fold.stdout()).toBe("Opening.\n\n<details><summary>Tests</summary>\n\n- one\n\n</details>\n");
|
||||
expect(fold.calls.filter(c => c.cmd === "gh" || c.cmd === "glab")).toEqual([]);
|
||||
const bad = fakeEnv({ root, files: { "/b": LONG } });
|
||||
expect(run(["fold", "--body-file", "/b"], bad)).toBe(EXIT.plainTitle);
|
||||
expect(bad.stderr()).toContain("PLAIN_BODY: refused=2");
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user