Public: anyone can read this; the crew can change it.
A pull's page and inbox row say 'Conflicts in N files' before anything else, and never show a green mark on a conflicted pull #12543
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12523-a-pull-s-page-and-inbox-row-say-conflict → main 3 commits fork
5 files
changed +161
−2
src/crew/stale_asks.ts +9
| @@ -92,6 +92,15 @@ export function conflictsOf( | ||
| 92 | 92 | return known !== undefined && known.head === headOid ? known.conflicts : 0; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | /** | |
| 96 | * "Conflicts in 2 files": what a pull that does not merge says before | |
| 97 | * anything else, in the same words on its checks line, its inbox row and | |
| 98 | * its feed item (#1133). | |
| 99 | */ | |
| 100 | export function conflictWords(files: number): string { | |
| 101 | return `Conflicts in ${files} ${files === 1 ? "file" : "files"}`; | |
| 102 | } | |
| 103 | ||
| 95 | 104 | /** |
| 96 | 105 | * When this pull, at this head, last went from not merging to merging — a |
| 97 | 106 | * new cause for its ask even with no new check, so a dismissal from before |
src/feed/items.ts +14
| @@ -38,6 +38,7 @@ import { writeStamp } from "../core/write_clock.ts"; | ||
| 38 | 38 | import { Stamped } from "../kernel/stamped.ts"; |
| 39 | 39 | import { QUIET_WINDOW_MS, quietRunEventIds } from "./quiet.ts"; |
| 40 | 40 | import { hotSays, standingHot, standingWide, wideSays } from "../crew/hot_files.ts"; |
| 41 | import { conflictsOf, conflictWords } from "../crew/stale_asks.ts"; | |
| 41 | 42 | import { ago } from "./rank.ts"; |
| 42 | 43 | import { askLinesFor } from "../web/studio/asks.ts"; |
| 43 | 44 | |
| @@ -682,6 +683,19 @@ function fromEvent( | ||
| 682 | 683 | link, |
| 683 | 684 | what: `a run cost $${cost.toFixed(2)}${summary ? `: ${summary}` : ""}`, |
| 684 | 685 | }; |
| 686 | // A green check of a pull that does not merge is no green: it says | |
| 687 | // the conflicts, as the pull's checks line does (#1133). | |
| 688 | const files = | |
| 689 | state === "ok" && kind === "check" && typeof p["issueId"] === "string" && typeof p["commitOid"] === "string" | |
| 690 | ? conflictsOf(db, p["issueId"], p["commitOid"]) | |
| 691 | : 0; | |
| 692 | if (files > 0) | |
| 693 | return { | |
| 694 | ...common, | |
| 695 | kind: "run", | |
| 696 | link, | |
| 697 | what: `a check run${subject}: ${conflictWords(files)}; it does not merge as it stands`, | |
| 698 | }; | |
| 685 | 699 | return { |
| 686 | 700 | ...common, |
| 687 | 701 | kind: "run", |
src/web/pages/pull.ts +2 −1
| @@ -125,6 +125,7 @@ import { crewActivityCard } from "./runs.ts"; | ||
| 125 | 125 | import { holdCard } from "../studio/hold.ts"; |
| 126 | 126 | import { guestWalls, strangerCard } from "./pull-guest.ts"; |
| 127 | 127 | import { guardedRefusal } from "../../crew/stranger.ts"; |
| 128 | import { conflictWords } from "../../crew/stale_asks.ts"; | |
| 128 | 129 | import { |
| 129 | 130 | changeHead, |
| 130 | 131 | changeTabs, |
| @@ -337,7 +338,7 @@ export function checksLine( | ||
| 337 | 338 | const body = |
| 338 | 339 | check.state === "ok" && conflicts > 0 |
| 339 | 340 | ? html`<span class="bad" |
| 340 | >${icon("x")}Conflicts in ${conflicts} ${conflicts === 1 ? "file" : "files"}</span | |
| 341 | >${icon("x")}${conflictWords(conflicts)}</span | |
| 341 | 342 | >${link}` |
| 342 | 343 | : check.state === "ok" && stale |
| 343 | 344 | ? html`<span class="now" |
src/web/studio/decisions.ts +8 −1
| @@ -22,6 +22,7 @@ import { changeHref } from "./nouns.ts"; | ||
| 22 | 22 | import { flatten } from "./note.ts"; |
| 23 | 23 | import { testsClause } from "./words.ts"; |
| 24 | 24 | import { reviewerPaused } from "../../crew/reviewer_paused.ts"; |
| 25 | import { conflictsOf, conflictWords } from "../../crew/stale_asks.ts"; | |
| 25 | 26 | import type { Database } from "bun:sqlite"; |
| 26 | 27 | import type { User } from "../../core/users.ts"; |
| 27 | 28 | import { reviewWhy, scoredFor, waitingSplit, type Decision, type Scored } from "./asks.ts"; |
| @@ -206,8 +207,14 @@ export function decisionsFor( | ||
| 206 | 207 | c.pull === undefined || !records.has(c.repo.id) |
| 207 | 208 | ? undefined |
| 208 | 209 | : `${repoBase(c.repo)}/app/pull-${c.pull.number}/open`; |
| 210 | // A pull that does not merge says so before anything else (#1133). | |
| 211 | const leading = (c: Scored): Omit<Decision, "consequence" | "waiting"> => { | |
| 212 | const d = worded(c); | |
| 213 | const files = c.pull === undefined ? 0 : conflictsOf(db, c.pull.id, c.pull.headOid); | |
| 214 | return files === 0 ? d : { ...d, short: `${conflictWords(files).toLowerCase()} — ${d.short}` }; | |
| 215 | }; | |
| 209 | 216 | return candidates.map((c) => ({ |
| 210 | ...worded(c), | |
| 217 | ...leading(c), | |
| 211 | 218 | preview: previewOf(c), |
| 212 | 219 | consequence: c.consequence, |
| 213 | 220 | waiting: c.waiting, |
test/conflict-words.test.ts added +128
| @@ -0,0 +1,128 @@ | ||
| 1 | /** | |
| 2 | * A pull that does not merge says "Conflicts in N files" before anything | |
| 3 | * else, in the same words on its inbox row and its feed item as on its | |
| 4 | * checks line (`pull-checks-line.test.ts`), and never reads green (#1133). | |
| 5 | */ | |
| 6 | ||
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 13 | import { openPull } from "../src/actions/pulls.ts"; | |
| 14 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 15 | import { announceRun } from "../src/actions/runs.ts"; | |
| 16 | import { setAssignee } from "../src/core/issues.ts"; | |
| 17 | import type { Pull } from "../src/core/pulls.ts"; | |
| 18 | import type { Repo } from "../src/core/repos.ts"; | |
| 19 | import { claimRun, createRun, finishRun, getRun } from "../src/core/runs.ts"; | |
| 20 | import { getUserByName, type User } from "../src/core/users.ts"; | |
| 21 | import { conflictWords, sweepStaleAsks } from "../src/crew/stale_asks.ts"; | |
| 22 | import { readFeed } from "../src/feed/feed.ts"; | |
| 23 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 24 | import { quietLogs } from "./helpers/globals.ts"; | |
| 25 | import { adminCookie } from "./helpers/admin.ts"; | |
| 26 | ||
| 27 | quietLogs(); | |
| 28 | ||
| 29 | describe("a conflicted pull says its conflicts first", () => { | |
| 30 | let dataDir = ""; | |
| 31 | let app: App; | |
| 32 | let servers: Servers; | |
| 33 | let cookie = ""; | |
| 34 | let alice: User; | |
| 35 | let repo: Repo; | |
| 36 | let pull: Pull; | |
| 37 | ||
| 38 | const asks = async (): Promise<string> => { | |
| 39 | const response = await fetch(`${servers.url}/asks`, { headers: { cookie }, redirect: "manual" }); | |
| 40 | expect(response.status).toBe(200); | |
| 41 | return (await response.text()).replace(/\s+/g, " "); | |
| 42 | }; | |
| 43 | ||
| 44 | const green = (p: Pull): void => { | |
| 45 | const run = createRun(app.db, { | |
| 46 | repoId: repo.id, | |
| 47 | kind: "check", | |
| 48 | issueId: p.id, | |
| 49 | env: `pull-${p.number}`, | |
| 50 | commitOid: p.headOid, | |
| 51 | reason: "pull", | |
| 52 | }); | |
| 53 | claimRun(app.db, run.id); | |
| 54 | finishRun(app.db, run.id, { state: "ok", summary: "check passed in 1s" }); | |
| 55 | announceRun(app, getRun(app.db, run.id)!); | |
| 56 | }; | |
| 57 | ||
| 58 | beforeAll(async () => { | |
| 59 | dataDir = await mkdtemp(join(tmpdir(), "forge-conflict-words-")); | |
| 60 | app = createApp({ dataDir, port: 0, disk: () => ({ freeBytes: 500e9, totalBytes: 1000e9 }) }); | |
| 61 | servers = await serve(app); | |
| 62 | cookie = `${await adminCookie(app, { username: "alice", email: "[email protected]", password: "a-long-conflict-passphrase" })}; forge_mode=studio`; | |
| 63 | alice = getUserByName(app.db, "alice")!; | |
| 64 | const made = await createRepo(app, alice, { name: "orchard", visibility: "public" }); | |
| 65 | if (!made.ok) throw new Error(String(made.error)); | |
| 66 | repo = made.value; | |
| 67 | await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# orchard\n" }] }); | |
| 68 | await createAgent(app, alice, { username: "bot" }); | |
| 69 | addToCrew(app, alice, repo, "bot"); | |
| 70 | const branch = await commitToBranch(app, alice, repo, { | |
| 71 | branch: "bot/plums", | |
| 72 | base: "main", | |
| 73 | message: "plums", | |
| 74 | files: [{ path: "README.md", content: "# plums\n" }], | |
| 75 | }); | |
| 76 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 77 | const opened = await openPull(app, getUserByName(app.db, "bot")!, repo, { | |
| 78 | title: "Bot: plums", | |
| 79 | body: "", | |
| 80 | baseBranch: "main", | |
| 81 | headBranch: "bot/plums", | |
| 82 | }); | |
| 83 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 84 | pull = opened.value; | |
| 85 | }, 30_000); | |
| 86 | ||
| 87 | afterAll(async () => { | |
| 88 | await servers.stop(); | |
| 89 | await rm(dataDir, { recursive: true, force: true }); | |
| 90 | }); | |
| 91 | ||
| 92 | test("the words are one: 'Conflicts in 1 file', 'Conflicts in 2 files'", () => { | |
| 93 | expect(conflictWords(1)).toBe("Conflicts in 1 file"); | |
| 94 | expect(conflictWords(2)).toBe("Conflicts in 2 files"); | |
| 95 | }); | |
| 96 | ||
| 97 | test("a green check of a pull that merges stays green in the feed", async () => { | |
| 98 | green(pull); | |
| 99 | await sweepStaleAsks(app); | |
| 100 | const run = readFeed(app.db, alice, { limit: 50 }).items.find((i) => i.kind === "run"); | |
| 101 | expect(run?.what).toContain("finished"); | |
| 102 | expect(run?.what).not.toContain("Conflicts in"); | |
| 103 | }); | |
| 104 | ||
| 105 | test("once main moves under it, the inbox row and the feed item lead with the conflicts and nothing green", async () => { | |
| 106 | await commitToBranch(app, alice, repo, { | |
| 107 | message: "main moves", | |
| 108 | files: [{ path: "README.md", content: "# orchard, renamed\n" }], | |
| 109 | }); | |
| 110 | await sweepStaleAsks(app); | |
| 111 | setAssignee(app.db, pull.id, alice.id); | |
| 112 | const page = await asks(); | |
| 113 | const at = page.indexOf(`id="assigned-${pull.id}"`); | |
| 114 | expect(at).toBeGreaterThan(-1); | |
| 115 | const card = page.slice(at, page.indexOf("</section>", at)); | |
| 116 | expect(card).toContain("Conflicts in 1 file — assigned to you"); | |
| 117 | expect(card).not.toContain("green"); | |
| 118 | ||
| 119 | const runs = readFeed(app.db, alice, { limit: 50 }).items.filter((i) => i.kind === "run"); | |
| 120 | expect(runs.length).toBeGreaterThan(0); | |
| 121 | for (const item of runs) { | |
| 122 | expect(item.what).toContain("Conflicts in 1 file"); | |
| 123 | expect(item.what).not.toContain("finished"); | |
| 124 | expect(item.what).not.toContain("passed"); | |
| 125 | } | |
| 126 | setAssignee(app.db, pull.id, null); | |
| 127 | }); | |
| 128 | }); |
new above
offline