Public: anyone can read this; the crew can change it.
Inbox rows, feed items and MCP asks and feed never mark a conflicted pull green #1646
scout/forge:scout/1587-inbox-rows-feed-items-and-mcp-asks-and-f → main 4 commits fork 3 threads · 3 unresolved
7 files
changed +226
−5
scripts/gate.ts +1
| @@ -110,6 +110,7 @@ export const GATE: readonly string[] = [ | ||
| 110 | 110 | "test/cross-repo-pull.test.ts", |
| 111 | 111 | "test/pull-mergeable.test.ts", |
| 112 | 112 | "test/pull-checks-line.test.ts", |
| 113 | "test/conflicted-green.test.ts", | |
| 113 | 114 | "test/pulls.test.ts", |
| 114 | 115 | "test/api-reader-marks.test.ts", |
| 115 | 116 | "test/app-members.test.ts", |
src/crew/stale_asks.ts +50 −2
| @@ -14,8 +14,8 @@ | ||
| 14 | 14 | |
| 15 | 15 | import type { Database } from "bun:sqlite"; |
| 16 | 16 | import type { App } from "../app.ts"; |
| 17 | import { joinMany, pullStatus } from "../core/pulls.ts"; | |
| 18 | import { getIssuesByIds } from "../core/issues.ts"; | |
| 17 | import { getPull, joinMany, pullStatus } from "../core/pulls.ts"; | |
| 18 | import { getIssuesByIds, type Issue } from "../core/issues.ts"; | |
| 19 | 19 | import { getRepoById } from "../core/repos.ts"; |
| 20 | 20 | import { latestRunsForIssues } from "../core/runs.ts"; |
| 21 | 21 | import { resolveOid } from "../git/merge.ts"; |
| @@ -27,6 +27,8 @@ interface Known { | ||
| 27 | 27 | /** The pull's head the answer was taken at, as the database names it. */ |
| 28 | 28 | readonly head: string; |
| 29 | 29 | readonly stale: boolean; |
| 30 | /** Files the pull conflicts in at that head; 0 when it merges. */ | |
| 31 | readonly conflicts: number; | |
| 30 | 32 | /** When a sweep last saw it go from not merging to merging: its ask is new from then. */ |
| 31 | 33 | readonly mergesSince?: string; |
| 32 | 34 | } |
| @@ -49,6 +51,31 @@ export function isStalePull( | ||
| 49 | 51 | return known !== undefined && known.stale && known.head === headOid; |
| 50 | 52 | } |
| 51 | 53 | |
| 54 | /** | |
| 55 | * In how many files this pull, at this head, was last found to conflict | |
| 56 | * with its base; 0 when it merges, or when this process has not seen it — | |
| 57 | * a pull never reads as conflicted on a guess. | |
| 58 | */ | |
| 59 | export function conflictsOf( | |
| 60 | db: Database, | |
| 61 | pullId: string, | |
| 62 | headOid: string, | |
| 63 | ): number { | |
| 64 | const known = knownByDb.get(db)?.get(pullId); | |
| 65 | return known !== undefined && known.head === headOid ? known.conflicts : 0; | |
| 66 | } | |
| 67 | ||
| 68 | /** `conflictsOf` for a row that may be an issue or a pull: 0 for an issue. */ | |
| 69 | export function conflictsOfIssue(db: Database, issue: Issue): number { | |
| 70 | if (issue.kind !== "pull") return 0; | |
| 71 | const pull = getPull(db, issue.repoId, issue.number); | |
| 72 | return pull === undefined ? 0 : conflictsOf(db, pull.id, pull.headOid); | |
| 73 | } | |
| 74 | ||
| 75 | /** The words a conflicted pull carries instead of a green mark. */ | |
| 76 | export const conflictWords = (n: number): string => | |
| 77 | `Conflicts in ${n} ${n === 1 ? "file" : "files"}`; | |
| 78 | ||
| 52 | 79 | /** |
| 53 | 80 | * When this pull, at this head, last went from not merging to merging — a |
| 54 | 81 | * new cause for its ask even with no new check, so a dismissal from before |
| @@ -69,6 +96,26 @@ export function mergesAgainSince( | ||
| 69 | 96 | /** The most pulls one sweep looks at: enough for a busy forge, bounded for a strange one. */ |
| 70 | 97 | export const SWEEP_LIMIT = 300; |
| 71 | 98 | |
| 99 | /** How long boot waits for the first sweep before it serves anyway. */ | |
| 100 | export const SEED_MS = 5_000; | |
| 101 | ||
| 102 | /** | |
| 103 | * The first sweep, before the first request: the answers live in memory, so | |
| 104 | * without it a restarted forge would call a conflicted pull green until the | |
| 105 | * tick came round. Bounded — a slow disk delays boot by `SEED_MS` at most, | |
| 106 | * and the sweep goes on behind it. | |
| 107 | */ | |
| 108 | export async function seedStaleAsks(app: App, ms = SEED_MS): Promise<void> { | |
| 109 | let timer: ReturnType<typeof setTimeout> | undefined; | |
| 110 | await Promise.race([ | |
| 111 | sweepStaleAsks(app), | |
| 112 | new Promise<void>((done) => { | |
| 113 | timer = setTimeout(done, ms); | |
| 114 | }), | |
| 115 | ]); | |
| 116 | clearTimeout(timer); | |
| 117 | } | |
| 118 | ||
| 72 | 119 | /** |
| 73 | 120 | * Look again at every open pull with a green check in a repository that |
| 74 | 121 | * asks a person (anything not `autonomous`: those settle their own). Never |
| @@ -115,6 +162,7 @@ export async function sweepStaleAsks(app: App): Promise<void> { | ||
| 115 | 162 | between, |
| 116 | 163 | head: pull.headOid, |
| 117 | 164 | stale, |
| 165 | conflicts: status.mergeable ? 0 : status.conflicts.length, | |
| 118 | 166 | ...(mergesSince === undefined ? {} : { mergesSince }), |
| 119 | 167 | }); |
| 120 | 168 | } catch (error) { |
src/main.ts +3 −1
| @@ -33,7 +33,7 @@ import { typeSafeDecider } from "./crew/decide.ts"; | ||
| 33 | 33 | import { graphInstagram } from "./crew/instagram.ts"; |
| 34 | 34 | import { peopleOnCrews } from "./core/agents.ts"; |
| 35 | 35 | import { startNotifier } from "./crew/notify.ts"; |
| 36 | import { sweepStaleAsks } from "./crew/stale_asks.ts"; | |
| 36 | import { seedStaleAsks, sweepStaleAsks } from "./crew/stale_asks.ts"; | |
| 37 | 37 | import { recordAskLedger } from "./web/studio/asks.ts"; |
| 38 | 38 | import { startPromptRoutine } from "./crew/prompts.ts"; |
| 39 | 39 | import { pruneTokens } from "./core/tokens.ts"; |
| @@ -167,6 +167,8 @@ await reconcile(app); | ||
| 167 | 167 | // Issues linked under a pillar's umbrella before pillars had labels. |
| 168 | 168 | const labelled = syncAllPillars(app); |
| 169 | 169 | if (labelled > 0) app.log.info("pillars labelled", { issues: labelled }); |
| 170 | // Which green pulls conflict is learned before the first request, not after. | |
| 171 | await seedStaleAsks(app); | |
| 170 | 172 | const servers = await serve(app); |
| 171 | 173 | const sshStarted = |
| 172 | 174 | sshPort > 0 ? await startForgeSsh(app, { port: sshPort }) : undefined; |
src/tui/screens/dashboard.ts +3 −1
| @@ -29,6 +29,7 @@ import { mutedRepos, removeMutes } from "../../core/interactions.ts"; | ||
| 29 | 29 | import type { Operation } from "../../core/fleet_ops.ts"; |
| 30 | 30 | import { listPins, pinnedRepoIds, type Pin } from "../../core/pins.ts"; |
| 31 | 31 | import { listOrgsForUser } from "../../core/orgs.ts"; |
| 32 | import { conflictWords, conflictsOfIssue } from "../../crew/stale_asks.ts"; | |
| 32 | 33 | import { |
| 33 | 34 | canRead, |
| 34 | 35 | getRepo, |
| @@ -573,9 +574,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 573 | 574 | : item.issue.kind === "pull" |
| 574 | 575 | ? PULL_MARK |
| 575 | 576 | : ISSUE_MARK; |
| 577 | const conflicts = conflictsOfIssue(f.db, item.issue); | |
| 576 | 578 | return { |
| 577 | 579 | title: `${marked.has(item.issue.id) ? "[x] " : ""}${mark} #${item.issue.number} ${item.issue.title}`, |
| 578 | meta: `${item.repo.ownerName}/${item.repo.name}`, | |
| 580 | meta: `${item.repo.ownerName}/${item.repo.name}${conflicts > 0 ? ` · ${conflictWords(conflicts)}` : ""}`, | |
| 579 | 581 | }; |
| 580 | 582 | }), |
| 581 | 583 | on, |
src/web/pages/site.ts +6 −1
| @@ -33,6 +33,7 @@ import { studioDoor, studioHome } from "../studio/home.ts"; | ||
| 33 | 33 | import { homeTop, onYouBulk } from "../studio/asks_page.ts"; |
| 34 | 34 | import { latestUndoable } from "../../actions/asks_bulk.ts"; |
| 35 | 35 | import { mutedRepos } from "../../core/interactions.ts"; |
| 36 | import { conflictWords, conflictsOfIssue } from "../../crew/stale_asks.ts"; | |
| 36 | 37 | import { edgeLoginUrl } from "../../http/edge.ts"; |
| 37 | 38 | import { sshCommand } from "../../ssh/command.ts"; |
| 38 | 39 | import { hostOf, pageHead, signInFirst } from "../chrome.ts"; |
| @@ -176,6 +177,10 @@ export function downloadsCard(ctx: Ctx, user: User): Html { | ||
| 176 | 177 | const threadPath = (repo: Repo, issue: Issue): string => |
| 177 | 178 | `/${repo.ownerName}/${repo.name}/${issue.kind === "pull" ? "pulls" : "issues"}/${issue.number}`; |
| 178 | 179 | |
| 180 | /** A pull the sweep found conflicting says so, in red: a passing check is not a green mark then. */ | |
| 181 | const conflictNote = (n: number): Html | "" => | |
| 182 | n === 0 ? "" : html` · <span class="conflict">${conflictWords(n)}</span>`; | |
| 183 | ||
| 179 | 184 | /** Open issues and pulls assigned to the viewer, anywhere they can see. */ |
| 180 | 185 | export function onYouCard(ctx: Ctx, user: User): Html | undefined { |
| 181 | 186 | const db = ctx.app.db; |
| @@ -233,7 +238,7 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined { | ||
| 233 | 238 | : issue.title, |
| 234 | 239 | titleAttr: issue.title, |
| 235 | 240 | meta: html`${repo.ownerName}/${repo.name} #${issue.number} · updated |
| 236 | ${time(issue.updatedAt)}`, | |
| 241 | ${time(issue.updatedAt)}${conflictNote(conflictsOfIssue(db, issue))}`, | |
| 237 | 242 | }), |
| 238 | 243 | ); |
| 239 | 244 | if (rows.length === 0 && silenced.size === 0) return undefined; |
src/web/style/components.ts +1
| @@ -291,6 +291,7 @@ a.row:hover .row-title { color: var(--accent); } | ||
| 291 | 291 | font-variant-numeric: tabular-nums; |
| 292 | 292 | } |
| 293 | 293 | .row-meta .byline { display: inline; } |
| 294 | .row-meta .conflict { color: var(--danger); } | |
| 294 | 295 | .row-meta .avatar { width: 16px; height: 16px; font-size: 8.5px; vertical-align: -0.28em; } |
| 295 | 296 | .row-meta .byline-name { margin-left: 4px; } |
| 296 | 297 | .row-lead { color: var(--faint); display: inline-flex; flex: none; } |
test/conflicted-green.test.ts added +162
| @@ -0,0 +1,162 @@ | ||
| 1 | /** | |
| 2 | * A pull with a passing check that no longer merges is never green (#1587): | |
| 3 | * not in the asks, the feed or the MCP's `asks` and `feed`, and the home's | |
| 4 | * "On you" says "Conflicts in N files" on it. | |
| 5 | */ | |
| 6 | ||
| 7 | import { afterAll, beforeAll, 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 { setAssignee } from "../src/core/issues.ts"; | |
| 16 | import type { Pull } from "../src/core/pulls.ts"; | |
| 17 | import type { Repo } from "../src/core/repos.ts"; | |
| 18 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 19 | import { getUserByName, type User } from "../src/core/users.ts"; | |
| 20 | import { conflictsOf, seedStaleAsks, sweepStaleAsks } from "../src/crew/stale_asks.ts"; | |
| 21 | import { readFeed } from "../src/feed/feed.ts"; | |
| 22 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 23 | import { askLinesFor } from "../src/web/studio/asks.ts"; | |
| 24 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 25 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 26 | import { components } from "../src/web/style/components.ts"; | |
| 27 | import { quietLogs } from "./helpers/globals.ts"; | |
| 28 | import { settleApp } from "./helpers/tui.ts"; | |
| 29 | ||
| 30 | quietLogs(); | |
| 31 | ||
| 32 | let dataDir = ""; | |
| 33 | let app: App; | |
| 34 | let servers: Servers; | |
| 35 | let cookie = ""; | |
| 36 | let alice: User; | |
| 37 | let repo: Repo; | |
| 38 | let pull: Pull; | |
| 39 | ||
| 40 | const get = async (path: string): Promise<string> => { | |
| 41 | const response = await fetch(`${servers.url}${path}`, { | |
| 42 | headers: { cookie }, | |
| 43 | redirect: "manual", | |
| 44 | }); | |
| 45 | expect(response.status).toBe(200); | |
| 46 | return (await response.text()).replace(/\s+/g, " "); | |
| 47 | }; | |
| 48 | ||
| 49 | beforeAll(async () => { | |
| 50 | dataDir = await mkdtemp(join(tmpdir(), "forge-conflicted-green-")); | |
| 51 | app = createApp({ dataDir, port: 0 }); | |
| 52 | servers = await serve(app); | |
| 53 | const response = await fetch(`${servers.url}/signup`, { | |
| 54 | method: "POST", | |
| 55 | body: new URLSearchParams({ | |
| 56 | username: "alice", | |
| 57 | email: "[email protected]", | |
| 58 | password: "a-long-conflict-passphrase", | |
| 59 | }), | |
| 60 | redirect: "manual", | |
| 61 | }); | |
| 62 | cookie = `${(response.headers.get("set-cookie") ?? "").split(";")[0]!}; 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, { | |
| 68 | message: "seed", | |
| 69 | files: [{ path: "README.md", content: "# orchard\n" }], | |
| 70 | }); | |
| 71 | await createAgent(app, alice, { username: "bot" }); | |
| 72 | addToCrew(app, alice, repo, "bot"); | |
| 73 | await commitToBranch(app, alice, repo, { | |
| 74 | branch: "bot/plums", | |
| 75 | base: "main", | |
| 76 | message: "plums", | |
| 77 | files: [{ path: "README.md", content: "# plums\n" }], | |
| 78 | }); | |
| 79 | const opened = await openPull(app, getUserByName(app.db, "bot")!, repo, { | |
| 80 | title: "Bot: plums", | |
| 81 | body: "", | |
| 82 | baseBranch: "main", | |
| 83 | headBranch: "bot/plums", | |
| 84 | }); | |
| 85 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 86 | pull = opened.value; | |
| 87 | const run = createRun(app.db, { | |
| 88 | repoId: repo.id, | |
| 89 | kind: "check", | |
| 90 | issueId: pull.id, | |
| 91 | env: `pull-${pull.number}`, | |
| 92 | commitOid: pull.headOid, | |
| 93 | reason: "pull", | |
| 94 | }); | |
| 95 | claimRun(app.db, run.id); | |
| 96 | finishRun(app.db, run.id, { state: "ok", summary: "green" }); | |
| 97 | setAssignee(app.db, pull.id, alice.id); | |
| 98 | }, 30_000); | |
| 99 | ||
| 100 | afterAll(async () => { | |
| 101 | await servers.stop(); | |
| 102 | await rm(dataDir, { recursive: true, force: true }); | |
| 103 | }); | |
| 104 | ||
| 105 | test("a conflicted pull with a passing check is on you as conflicts, and no ask calls it green", async () => { | |
| 106 | // Merging cleanly: the sweep finds nothing to say, and the ask is green. | |
| 107 | await sweepStaleAsks(app); | |
| 108 | expect(await get("/")).not.toContain("Conflicts in"); | |
| 109 | expect(askLinesFor(app.db, alice)[0]!.line).toContain("is green"); | |
| 110 | ||
| 111 | await commitToBranch(app, alice, repo, { | |
| 112 | message: "main moves", | |
| 113 | files: [{ path: "README.md", content: "# orchard, renamed\n" }], | |
| 114 | }); | |
| 115 | await sweepStaleAsks(app); | |
| 116 | ||
| 117 | const home = await get("/"); | |
| 118 | expect(home).toContain("Conflicts in 1 file<"); | |
| 119 | expect(home).not.toContain("green, waiting"); | |
| 120 | expect(home).not.toContain("is green"); | |
| 121 | // The note is red where it sits: the stylesheet has a rule for it. | |
| 122 | expect(home).toContain('<span class="conflict">Conflicts in 1 file</span>'); | |
| 123 | expect(components).toContain(".row-meta .conflict { color: var(--danger); }"); | |
| 124 | ||
| 125 | // What the MCP's `asks` reads, and what its `feed` and the home's feed read. | |
| 126 | // Its ask is gone, not reworded: "ship it" cannot work on a conflict. | |
| 127 | expect(askLinesFor(app.db, alice)).toEqual([]); | |
| 128 | const items = readFeed(app.db, alice).items; | |
| 129 | expect(JSON.stringify(items)).not.toContain("is green"); | |
| 130 | expect(items.some((i) => i.kind === "ask")).toBe(false); | |
| 131 | }); | |
| 132 | ||
| 133 | test("the terminal's On you says Conflicts in N files too", async () => { | |
| 134 | const terminal = headlessTerminal(200, 32); | |
| 135 | const { app: tty } = createForgeApp( | |
| 136 | app, | |
| 137 | { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: alice }, | |
| 138 | { terminal, exitHooks: false }, | |
| 139 | ); | |
| 140 | tty.start(); | |
| 141 | await settleApp(tty); | |
| 142 | tty.dispatch({ type: "key", key: "tab", ctrl: false, alt: false, shift: false }); | |
| 143 | await settleApp(tty); | |
| 144 | const text = tty.screen.toText(); | |
| 145 | tty.stop(); | |
| 146 | expect(text).toContain("Bot: plums"); | |
| 147 | expect(text).toContain("Conflicts in 1 file"); | |
| 148 | }); | |
| 149 | ||
| 150 | test("a restarted forge seeds the conflict at boot, before any tick", async () => { | |
| 151 | const fresh = createApp({ dataDir, port: 0 }); | |
| 152 | try { | |
| 153 | // A new process knows nothing yet: without the seed it reads 0 and the ask is green. | |
| 154 | expect(conflictsOf(fresh.db, pull.id, pull.headOid)).toBe(0); | |
| 155 | expect(askLinesFor(fresh.db, alice)[0]!.line).toContain("is green"); | |
| 156 | await seedStaleAsks(fresh); | |
| 157 | expect(conflictsOf(fresh.db, pull.id, pull.headOid)).toBe(1); | |
| 158 | expect(askLinesFor(fresh.db, alice)).toEqual([]); | |
| 159 | } finally { | |
| 160 | fresh.close(); | |
| 161 | } | |
| 162 | }); |
new above
offline
Garbled comment: "or only adds nothing". Say: 0 when it merges.