Public: anyone can read this; the crew can change it.
A conflicted pull never shows a green mark: inbox, feed, asks and the checks line say "Conflicts in N files" instead #1552
scout/forge:scout/1414-a-conflicted-pull-never-shows-a-green-ma → main 2 commits fork
13 files
changed +321
−14
scripts/gate.ts +1
| @@ -38,6 +38,7 @@ export const GATE: readonly string[] = [ | ||
| 38 | 38 | "test/health.test.ts", |
| 39 | 39 | "test/client-address.test.ts", |
| 40 | 40 | "test/client-list.test.ts", |
| 41 | "test/conflicted-green.test.ts", | |
| 41 | 42 | "test/contents-api.test.ts", |
| 42 | 43 | "test/crew-agents-only.test.ts", |
| 43 | 44 | "test/crew-brief-audience.test.ts", |
src/core/conflicts.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | /** | |
| 2 | * What the forge last saw of a pull's conflicts, readable without a git call. | |
| 3 | * | |
| 4 | * `pullStatus` is where a pull is judged against its base; lists and asks are | |
| 5 | * built synchronously and must not run git per row (`askCandidatesFor`). So | |
| 6 | * every reading is remembered here, by pull, with the head it was taken at, | |
| 7 | * and a list asks `conflictsKnown` — a reading of another head counts for | |
| 8 | * nothing. Memory only: a restart forgets, and the next reading refills it. | |
| 9 | */ | |
| 10 | ||
| 11 | const seen = new Map<string, { headOid: string; files: string[] }>(); | |
| 12 | const SEEN_MAX = 2000; | |
| 13 | ||
| 14 | /** Remember a reading of an open pull at `headOid`. */ | |
| 15 | export function noteConflicts( | |
| 16 | pullId: string, | |
| 17 | headOid: string, | |
| 18 | files: readonly string[], | |
| 19 | ): void { | |
| 20 | if (seen.size >= SEEN_MAX && !seen.has(pullId)) | |
| 21 | seen.delete(seen.keys().next().value!); | |
| 22 | seen.set(pullId, { headOid, files: [...files] }); | |
| 23 | } | |
| 24 | ||
| 25 | /** The conflicting paths last read for this head; empty when none or unread. */ | |
| 26 | export function conflictsKnown(pullId: string, headOid: string): string[] { | |
| 27 | const known = seen.get(pullId); | |
| 28 | return known !== undefined && known.headOid === headOid ? [...known.files] : []; | |
| 29 | } | |
| 30 | ||
| 31 | /** "Conflicts in 2 files" — the words wherever a green mark would be. */ | |
| 32 | export function conflictsWords(count: number): string { | |
| 33 | return `Conflicts in ${count} file${count === 1 ? "" : "s"}`; | |
| 34 | } |
src/core/pulls.ts +4
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * Forgejo left open (#30972). |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { noteConflicts } from "./conflicts.ts"; | |
| 9 | 10 | import { getRepoById } from "./repos.ts"; |
| 10 | 11 | import { repoDir } from "../git/repos.ts"; |
| 11 | 12 | import { sealedByNumber } from "./sealed.ts"; |
| @@ -633,6 +634,8 @@ export async function pullStatus( | ||
| 633 | 634 | baseOid, |
| 634 | 635 | headOid, |
| 635 | 636 | ); |
| 637 | if (pull.state === "open" && pull.mergedAt === null) | |
| 638 | noteConflicts(pull.id, headOid, conflicts); | |
| 636 | 639 | return { baseOid, headOid, ahead, mergeable: clean, conflicts, reviews }; |
| 637 | 640 | } |
| 638 | 641 | |
| @@ -727,6 +730,7 @@ export async function pullMergeStates( | ||
| 727 | 730 | : `refs/heads/${pull.headBranch}`; |
| 728 | 731 | const headOid = live.get(headRef) ?? pull.headOid; |
| 729 | 732 | const r = await mergeReading(dir, baseOid, headOid); |
| 733 | noteConflicts(pull.id, headOid, r.conflicts); | |
| 730 | 734 | out[i] = { mergeable: r.mergeable, conflicts: r.conflicts }; |
| 731 | 735 | } |
| 732 | 736 | }; |
src/http/feed.ts +5 −3
| @@ -19,7 +19,7 @@ import { | ||
| 19 | 19 | parseCursor, |
| 20 | 20 | readFeed, |
| 21 | 21 | } from "../feed/feed.ts"; |
| 22 | import { asksAnswer } from "../web/studio/asks.ts"; | |
| 22 | import { asksAnswer, warmConflicts } from "../web/studio/asks.ts"; | |
| 23 | 23 | import { |
| 24 | 24 | applyAsksBulk, |
| 25 | 25 | undoAsksBulk, |
| @@ -39,7 +39,7 @@ import { | ||
| 39 | 39 | } from "./respond.ts"; |
| 40 | 40 | |
| 41 | 41 | export function feedRoutes(router: Router<Handler>): void { |
| 42 | router.add("GET", "/api/v1/feed", (ctx) => { | |
| 42 | router.add("GET", "/api/v1/feed", async (ctx) => { | |
| 43 | 43 | const viewer = ctx.auth.user; |
| 44 | 44 | if (!viewer) return unauthorized(); |
| 45 | 45 | const q = ctx.url.searchParams; |
| @@ -54,6 +54,7 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 54 | 54 | const cursor = rawCursor === null ? undefined : parseCursor(rawCursor); |
| 55 | 55 | if (rawCursor !== null && cursor === undefined) |
| 56 | 56 | return apiError("invalid_cursor", 422, "that cursor was not issued here"); |
| 57 | await warmConflicts(ctx, viewer); | |
| 57 | 58 | return json( |
| 58 | 59 | readFeed(ctx.app.db, viewer, { |
| 59 | 60 | ...(limit === undefined ? {} : { limit }), |
| @@ -65,9 +66,10 @@ export function feedRoutes(router: Router<Handler>): void { | ||
| 65 | 66 | }); |
| 66 | 67 | |
| 67 | 68 | // What asks the viewer, ranked, with the week's measure (`asksAnswer`). |
| 68 | router.add("GET", "/api/v1/asks", (ctx) => { | |
| 69 | router.add("GET", "/api/v1/asks", async (ctx) => { | |
| 69 | 70 | const viewer = ctx.auth.user; |
| 70 | 71 | if (!viewer) return unauthorized(); |
| 72 | await warmConflicts(ctx, viewer); | |
| 71 | 73 | return json(asksAnswer(ctx, viewer), 200, { |
| 72 | 74 | "cache-control": "private, no-store", |
| 73 | 75 | }); |
src/http/mcp.ts +5 −3
| @@ -102,7 +102,7 @@ import { | ||
| 102 | 102 | milestoneData, |
| 103 | 103 | milestonesJson, |
| 104 | 104 | } from "../web/pages/milestones.ts"; |
| 105 | import { appsOf, asksAnswer } from "../web/studio/asks.ts"; | |
| 105 | import { appsOf, asksAnswer, warmConflicts } from "../web/studio/asks.ts"; | |
| 106 | 106 | import { applyAsksBulk, previewAsksBulk } from "../actions/asks_bulk.ts"; |
| 107 | 107 | import type { Ctx, Handler } from "./context.ts"; |
| 108 | 108 | import { |
| @@ -496,7 +496,8 @@ const TOOLS: readonly Tool[] = [ | ||
| 496 | 496 | "What waits on you, most consequential first: each row names the decision, its options and what happens if nobody acts, and why it ranks where it does (security, money, held-up work, then age). Rows of one kind in one app are collapsed with their item ids. Also the forge's own needs (for a site admin) and the last 7 days' asks raised, acted on, dismissed and gone by themselves.", |
| 497 | 497 | inputSchema: { type: "object", properties: {} }, |
| 498 | 498 | writes: false, |
| 499 | run(ctx, user) { | |
| 499 | async run(ctx, user) { | |
| 500 | await warmConflicts(ctx, user); | |
| 500 | 501 | return good(asksAnswer(ctx, user)); |
| 501 | 502 | }, |
| 502 | 503 | }, |
| @@ -1110,7 +1111,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1110 | 1111 | }, |
| 1111 | 1112 | }, |
| 1112 | 1113 | writes: false, |
| 1113 | run(ctx, user, args) { | |
| 1114 | async run(ctx, user, args) { | |
| 1114 | 1115 | const raw = args["limit"]; |
| 1115 | 1116 | const limit = raw === undefined ? FEED_LIMIT_DEFAULT : Number(raw); |
| 1116 | 1117 | if (!Number.isInteger(limit) || limit < 1 || limit > FEED_LIMIT_MAX) |
| @@ -1119,6 +1120,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1119 | 1120 | const cursor = given === undefined ? undefined : parseCursor(str(given)); |
| 1120 | 1121 | if (given !== undefined && cursor === undefined) |
| 1121 | 1122 | return bad("invalid", "that cursor was not issued here"); |
| 1123 | await warmConflicts(ctx, user); | |
| 1122 | 1124 | return good( |
| 1123 | 1125 | readFeed(ctx.app.db, user, { |
| 1124 | 1126 | limit, |
src/http/server.ts +5 −1
| @@ -193,6 +193,7 @@ import { | ||
| 193 | 193 | asksPage, |
| 194 | 194 | } from "../web/studio/asks_page.ts"; |
| 195 | 195 | import { liveFeedFragment } from "../web/studio/feed.ts"; |
| 196 | import { warmConflicts } from "../web/studio/asks.ts"; | |
| 196 | 197 | import { serviceWorker } from "../web/sw.ts"; |
| 197 | 198 | import { explorePage } from "../web/studio/explore.ts"; |
| 198 | 199 | import { |
| @@ -611,7 +612,10 @@ export function buildRouter(): Router<Handler> { | ||
| 611 | 612 | // fetches a region and not the page. Literal, above /:owner. |
| 612 | 613 | router.add("GET", "/live/apps", liveAppsFragment); |
| 613 | 614 | router.add("GET", "/live/on-you", liveOnYouFragment); |
| 614 | router.add("GET", "/live/feed", liveFeedFragment); | |
| 615 | router.add("GET", "/live/feed", async (ctx) => { | |
| 616 | await warmConflicts(ctx, ctx.auth.user, true); | |
| 617 | return liveFeedFragment(ctx); | |
| 618 | }); | |
| 615 | 619 | // Whether a hostname is an app's verified domain — what Caddy's |
| 616 | 620 | // `on_demand_tls { ask … }` asks before it fetches a certificate for a |
| 617 | 621 | // name it has never seen (docs/EXTRACT.md). 200 says yes, 404 says no, |
src/web/pages/pull.ts +8 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * it needs. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { conflictsWords } from "../../core/conflicts.ts"; | |
| 11 | 12 | import { askCheck } from "../../checks/again.ts"; |
| 12 | 13 | import { addCommentThrough } from "../../actions/issues.ts"; |
| 13 | 14 | import type { AccessError } from "../../actions/access.ts"; |
| @@ -210,6 +211,8 @@ function checksLine( | ||
| 210 | 211 | tier = "", |
| 211 | 212 | /** A writer's button to ask for a check again; empty for anyone else. */ |
| 212 | 213 | again: Html | "" = "", |
| 214 | /** Files that stop this head merging; a passing check is not shown over them. */ | |
| 215 | conflicts = 0, | |
| 213 | 216 | ): Html { |
| 214 | 217 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| 215 | 218 | return html``; |
| @@ -222,7 +225,10 @@ function checksLine( | ||
| 222 | 225 | >deploy ${run.commitOid.slice(0, 7)}</a |
| 223 | 226 | >`; |
| 224 | 227 | const body = |
| 225 | check.state === "ok" | |
| 228 | check.state === "ok" && conflicts > 0 | |
| 229 | ? html`<span class="bad">${icon("x")}${conflictsWords(conflicts)}</span | |
| 230 | >${link}` | |
| 231 | : check.state === "ok" | |
| 226 | 232 | ? html`<span class="ok">${icon("check")}Checks passed</span>${link}` |
| 227 | 233 | : check.state === "failed" |
| 228 | 234 | ? html`<span class="bad">${icon("x")}Checks failed</span>${link}` |
| @@ -319,6 +325,7 @@ function mergeBox( | ||
| 319 | 325 | ${btn("Check again", { size: "sm", icon: "loader" })} |
| 320 | 326 | </form>` |
| 321 | 327 | : "", |
| 328 | status.conflicts.length, | |
| 322 | 329 | ); |
| 323 | 330 | const reopen = html`<form method="post" action="${thread}/state"> |
| 324 | 331 | <input type="hidden" name="state" value="open" /> |
src/web/pages/site.ts +2
| @@ -30,6 +30,7 @@ import { isThemeName } from "../../design/themes.ts"; | ||
| 30 | 30 | import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts"; |
| 31 | 31 | import { studioDoor, studioHome } from "../studio/home.ts"; |
| 32 | 32 | import { homeTop, onYouBulk } from "../studio/asks_page.ts"; |
| 33 | import { warmConflicts } from "../studio/asks.ts"; | |
| 33 | 34 | import { latestUndoable } from "../../actions/asks_bulk.ts"; |
| 34 | 35 | import { mutedRepos } from "../../core/interactions.ts"; |
| 35 | 36 | import { edgeLoginUrl } from "../../http/edge.ts"; |
| @@ -308,6 +309,7 @@ export function terminalCard(ctx: Ctx): Html { | ||
| 308 | 309 | export async function home(ctx: Ctx): Promise<Response> { |
| 309 | 310 | const user = ctx.auth.user; |
| 310 | 311 | if (user === undefined) return studioDoor(ctx); |
| 312 | await warmConflicts(ctx, user, true); | |
| 311 | 313 | return await studioHome(ctx, user, homeTop(ctx)); |
| 312 | 314 | } |
| 313 | 315 |
src/web/studio/asks.ts +66 −3
| @@ -25,7 +25,15 @@ import { | ||
| 25 | 25 | type Issue, |
| 26 | 26 | } from "../../core/issues.ts"; |
| 27 | 27 | import { looksForApps } from "../../core/looks.ts"; |
| 28 | import { closesFromBody, getPull, joinMany, type Pull } from "../../core/pulls.ts"; | |
| 28 | import { conflictsKnown } from "../../core/conflicts.ts"; | |
| 29 | import { | |
| 30 | closesFromBody, | |
| 31 | getPull, | |
| 32 | joinMany, | |
| 33 | pullDir, | |
| 34 | pullStatus, | |
| 35 | type Pull, | |
| 36 | } from "../../core/pulls.ts"; | |
| 29 | 37 | import { |
| 30 | 38 | listReposVisibleTo, |
| 31 | 39 | canWrite, |
| @@ -300,7 +308,8 @@ function askCandidatesFor( | ||
| 300 | 308 | repo.autonomy !== "autonomous" && |
| 301 | 309 | // A green pull that no longer merges as it stands cannot be shipped: |
| 302 | 310 | // bringing it up to date is work, not a person's decision. |
| 303 | !isStalePull(db, pull.id, pull.headOid) | |
| 311 | !isStalePull(db, pull.id, pull.headOid) && | |
| 312 | conflictsKnown(pull.id, pull.headOid).length === 0 | |
| 304 | 313 | ) { |
| 305 | 314 | // Autonomous repositories look at their own green pulls: the decider, |
| 306 | 315 | // then the crew's reviewer. Everything else waits for a person — |
| @@ -320,7 +329,8 @@ function askCandidatesFor( | ||
| 320 | 329 | } else if ( |
| 321 | 330 | check?.state === "ok" && |
| 322 | 331 | repo.autonomy === "autonomous" && |
| 323 | !isStalePull(db, pull.id, pull.headOid) | |
| 332 | !isStalePull(db, pull.id, pull.headOid) && | |
| 333 | conflictsKnown(pull.id, pull.headOid).length === 0 | |
| 324 | 334 | ) { |
| 325 | 335 | // An autonomous repository lands its own green pulls once reviewed; |
| 326 | 336 | // an agent's change with no reviewer, or whose review lapsed, waits |
| @@ -958,6 +968,59 @@ export function forgeNeedsFor(ctx: Ctx, user: User | undefined): string[] { | ||
| 958 | 968 | }).needs; |
| 959 | 969 | } |
| 960 | 970 | |
| 971 | /** | |
| 972 | * Read, for the viewer's open pulls whose check is green, whether each still | |
| 973 | * merges — so the synchronous asks that follow (`askCandidatesFor`) never | |
| 974 | * call a conflicted pull green. One cached merge reading per pull | |
| 975 | * (`pullStatus`), at most `WARM_AT_ONCE` in flight; a pull that cannot be | |
| 976 | * read is left unremarked. | |
| 977 | */ | |
| 978 | const WARM_AT_ONCE = 4; | |
| 979 | /** When each pull was last read here: a page render (`quick`) does not re-ask within this. */ | |
| 980 | const WARM_FRESH_MS = 10_000; | |
| 981 | const warmedAt = new Map<string, number>(); | |
| 982 | export async function warmConflicts( | |
| 983 | ctx: Ctx, | |
| 984 | user: User | undefined, | |
| 985 | /** A page render: trust a reading made in the last few seconds. */ | |
| 986 | quick = false, | |
| 987 | ): Promise<void> { | |
| 988 | if (!user) return; | |
| 989 | const db = ctx.app.db; | |
| 990 | const repos = new Map( | |
| 991 | listReposVisibleTo(db, user, { limit: 200 }).map((r) => [r.id, r]), | |
| 992 | ); | |
| 993 | const pulls = listOpenPullsVisibleTo(db, user, 50).filter((p) => | |
| 994 | repos.has(p.repoId), | |
| 995 | ); | |
| 996 | const checks = latestRunsForIssues(db, pulls.map((p) => p.id)); | |
| 997 | const green: Pull[] = []; | |
| 998 | for (const issue of pulls) { | |
| 999 | if (checks.get(issue.id)?.state !== "ok") continue; | |
| 1000 | const pull = getPull(db, issue.repoId, issue.number); | |
| 1001 | if (pull === undefined) continue; | |
| 1002 | if (quick && Date.now() - (warmedAt.get(pull.id) ?? 0) < WARM_FRESH_MS) continue; | |
| 1003 | green.push(pull); | |
| 1004 | } | |
| 1005 | let next = 0; | |
| 1006 | const worker = async (): Promise<void> => { | |
| 1007 | for (let i = next++; i < green.length; i = next++) { | |
| 1008 | const pull = green[i]!; | |
| 1009 | const repo = repos.get(pull.repoId)!; | |
| 1010 | if (warmedAt.size > 2000) warmedAt.clear(); | |
| 1011 | warmedAt.set(pull.id, Date.now()); | |
| 1012 | try { | |
| 1013 | await pullStatus(await pullDir(db, ctx.app.reposRoot, repo, pull), pull); | |
| 1014 | } catch { | |
| 1015 | // an unreadable repository is not a verdict | |
| 1016 | } | |
| 1017 | } | |
| 1018 | }; | |
| 1019 | await Promise.all( | |
| 1020 | Array.from({ length: Math.min(WARM_AT_ONCE, green.length) }, worker), | |
| 1021 | ); | |
| 1022 | } | |
| 1023 | ||
| 961 | 1024 | /** |
| 962 | 1025 | * How many things ask the viewer: the one number the studio header and the |
| 963 | 1026 | * asks page both show. It counts the rows the cards are made into |
src/web/studio/change.ts +3 −1
| @@ -286,7 +286,6 @@ async function pullPanels(ctx: Ctx, repo: Repo, pull: Pull) { | ||
| 286 | 286 | history: servingHistory(), |
| 287 | 287 | viewer: ctx.auth.user, |
| 288 | 288 | }; |
| 289 | const { word, note: checkNote } = await pullWord(wordCtx, pull); | |
| 290 | 289 | // Whether this change still merges into its base is asked here, on its own |
| 291 | 290 | // page, and nowhere a list of changes renders — a git call per open pull |
| 292 | 291 | // would undo the home's own bound (`askCandidatesFor`). Only an open, |
| @@ -300,8 +299,11 @@ async function pullPanels(ctx: Ctx, repo: Repo, pull: Pull) { | ||
| 300 | 299 | requireReview: repo.requireReview, |
| 301 | 300 | }) |
| 302 | 301 | : undefined; |
| 302 | const { word: judged, note: checkNote } = await pullWord(wordCtx, pull); | |
| 303 | 303 | const conflicted = |
| 304 | 304 | status !== undefined && !status.mergeable && status.conflicts.length > 0; |
| 305 | // A green check on a conflicted head is no look: it reads stopped. | |
| 306 | const word = conflicted && judged === "look" ? "stopped" : judged; | |
| 305 | 307 | // A reader's head runs nothing until a writer approves it (#777): say |
| 306 | 308 | // that, rather than leave a word waiting on something that will not come. |
| 307 | 309 | const waitingOnApproval = |
src/web/studio/words.ts +6
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * thing about the same commit. Nothing here knows about a page. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { conflictsKnown, conflictsWords } from "../../core/conflicts.ts"; | |
| 11 | 12 | import type { Database } from "bun:sqlite"; |
| 12 | 13 | import { ancestorsOf } from "../../git/merge.ts"; |
| 13 | 14 | import type { AppsRuntime, EnvStatus } from "../../apps/runtime.ts"; |
| @@ -211,6 +212,11 @@ export async function pullWord( | ||
| 211 | 212 | if (pull.state === "closed") |
| 212 | 213 | return { word: "stopped", note: "closed without shipping" }; |
| 213 | 214 | const check = checkSummary(ctx.db, pull.id, pull.headOid); |
| 215 | // A green check on a head that no longer merges is not a look: the | |
| 216 | // conflicts are the word, wherever the green would have been. | |
| 217 | const conflicts = conflictsKnown(pull.id, pull.headOid); | |
| 218 | if (check.state === "ok" && conflicts.length > 0) | |
| 219 | return { word: "stopped", note: conflictsWords(conflicts.length).toLowerCase() }; | |
| 214 | 220 | // A repository that is not an app never deploys a head, so it never gets |
| 215 | 221 | // a look: an open change there waits on a person, and says so. |
| 216 | 222 | if (ctx.record === undefined && check.state === "none") |
test/conflicted-green.test.ts added +178
| @@ -0,0 +1,178 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp, type App } from "../src/app.ts"; | |
| 6 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 7 | import { getPull } from "../src/core/pulls.ts"; | |
| 8 | import { getRepo } from "../src/core/repos.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { gitClientEnv } from "./helpers/git-client.ts"; | |
| 11 | ||
| 12 | const gitEnv = gitClientEnv(); | |
| 13 | ||
| 14 | describe("a conflicted pull never shows a green mark", () => { | |
| 15 | let dataDir: string; | |
| 16 | let work: string; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | let base: string; | |
| 20 | let dir: string; | |
| 21 | const auth = { authorization: "" }; | |
| 22 | ||
| 23 | async function gitOk(args: string[]): Promise<void> { | |
| 24 | const p = Bun.spawn(["git", ...args], { | |
| 25 | cwd: dir, | |
| 26 | env: gitEnv, | |
| 27 | stdout: "ignore", | |
| 28 | stderr: "pipe", | |
| 29 | }); | |
| 30 | const [err, code] = await Promise.all([ | |
| 31 | new Response(p.stderr).text(), | |
| 32 | p.exited, | |
| 33 | ]); | |
| 34 | if (code !== 0) throw new Error(`git ${args.join(" ")}: ${err}`); | |
| 35 | } | |
| 36 | const write = async (text: string, message: string) => { | |
| 37 | await Bun.write(join(dir, "code.txt"), text); | |
| 38 | await gitOk(["commit", "-am", message]); | |
| 39 | }; | |
| 40 | const page = async (path: string) => | |
| 41 | (await fetch(`${base}${path}`, { headers: auth })).text(); | |
| 42 | const json = async (path: string) => | |
| 43 | (await fetch(`${base}${path}`, { headers: auth })).json() as Promise<any>; | |
| 44 | const mcp = async (name: string) => { | |
| 45 | const res = await fetch(`${base}/mcp`, { | |
| 46 | method: "POST", | |
| 47 | headers: { | |
| 48 | "content-type": "application/json", | |
| 49 | accept: "application/json, text/event-stream", | |
| 50 | ...auth, | |
| 51 | }, | |
| 52 | body: JSON.stringify({ | |
| 53 | jsonrpc: "2.0", | |
| 54 | id: 1, | |
| 55 | method: "tools/call", | |
| 56 | params: { name, arguments: {} }, | |
| 57 | }), | |
| 58 | }); | |
| 59 | const body = (await res.json()) as any; | |
| 60 | return JSON.parse(body.result.content[0].text); | |
| 61 | }; | |
| 62 | const checksLine = (html: string) => | |
| 63 | /<p class="checks-line">[\s\S]*?<\/p>/.exec(html)?.[0] ?? ""; | |
| 64 | const asking = (rows: any) => JSON.stringify(rows).includes("Feat"); | |
| 65 | ||
| 66 | beforeAll(async () => { | |
| 67 | dataDir = await mkdtemp(join(tmpdir(), "forge-cg-")); | |
| 68 | work = await mkdtemp(join(tmpdir(), "forge-cg-work-")); | |
| 69 | app = createApp({ dataDir, port: 0 }); | |
| 70 | servers = await serve(app); | |
| 71 | base = servers.url; | |
| 72 | await fetch(`${base}/signup`, { | |
| 73 | method: "POST", | |
| 74 | body: new URLSearchParams({ | |
| 75 | username: "dev", | |
| 76 | email: "[email protected]", | |
| 77 | password: "conflicted-green-pass", | |
| 78 | }), | |
| 79 | redirect: "manual", | |
| 80 | }); | |
| 81 | const token = await fetch(`${base}/api/v1/tokens`, { | |
| 82 | method: "POST", | |
| 83 | headers: { "content-type": "application/json" }, | |
| 84 | body: JSON.stringify({ | |
| 85 | adminConfirm: true, | |
| 86 | username: "dev", | |
| 87 | password: "conflicted-green-pass", | |
| 88 | name: "cli", | |
| 89 | scope: "rw", | |
| 90 | }), | |
| 91 | }) | |
| 92 | .then((r) => r.json()) | |
| 93 | .then((j) => (j as { token: string }).token); | |
| 94 | auth.authorization = `Bearer ${token}`; | |
| 95 | await fetch(`${base}/api/v1/repos`, { | |
| 96 | method: "POST", | |
| 97 | headers: { ...auth, "content-type": "application/json" }, | |
| 98 | body: JSON.stringify({ name: "app", visibility: "public" }), | |
| 99 | }); | |
| 100 | const remote = `${base.replace("http://", `http://dev:${token}@`)}/dev/app.git`; | |
| 101 | dir = work; | |
| 102 | await gitOk(["clone", remote, "app"]); | |
| 103 | dir = join(work, "app"); | |
| 104 | await Bun.write(join(dir, "code.txt"), "alpha\nbeta\ngamma\n"); | |
| 105 | await gitOk(["add", "."]); | |
| 106 | await gitOk(["commit", "-m", "base"]); | |
| 107 | await gitOk(["push", "origin", "main"]); | |
| 108 | }); | |
| 109 | ||
| 110 | afterAll(async () => { | |
| 111 | servers.stop(); | |
| 112 | app.close(); | |
| 113 | await rm(dataDir, { recursive: true, force: true }); | |
| 114 | await rm(work, { recursive: true, force: true }); | |
| 115 | }); | |
| 116 | ||
| 117 | test("a passing check reads Conflicts in 1 file, not green, on the page and in the asks; resolving brings green back", async () => { | |
| 118 | await gitOk(["checkout", "-b", "feat"]); | |
| 119 | await write("alpha\nBETA\ngamma\n", "feat beta"); | |
| 120 | await gitOk(["push", "origin", "feat"]); | |
| 121 | const made = await fetch(`${base}/api/v1/repos/dev/app/pulls`, { | |
| 122 | method: "POST", | |
| 123 | headers: { ...auth, "content-type": "application/json" }, | |
| 124 | body: JSON.stringify({ base: "main", head: "feat", title: "Feat" }), | |
| 125 | }); | |
| 126 | expect(made.status).toBe(201); | |
| 127 | const repo = getRepo(app.db, "dev", "app")!; | |
| 128 | const pull = getPull(app.db, repo.id, 1)!; | |
| 129 | const run = createRun(app.db, { | |
| 130 | repoId: repo.id, | |
| 131 | kind: "check", | |
| 132 | issueId: pull.id, | |
| 133 | commitOid: pull.headOid, | |
| 134 | }); | |
| 135 | claimRun(app.db, run.id); | |
| 136 | finishRun(app.db, run.id, { state: "ok", summary: "passed" }); | |
| 137 | ||
| 138 | // Clean and green: the mark, the look, the ask. | |
| 139 | const green = checksLine(await page("/dev/app/pulls/1/files")); | |
| 140 | expect(green).toContain("Checks passed"); | |
| 141 | expect(green).toContain('class="ok"'); | |
| 142 | expect(await page("/dev/app/pulls/1")).toContain('data-word="look"'); | |
| 143 | expect(await page("/")).toContain("Green — ready for a look"); | |
| 144 | expect(asking(await mcp("asks"))).toBe(true); | |
| 145 | expect(asking(await json("/api/v1/asks"))).toBe(true); | |
| 146 | expect(JSON.stringify(await mcp("feed"))).toContain("green"); | |
| 147 | ||
| 148 | // The base takes a different edit of the same line. | |
| 149 | await gitOk(["checkout", "main"]); | |
| 150 | await write("alpha\nbeta!\ngamma\n", "quiet beta"); | |
| 151 | await gitOk(["push", "origin", "main"]); | |
| 152 | ||
| 153 | const line = checksLine(await page("/dev/app/pulls/1/files")); | |
| 154 | expect(line).toContain("Conflicts in 1 file"); | |
| 155 | expect(line).not.toContain("Checks passed"); | |
| 156 | expect(line).not.toContain('class="ok"'); | |
| 157 | ||
| 158 | // The change's own page, the home, the asks and the feed read the same. | |
| 159 | const change = await page("/dev/app/pulls/1"); | |
| 160 | expect(change).not.toContain('data-word="look"'); | |
| 161 | expect(change).toContain("it conflicts with main"); | |
| 162 | const home = await page("/"); | |
| 163 | expect(home).not.toContain("Green — ready for a look"); | |
| 164 | expect(home).not.toContain("Ready to ship"); | |
| 165 | expect(asking(await mcp("asks"))).toBe(false); | |
| 166 | expect(asking(await json("/api/v1/asks"))).toBe(false); | |
| 167 | expect(JSON.stringify(await mcp("feed"))).not.toContain("green"); | |
| 168 | ||
| 169 | // The base moves to hold the same line: the green is back. | |
| 170 | await write("alpha\nBETA\ngamma\n", "the same edit"); | |
| 171 | await gitOk(["push", "origin", "main"]); | |
| 172 | const back = checksLine(await page("/dev/app/pulls/1/files")); | |
| 173 | expect(back).toContain("Checks passed"); | |
| 174 | expect(back).toContain('class="ok"'); | |
| 175 | expect(await page("/dev/app/pulls/1")).toContain('data-word="look"'); | |
| 176 | expect(asking(await mcp("asks"))).toBe(true); | |
| 177 | }); | |
| 178 | }); |
test/studio.test.ts +4 −2
| @@ -622,8 +622,10 @@ describe("the studio", () => { | ||
| 622 | 622 | expect(studio).toContain("bring the branch up to date"); |
| 623 | 623 | expect(studio).not.toContain("Ship"); |
| 624 | 624 | expect(studio).toContain("Bring up to date"); |
| 625 | // Still one of the five words — no sixth badge invented for this. | |
| 626 | expect(studio).toContain('data-word="look"'); | |
| 625 | // Still one of the five words — no sixth badge invented for this — and | |
| 626 | // never the green one: a conflicted change is not ready for a look. | |
| 627 | expect(studio).toContain('data-word="stopped"'); | |
| 628 | expect(studio).not.toContain('data-word="look"'); | |
| 627 | 629 | |
| 628 | 630 | setIssueState(app, alice, repo, pull, "closed"); |
| 629 | 631 |
new above
offline