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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16213-four-tests-fail-on-main-or-by-turns-so-e → main 2 commits fork
3 files
changed +57
−18
test/talk-page.test.ts +27 −9
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * signed out goes to /signin; Talk is in the chrome, the palette and home; |
| 6 | 6 | * a stream is capped per person; a once-result is never confirmed here. |
| 7 | 7 | */ |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"; | |
| 9 | 9 | import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 10 | 10 | import { mkdtemp, rm } from "node:fs/promises"; |
| 11 | 11 | import { tmpdir } from "node:os"; |
| @@ -66,6 +66,13 @@ async function frames(path: string, u: User, headers: Record<string, string> = { | ||
| 66 | 66 | .filter((f) => f.event !== undefined); |
| 67 | 67 | } |
| 68 | 68 | |
| 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 | ||
| 69 | 76 | beforeAll(async () => { |
| 70 | 77 | dir = await mkdtemp(join(tmpdir(), "forge-talk-page-")); |
| 71 | 78 | app = createApp({ dataDir: dir, port: 0 }); |
| @@ -452,7 +459,11 @@ describe("the page", () => { | ||
| 452 | 459 | if (!sizer.ok) throw new Error(sizer.error); |
| 453 | 460 | say(sizer.value, "person", "how?"); |
| 454 | 461 | 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); | |
| 456 | 467 | // Raised from 47,000 by the widgets' rules and no more (widgetCss, 2,495 B raw): they ride every |
| 457 | 468 | // Talk page, because a chart can arrive in a live reply, and a page drawn without them would |
| 458 | 469 | // 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", () => { | ||
| 1728 | 1739 | expect(subject(await (await get(`/talk?about=${encodeURIComponent(ref)}`, alice)).text())).toContain("Secret pull"); |
| 1729 | 1740 | }); |
| 1730 | 1741 | |
| 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; | |
| 1732 | 1750 | const run = (user: User | undefined, words: string) => { |
| 1733 | 1751 | let out = ""; |
| 1734 | 1752 | let code: number | undefined; |
| @@ -1736,12 +1754,12 @@ describe("?about= names the subject", () => { | ||
| 1736 | 1754 | serveTalk(app, session as never, user, words); |
| 1737 | 1755 | return { out, code }; |
| 1738 | 1756 | }; |
| 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"); | |
| 1745 | 1763 | expect(run(bob, "--about ../x")).toEqual({ out: "", code: 0 }); |
| 1746 | 1764 | }); |
| 1747 | 1765 | }); |
test/tui-talk-receipts.test.ts +11 −2
| @@ -8,7 +8,7 @@ import { tmpdir } from "node:os"; | ||
| 8 | 8 | import { join } from "node:path"; |
| 9 | 9 | import { setIssueState } from "../src/actions/issues.ts"; |
| 10 | 10 | 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"; | |
| 12 | 12 | import { createApp, type App } from "../src/app.ts"; |
| 13 | 13 | import { openConversation } from "../src/core/conversations.ts"; |
| 14 | 14 | import { hold } from "../src/core/fence.ts"; |
| @@ -61,9 +61,18 @@ afterAll(async () => { | ||
| 61 | 61 | |
| 62 | 62 | describe("the terminal's receipts screen", () => { |
| 63 | 63 | 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([]); | |
| 64 | 70 | const text = await drive(bob, open); |
| 65 | 71 | 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([]); | |
| 67 | 76 | }); |
| 68 | 77 | |
| 69 | 78 | test("u undoes the receipt under the cursor, once", async () => { |
test/web-ui.test.ts +19 −7
| @@ -47,6 +47,8 @@ describe("web ui", () => { | ||
| 47 | 47 | GIT_COMMITTER_EMAIL: "[email protected]", |
| 48 | 48 | }); |
| 49 | 49 | |
| 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. | |
| 50 | 52 | async function git(args: string[], cwd: string): Promise<number> { |
| 51 | 53 | const proc = Bun.spawn(["git", ...args], { |
| 52 | 54 | cwd, |
| @@ -54,7 +56,9 @@ describe("web ui", () => { | ||
| 54 | 56 | stdout: "pipe", |
| 55 | 57 | stderr: "pipe", |
| 56 | 58 | }); |
| 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; | |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | 64 | async function signup(username: string): Promise<string> { |
| @@ -80,12 +84,13 @@ describe("web ui", () => { | ||
| 80 | 84 | owner = await adminCookie(app, { username: "mel", email: "[email protected]", password: "web-ui-password" }); |
| 81 | 85 | stranger = await signup("kim"); |
| 82 | 86 | |
| 83 | await fetch(`${base}/new`, { | |
| 87 | const created = await fetch(`${base}/new`, { | |
| 84 | 88 | method: "POST", |
| 85 | 89 | headers: { cookie: owner }, |
| 86 | 90 | body: form({ name: "proj", visibility: "public", description: "a repo" }), |
| 87 | 91 | redirect: "manual", |
| 88 | 92 | }); |
| 93 | if (created.status !== 303) throw new Error(`creating mel/proj answered ${created.status}: ${(await created.text()).slice(0, 300)}`); | |
| 89 | 94 | |
| 90 | 95 | // A real repository, so tree/blob/raw/commits have something to render. |
| 91 | 96 | const repo = join(work, "proj"); |
| @@ -200,8 +205,10 @@ describe("web ui", () => { | ||
| 200 | 205 | expect(page).toContain(".lc-d73a4a{--label:#d73a4a}"); |
| 201 | 206 | expect(page).toContain(">bug</span>"); |
| 202 | 207 | // 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>/); | |
| 205 | 212 | |
| 206 | 213 | // And the list can filter by it. |
| 207 | 214 | const filtered = await ( |
| @@ -211,6 +218,8 @@ describe("web ui", () => { | ||
| 211 | 218 | }); |
| 212 | 219 | |
| 213 | 220 | 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); | |
| 214 | 223 | const res = await fetch(`${base}/mel/proj/issues/1/labels`, { |
| 215 | 224 | method: "POST", |
| 216 | 225 | headers: { cookie: stranger }, |
| @@ -220,7 +229,7 @@ describe("web ui", () => { | ||
| 220 | 229 | expect(res.status).toBe(303); // a flash explaining the refusal |
| 221 | 230 | const repo = getRepo(app.db, "mel", "proj")!; |
| 222 | 231 | 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); | |
| 224 | 233 | }); |
| 225 | 234 | |
| 226 | 235 | // ---- pull state ---- |
| @@ -531,9 +540,12 @@ describe("web ui", () => { | ||
| 531 | 540 | // ---- account forms ---- |
| 532 | 541 | |
| 533 | 542 | 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"); | |
| 534 | 546 | const bad = await fetch(`${base}/settings`, { |
| 535 | 547 | method: "POST", |
| 536 | headers: { cookie: owner }, | |
| 548 | headers: { cookie: pat }, | |
| 537 | 549 | body: form({ displayName: "Mel Tester", email: "not-an-email" }), |
| 538 | 550 | redirect: "manual", |
| 539 | 551 | }); |
| @@ -544,7 +556,7 @@ describe("web ui", () => { | ||
| 544 | 556 | |
| 545 | 557 | const good = await fetch(`${base}/settings`, { |
| 546 | 558 | method: "POST", |
| 547 | headers: { cookie: owner }, | |
| 559 | headers: { cookie: pat }, | |
| 548 | 560 | body: form({ displayName: "Mel Tester", email: "[email protected]" }), |
| 549 | 561 | redirect: "manual", |
| 550 | 562 | }); |
new above
offline