Public: anyone can read this; the crew can change it.
The terminal's pull screen says a queued check goes ahead of the crew's, as the pull page does #16982
Check · Review · Land · Live done — Landed and live in production.
checks/own-first-terminal → main 0 commits
4 files
changed +117
−12
src/checks/place.ts +7 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| 10 | 10 | import type { Run } from "../core/runs.ts"; |
| 11 | import { OWN_PULL_JOINS, OWN_PULL_WHERE } from "./own_first.ts"; | |
| 11 | import { OWN_FIRST_WORDS, OWN_PULL_JOINS, OWN_PULL_WHERE } from "./own_first.ts"; | |
| 12 | 12 | |
| 13 | 13 | export interface Place { |
| 14 | 14 | readonly place: number; |
| @@ -33,5 +33,11 @@ export function queuePlace(db: Database, run: Pick<Run, "id" | "state" | "kind"> | ||
| 33 | 33 | return row === null || row.before === 0 ? undefined : { place: row.before, of: row.total, own: row.own === 1 }; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | /** | |
| 37 | * Where a queued check stands, and when it is the owner's own pull, that it goes ahead of the crew's: | |
| 38 | * the words the pull page's checks line and the terminal's pull screen both say. | |
| 39 | */ | |
| 40 | export const placeAndOwn = (p: Place | undefined): string => (p === undefined ? "" : p.own === true ? `${placeWords(p)}, ${OWN_FIRST_WORDS}` : placeWords(p)); | |
| 41 | ||
| 36 | 42 | /** `place 3 of 12`, or empty when the check is not waiting in line. */ |
| 37 | 43 | export const placeWords = (p: Place | undefined): string => (p === undefined ? "" : `place ${p.place} of ${p.of}`); |
src/tui/screens/pull.ts +9 −2
| @@ -96,6 +96,7 @@ import { verdictOf, type Verdict } from "../../web/pages/pull-verdict.ts"; | ||
| 96 | 96 | import { wallOf, wallPlain, type Wall } from "../../contract/policy.ts"; |
| 97 | 97 | import { changedSentences } from "../../core/pulls.ts"; |
| 98 | 98 | import { checkSummary, runnerSilent, type CheckSummary } from "../../core/runs.ts"; |
| 99 | import { placeAndOwn, queuePlace } from "../../checks/place.ts"; | |
| 99 | 100 | import { err, ok } from "../../kernel/result.ts"; |
| 100 | 101 | import { getUsersByIds } from "../../core/users.ts"; |
| 101 | 102 | import { |
| @@ -344,6 +345,8 @@ export function pullScreen( | ||
| 344 | 345 | /** `findingsWords` of the preview's website-spec findings; empty when none were recorded. */ |
| 345 | 346 | let specWords = ""; |
| 346 | 347 | let redWords = ""; |
| 348 | /** The queued check's place in line, and that the owner's own pull goes ahead (`placeAndOwn`). */ | |
| 349 | let placeText = ""; | |
| 347 | 350 | /** The check's green was against a base that has since moved. */ |
| 348 | 351 | let checkOld = false; |
| 349 | 352 | /** Agent runs about this pull, newest first. */ |
| @@ -454,6 +457,7 @@ export function pullScreen( | ||
| 454 | 457 | ? NO_CHECK |
| 455 | 458 | : checkSummary(f.db, row.id, row.headOid || (facts?.headOid ?? "")); |
| 456 | 459 | checkBase = row?.baseBranch ?? facts?.baseBranch ?? ""; |
| 460 | placeText = check.run === null ? "" : placeAndOwn(queuePlace(f.db, check.run)); | |
| 457 | 461 | const originSaid = |
| 458 | 462 | row === undefined || repo?.origin == null ? undefined : originCheckOf(f.db, row.id); |
| 459 | 463 | originCheckText = |
| @@ -1329,7 +1333,7 @@ export function pullScreen( | ||
| 1329 | 1333 | // The box is exactly as tall as what is in it: the state, then a row |
| 1330 | 1334 | // for the verdicts when there are any, then a row for the checks when |
| 1331 | 1335 | // a deploy has run or the gate demands one. |
| 1332 | const checksLine = checksText(check, requireChecks, isApp, checkBase, checkOld, checkProgress, checkSteps, specWords, redWords); | |
| 1336 | const checksLine = checksText(check, requireChecks, isApp, checkBase, checkOld, checkProgress, checkSteps, specWords, redWords, placeText); | |
| 1333 | 1337 | const boxH = |
| 1334 | 1338 | 3 + |
| 1335 | 1339 | (standingText(standing(), requireReview) === "" ? 0 : 1) + |
| @@ -1977,11 +1981,14 @@ export function checksText( | ||
| 1977 | 1981 | spec = "", |
| 1978 | 1982 | /** The queue holds the pull as red alone: its words; empty when it does not. */ |
| 1979 | 1983 | red = "", |
| 1984 | /** `placeAndOwn` of a queued check: its place in line, and that an owner's own pull goes ahead. */ | |
| 1985 | place = "", | |
| 1980 | 1986 | ): string { |
| 1981 | 1987 | const line = checksLine(check, required, isApp, baseBranch, stale, progress); |
| 1982 | 1988 | const withSteps = line === "" || steps === "" ? line : `${line} · ${steps}`; |
| 1983 | 1989 | const withSpec = withSteps === "" || spec === "" ? withSteps : `${withSteps} · ${spec}`; |
| 1984 | return withSpec === "" || red === "" ? `${withSpec}${red}` : `${withSpec} · ${red}`; | |
| 1990 | const withRed = withSpec === "" || red === "" ? `${withSpec}${red}` : `${withSpec} · ${red}`; | |
| 1991 | return withRed === "" || place === "" ? withRed : `${withRed} · ${place}`; | |
| 1985 | 1992 | } |
| 1986 | 1993 | |
| 1987 | 1994 | function checksLine( |
src/web/pages/pull.ts +2 −9
| @@ -14,8 +14,7 @@ import { pullRoster } from "../studio/pull_roster.ts"; | ||
| 14 | 14 | import { originCheckLead, originCheckOf } from "../../origins/pull-check.ts"; |
| 15 | 15 | import { askCheck, askedWords } from "../../checks/again.ts"; |
| 16 | 16 | import { isPileChoice, pileWords, takePileChoice } from "../../crew/stuck_pile.ts"; |
| 17 | import { placeWords, queuePlace, type Place } from "../../checks/place.ts"; | |
| 18 | import { OWN_FIRST_WORDS } from "../../checks/own_first.ts"; | |
| 17 | import { placeAndOwn, queuePlace } from "../../checks/place.ts"; | |
| 19 | 18 | import { addCommentThrough } from "../../actions/issues.ts"; |
| 20 | 19 | import { COMMENT_EMPTY, COMMENT_NOT_POSTED } from "../../actions/comment_words.ts"; |
| 21 | 20 | import { PULL_GONE } from "../../actions/pull_words.ts"; |
| @@ -327,7 +326,7 @@ export function checksLine( | ||
| 327 | 326 | progress = "", |
| 328 | 327 | /** Where this line answers for itself (`data-live-src`); empty for none. */ |
| 329 | 328 | liveSrc = "", |
| 330 | /** `placeWords` of a queued check; empty when it is not waiting in line. */ | |
| 329 | /** `placeAndOwn` of a queued check; empty when it is not waiting in line. */ | |
| 331 | 330 | place = "", |
| 332 | 331 | ): Html { |
| 333 | 332 | if (!isApp && !required && check.state === "none" && !waiting && again === "") |
| @@ -485,12 +484,6 @@ async function tierOf( | ||
| 485 | 484 | |
| 486 | 485 | // ---- the merge box ---- |
| 487 | 486 | |
| 488 | /** | |
| 489 | * Where a queued check stands, and when it is the owner's own pull, that it goes ahead of the | |
| 490 | * crew's. | |
| 491 | */ | |
| 492 | const placeAndOwn = (p: Place | undefined): string => (p === undefined ? "" : p.own ? `${placeWords(p)}, ${OWN_FIRST_WORDS}` : placeWords(p)); | |
| 493 | ||
| 494 | 487 | /** |
| 495 | 488 | * The checks line of a pull, as the merge box shows it and as its live |
| 496 | 489 | * address answers it: one function, so the two never disagree. A running |
test/checks-own-first-doors.test.ts added +99
| @@ -0,0 +1,99 @@ | ||
| 1 | /** | |
| 2 | * Both doors say it: a queued check of the owner's own pull reads "queued ahead of the crew's | |
| 3 | * checks: your own pull" on the pull page's checks line and on the terminal's pull screen, from the | |
| 4 | * one `placeAndOwn` over `queuePlace` (`checks/place.ts`); a crew agent's pull says only its place. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createAgent } from "../src/actions/crew.ts"; | |
| 12 | import { openPull } from "../src/actions/pulls.ts"; | |
| 13 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { OWN_FIRST_WORDS } from "../src/checks/own_first.ts"; | |
| 15 | import type { Pull } from "../src/core/pulls.ts"; | |
| 16 | import type { Repo } from "../src/core/repos.ts"; | |
| 17 | import { createRun } from "../src/core/runs.ts"; | |
| 18 | import { createSession } from "../src/core/sessions.ts"; | |
| 19 | import { createUser, type User } from "../src/core/users.ts"; | |
| 20 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 21 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 22 | import { pullScreen } from "../src/tui/screens/pull.ts"; | |
| 23 | import { local } from "../src/tui/screens/where.ts"; | |
| 24 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 25 | import { settleApp } from "./helpers/tui.ts"; | |
| 26 | import { quietLogs } from "./helpers/globals.ts"; | |
| 27 | ||
| 28 | quietLogs(); | |
| 29 | let dir: string, app: App, servers: Servers, alice: User, bot: User, repo: Repo; | |
| 30 | let n = 0; | |
| 31 | ||
| 32 | /** A pull in Alice's repository said to be `author`'s, with its head's check queued. */ | |
| 33 | async function queued(author: User): Promise<Pull> { | |
| 34 | const i = ++n; | |
| 35 | const branch = await commitToBranch(app, alice, repo, { branch: `f/${i}`, base: "main", message: `Change ${i}`, files: [{ path: `f${i}.ts`, content: `export const f = ${i};\n` }] }); | |
| 36 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 37 | const opened = await openPull(app, alice, repo, { title: `Change ${i}`, body: "", baseBranch: "main", headBranch: `f/${i}` }); | |
| 38 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 39 | app.db.query("UPDATE issue SET author_id = ?2 WHERE id = ?1").run(opened.value.id, author.id); | |
| 40 | app.db.query("UPDATE run SET state = 'cancelled' WHERE issue_id = ?1 AND kind = 'check'").run(opened.value.id); | |
| 41 | createRun(app.db, { repoId: repo.id, kind: "check", env: `pull-${opened.value.number}`, issueId: opened.value.id, commitOid: opened.value.headOid }); | |
| 42 | return opened.value; | |
| 43 | } | |
| 44 | ||
| 45 | /** The pull page as its owner reads it, entities read back as text. */ | |
| 46 | const page = async (p: Pull): Promise<string> => | |
| 47 | (await (await fetch(`${servers.url}/alice/game/pulls/${p.number}`, { headers: { cookie: `forge_session=${createSession(app.db, alice.id).token}` } })).text()) | |
| 48 | .replace(/'/g, "'") | |
| 49 | .replace(/\s+/g, " "); | |
| 50 | ||
| 51 | async function terminal(p: Pull): Promise<string> { | |
| 52 | const term = headlessTerminal(240, 44); | |
| 53 | const { app: tui, session } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: alice }, { terminal: term, exitHooks: false }); | |
| 54 | tui.start(); | |
| 55 | await settleApp(tui); | |
| 56 | tui.push(pullScreen(session, tui.ctx, local(session, repo), p.number)); | |
| 57 | await settleApp(tui); | |
| 58 | const shown = tui.screen.toText(); | |
| 59 | tui.stop(); | |
| 60 | return shown.replace(/\s+/g, " "); | |
| 61 | } | |
| 62 | ||
| 63 | beforeAll(async () => { | |
| 64 | dir = await mkdtemp(join(tmpdir(), "forge-own-doors-")); | |
| 65 | app = createApp({ dataDir: dir, port: 0 }); | |
| 66 | servers = await serve(app); | |
| 67 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 68 | if (!u.ok) throw new Error(u.error); | |
| 69 | alice = u.value; | |
| 70 | const made = await createRepo(app, alice, { name: "game", visibility: "private" }); | |
| 71 | if (!made.ok) throw new Error(String(made.error)); | |
| 72 | repo = made.value; | |
| 73 | const seeded = await commitToBranch(app, alice, repo, { branch: "main", message: "Start", files: [{ path: "README.md", content: "game\n" }] }); | |
| 74 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 75 | const agent = await createAgent(app, alice, { username: "builderbot" }); | |
| 76 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 77 | bot = agent.value.user; | |
| 78 | }, 30_000); | |
| 79 | ||
| 80 | afterAll(async () => { | |
| 81 | servers.stop(); | |
| 82 | app.close(); | |
| 83 | await rm(dir, { recursive: true, force: true }); | |
| 84 | }); | |
| 85 | ||
| 86 | test("the owner's own pull: the page's checks line and the terminal's pull screen both say it goes ahead", async () => { | |
| 87 | const mine = await queued(alice); | |
| 88 | expect(await page(mine)).toContain(OWN_FIRST_WORDS); | |
| 89 | expect(await terminal(mine)).toContain(OWN_FIRST_WORDS); | |
| 90 | }); | |
| 91 | ||
| 92 | test("a crew agent's pull: both doors give its place in line and nothing about going ahead", async () => { | |
| 93 | const crews = await queued(bot); | |
| 94 | const [onPage, onTerminal] = [await page(crews), await terminal(crews)]; | |
| 95 | expect(onPage).toMatch(/place \d+ of \d+/); | |
| 96 | expect(onTerminal).toMatch(/place \d+ of \d+/); | |
| 97 | expect(onPage).not.toContain(OWN_FIRST_WORDS); | |
| 98 | expect(onTerminal).not.toContain(OWN_FIRST_WORDS); | |
| 99 | }); |
new above
offline