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 #1675

Closed opened this
Closed without merging

scout/forge:scout/1587-inbox-rows-feed-items-and-mcp-asks-and-f → main 6 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +227 −7
scripts/gate.ts +1
@@ -111,6 +111,7 @@ export const GATE: readonly string[] = [
111111 "test/pull-mergeable.test.ts",
112112 "test/pull-variants.test.ts",
113113 "test/pull-checks-line.test.ts",
114 "test/conflicted-green.test.ts",
114115 "test/pulls.test.ts",
115116 "test/api-reader-marks.test.ts",
116117 "test/app-members.test.ts",
src/crew/stale_asks.ts +50 −2
@@ -14,8 +14,8 @@
1414
1515 import type { Database } from "bun:sqlite";
1616 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";
1919 import { getRepoById } from "../core/repos.ts";
2020 import { latestRunsForIssues } from "../core/runs.ts";
2121 import { resolveOid } from "../git/merge.ts";
@@ -27,6 +27,8 @@ interface Known {
2727 /** The pull's head the answer was taken at, as the database names it. */
2828 readonly head: string;
2929 readonly stale: boolean;
30 /** Files the pull conflicts in at that head; 0 when it merges. */
31 readonly conflicts: number;
3032 /** When a sweep last saw it go from not merging to merging: its ask is new from then. */
3133 readonly mergesSince?: string;
3234 }
@@ -49,6 +51,31 @@ export function isStalePull(
4951 return known !== undefined && known.stale && known.head === headOid;
5052 }
5153
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
5279 /**
5380 * When this pull, at this head, last went from not merging to merging — a
5481 * new cause for its ask even with no new check, so a dismissal from before
@@ -69,6 +96,26 @@ export function mergesAgainSince(
6996 /** The most pulls one sweep looks at: enough for a busy forge, bounded for a strange one. */
7097 export const SWEEP_LIMIT = 300;
7198
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
72119 /**
73120 * Look again at every open pull with a green check in a repository that
74121 * asks a person (anything not `autonomous`: those settle their own). Never
@@ -115,6 +162,7 @@ export async function sweepStaleAsks(app: App): Promise<void> {
115162 between,
116163 head: pull.headOid,
117164 stale,
165 conflicts: status.mergeable ? 0 : status.conflicts.length,
118166 ...(mergesSince === undefined ? {} : { mergesSince }),
119167 });
120168 } catch (error) {
src/main.ts +3 −1
@@ -33,7 +33,7 @@ import { typeSafeDecider } from "./crew/decide.ts";
3333 import { graphInstagram } from "./crew/instagram.ts";
3434 import { peopleOnCrews } from "./core/agents.ts";
3535 import { startNotifier } from "./crew/notify.ts";
36 import { sweepStaleAsks } from "./crew/stale_asks.ts";
36 import { seedStaleAsks, sweepStaleAsks } from "./crew/stale_asks.ts";
3737 import { recordAskLedger } from "./web/studio/asks.ts";
3838 import { startPromptRoutine } from "./crew/prompts.ts";
3939 import { pruneTokens } from "./core/tokens.ts";
@@ -167,6 +167,8 @@ await reconcile(app);
167167 // Issues linked under a pillar's umbrella before pillars had labels.
168168 const labelled = syncAllPillars(app);
169169 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);
170172 const servers = await serve(app);
171173 const sshStarted =
172174 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";
2929 import type { Operation } from "../../core/fleet_ops.ts";
3030 import { listPins, pinnedRepoIds, type Pin } from "../../core/pins.ts";
3131 import { listOrgsForUser } from "../../core/orgs.ts";
32 import { conflictWords, conflictsOfIssue } from "../../crew/stale_asks.ts";
3233 import {
3334 canRead,
3435 getRepo,
@@ -573,9 +574,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
573574 : item.issue.kind === "pull"
574575 ? PULL_MARK
575576 : ISSUE_MARK;
577 const conflicts = conflictsOfIssue(f.db, item.issue);
576578 return {
577579 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)}` : ""}`,
579581 };
580582 }),
581583 on,
src/web/pages/site.ts +6 −1
@@ -33,6 +33,7 @@ import { studioDoor, studioHome } from "../studio/home.ts";
3333 import { homeTop, onYouBulk } from "../studio/asks_page.ts";
3434 import { latestUndoable } from "../../actions/asks_bulk.ts";
3535 import { mutedRepos } from "../../core/interactions.ts";
36 import { conflictWords, conflictsOfIssue } from "../../crew/stale_asks.ts";
3637 import { edgeLoginUrl } from "../../http/edge.ts";
3738 import { sshCommand } from "../../ssh/command.ts";
3839 import { hostOf, pageHead, signInFirst } from "../chrome.ts";
@@ -176,6 +177,10 @@ export function downloadsCard(ctx: Ctx, user: User): Html {
176177 const threadPath = (repo: Repo, issue: Issue): string =>
177178 `/${repo.ownerName}/${repo.name}/${issue.kind === "pull" ? "pulls" : "issues"}/${issue.number}`;
178179
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
179184 /** Open issues and pulls assigned to the viewer, anywhere they can see. */
180185 export function onYouCard(ctx: Ctx, user: User): Html | undefined {
181186 const db = ctx.app.db;
@@ -233,7 +238,7 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined {
233238 : issue.title,
234239 titleAttr: issue.title,
235240 meta: html`${repo.ownerName}/${repo.name} #${issue.number} · updated
236 ${time(issue.updatedAt)}`,
241 ${time(issue.updatedAt)}${conflictNote(conflictsOfIssue(db, issue))}`,
237242 }),
238243 );
239244 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); }
291291 font-variant-numeric: tabular-nums;
292292 }
293293 .row-meta .byline { display: inline; }
294 .row-meta .conflict { color: var(--danger); }
294295 .row-meta .avatar { width: 16px; height: 16px; font-size: 8.5px; vertical-align: -0.28em; }
295296 .row-meta .byline-name { margin-left: 4px; }
296297 .row-lead { color: var(--faint); display: inline-flex; flex: none; }
test/asks-bulk.test.ts +1 −2
@@ -684,7 +684,6 @@ describe("acting on many asks at once", () => {
684684 expect(res.status).toBe(200);
685685 const text = await res.text();
686686 expect(text).toContain('id="live-on-you"');
687 expect(text).toContain('id="asks-link"');
688687 expect(text).not.toContain("Card one");
689688 expect(getIssueById(app.db, a.id)!.state).toBe("closed");
690689 // The undo link rides on the card, and is the same one after a refresh.
@@ -715,7 +714,7 @@ describe("acting on many asks at once", () => {
715714 for (const pull of [a, b])
716715 expect(assignIssue(app, alice, open, getIssueById(app.db, pull.id)!, alice).ok).toBe(true);
717716 const card = () => onYouCard({ app, auth: { user: alice } } as never, alice)?.text ?? "";
718 expect(card()).not.toContain("muted");
717 expect(card()).not.toContain("repository muted");
719718 const done = await api(aliceRw, "/api/v1/asks/bulk", {
720719 action: "mute",
721720 items: [`issue:${a.id}`, `issue:${b.id}`],
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs