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

Closed opened this
Closed without merging

scout/forge:scout/280-a-change-that-answers-reads-green-and-ne → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +137 −13
src/apps/runtime.ts +6 −1
@@ -154,6 +154,11 @@ const BUSY_GRACE_MS = 45 * 60_000;
154154 * the studio reads the same constant to word its badge. */
155155 export const VERIFYING_NOTE = "serving — still verifying its tests";
156156
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
157162 export interface EnvStatus {
158163 readonly env: EnvName;
159164 readonly state: EnvState;
@@ -1102,7 +1107,7 @@ export class AppsRuntime {
11021107 if (tested.ok) {
11031108 const done = finishRun(this.app.db, run.id, {
11041109 state: "ok",
1105 summary: `running at ${url}`,
1110 summary: `running at ${url}${live.manifest.test === null ? NO_TESTS_TAIL : TESTS_PASSED_TAIL}`,
11061111 });
11071112 write(`done: ${url}`);
11081113 if (done) announceRun(this.app, done);
src/web/studio/asks.ts +10 −4
@@ -37,6 +37,7 @@ import {
3737 activeRunFor,
3838 automaticRunsSince,
3939 latestRunsForIssues,
40 type Run,
4041 } from "../../core/runs.ts";
4142 import { getUserById, type User } from "../../core/users.ts";
4243 import {
@@ -56,6 +57,7 @@ import { btn, card, icon, row } from "../ui.ts";
5657 import { lookUrl } from "../../core/looks.ts";
5758 import { lookThumb, thumbLook } from "../pages/looks.ts";
5859 import { changeHref } from "./nouns.ts";
60 import { testsClause } from "./words.ts";
5961
6062 /** Repos narrowed to those with an app record, with the records — the one
6163 * join `appsOf` and `writableAppsOf` share. */
@@ -213,6 +215,8 @@ interface AskCandidate {
213215 * differently for a person's own change than for the crew's (below).
214216 * Absent for "paused", which names no author at all. */
215217 readonly authorIsAgent?: boolean;
218 /** For "look": the green check, whose summary says what its tests did. */
219 readonly check?: Run;
216220 /** For "review": why the agent's change waits for a person, and since when. */
217221 readonly reviewWait?: ReviewWait;
218222 /** For "stopped": how many automatic tries, and whether the decider itself stopped it. */
@@ -315,6 +319,7 @@ function askCandidatesFor(
315319 pull,
316320 who,
317321 authorIsAgent: issue.authorIsAgent,
322 check,
318323 });
319324 } else if (
320325 check?.state === "ok" &&
@@ -814,6 +819,7 @@ export function decisionsFor(
814819 };
815820 if (c.kind === "look" && c.pull) {
816821 const picture = pictureOf(c.repo, c.pull);
822 const clause = testsClause(c.check ?? null);
817823 // The crew's own words say who finished it; a person's own change
818824 // gets the wording that is true of it — nobody "finished" it for
819825 // them, it is simply green and waiting.
@@ -824,11 +830,11 @@ export function decisionsFor(
824830 pull: c.pull,
825831 who: c.who,
826832 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.`,
829835 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`,
832838 ...(picture === undefined ? {} : { picture }),
833839 };
834840 }
src/web/studio/previews.ts +14 −4
@@ -17,10 +17,11 @@ import {
1717 import { getAppByRepo, type AppRecord } from "../../core/apps.ts";
1818 import { listPulls, type Pull } from "../../core/pulls.ts";
1919 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";
2121 import type { Ctx } from "../../http/context.ts";
2222 import { readRunLogTail } from "../../runs/log.ts";
2323 import { loadRepo, repoBase } from "../chrome.ts";
24 import { testsClause } from "./words.ts";
2425 import { html, when, type Html } from "../html.ts";
2526 import { fragment } from "../layout.ts";
2627 import {
@@ -102,6 +103,7 @@ function previewRow(
102103 pull: Pull,
103104 env: EnvStatus | undefined,
104105 writer: boolean,
106 check: Run | undefined,
105107 ): Html {
106108 const href =
107109 runtime === undefined
@@ -113,7 +115,13 @@ function previewRow(
113115 : runtime.urlFor(record, previewEnv(pull.number)).replace(/^https?:\/\//, "");
114116 const bits: Html[] = [html`#${pull.number} ${pull.title}`];
115117 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);
117125 if (say) bits.push(html`${say}`);
118126 const asleep = env === undefined ? null : dormantNote(env);
119127 if (asleep !== null) bits.push(asleep);
@@ -160,6 +168,7 @@ function previewsPanel(
160168 openPulls: readonly Pull[],
161169 envs: readonly EnvStatus[],
162170 writer: boolean,
171 checks: ReadonlyMap<string, Run>,
163172 ): Html | null {
164173 if (openPulls.length === 0) return null;
165174 const byPull = new Map(
@@ -169,7 +178,7 @@ function previewsPanel(
169178 );
170179 return listCard(
171180 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)),
173182 ),
174183 {
175184 head: html`${icon("rocket")}
@@ -273,7 +282,8 @@ export function appPanels(
273282 const runtime = appsRuntime(ctx.app);
274283 const envs: EnvStatus[] = envsFor(ctx.app, ctx.auth.user, record);
275284 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);
277287 const production = envs.find((e) => e.env === "production");
278288 const url = runtime?.urlFor(record, "production");
279289 const tail = productionTail(ctx, repo, production, writer);
src/web/studio/words.ts +25 −3
@@ -10,7 +10,12 @@
1010
1111 import type { Database } from "bun:sqlite";
1212 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";
1419 import type { AppRecord } from "../../core/apps.ts";
1520 import { canEnterApp, getRepoById } from "../../core/repos.ts";
1621 import type { User } from "../../core/users.ts";
@@ -150,11 +155,28 @@ function detailNote(detail: CheckDetail): string {
150155 return `${detail.passed} passed, ${detail.failed} failed: ${names}`;
151156 }
152157
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
153170 /** A single open pull's check, in the studio's own words — never dev's
154171 * "Checks passed/failed": the same five words as the rest of the page. */
155172 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 }
158180 if (check.state === "failed") {
159181 const base =
160182 check.run?.servingAt != null
test/apps.test.ts +64 −1
@@ -49,7 +49,7 @@ import {
4949 STOPPED_SUMMARY,
5050 type Run,
5151 } 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";
5353 import { createToken } from "../src/core/tokens.ts";
5454 import { createUser, type User } from "../src/core/users.ts";
5555 import { serve, type Servers } from "../src/http/server.ts";
@@ -507,6 +507,21 @@ describe("apps: production, previews, data, gates, crew", () => {
507507 r.commitOid === fixed.value.commitOid,
508508 );
509509 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");
510525 const merged = await mergePull(
511526 app,
512527 alice,
@@ -517,6 +532,54 @@ describe("apps: production, previews, data, gates, crew", () => {
517532 expect(merged.ok).toBe(true);
518533 }, 120_000);
519534
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
520583 test("a deploy whose test step sleeps: the preview answers before it finishes, and the run stays open until it does", async () => {
521584 const committed = await commitToBranch(app, alice, repo, {
522585 branch: "slow-test",
test/studio-words.test.ts +18
@@ -24,6 +24,9 @@
2424 * this file from landing first.
2525 */
2626 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";
2730 import { mkdtemp, rm } from "node:fs/promises";
2831 import { tmpdir } from "node:os";
2932 import { join } from "node:path";
@@ -883,3 +886,18 @@ describe("dev's vocabulary never reaches a studio page", () => {
883886 );
884887 });
885888 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs