Public: anyone can read this; the crew can change it.
A change that answers reads green, and never says its tests ran: the deploy's test result is nowhere on the page #962
scout/forge:scout/280-a-change-that-answers-reads-green-and-ne → main 2 commits fork
6 files
changed +137
−13
src/apps/runtime.ts +6 −1
| @@ -154,6 +154,11 @@ const BUSY_GRACE_MS = 45 * 60_000; | ||
| 154 | 154 | * the studio reads the same constant to word its badge. */ |
| 155 | 155 | export const VERIFYING_NOTE = "serving — still verifying its tests"; |
| 156 | 156 | |
| 157 | /** What a finished deploy's summary ends with: the studio words its green | |
| 158 | * from these, so a pull says whether its tests ran (`words.ts`). */ | |
| 159 | export const TESTS_PASSED_TAIL = " · its tests passed"; | |
| 160 | export const NO_TESTS_TAIL = " · no tests declared, none run"; | |
| 161 | ||
| 157 | 162 | export interface EnvStatus { |
| 158 | 163 | readonly env: EnvName; |
| 159 | 164 | readonly state: EnvState; |
| @@ -1102,7 +1107,7 @@ export class AppsRuntime { | ||
| 1102 | 1107 | if (tested.ok) { |
| 1103 | 1108 | const done = finishRun(this.app.db, run.id, { |
| 1104 | 1109 | state: "ok", |
| 1105 | summary: `running at ${url}`, | |
| 1110 | summary: `running at ${url}${live.manifest.test === null ? NO_TESTS_TAIL : TESTS_PASSED_TAIL}`, | |
| 1106 | 1111 | }); |
| 1107 | 1112 | write(`done: ${url}`); |
| 1108 | 1113 | if (done) announceRun(this.app, done); |
src/web/studio/asks.ts +10 −4
| @@ -37,6 +37,7 @@ import { | ||
| 37 | 37 | activeRunFor, |
| 38 | 38 | automaticRunsSince, |
| 39 | 39 | latestRunsForIssues, |
| 40 | type Run, | |
| 40 | 41 | } from "../../core/runs.ts"; |
| 41 | 42 | import { getUserById, type User } from "../../core/users.ts"; |
| 42 | 43 | import { |
| @@ -56,6 +57,7 @@ import { btn, card, icon, row } from "../ui.ts"; | ||
| 56 | 57 | import { lookUrl } from "../../core/looks.ts"; |
| 57 | 58 | import { lookThumb, thumbLook } from "../pages/looks.ts"; |
| 58 | 59 | import { changeHref } from "./nouns.ts"; |
| 60 | import { testsClause } from "./words.ts"; | |
| 59 | 61 | |
| 60 | 62 | /** Repos narrowed to those with an app record, with the records — the one |
| 61 | 63 | * join `appsOf` and `writableAppsOf` share. */ |
| @@ -213,6 +215,8 @@ interface AskCandidate { | ||
| 213 | 215 | * differently for a person's own change than for the crew's (below). |
| 214 | 216 | * Absent for "paused", which names no author at all. */ |
| 215 | 217 | readonly authorIsAgent?: boolean; |
| 218 | /** For "look": the green check, whose summary says what its tests did. */ | |
| 219 | readonly check?: Run; | |
| 216 | 220 | /** For "review": why the agent's change waits for a person, and since when. */ |
| 217 | 221 | readonly reviewWait?: ReviewWait; |
| 218 | 222 | /** For "stopped": how many automatic tries, and whether the decider itself stopped it. */ |
| @@ -315,6 +319,7 @@ function askCandidatesFor( | ||
| 315 | 319 | pull, |
| 316 | 320 | who, |
| 317 | 321 | authorIsAgent: issue.authorIsAgent, |
| 322 | check, | |
| 318 | 323 | }); |
| 319 | 324 | } else if ( |
| 320 | 325 | check?.state === "ok" && |
| @@ -814,6 +819,7 @@ export function decisionsFor( | ||
| 814 | 819 | }; |
| 815 | 820 | if (c.kind === "look" && c.pull) { |
| 816 | 821 | const picture = pictureOf(c.repo, c.pull); |
| 822 | const clause = testsClause(c.check ?? null); | |
| 817 | 823 | // The crew's own words say who finished it; a person's own change |
| 818 | 824 | // gets the wording that is true of it — nobody "finished" it for |
| 819 | 825 | // them, it is simply green and waiting. |
| @@ -824,11 +830,11 @@ export function decisionsFor( | ||
| 824 | 830 | pull: c.pull, |
| 825 | 831 | who: c.who, |
| 826 | 832 | says: c.authorIsAgent |
| 827 | ? `${c.who} finished "${c.pull.title}" and the check is green. Look at the preview, then ship it or say what is off.` | |
| 828 | : `"${c.pull.title}" is green — ready for a look. Ship it, or say what is off.`, | |
| 833 | ? `${c.who} finished "${c.pull.title}" and the check is green${clause === "" ? "" : ` (${clause})`}. Look at the preview, then ship it or say what is off.` | |
| 834 | : `"${c.pull.title}" is green — ${clause === "" ? "" : `${clause}, `}ready for a look. Ship it, or say what is off.`, | |
| 829 | 835 | short: c.authorIsAgent |
| 830 | ? `${c.who} finished it; the check is green` | |
| 831 | : `green — ready for a look`, | |
| 836 | ? `${c.who} finished it; the check is green${clause === "" ? "" : ` (${clause})`}` | |
| 837 | : `green — ${clause === "" ? "" : `${clause}, `}ready for a look`, | |
| 832 | 838 | ...(picture === undefined ? {} : { picture }), |
| 833 | 839 | }; |
| 834 | 840 | } |
src/web/studio/previews.ts +14 −4
| @@ -17,10 +17,11 @@ import { | ||
| 17 | 17 | import { getAppByRepo, type AppRecord } from "../../core/apps.ts"; |
| 18 | 18 | import { listPulls, type Pull } from "../../core/pulls.ts"; |
| 19 | 19 | import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts"; |
| 20 | import { listRuns } from "../../core/runs.ts"; | |
| 20 | import { latestRunsForIssues, listRuns, type Run } from "../../core/runs.ts"; | |
| 21 | 21 | import type { Ctx } from "../../http/context.ts"; |
| 22 | 22 | import { readRunLogTail } from "../../runs/log.ts"; |
| 23 | 23 | import { loadRepo, repoBase } from "../chrome.ts"; |
| 24 | import { testsClause } from "./words.ts"; | |
| 24 | 25 | import { html, when, type Html } from "../html.ts"; |
| 25 | 26 | import { fragment } from "../layout.ts"; |
| 26 | 27 | import { |
| @@ -102,6 +103,7 @@ function previewRow( | ||
| 102 | 103 | pull: Pull, |
| 103 | 104 | env: EnvStatus | undefined, |
| 104 | 105 | writer: boolean, |
| 106 | check: Run | undefined, | |
| 105 | 107 | ): Html { |
| 106 | 108 | const href = |
| 107 | 109 | runtime === undefined |
| @@ -113,7 +115,13 @@ function previewRow( | ||
| 113 | 115 | : runtime.urlFor(record, previewEnv(pull.number)).replace(/^https?:\/\//, ""); |
| 114 | 116 | const bits: Html[] = [html`#${pull.number} ${pull.title}`]; |
| 115 | 117 | if (env !== undefined) bits.push(...envLine(base, env)); |
| 116 | const say = env?.error ?? env?.failedDeploy?.error ?? env?.note; | |
| 118 | // A serving preview whose deploy finished green says what its tests did. | |
| 119 | const verdict = | |
| 120 | env?.state === "running" && check?.state === "ok" && check.commitOid === env.commitOid | |
| 121 | ? testsClause(check) | |
| 122 | : ""; | |
| 123 | const say = | |
| 124 | env?.error ?? env?.failedDeploy?.error ?? env?.note ?? (verdict || undefined); | |
| 117 | 125 | if (say) bits.push(html`${say}`); |
| 118 | 126 | const asleep = env === undefined ? null : dormantNote(env); |
| 119 | 127 | if (asleep !== null) bits.push(asleep); |
| @@ -160,6 +168,7 @@ function previewsPanel( | ||
| 160 | 168 | openPulls: readonly Pull[], |
| 161 | 169 | envs: readonly EnvStatus[], |
| 162 | 170 | writer: boolean, |
| 171 | checks: ReadonlyMap<string, Run>, | |
| 163 | 172 | ): Html | null { |
| 164 | 173 | if (openPulls.length === 0) return null; |
| 165 | 174 | const byPull = new Map( |
| @@ -169,7 +178,7 @@ function previewsPanel( | ||
| 169 | 178 | ); |
| 170 | 179 | return listCard( |
| 171 | 180 | openPulls.map((p) => |
| 172 | previewRow(base, runtime, record, p, byPull.get(p.number), writer), | |
| 181 | previewRow(base, runtime, record, p, byPull.get(p.number), writer, checks.get(p.id)), | |
| 173 | 182 | ), |
| 174 | 183 | { |
| 175 | 184 | head: html`${icon("rocket")} |
| @@ -273,7 +282,8 @@ export function appPanels( | ||
| 273 | 282 | const runtime = appsRuntime(ctx.app); |
| 274 | 283 | const envs: EnvStatus[] = envsFor(ctx.app, ctx.auth.user, record); |
| 275 | 284 | const writer = canSeeOwnerFacts(db, repo, ctx.auth.user); |
| 276 | const previews = previewsPanel(base, runtime, record, openPulls, envs, writer); | |
| 285 | const checks = latestRunsForIssues(db, openPulls.map((p) => p.id)); | |
| 286 | const previews = previewsPanel(base, runtime, record, openPulls, envs, writer, checks); | |
| 277 | 287 | const production = envs.find((e) => e.env === "production"); |
| 278 | 288 | const url = runtime?.urlFor(record, "production"); |
| 279 | 289 | const tail = productionTail(ctx, repo, production, writer); |
src/web/studio/words.ts +25 −3
| @@ -10,7 +10,12 @@ | ||
| 10 | 10 | |
| 11 | 11 | import type { Database } from "bun:sqlite"; |
| 12 | 12 | import { ancestorsOf } from "../../git/merge.ts"; |
| 13 | import type { AppsRuntime, EnvStatus } from "../../apps/runtime.ts"; | |
| 13 | import { | |
| 14 | NO_TESTS_TAIL, | |
| 15 | TESTS_PASSED_TAIL, | |
| 16 | type AppsRuntime, | |
| 17 | type EnvStatus, | |
| 18 | } from "../../apps/runtime.ts"; | |
| 14 | 19 | import type { AppRecord } from "../../core/apps.ts"; |
| 15 | 20 | import { canEnterApp, getRepoById } from "../../core/repos.ts"; |
| 16 | 21 | import type { User } from "../../core/users.ts"; |
| @@ -150,11 +155,28 @@ function detailNote(detail: CheckDetail): string { | ||
| 150 | 155 | return `${detail.passed} passed, ${detail.failed} failed: ${names}`; |
| 151 | 156 | } |
| 152 | 157 | |
| 158 | /** | |
| 159 | * What a green deploy says about its tests, from the summary the runtime | |
| 160 | * wrote when it finished: the one clause every surface that draws a green | |
| 161 | * change uses. Empty for a run that predates the clause. | |
| 162 | */ | |
| 163 | export function testsClause(run: Run | null): string { | |
| 164 | const summary = run?.summary ?? ""; | |
| 165 | if (summary.endsWith(TESTS_PASSED_TAIL)) return "its tests passed"; | |
| 166 | if (summary.endsWith(NO_TESTS_TAIL)) return "it answered, no tests were run"; | |
| 167 | return ""; | |
| 168 | } | |
| 169 | ||
| 153 | 170 | /** A single open pull's check, in the studio's own words — never dev's |
| 154 | 171 | * "Checks passed/failed": the same five words as the rest of the page. */ |
| 155 | 172 | function checkRunWord(check: CheckSummary): { word: Word; note: string } { |
| 156 | if (check.state === "ok") | |
| 157 | return { word: "look", note: "green — ready for a look" }; | |
| 173 | if (check.state === "ok") { | |
| 174 | const clause = testsClause(check.run); | |
| 175 | return { | |
| 176 | word: "look", | |
| 177 | note: `green — ${clause === "" ? "" : `${clause}, `}ready for a look`, | |
| 178 | }; | |
| 179 | } | |
| 158 | 180 | if (check.state === "failed") { |
| 159 | 181 | const base = |
| 160 | 182 | check.run?.servingAt != null |
test/apps.test.ts +64 −1
| @@ -49,7 +49,7 @@ import { | ||
| 49 | 49 | STOPPED_SUMMARY, |
| 50 | 50 | type Run, |
| 51 | 51 | } from "../src/core/runs.ts"; |
| 52 | import { runWord, servingHistory } from "../src/web/studio/words.ts"; | |
| 52 | import { pullWord, runWord, servingHistory } from "../src/web/studio/words.ts"; | |
| 53 | 53 | import { createToken } from "../src/core/tokens.ts"; |
| 54 | 54 | import { createUser, type User } from "../src/core/users.ts"; |
| 55 | 55 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -507,6 +507,21 @@ describe("apps: production, previews, data, gates, crew", () => { | ||
| 507 | 507 | r.commitOid === fixed.value.commitOid, |
| 508 | 508 | ); |
| 509 | 509 | expect(green.state).toBe("ok"); |
| 510 | expect( | |
| 511 | ( | |
| 512 | await pullWord( | |
| 513 | { | |
| 514 | db: app.db, | |
| 515 | dir: repoDir(app.reposRoot, repo.ownerName, repo.name), | |
| 516 | runtime, | |
| 517 | record, | |
| 518 | history: servingHistory(), | |
| 519 | viewer: alice, | |
| 520 | }, | |
| 521 | getPull(app.db, repo.id, opened.value.number)!, | |
| 522 | ) | |
| 523 | ).note, | |
| 524 | ).toBe("green — its tests passed, ready for a look"); | |
| 510 | 525 | const merged = await mergePull( |
| 511 | 526 | app, |
| 512 | 527 | alice, |
| @@ -517,6 +532,54 @@ describe("apps: production, previews, data, gates, crew", () => { | ||
| 517 | 532 | expect(merged.ok).toBe(true); |
| 518 | 533 | }, 120_000); |
| 519 | 534 | |
| 535 | test("a green deploy of an app that declares no test says nothing was run", async () => { | |
| 536 | const committed = await commitToBranch(app, alice, repo, { | |
| 537 | branch: "untested", | |
| 538 | base: repo.defaultBranch, | |
| 539 | message: "No tests declared", | |
| 540 | files: [ | |
| 541 | { | |
| 542 | path: "forge.json", | |
| 543 | content: `${JSON.stringify( | |
| 544 | { app: { run: "bun run src/server.ts", tty: "bun run src/tty.ts" } }, | |
| 545 | null, | |
| 546 | 2, | |
| 547 | )}\n`, | |
| 548 | }, | |
| 549 | ], | |
| 550 | }); | |
| 551 | expect(committed.ok).toBe(true); | |
| 552 | if (!committed.ok) return; | |
| 553 | const opened = await openPull(app, alice, repo, { | |
| 554 | title: "Untested", | |
| 555 | baseBranch: repo.defaultBranch, | |
| 556 | headBranch: "untested", | |
| 557 | }); | |
| 558 | expect(opened.ok).toBe(true); | |
| 559 | if (!opened.ok) return; | |
| 560 | const green = await settled( | |
| 561 | (r) => | |
| 562 | r.env === `pull-${opened.value.number}` && | |
| 563 | r.commitOid === committed.value.commitOid, | |
| 564 | ); | |
| 565 | expect(green.state).toBe("ok"); | |
| 566 | const word = await pullWord( | |
| 567 | { | |
| 568 | db: app.db, | |
| 569 | dir: repoDir(app.reposRoot, repo.ownerName, repo.name), | |
| 570 | runtime, | |
| 571 | record, | |
| 572 | history: servingHistory(), | |
| 573 | viewer: alice, | |
| 574 | }, | |
| 575 | getPull(app.db, repo.id, opened.value.number)!, | |
| 576 | ); | |
| 577 | expect(word).toEqual({ | |
| 578 | word: "look", | |
| 579 | note: "green — it answered, no tests were run, ready for a look", | |
| 580 | }); | |
| 581 | }, 120_000); | |
| 582 | ||
| 520 | 583 | test("a deploy whose test step sleeps: the preview answers before it finishes, and the run stays open until it does", async () => { |
| 521 | 584 | const committed = await commitToBranch(app, alice, repo, { |
| 522 | 585 | branch: "slow-test", |
test/studio-words.test.ts +18
| @@ -24,6 +24,9 @@ | ||
| 24 | 24 | * this file from landing first. |
| 25 | 25 | */ |
| 26 | 26 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 27 | import { NO_TESTS_TAIL, TESTS_PASSED_TAIL } from "../src/apps/runtime.ts"; | |
| 28 | import type { Run } from "../src/core/runs.ts"; | |
| 29 | import { testsClause } from "../src/web/studio/words.ts"; | |
| 27 | 30 | import { mkdtemp, rm } from "node:fs/promises"; |
| 28 | 31 | import { tmpdir } from "node:os"; |
| 29 | 32 | import { join } from "node:path"; |
| @@ -883,3 +886,18 @@ describe("dev's vocabulary never reaches a studio page", () => { | ||
| 883 | 886 | ); |
| 884 | 887 | }); |
| 885 | 888 | }); |
| 889 | ||
| 890 | describe("testsClause", () => { | |
| 891 | const run = (summary: string) => ({ summary }) as unknown as Run; | |
| 892 | ||
| 893 | test("a deploy from before the clause existed says nothing about tests; the two tails say their own", () => { | |
| 894 | expect(testsClause(run("running at http://x"))).toBe(""); | |
| 895 | expect(testsClause(null)).toBe(""); | |
| 896 | expect(testsClause(run(`running at http://x${TESTS_PASSED_TAIL}`))).toBe( | |
| 897 | "its tests passed", | |
| 898 | ); | |
| 899 | expect(testsClause(run(`running at http://x${NO_TESTS_TAIL}`))).toBe( | |
| 900 | "it answered, no tests were run", | |
| 901 | ); | |
| 902 | }); | |
| 903 | }); |
new above
offline