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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

checks/own-first-terminal → main 0 commits

  • Merged. checks/own-first-terminal was merged into main as 86ae300.

Review

Sign in to review this change.
4 files changed +117 −12
src/checks/place.ts +7 −1
@@ -8,7 +8,7 @@
88
99 import type { Database } from "bun:sqlite";
1010 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";
1212
1313 export interface Place {
1414 readonly place: number;
@@ -33,5 +33,11 @@ export function queuePlace(db: Database, run: Pick<Run, "id" | "state" | "kind">
3333 return row === null || row.before === 0 ? undefined : { place: row.before, of: row.total, own: row.own === 1 };
3434 }
3535
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
3642 /** `place 3 of 12`, or empty when the check is not waiting in line. */
3743 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";
9696 import { wallOf, wallPlain, type Wall } from "../../contract/policy.ts";
9797 import { changedSentences } from "../../core/pulls.ts";
9898 import { checkSummary, runnerSilent, type CheckSummary } from "../../core/runs.ts";
99 import { placeAndOwn, queuePlace } from "../../checks/place.ts";
99100 import { err, ok } from "../../kernel/result.ts";
100101 import { getUsersByIds } from "../../core/users.ts";
101102 import {
@@ -344,6 +345,8 @@ export function pullScreen(
344345 /** `findingsWords` of the preview's website-spec findings; empty when none were recorded. */
345346 let specWords = "";
346347 let redWords = "";
348 /** The queued check's place in line, and that the owner's own pull goes ahead (`placeAndOwn`). */
349 let placeText = "";
347350 /** The check's green was against a base that has since moved. */
348351 let checkOld = false;
349352 /** Agent runs about this pull, newest first. */
@@ -454,6 +457,7 @@ export function pullScreen(
454457 ? NO_CHECK
455458 : checkSummary(f.db, row.id, row.headOid || (facts?.headOid ?? ""));
456459 checkBase = row?.baseBranch ?? facts?.baseBranch ?? "";
460 placeText = check.run === null ? "" : placeAndOwn(queuePlace(f.db, check.run));
457461 const originSaid =
458462 row === undefined || repo?.origin == null ? undefined : originCheckOf(f.db, row.id);
459463 originCheckText =
@@ -1329,7 +1333,7 @@ export function pullScreen(
13291333 // The box is exactly as tall as what is in it: the state, then a row
13301334 // for the verdicts when there are any, then a row for the checks when
13311335 // 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);
13331337 const boxH =
13341338 3 +
13351339 (standingText(standing(), requireReview) === "" ? 0 : 1) +
@@ -1977,11 +1981,14 @@ export function checksText(
19771981 spec = "",
19781982 /** The queue holds the pull as red alone: its words; empty when it does not. */
19791983 red = "",
1984 /** `placeAndOwn` of a queued check: its place in line, and that an owner's own pull goes ahead. */
1985 place = "",
19801986 ): string {
19811987 const line = checksLine(check, required, isApp, baseBranch, stale, progress);
19821988 const withSteps = line === "" || steps === "" ? line : `${line} · ${steps}`;
19831989 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}`;
19851992 }
19861993
19871994 function checksLine(
src/web/pages/pull.ts +2 −9
@@ -14,8 +14,7 @@ import { pullRoster } from "../studio/pull_roster.ts";
1414 import { originCheckLead, originCheckOf } from "../../origins/pull-check.ts";
1515 import { askCheck, askedWords } from "../../checks/again.ts";
1616 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";
1918 import { addCommentThrough } from "../../actions/issues.ts";
2019 import { COMMENT_EMPTY, COMMENT_NOT_POSTED } from "../../actions/comment_words.ts";
2120 import { PULL_GONE } from "../../actions/pull_words.ts";
@@ -327,7 +326,7 @@ export function checksLine(
327326 progress = "",
328327 /** Where this line answers for itself (`data-live-src`); empty for none. */
329328 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. */
331330 place = "",
332331 ): Html {
333332 if (!isApp && !required && check.state === "none" && !waiting && again === "")
@@ -485,12 +484,6 @@ async function tierOf(
485484
486485 // ---- the merge box ----
487486
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
494487 /**
495488 * The checks line of a pull, as the merge box shows it and as its live
496489 * 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(/&#39;/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 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs