Public: anyone can read this; the crew can change it.

Four tests fail on main or by turns, so every pull's check is red for reasons… #16334

Merged opened this in answer to

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

Merged

mason/forge:mason/16213-four-tests-fail-on-main-or-by-turns-so-e → main 2 commits fork

  • Merged. mason/16213-four-tests-fail-on-main-or-by-turns-so-e was merged into main as 2559779.

Review

Sign in to review this change.
3 files changed +57 −18
test/talk-page.test.ts +27 −9
@@ -5,7 +5,7 @@
55 * signed out goes to /signin; Talk is in the chrome, the palette and home;
66 * a stream is capped per person; a once-result is never confirmed here.
77 */
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
99 import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1010 import { mkdtemp, rm } from "node:fs/promises";
1111 import { tmpdir } from "node:os";
@@ -66,6 +66,13 @@ async function frames(path: string, u: User, headers: Record<string, string> = {
6666 .filter((f) => f.event !== undefined);
6767 }
6868
69 // Every test starts from no conversations: the turns, waiting confirms and
70 // counts one test leaves must not reach the next, whatever order they run in.
71 beforeEach(() => {
72 app.db.run("DELETE FROM conversation");
73 app.db.run("DELETE FROM conversation_held");
74 });
75
6976 beforeAll(async () => {
7077 dir = await mkdtemp(join(tmpdir(), "forge-talk-page-"));
7178 app = createApp({ dataDir: dir, port: 0 });
@@ -452,7 +459,11 @@ describe("the page", () => {
452459 if (!sizer.ok) throw new Error(sizer.error);
453460 say(sizer.value, "person", "how?");
454461 say(sizer.value, "agent", "```ts\nlet x = 1;\n```");
455 const size = (await (await get("/talk", sizer.value)).arrayBuffer()).byteLength;
462 // The palette index lists the people and repositories other tests made, so it is left out: it
463 // grows with the order the tests ran in, not with the page. So the cap below measures the page
464 // WITHOUT its palette index; whoever raises it should measure the same way.
465 const page = (await (await get("/talk", sizer.value)).text()).replace(/<script type="application\/json" id="palette-index">[\s\S]*?<\/script>/, "");
466 const size = Buffer.byteLength(page);
456467 // Raised from 47,000 by the widgets' rules and no more (widgetCss, 2,495 B raw): they ride every
457468 // Talk page, because a chart can arrive in a live reply, and a page drawn without them would
458469 // show it unstyled until a reload. 48,328 measured. Then to 50,000 by the reply's one last line
@@ -1728,7 +1739,14 @@ describe("?about= names the subject", () => {
17281739 expect(subject(await (await get(`/talk?about=${encodeURIComponent(ref)}`, alice)).text())).toContain("Secret pull");
17291740 });
17301741
1731 test("the terminal prints the same gated line: `talk --about <ref>`", () => {
1742 test("the terminal prints the same gated line: `talk --about <ref>`", async () => {
1743 // Its own repositories: it must not lean on what an earlier test made.
1744 const priv = await createRepo(app, alice, { name: "about-term-priv", visibility: "private" });
1745 const pub = await createRepo(app, alice, { name: "about-term-pub", visibility: "public" });
1746 if (!priv.ok || !pub.ok) throw new Error("repos");
1747 const opened = openIssue(app, alice, priv.value, { title: "Secret title", body: "x" });
1748 if (!opened.ok) throw new Error(String(opened.error));
1749 const n = opened.value.number;
17321750 const run = (user: User | undefined, words: string) => {
17331751 let out = "";
17341752 let code: number | undefined;
@@ -1736,12 +1754,12 @@ describe("?about= names the subject", () => {
17361754 serveTalk(app, session as never, user, words);
17371755 return { out, code };
17381756 };
1739 const priv = run(alice, "--about alice/about-priv#1");
1740 expect(priv.code).toBe(0);
1741 expect(priv.out.startsWith("About alice/about-priv#1: ")).toBe(true);
1742 expect(run(bob, "--about alice/about-priv#1")).toEqual({ out: "", code: 0 });
1743 expect(run(undefined, "--about alice/about-priv")).toEqual({ out: "", code: 0 });
1744 expect(run(bob, "--about alice/about-pub").out).toBe("About alice/about-pub\r\n");
1757 const mine = run(alice, `--about alice/about-term-priv#${n}`);
1758 expect(mine.code).toBe(0);
1759 expect(mine.out.startsWith(`About alice/about-term-priv#${n}: `)).toBe(true);
1760 expect(run(bob, `--about alice/about-term-priv#${n}`)).toEqual({ out: "", code: 0 });
1761 expect(run(undefined, "--about alice/about-term-priv")).toEqual({ out: "", code: 0 });
1762 expect(run(bob, "--about alice/about-term-pub").out).toBe("About alice/about-term-pub\r\n");
17451763 expect(run(bob, "--about ../x")).toEqual({ out: "", code: 0 });
17461764 });
17471765 });
test/tui-talk-receipts.test.ts +11 −2
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
88 import { join } from "node:path";
99 import { setIssueState } from "../src/actions/issues.ts";
1010 import { createRepo } from "../src/actions/repos.ts";
11 import { sayYes } from "../src/actions/conversation_confirms.ts";
11 import { sayYes, undoableReceipts } from "../src/actions/conversation_confirms.ts";
1212 import { createApp, type App } from "../src/app.ts";
1313 import { openConversation } from "../src/core/conversations.ts";
1414 import { hold } from "../src/core/fence.ts";
@@ -61,9 +61,18 @@ afterAll(async () => {
6161
6262 describe("the terminal's receipts screen", () => {
6363 test("another person sees none of it", async () => {
64 // Whatever state an earlier test left it in, bob's screen must leave it so: his own receipts
65 // are none (so there is nothing for `u` to find), and alice's are the same list as before.
66 const state = () => getIssue(app.db, repoId, number)?.state;
67 const stateBefore = state();
68 const aliceBefore = undoableReceipts(app.db, alice.id);
69 expect(undoableReceipts(app.db, bob.id)).toEqual([]);
6470 const text = await drive(bob, open);
6571 expect(text).toContain("Nothing to undo");
66 expect(getIssue(app.db, repoId, number)?.state).toBe("closed");
72 await drive(bob, [...open, "u", "\t", "\r"]);
73 expect(state()).toBe(stateBefore);
74 expect(undoableReceipts(app.db, alice.id)).toEqual(aliceBefore);
75 expect(undoableReceipts(app.db, bob.id)).toEqual([]);
6776 });
6877
6978 test("u undoes the receipt under the cursor, once", async () => {
test/web-ui.test.ts +19 −7
@@ -47,6 +47,8 @@ describe("web ui", () => {
4747 GIT_COMMITTER_EMAIL: "[email protected]",
4848 });
4949
50 // A git that fails stops the setup with what git said: a push that was refused and ignored
51 // left `mel/proj` empty, and only the tests that read its files failed, in 3 ms, with no cause.
5052 async function git(args: string[], cwd: string): Promise<number> {
5153 const proc = Bun.spawn(["git", ...args], {
5254 cwd,
@@ -54,7 +56,9 @@ describe("web ui", () => {
5456 stdout: "pipe",
5557 stderr: "pipe",
5658 });
57 return await proc.exited;
59 const [code, err] = await Promise.all([proc.exited, new Response(proc.stderr).text()]);
60 if (code !== 0) throw new Error(`git ${args[0]} exited ${code}: ${err.trim()}`);
61 return code;
5862 }
5963
6064 async function signup(username: string): Promise<string> {
@@ -80,12 +84,13 @@ describe("web ui", () => {
8084 owner = await adminCookie(app, { username: "mel", email: "[email protected]", password: "web-ui-password" });
8185 stranger = await signup("kim");
8286
83 await fetch(`${base}/new`, {
87 const created = await fetch(`${base}/new`, {
8488 method: "POST",
8589 headers: { cookie: owner },
8690 body: form({ name: "proj", visibility: "public", description: "a repo" }),
8791 redirect: "manual",
8892 });
93 if (created.status !== 303) throw new Error(`creating mel/proj answered ${created.status}: ${(await created.text()).slice(0, 300)}`);
8994
9095 // A real repository, so tree/blob/raw/commits have something to render.
9196 const repo = join(work, "proj");
@@ -200,8 +205,10 @@ describe("web ui", () => {
200205 expect(page).toContain(".lc-d73a4a{--label:#d73a4a}");
201206 expect(page).toContain(">bug</span>");
202207 // A colour mixed from the labels on *this* page is what `styleCss` is
203 // for, and the only thing left using it: nothing static rides along.
204 expect(page).toMatch(/<style>\.lc-d73a4a\{--label:#d73a4a\}<\/style>/);
208 // for, and the only thing left using it: nothing static rides along, only one rule per
209 // colour in use on the page (the picker lists every label of the repository, so which
210 // others are there depends on what other tests made).
211 expect(page).toMatch(/<style>(\.lc-[0-9a-f]{6}\{--label:#[0-9a-f]{6}\})+<\/style>/);
205212
206213 // And the list can filter by it.
207214 const filtered = await (
@@ -211,6 +218,8 @@ describe("web ui", () => {
211218 });
212219
213220 test("a stranger cannot apply labels", async () => {
221 const proj = getRepo(app.db, "mel", "proj")!;
222 const before = labelsFor(app.db, getIssue(app.db, proj.id, 1)!.id).map((l) => l.name);
214223 const res = await fetch(`${base}/mel/proj/issues/1/labels`, {
215224 method: "POST",
216225 headers: { cookie: stranger },
@@ -220,7 +229,7 @@ describe("web ui", () => {
220229 expect(res.status).toBe(303); // a flash explaining the refusal
221230 const repo = getRepo(app.db, "mel", "proj")!;
222231 const issue = getIssue(app.db, repo.id, 1)!;
223 expect(labelsFor(app.db, issue.id).map((l) => l.name)).toEqual(["bug"]);
232 expect(labelsFor(app.db, issue.id).map((l) => l.name)).toEqual(before);
224233 });
225234
226235 // ---- pull state ----
@@ -531,9 +540,12 @@ describe("web ui", () => {
531540 // ---- account forms ----
532541
533542 test("the profile form saves, and rejects a bad email without losing input", async () => {
543 // Its own account: a changed address is unverified until confirmed, and an unverified
544 // owner cannot create a repository, so doing this as mel broke every test that ran after it.
545 const pat = await signup("pat");
534546 const bad = await fetch(`${base}/settings`, {
535547 method: "POST",
536 headers: { cookie: owner },
548 headers: { cookie: pat },
537549 body: form({ displayName: "Mel Tester", email: "not-an-email" }),
538550 redirect: "manual",
539551 });
@@ -544,7 +556,7 @@ describe("web ui", () => {
544556
545557 const good = await fetch(`${base}/settings`, {
546558 method: "POST",
547 headers: { cookie: owner },
559 headers: { cookie: pat },
548560 body: form({ displayName: "Mel Tester", email: "[email protected]" }),
549561 redirect: "manual",
550562 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs