Public: anyone can read this; the crew can change it.
Tests depend on their order within a file: 66 tests in 24 of 80 sampled files fail under --randomize #17505
Merged 18h 19m ago, live in production
scout/forge:scout/17500-tests-depend-on-their-order-within-a-fil → main 0 commits fork
24 files
changed +285
−114
- test/app-empty-crew.test.ts
- test/app-home-batched.test.ts
- test/app-secrets-org-grant.test.ts
- test/branches-action.test.ts
- test/build-pins.test.ts
- test/code-scanning.test.ts
- test/dataimport-doors.test.ts
- test/feed-chips.test.ts
- test/feed-team-waits.test.ts
- test/flows-actions.test.ts
- test/forge-budget-verdict.test.ts
- test/forge-signin.test.ts
- test/forks.test.ts
- test/front.test.ts
- test/mcp-releases.test.ts
- test/origins-import-labels.test.ts
- test/perf-jobs-per-forge.test.ts
- test/pinned-forge-recovery.test.ts
- test/snapshot-mirror-page.test.ts
- test/spawn-upstream.test.ts
- test/teams-crew.test.ts
- test/tui-newforge-recipes.test.ts
- test/tui-signins-password.test.ts
- test/view-source.test.ts
test/app-empty-crew.test.ts +3 −3
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * MCP tool answers the same line and has the same action (#15831). |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| @@ -32,7 +32,7 @@ let owner = ""; | ||
| 32 | 32 | let reader = ""; |
| 33 | 33 | const KEY = process.env["ANTHROPIC_API_KEY"]; |
| 34 | 34 | |
| 35 | beforeAll(async () => { | |
| 35 | beforeEach(async () => { | |
| 36 | 36 | process.env["ANTHROPIC_API_KEY"] = "test-key"; |
| 37 | 37 | dir = await mkdtemp(join(tmpdir(), "forge-empty-crew-")); |
| 38 | 38 | app = createApp({ dataDir: dir, port: 0 }); |
| @@ -54,7 +54,7 @@ beforeAll(async () => { | ||
| 54 | 54 | owner = await signInCookie(servers.url, "alice"); |
| 55 | 55 | reader = await signInCookie(servers.url, "bob"); |
| 56 | 56 | }); |
| 57 | afterAll(async () => { | |
| 57 | afterEach(async () => { | |
| 58 | 58 | servers.stop?.(); |
| 59 | 59 | if (KEY === undefined) delete process.env["ANTHROPIC_API_KEY"]; |
| 60 | 60 | else process.env["ANTHROPIC_API_KEY"] = KEY; |
test/app-home-batched.test.ts +25 −14
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** An app home's `now` and `following` read in batches: 200 issues, 40 pulls, 5 runs (#6184); no statement grows with the rows (#6819). */ |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 2 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 3 | 3 | import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| @@ -9,6 +9,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 9 | 9 | import { forkRelation } from "../src/core/following.ts"; |
| 10 | 10 | import { deferredOf, repoGraph } from "../src/core/dependencies.ts"; |
| 11 | 11 | import { getRepo } from "../src/core/repos.ts"; |
| 12 | import { setMember } from "../src/core/roles.ts"; | |
| 12 | 13 | import { createUser } from "../src/core/users.ts"; |
| 13 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | 15 | import { proveAll } from "./helpers/verified.ts"; |
| @@ -92,18 +93,19 @@ async function queriesFor(path: string): Promise<number> { | ||
| 92 | 93 | } |
| 93 | 94 | /** |
| 94 | 95 | * Background work (timers, following, run loops) can prepare statements on the same db |
| 95 | * while a page is read, and only ever adds to the count; the fewest of several reads is the page's own cost. | |
| 96 | * while a page is read, and only ever adds to the count; the fewest of three reads is the page's | |
| 97 | * own cost. | |
| 96 | 98 | */ |
| 97 | 99 | async function costOf(path: string): Promise<number> { |
| 98 | 100 | let least = Infinity; |
| 99 | for (let i = 0; i < 7; i++) { | |
| 101 | for (let i = 0; i < 3; i++) { | |
| 100 | 102 | await quiet(app.db); // start from rest, not in the tail of the last request's work |
| 101 | 103 | least = Math.min(least, await queriesFor(path)); |
| 102 | 104 | } |
| 103 | 105 | return least; |
| 104 | 106 | } |
| 105 | 107 | |
| 106 | beforeAll(async () => { | |
| 108 | beforeEach(async () => { | |
| 107 | 109 | root = mkdtempSync(join(tmpdir(), "forge-home-batched-")); |
| 108 | 110 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); |
| 109 | 111 | const u = await createUser(app.db, { |
| @@ -116,7 +118,7 @@ beforeAll(async () => { | ||
| 116 | 118 | }); |
| 117 | 119 | if (!u.ok) throw new Error(u.error); |
| 118 | 120 | proveAll(app); |
| 119 | const made = await createRepo(app, { id: u.value.id, username: "alice" } as never, { name: "vault" }); | |
| 121 | const made = await createRepo(app, u.value, { name: "vault" }); | |
| 120 | 122 | if (!made.ok) throw new Error(String(made.error)); |
| 121 | 123 | const seeded = await commitToBranch(app, u.value, made.value, { |
| 122 | 124 | message: "Start", |
| @@ -142,7 +144,7 @@ beforeAll(async () => { | ||
| 142 | 144 | let diverged = false; |
| 143 | 145 | for (let i = 0; i < 1000 && !diverged; i++) { |
| 144 | 146 | diverged = (await forkRelation(app, forked.value))?.state === "diverged"; |
| 145 | if (!diverged) await new Promise((r) => setTimeout(r, 30)); | |
| 147 | if (!diverged) await new Promise((r) => setTimeout(r, 5)); // real-timer: git follows the parent in the background; poll for its verdict | |
| 146 | 148 | } |
| 147 | 149 | if (!diverged) throw new Error("the fork never read diverged"); |
| 148 | 150 | const db = app.db; |
| @@ -159,7 +161,9 @@ beforeAll(async () => { | ||
| 159 | 161 | password: "a-good-passphrase", |
| 160 | 162 | }); |
| 161 | 163 | if (!bob.ok) throw new Error(bob.error); |
| 162 | const elsewhere = await createRepo(app, { id: bob.value.id, username: "bob" } as never, { name: "elsewhere" }); | |
| 164 | proveAll(app); | |
| 165 | setMember(app.db, bob.value.id, true, u.value.id, new Date()); | |
| 166 | const elsewhere = await createRepo(app, bob.value, { name: "elsewhere" }); | |
| 163 | 167 | if (!elsewhere.ok) throw new Error(String(elsewhere.error)); |
| 164 | 168 | const seedElsewhere = (from: number, to: number) => |
| 165 | 169 | db.transaction(() => { |
| @@ -213,7 +217,7 @@ beforeAll(async () => { | ||
| 213 | 217 | seedElsewhere(2, 30); |
| 214 | 218 | manyStatements = await statementsByText(PAGES[0]!); |
| 215 | 219 | }); |
| 216 | afterAll(() => { | |
| 220 | afterEach(() => { | |
| 217 | 221 | servers.stop(); |
| 218 | 222 | app.close(); |
| 219 | 223 | rmSync(root, { recursive: true, force: true }); |
| @@ -237,17 +241,21 @@ test("following stays cheap on a diverged fork (regression guard; this pull does | ||
| 237 | 241 | expect(Math.abs((await costOf(path)) - small[path]!)).toBeLessThanOrEqual(SLACK); |
| 238 | 242 | }); |
| 239 | 243 | |
| 240 | test("now costs the same statements on the live shape: 300 open issues, 2,000 closed, 3,500 edges, 20 pillars", async () => { | |
| 241 | const repo = getRepo(app.db, "alice", "vault")!; | |
| 242 | const author = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 244 | /** Open issues past the seeded ones, then the live shape: closed issues, edges and pillars. */ | |
| 245 | const growToLive = (repoId: string, author: string) => | |
| 243 | 246 | app.db.transaction(() => { |
| 244 | 247 | for (let i = 200; i < 280; i++) |
| 245 | 248 | app.db.query( |
| 246 | 249 | `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state) |
| 247 | 250 | VALUES (?1, ?2, ?3, 'issue', ?4, '', ?5, 'open')`, |
| 248 | ).run(`${repo.id}i${i}`, repo.id, 5000 + i, `Tell ${i}`, author); | |
| 249 | seedLive(app.db, repo.id, author, 0); | |
| 251 | ).run(`${repoId}i${i}`, repoId, 5000 + i, `Tell ${i}`, author); | |
| 252 | seedLive(app.db, repoId, author, 0); | |
| 250 | 253 | })(); |
| 254 | ||
| 255 | test("now costs the same statements on the live shape: 300 open issues, 2,000 closed, 3,500 edges, 20 pillars", async () => { | |
| 256 | const repo = getRepo(app.db, "alice", "vault")!; | |
| 257 | const author = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 258 | growToLive(repo.id, author); | |
| 251 | 259 | // Counted, not timed: 2,000 closed issues and 3,500 edges cost four statements more than the small page |
| 252 | 260 | // (measured), not one per row; a per-row read would add thousands. |
| 253 | 261 | expect(Math.abs((await costOf("/alice/vault")) - small["/alice/vault"]!)).toBeLessThanOrEqual(4); |
| @@ -255,6 +263,9 @@ test("now costs the same statements on the live shape: 300 open issues, 2,000 cl | ||
| 255 | 263 | |
| 256 | 264 | test("the lean deferred read says what the whole graph says, and something is deferred", () => { |
| 257 | 265 | const repo = getRepo(app.db, "alice", "vault")!; |
| 266 | // The live shape is what defers anything: a few issues alone defer nothing. | |
| 267 | const author = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'alice'").get()!.id; | |
| 268 | growToLive(repo.id, author); | |
| 258 | 269 | const whole = repoGraph(app.db, repo.id).deferred; |
| 259 | 270 | expect(whole.size).toBeGreaterThan(0); |
| 260 | 271 | expect([...deferredOf(app.db, repo)].sort()).toEqual([...whole].sort()); |
| @@ -265,7 +276,7 @@ async function statementsByText(path: string): Promise<Map<string, number>> { | ||
| 265 | 276 | const door = app.db as unknown as { query: (sql: string) => unknown }; |
| 266 | 277 | const original = app.db.query.bind(app.db); |
| 267 | 278 | let best: Map<string, number> | undefined; |
| 268 | for (let run = 0; run < 5; run++) { | |
| 279 | for (let run = 0; run < 3; run++) { | |
| 269 | 280 | await quiet(app.db); |
| 270 | 281 | const seen = new Map<string, number>(); |
| 271 | 282 | door.query = (sql: string) => { |
test/app-secrets-org-grant.test.ts +3 −3
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * grant names, a move to another organization ends the grant, and a grant of |
| 5 | 5 | * one organization's secret to another's repository is refused. |
| 6 | 6 | */ |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| @@ -38,7 +38,7 @@ const started = (r: Repo): Record<string, string> => | ||
| 38 | 38 | needs: ["STRIPE_KEY"], |
| 39 | 39 | }); |
| 40 | 40 | |
| 41 | beforeAll(async () => { | |
| 41 | beforeEach(async () => { | |
| 42 | 42 | dataDir = await mkdtemp(join(tmpdir(), "forge-org-grant-")); |
| 43 | 43 | app = createApp({ dataDir, port: 0 }); |
| 44 | 44 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); |
| @@ -58,7 +58,7 @@ beforeAll(async () => { | ||
| 58 | 58 | expect(putSecret(app, alice, "org", "orga", "STRIPE_KEY", "key-of-a").ok).toBe(true); |
| 59 | 59 | expect(putSecret(app, alice, "org", "orgb", "STRIPE_KEY", "key-of-b").ok).toBe(true); |
| 60 | 60 | }); |
| 61 | afterAll(async () => { | |
| 61 | afterEach(async () => { | |
| 62 | 62 | app.close(); |
| 63 | 63 | await rm(dataDir, { recursive: true, force: true }); |
| 64 | 64 | }); |
test/branches-action.test.ts +12 −4
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** createBranch / deleteBranch: a mirror's ref moves only after its origin took the push; a native repo's moves at once; a reader is refused. */ |
| 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 3 | 3 | import { chmod, mkdtemp, rm } from "node:fs/promises"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| @@ -41,7 +41,7 @@ const tip = (repo: Repo, branch: string) => | ||
| 41 | 41 | resolveOid(repoDir(app.reposRoot, repo.ownerName, repo.name), `refs/heads/${branch}`); |
| 42 | 42 | const originTip = (branch: string) => resolveOid(originDir, `refs/heads/${branch}`); |
| 43 | 43 | |
| 44 | beforeAll(async () => { | |
| 44 | beforeEach(async () => { | |
| 45 | 45 | dataDir = await mkdtemp(join(tmpdir(), "forge-branches-action-")); |
| 46 | 46 | app = createApp({ dataDir, port: 0 }); |
| 47 | 47 | app.bus.subscribe((e) => events.push(e)); |
| @@ -91,7 +91,7 @@ beforeAll(async () => { | ||
| 91 | 91 | mirror = getRepo(app.db, "ada", "gears")!; |
| 92 | 92 | }, 30_000); |
| 93 | 93 | |
| 94 | afterAll(async () => { | |
| 94 | afterEach(async () => { | |
| 95 | 95 | server?.stop(true); |
| 96 | 96 | app?.close(); |
| 97 | 97 | await rm(dataDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 }); |
| @@ -132,6 +132,12 @@ describe("a reader", () => { | ||
| 132 | 132 | }); |
| 133 | 133 | |
| 134 | 134 | describe("a mirrored repository", () => { |
| 135 | /** `feat` exists on the origin and on the mirror, as an accepted create leaves it. */ | |
| 136 | const withFeat = async () => { | |
| 137 | reject = ""; | |
| 138 | must(await createBranch(app, ada, mirror, { name: "feat" })); | |
| 139 | }; | |
| 140 | ||
| 135 | 141 | test("a refusing origin leaves the local ref where it was, and the refusal is a refusal, not a failure", async () => { |
| 136 | 142 | reject = "branch creation is closed here"; |
| 137 | 143 | const before = events.length; |
| @@ -151,6 +157,7 @@ describe("a mirrored repository", () => { | ||
| 151 | 157 | }); |
| 152 | 158 | |
| 153 | 159 | test("a branch that exists locally is not created again", async () => { |
| 160 | await withFeat(); | |
| 154 | 161 | expect(await createBranch(app, ada, mirror, { name: "feat" })).toEqual({ ok: false, error: "exists" }); |
| 155 | 162 | }); |
| 156 | 163 | |
| @@ -169,6 +176,7 @@ describe("a mirrored repository", () => { | ||
| 169 | 176 | }); |
| 170 | 177 | |
| 171 | 178 | test("a refusing origin keeps the local branch on delete", async () => { |
| 179 | await withFeat(); | |
| 172 | 180 | reject = "deletes need review"; |
| 173 | 181 | const before = await tip(mirror, "feat"); |
| 174 | 182 | const r = await deleteBranch(app, ada, mirror, "feat"); |
| @@ -178,7 +186,7 @@ describe("a mirrored repository", () => { | ||
| 178 | 186 | }); |
| 179 | 187 | |
| 180 | 188 | test("an accepting origin drops the ref, then the local one goes and it is announced", async () => { |
| 181 | reject = ""; | |
| 189 | await withFeat(); | |
| 182 | 190 | must(await deleteBranch(app, ada, mirror, "feat")); |
| 183 | 191 | expect(await originTip("feat")).toBeUndefined(); |
| 184 | 192 | expect(await tip(mirror, "feat")).toBeUndefined(); |
test/build-pins.test.ts +29 −2
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | * Build pins: a writer marks a commit under refs/builds/<label>; the |
| 3 | 3 | * builds page lists them. |
| 4 | 4 | */ |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 5 | import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"; | |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 7 | import { tmpdir } from "node:os"; |
| 8 | 8 | import { join } from "node:path"; |
| @@ -17,6 +17,12 @@ import { repoDir } from "../src/git/repos.ts"; | ||
| 17 | 17 | import { serve, type Servers } from "../src/http/server.ts"; |
| 18 | 18 | import { nextLabel } from "../src/web/pages/builds.ts"; |
| 19 | 19 | |
| 20 | /** Remove every pin of a repository: the refs under refs/builds, and the notes kept for them. */ | |
| 21 | const clearPins = async (dir: string) => { | |
| 22 | await Bun.$`git -C ${dir} update-ref -d refs/forge/notes`.quiet().nothrow(); | |
| 23 | for (const pin of await listBuildPins(dir)) await Bun.$`git -C ${dir} update-ref -d refs/builds/${pin.label}`.quiet(); | |
| 24 | }; | |
| 25 | ||
| 20 | 26 | describe("build pins", () => { |
| 21 | 27 | let dataDir: string; |
| 22 | 28 | let app: App; |
| @@ -92,6 +98,13 @@ describe("build pins", () => { | ||
| 92 | 98 | await rm(dataDir, { recursive: true, force: true }); |
| 93 | 99 | }); |
| 94 | 100 | |
| 101 | // Every test starts with no pins and pins what it needs itself. | |
| 102 | beforeEach(() => clearPins(repoDir(app.reposRoot, "alice", "game"))); | |
| 103 | const pinV1 = async () => { | |
| 104 | const made = await pinBuild(app, alice, fresh(), { label: "v1", oid: oids.one! }); | |
| 105 | if (!made.ok) throw new Error(String(made.error)); | |
| 106 | }; | |
| 107 | ||
| 95 | 108 | test("a writer pins a commit from the form; it is a ref with its note and source", async () => { |
| 96 | 109 | const res = await post("/alice/game/builds", aliceCookie, { |
| 97 | 110 | sha: oids.one!, |
| @@ -101,7 +114,7 @@ describe("build pins", () => { | ||
| 101 | 114 | }); |
| 102 | 115 | expect(res.status).toBe(303); |
| 103 | 116 | expect(res.headers.get("location")).toBe("/alice/game/iterations?build=alice%2Fgame%3Av1"); |
| 104 | const [pin] = await pins(); | |
| 117 | const pin = (await pins()).find((p) => p.label === "v1"); | |
| 105 | 118 | expect(pin?.label).toBe("v1"); |
| 106 | 119 | expect(pin?.oid).toBe(oids.one!); |
| 107 | 120 | expect(pin?.note).toBe("first playable"); |
| @@ -123,6 +136,7 @@ describe("build pins", () => { | ||
| 123 | 136 | }); |
| 124 | 137 | |
| 125 | 138 | test("bad labels, unknown commits and taken labels are refused", async () => { |
| 139 | await pinV1(); | |
| 126 | 140 | for (const label of ["-x", "a/b", "a b", "x".repeat(41), "refs..x"]) |
| 127 | 141 | expect( |
| 128 | 142 | (await pinBuild(app, alice, fresh(), { label, oid: oids.two! })).ok, |
| @@ -136,6 +150,7 @@ describe("build pins", () => { | ||
| 136 | 150 | }); |
| 137 | 151 | |
| 138 | 152 | test("the API lists the pins to a reader and refuses a write without a token", async () => { |
| 153 | await pinV1(); | |
| 139 | 154 | const listed = ((await (await fetch(`${base}/api/v1/repos/alice/game/builds`)).json()) as { |
| 140 | 155 | items: { label: string }[]; |
| 141 | 156 | }).items; |
| @@ -191,6 +206,13 @@ describe("build pins pages and notes", () => { | ||
| 191 | 206 | await rm(dataDir, { recursive: true, force: true }); |
| 192 | 207 | }); |
| 193 | 208 | |
| 209 | const gameDir = () => repoDir(app.reposRoot, "alice", "game"); | |
| 210 | beforeEach(() => clearPins(gameDir())); | |
| 211 | const pinV1 = async () => { | |
| 212 | const made = await pinBuild(app, alice, getRepo(app.db, "alice", "game")!, { label: "v1", oid }); | |
| 213 | if (!made.ok) throw new Error(String(made.error)); | |
| 214 | }; | |
| 215 | ||
| 194 | 216 | test("the form is offered to a writer, the list shows the pin, the branches page links both", async () => { |
| 195 | 217 | const form = await (await fetch(`${servers.url}/alice/game/builds/new?sha=${oid}`, { headers: { cookie } })).text(); |
| 196 | 218 | expect(form).toContain('name="label"'); |
| @@ -207,6 +229,7 @@ describe("build pins pages and notes", () => { | ||
| 207 | 229 | }); |
| 208 | 230 | |
| 209 | 231 | test("a taken label is flashed back, not pinned twice", async () => { |
| 232 | await pinV1(); | |
| 210 | 233 | const again = await post("/alice/game/builds", { sha: oid, label: "v1" }); |
| 211 | 234 | expect(again.status).toBe(303); |
| 212 | 235 | expect(again.headers.get("location")).toContain("/builds/new"); |
| @@ -214,6 +237,7 @@ describe("build pins pages and notes", () => { | ||
| 214 | 237 | }); |
| 215 | 238 | |
| 216 | 239 | test("a note is appended through the API, and copied once into the intent doc", async () => { |
| 240 | await pinV1(); | |
| 217 | 241 | const intent = join(dataDir, "intent.md"); |
| 218 | 242 | await Bun.write(intent, "# Intent\n"); |
| 219 | 243 | const noted = await notePin( |
| @@ -232,6 +256,7 @@ describe("build pins pages and notes", () => { | ||
| 232 | 256 | }); |
| 233 | 257 | |
| 234 | 258 | test("an agent cannot pin or note, even holding write access", async () => { |
| 259 | await pinV1(); | |
| 235 | 260 | const repo = getRepo(app.db, "alice", "game")!; |
| 236 | 261 | const pins = () => listBuildPins(repoDir(app.reposRoot, "alice", "game")); |
| 237 | 262 | const agent = { ...alice, kind: "agent" } as User; |
| @@ -242,6 +267,7 @@ describe("build pins pages and notes", () => { | ||
| 242 | 267 | }); |
| 243 | 268 | |
| 244 | 269 | test("a note cannot open a comment or a heading in the intent doc", async () => { |
| 270 | await pinV1(); | |
| 245 | 271 | const intent = join(dataDir, "intent-inject.md"); |
| 246 | 272 | await Bun.write(intent, "# Intent\n"); |
| 247 | 273 | const repo = getRepo(app.db, "alice", "game")!; |
| @@ -258,6 +284,7 @@ describe("build pins pages and notes", () => { | ||
| 258 | 284 | }); |
| 259 | 285 | |
| 260 | 286 | test("deleting a pin removes the ref and the list forgets it; a stranger's form is refused", async () => { |
| 287 | await pinV1(); | |
| 261 | 288 | expect((await post("/alice/game/builds/v1/delete", {}, "https://evil.test")).status).toBe(403); |
| 262 | 289 | expect((await listBuildPins(repoDir(app.reposRoot, "alice", "game"))).length).toBe(1); |
| 263 | 290 | expect((await post("/alice/game/builds/v1/delete", {})).status).toBe(303); |
test/code-scanning.test.ts +41 −21
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * with a reason. The fake secrets are built at run time, so this file is |
| 6 | 6 | * not itself a finding. |
| 7 | 7 | */ |
| 8 | import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test"; | |
| 8 | import { afterAll, beforeAll, beforeEach, describe, expect, spyOn, test } from "bun:test"; | |
| 9 | 9 | import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| @@ -84,7 +84,7 @@ const ok = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => | ||
| 84 | 84 | |
| 85 | 85 | /** The forge's own copy of the repository's default branch tip: what a release would cut. */ |
| 86 | 86 | async function tipOf(branch = "main"): Promise<string> { |
| 87 | const dir = join(dataDir, "repos", "alice", "square.git"); | |
| 87 | const dir = join(dataDir, "repos", "alice", `${repo.name}.git`); | |
| 88 | 88 | return (await git(["rev-parse", branch], dir)).out.trim(); |
| 89 | 89 | } |
| 90 | 90 | |
| @@ -113,34 +113,53 @@ afterAll(async () => { | ||
| 113 | 113 | await rm(work, { recursive: true, force: true }); |
| 114 | 114 | }); |
| 115 | 115 | |
| 116 | // Every test gets its own repository, so none leans on a finding another pushed. | |
| 117 | let made = 0; | |
| 118 | beforeEach(async () => { | |
| 119 | repo = ok(await createRepo(app, alice, { name: `square${made++}`, visibility: "public" })); | |
| 120 | ok(await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "README.md", content: "# square\n" }] })); | |
| 121 | }); | |
| 122 | ||
| 123 | const cloneRepo = async (): Promise<string> => { | |
| 124 | const url = `${servers.url.replace("http://", `http://alice:${token.alice}@`)}/alice/${repo.name}.git`; | |
| 125 | const clone = join(work, repo.name); | |
| 126 | expect((await git(["clone", "-q", url, clone], work)).code).toBe(0); | |
| 127 | return clone; | |
| 128 | }; | |
| 129 | ||
| 130 | /** A clone pushes a fake secret and a vulnerable pin to main, and the scan settles. */ | |
| 131 | const pushLeak = async () => { | |
| 132 | const clone = await cloneRepo(); | |
| 133 | await writeFile(join(clone, "deploy.ts"), `export const key = "${AWS}";\n`); | |
| 134 | await writeFile(join(clone, "package.json"), JSON.stringify({ dependencies: { lodash: "4.17.15" } })); | |
| 135 | expect((await git(["add", "."], clone)).code).toBe(0); | |
| 136 | expect((await git(["-c", "user.name=a", "-c", "user.email=a@x", "commit", "-qm", "oops"], clone)).code).toBe(0); | |
| 137 | const pushed = await git(["push", "-q", "origin", "HEAD:main"], clone); | |
| 138 | expect(pushed.code).toBe(0); | |
| 139 | // The scan runs off the hook's answer: wait on the scan itself, not on a clock. | |
| 140 | await scansSettled(app, repo.id); | |
| 141 | }; | |
| 142 | ||
| 143 | ||
| 116 | 144 | describe("a push", () => { |
| 117 | 145 | test("a pushed fake secret is found, without its text", async () => { |
| 118 | const url = `${servers.url.replace("http://", `http://alice:${token.alice}@`)}/alice/square.git`; | |
| 119 | const clone = join(work, "square"); | |
| 120 | expect((await git(["clone", "-q", url, clone], work)).code).toBe(0); | |
| 121 | await writeFile(join(clone, "deploy.ts"), `export const key = "${AWS}";\n`); | |
| 122 | await writeFile(join(clone, "package.json"), JSON.stringify({ dependencies: { lodash: "4.17.15" } })); | |
| 123 | expect((await git(["add", "."], clone)).code).toBe(0); | |
| 124 | expect((await git(["-c", "user.name=a", "-c", "user.email=a@x", "commit", "-qm", "oops"], clone)).code).toBe(0); | |
| 125 | const pushed = await git(["push", "-q", "origin", "HEAD:main"], clone); | |
| 126 | expect(pushed.code).toBe(0); | |
| 127 | // The scan runs off the hook's answer: wait on the scan itself, not on a clock. | |
| 128 | await scansSettled(app, repo.id); | |
| 146 | await pushLeak(); | |
| 129 | 147 | const found = listFindings(app.db, repo.id); |
| 130 | 148 | expect(found.map((f) => [f.kind, f.path, f.line]).sort()).toEqual([ |
| 131 | 149 | ["advisory", "package.json", 0], |
| 132 | 150 | ["secret", "deploy.ts", 1], |
| 133 | 151 | ]); |
| 134 | const page = await (await fetch(`${servers.url}/alice/square/findings`)).text(); | |
| 152 | const page = await (await fetch(`${servers.url}/alice/${repo.name}/findings`)).text(); | |
| 135 | 153 | expect(page).toContain("AWS access key"); |
| 136 | 154 | expect(page).toContain("deploy.ts:1"); |
| 137 | 155 | expect(page).not.toContain(AWS.slice(4)); |
| 138 | const flows = await (await fetch(`${servers.url}/alice/square/flows`)).text(); | |
| 156 | const flows = await (await fetch(`${servers.url}/alice/${repo.name}/flows`)).text(); | |
| 139 | 157 | expect(flows).toContain("Code scanning"); |
| 140 | 158 | expect(flows).toContain("2 high findings hold releases"); |
| 141 | 159 | }, 30_000); |
| 142 | 160 | |
| 143 | 161 | test("a high finding holds a release; acceptance with a reason lifts it", async () => { |
| 162 | await pushLeak(); | |
| 144 | 163 | const hold = await scanHold(app, repo, await tipOf()); |
| 145 | 164 | expect(hold.held).toBe(true); |
| 146 | 165 | if (hold.held) expect(hold.line).not.toContain(AWS.slice(4)); |
| @@ -154,7 +173,7 @@ describe("a push", () => { | ||
| 154 | 173 | expect(acceptFinding(app, repo, alice, secret!.id, "again")).toMatchObject({ ok: false, status: 409 }); |
| 155 | 174 | expect((await scanHold(app, repo, await tipOf())).held).toBe(true); |
| 156 | 175 | // Through the page's form, as a person does it. |
| 157 | const res = await fetch(`${servers.url}/alice/square/findings/${advisory!.id}/accept`, { | |
| 176 | const res = await fetch(`${servers.url}/alice/${repo.name}/findings/${advisory!.id}/accept`, { | |
| 158 | 177 | method: "POST", |
| 159 | 178 | headers: { authorization: `Bearer ${token.alice}`, "content-type": "application/x-www-form-urlencoded" }, |
| 160 | 179 | body: new URLSearchParams({ reason: "Dev only, upgrade tracked" }), |
| @@ -169,7 +188,7 @@ describe("a push", () => { | ||
| 169 | 188 | |
| 170 | 189 | test("the nightly pass adds static analysis over the default branch and is then not due", async () => { |
| 171 | 190 | ok(await commitToBranch(app, alice, repo, { message: "html", files: [{ path: "src/view.js", content: "el.inner" + "HTML = name;\n" }] })); |
| 172 | expect(nightlyDue(app.db, new Date().toISOString(), 10)).toContain(repo.id); | |
| 191 | expect(nightlyDue(app.db, new Date().toISOString(), 1000)).toContain(repo.id); | |
| 173 | 192 | await scanNightly(app, repo); |
| 174 | 193 | expect(listFindings(app.db, repo.id).some((f) => f.kind === "static" && f.path === "src/view.js")).toBe(true); |
| 175 | 194 | expect(nightlyDue(app.db, new Date(Date.now() - 3_600_000).toISOString(), 10)).not.toContain(repo.id); |
| @@ -177,7 +196,7 @@ describe("a push", () => { | ||
| 177 | 196 | }); |
| 178 | 197 | |
| 179 | 198 | test("a push of many new branches is scanned against main in a bounded number of git processes", async () => { |
| 180 | const clone = join(work, "square"); | |
| 199 | const clone = await cloneRepo(); | |
| 181 | 200 | expect((await git(["fetch", "-q", "origin", "main"], clone)).code).toBe(0); |
| 182 | 201 | let stream = ""; |
| 183 | 202 | for (let i = 0; i < 20; i++) { |
| @@ -223,7 +242,7 @@ describe("a push", () => { | ||
| 223 | 242 | }); |
| 224 | 243 | |
| 225 | 244 | test("a file named with a newline is skipped and counted, and later files keep their own text", async () => { |
| 226 | const clone = join(work, "square"); | |
| 245 | const clone = await cloneRepo(); | |
| 227 | 246 | expect((await git(["checkout", "-q", "-b", "nl", "origin/main"], clone)).code).toBe(0); |
| 228 | 247 | expect((await git(["pull", "-q", "origin", "main"], clone)).code).toBe(0); |
| 229 | 248 | await writeFile(join(clone, "a\nb.txt"), "plain\n"); |
| @@ -239,14 +258,14 @@ describe("a push", () => { | ||
| 239 | 258 | const at = listFindings(app.db, repo.id).filter((f) => f.oid === head); |
| 240 | 259 | expect(at.map((f) => [f.path, f.line])).toEqual([["c.ts", 3]]); |
| 241 | 260 | expect(lastScan(app.db, repo.id, "push")?.skipped).toBe(1); |
| 242 | const page = await (await fetch(`${servers.url}/alice/square/findings`)).text(); | |
| 261 | const page = await (await fetch(`${servers.url}/alice/${repo.name}/findings`)).text(); | |
| 243 | 262 | expect(page).toContain("partial: 1 file not read"); |
| 244 | 263 | }); |
| 245 | 264 | }); |
| 246 | 265 | |
| 247 | 266 | describe("cat-file replies (#14959)", () => { |
| 248 | 267 | test("a gitlink's commit body is stepped over: the file after it is still read", async () => { |
| 249 | const clone = join(work, "square"); | |
| 268 | const clone = await cloneRepo(); | |
| 250 | 269 | expect((await git(["checkout", "-q", "-b", "gl", "origin/main"], clone)).code).toBe(0); |
| 251 | 270 | expect((await git(["pull", "-q", "origin", "main"], clone)).code).toBe(0); |
| 252 | 271 | const base = (await git(["rev-parse", "HEAD"], clone)).out.trim(); |
| @@ -268,6 +287,7 @@ describe("cat-file replies (#14959)", () => { | ||
| 268 | 287 | }, 30_000); |
| 269 | 288 | |
| 270 | 289 | test("a missing name shaped like a blob header is read from the end and shifts no later reply", async () => { |
| 290 | await pushLeak(); | |
| 271 | 291 | const tip = await tipOf(); |
| 272 | 292 | const deploy = listFindings(app.db, repo.id).find((f) => f.kind === "secret" && f.path === "deploy.ts")!; |
| 273 | 293 | const ghost = { ...deploy, id: -1, path: "gone blob 100 x", fingerprint: "none" }; |
test/dataimport-doors.test.ts +3 −3
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | * gate as the API (the repository's admin; anyone else is offered nothing and |
| 4 | 4 | * changes nothing), the same engine, the same words. |
| 5 | 5 | */ |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 7 | 7 | import { mkdirSync, writeFileSync, existsSync } from "node:fs"; |
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| @@ -31,7 +31,7 @@ let dee: User; // a reader | ||
| 31 | 31 | let repo: Repo; |
| 32 | 32 | let appId: string; |
| 33 | 33 | |
| 34 | beforeAll(async () => { | |
| 34 | beforeEach(async () => { | |
| 35 | 35 | dataDir = await mkdtemp(join(tmpdir(), "forge-import-doors-")); |
| 36 | 36 | app = createApp({ dataDir, port: 0, host: "forge.test" }); |
| 37 | 37 | const make = async (username: string, adminIfFirst = false) => { |
| @@ -54,7 +54,7 @@ beforeAll(async () => { | ||
| 54 | 54 | writeFileSync(join(dir, "dump.sql"), "CREATE TABLE t(a); INSERT INTO t VALUES (1),(2);"); |
| 55 | 55 | }, 60_000); |
| 56 | 56 | |
| 57 | afterAll(async () => { | |
| 57 | afterEach(async () => { | |
| 58 | 58 | app.db.close(); |
| 59 | 59 | await rm(dataDir, { recursive: true, force: true }); |
| 60 | 60 | }); |
test/feed-chips.test.ts +4 −2
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | * The chips: each switches off what it names and nothing else, through the |
| 3 | 3 | * one filter, on the feed API and the pure function alike; saved per viewer. |
| 4 | 4 | */ |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 5 | import { afterAll, beforeAll, describe, expect, onTestFinished, test } from "bun:test"; | |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 7 | import { tmpdir } from "node:os"; |
| 8 | 8 | import { join } from "node:path"; |
| @@ -240,7 +240,9 @@ describe("the chips of a forge", () => { | ||
| 240 | 240 | |
| 241 | 241 | test("a count is the posts drawn of its kind, whatever asks the home pins aside", async () => { |
| 242 | 242 | const cookie = { cookie: `forge_session=${createSession(app.db, alice.id).token}` }; |
| 243 | emit("pull.opened", carol, { number: 2, title: "Wait for me" }); | |
| 243 | const opened = emit("pull.opened", carol, { number: 2, title: "Wait for me" }); | |
| 244 | // The extra ask is this test's alone: it leaves the feed as it found it. | |
| 245 | onTestFinished(() => void app.db.run("DELETE FROM event WHERE id = ?1", [opened.id])); | |
| 244 | 246 | const page = await (await fetch(`${servers.url}/live/feed`, { headers: cookie })).text(); |
| 245 | 247 | const drawnPulls = [...page.matchAll(/data-item="[^"]*"[^>]*data-kind="pull"/g)].length; |
| 246 | 248 | expect(page).toMatch(new RegExp(`Pull requests ${drawnPulls}\\s*<`)); |
test/feed-team-waits.test.ts +3 −3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { seatAs } from "./helpers/seat.ts"; |
| 8 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 9 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| @@ -67,7 +67,7 @@ const pullNaming = async (teams: string[], opts: { late?: true; in?: Repo } = {} | ||
| 67 | 67 | return o.value; |
| 68 | 68 | }; |
| 69 | 69 | |
| 70 | beforeAll(async () => { | |
| 70 | beforeEach(async () => { | |
| 71 | 71 | dataDir = await mkdtemp(join(tmpdir(), "forge-feed-team-waits-")); |
| 72 | 72 | app = createApp({ dataDir, port: 0 }); |
| 73 | 73 | const made = await createUser(app.db, { |
| @@ -97,7 +97,7 @@ beforeAll(async () => { | ||
| 97 | 97 | saveTeam(app.db, "data-science", { charter: "", dial: 0, members: [user("pike").id] }); |
| 98 | 98 | }, 120_000); |
| 99 | 99 | |
| 100 | afterAll(async () => { | |
| 100 | afterEach(async () => { | |
| 101 | 101 | for (let i = 0; i < 20; i++) await new Promise((done) => setImmediate(done)); |
| 102 | 102 | await Bun.sleep(100); |
| 103 | 103 | app?.close(); |
test/flows-actions.test.ts +5 −3
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** Acting on a flow line where it stands (#9591): follow or stop, update a dependency; writer yes, reader and cross-origin no. */ |
| 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 3 | 3 | import { createHmac } from "node:crypto"; |
| 4 | 4 | import { mkdtemp, rm } from "node:fs/promises"; |
| 5 | 5 | import { tmpdir } from "node:os"; |
| @@ -21,14 +21,14 @@ let dir: string; | ||
| 21 | 21 | let app: App; |
| 22 | 22 | let servers: Servers; |
| 23 | 23 | const KEY = "flows-actions-key"; |
| 24 | beforeAll(async () => { | |
| 24 | beforeEach(async () => { | |
| 25 | 25 | dir = await mkdtemp(join(tmpdir(), "forge-flows-actions-")); |
| 26 | 26 | app = createApp({ dataDir: dir, port: 0, previewIdentityKey: KEY }); |
| 27 | 27 | const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" }); |
| 28 | 28 | if (!seeded.ok) throw new Error(seeded.error); |
| 29 | 29 | servers = await serve(app); |
| 30 | 30 | }, 30_000); |
| 31 | afterAll(async () => { | |
| 31 | afterEach(async () => { | |
| 32 | 32 | servers.stop(); |
| 33 | 33 | app.close(); |
| 34 | 34 | await rm(dir, { recursive: true, force: true }); |
| @@ -63,6 +63,8 @@ describe("follow or stop, on the line", () => { | ||
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | 65 | test("the action posts through the existing route: admin stops it, cross-origin and anonymous do not", async () => { |
| 66 | const repo = repoNow(); | |
| 67 | app.db.query("INSERT INTO repo_source (id, repo_id, url, branch, by_id, created_at) VALUES ('sa', ?1, 'https://example.com/a.git', 'main', 'u1', '2026-11-01T00:00:00Z')").run(repo.id); | |
| 66 | 68 | const url = `${servers.url}/${PREVIEW_ADMIN}/${PREVIEW_REPO}/settings/sources/sa/remove`; |
| 67 | 69 | const count = () => app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM repo_source WHERE id = 'sa'").get()!.n; |
| 68 | 70 | const cross = await fetch(url, { method: "POST", redirect: "manual", headers: { ...headers(), origin: "https://evil.example" } }); |
test/forge-budget-verdict.test.ts +4 −4
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * limit; a wake wakes only what its cause can fix; the terminal door is |
| 6 | 6 | * gated like the page. |
| 7 | 7 | */ |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 9 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | 10 | import { writeFileSync } from "node:fs"; |
| 11 | 11 | import { tmpdir } from "node:os"; |
| @@ -45,7 +45,7 @@ describe("the owner's limits as a verdict", () => { | ||
| 45 | 45 | app.db.query("DELETE FROM run").run(); |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | beforeAll(async () => { | |
| 48 | beforeEach(async () => { | |
| 49 | 49 | dir = await mkdtemp(join(tmpdir(), "forge-verdict-")); |
| 50 | 50 | app = createApp({ dataDir: dir, port: 0 }); |
| 51 | 51 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-long-starter-passphrase", adminIfFirst: true }); |
| @@ -58,7 +58,7 @@ describe("the owner's limits as a verdict", () => { | ||
| 58 | 58 | repo = r.value; |
| 59 | 59 | app.db.query("UPDATE repo SET autonomy = 'autonomous' WHERE id = ?1").run(repo.id); |
| 60 | 60 | }); |
| 61 | afterAll(async () => { | |
| 61 | afterEach(async () => { | |
| 62 | 62 | app?.close(); |
| 63 | 63 | await rm(dir, { recursive: true, force: true }); |
| 64 | 64 | }); |
| @@ -69,7 +69,7 @@ describe("the owner's limits as a verdict", () => { | ||
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | 71 | describe("on a forge of its own", () => { |
| 72 | beforeAll(() => writeFileSync(join(dir, "parent.json"), "{}")); | |
| 72 | beforeEach(() => writeFileSync(join(dir, "parent.json"), "{}")); | |
| 73 | 73 | |
| 74 | 74 | test("a spent day stops the run and names the day limit", () => { |
| 75 | 75 | clear(); |
test/forge-signin.test.ts +21 −8
| @@ -291,19 +291,31 @@ describe("sign in through the parent forge", () => { | ||
| 291 | 291 | drained: async () => {}, |
| 292 | 292 | }; |
| 293 | 293 | forgeSshSession(child)(session as never); |
| 294 | await Bun.sleep(300); | |
| 294 | // The first paint is not instant on a cold process: wait for it, not a fixed time. | |
| 295 | for (let i = 0; i < 60 && !screen.includes("alice"); i++) await Bun.sleep(50); // real-timer: the terminal paints on its own clock | |
| 295 | 296 | session.exit(); |
| 296 | 297 | expect(screen).toContain("alice"); |
| 297 | 298 | }); |
| 298 | 299 | |
| 299 | 300 | test("starting a sign-in is throttled, so a flood cannot push out those in flight", async () => { |
| 300 | const statuses: number[] = []; | |
| 301 | for (let i = 0; i < 30; i++) | |
| 302 | statuses.push((await fetch(`${childServers.url}/signin/parent`, { redirect: "manual" })).status); | |
| 303 | expect(statuses).toContain(429); | |
| 304 | const slow = await fetch(`${childServers.url}/signin/parent`, { redirect: "manual" }); | |
| 305 | expect(slow.status).toBe(429); | |
| 306 | expect(Number(slow.headers.get("retry-after"))).toBeGreaterThan(0); | |
| 301 | // Its own child, already holding its registration: the flood spends this forge's budget and | |
| 302 | // registers nothing at the shared parent. | |
| 303 | const dir = await mkdtemp(join(tmpdir(), "forge-signin-")); | |
| 304 | dirs.push(dir); | |
| 305 | const flooded = createApp({ dataDir: dir, port: 0, parentUrl: parentServers.url, parentLoopback: true }); | |
| 306 | const floodedServers = await serve(flooded); | |
| 307 | keepClient(flooded.db, parentServers.url, `${floodedServers.url}${CALLBACK_PATH}`, "client-1"); | |
| 308 | try { | |
| 309 | const statuses: number[] = []; | |
| 310 | for (let i = 0; i < 30; i++) | |
| 311 | statuses.push((await fetch(`${floodedServers.url}/signin/parent`, { redirect: "manual" })).status); | |
| 312 | expect(statuses).toContain(429); | |
| 313 | const slow = await fetch(`${floodedServers.url}/signin/parent`, { redirect: "manual" }); | |
| 314 | expect(slow.status).toBe(429); | |
| 315 | expect(Number(slow.headers.get("retry-after"))).toBeGreaterThan(0); | |
| 316 | } finally { | |
| 317 | floodedServers.stop(); | |
| 318 | } | |
| 307 | 319 | }); |
| 308 | 320 | }); |
| 309 | 321 | |
| @@ -487,6 +499,7 @@ describe("a parent's oversized register and token answers", () => { | ||
| 487 | 499 | |
| 488 | 500 | test("a registration that streams forever is a 502, and few chunks are pulled", async () => { |
| 489 | 501 | streaming = "register"; |
| 502 | child.db.query("DELETE FROM rp_client").run(); | |
| 490 | 503 | const res = await fetch(`${servers.url}/signin/parent`, { redirect: "manual" }); |
| 491 | 504 | expect(res.status).toBe(502); |
| 492 | 505 | expect(pulled.n).toBeGreaterThan(0); |
test/forks.test.ts +19 −6
| @@ -1,4 +1,4 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 1 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 2 | 2 | import { mkdtemp, rm } from "node:fs/promises"; |
| 3 | 3 | import { tmpdir } from "node:os"; |
| 4 | 4 | import { join } from "node:path"; |
| @@ -82,7 +82,8 @@ describe("forks", () => { | ||
| 82 | 82 | return await res.text(); |
| 83 | 83 | }; |
| 84 | 84 | |
| 85 | beforeAll(async () => { | |
| 85 | // A fresh forge for every test: none leans on a fork or a commit another made. | |
| 86 | beforeEach(async () => { | |
| 86 | 87 | dataDir = await mkdtemp(join(tmpdir(), "forge-fork-")); |
| 87 | 88 | app = createApp({ dataDir, port: 0 }); |
| 88 | 89 | servers = await serve(app); |
| @@ -107,12 +108,19 @@ describe("forks", () => { | ||
| 107 | 108 | await commitAs("alice", upstream, "README.md", "seed"); |
| 108 | 109 | }, 60_000); |
| 109 | 110 | |
| 110 | afterAll(async () => { | |
| 111 | afterEach(async () => { | |
| 111 | 112 | servers.stop(); |
| 112 | 113 | app.close(); |
| 113 | 114 | await rm(dataDir, { recursive: true, force: true }); |
| 114 | 115 | }); |
| 115 | 116 | |
| 117 | /** Bob's fork of upstream, with a commit of his own. */ | |
| 118 | const bobWithWork = async () => { | |
| 119 | const bob = await forkAs("bob", upstream); | |
| 120 | await commitAs("bob", bob, "feature.txt", "bob feature"); | |
| 121 | return bob; | |
| 122 | }; | |
| 123 | ||
| 116 | 124 | test("a fork borrows its parent's objects and a push to it never reaches the parent", async () => { |
| 117 | 125 | const bob = await forkAs("bob", upstream); |
| 118 | 126 | expect(bob.ownerName).toBe("bob"); |
| @@ -129,6 +137,7 @@ describe("forks", () => { | ||
| 129 | 137 | }); |
| 130 | 138 | |
| 131 | 139 | test("a fork follows its parent fast-forward only; one with work of its own is refused", async () => { |
| 140 | const bobOwn = await bobWithWork(); | |
| 132 | 141 | const carol = await forkAs("carol", upstream); |
| 133 | 142 | await commitAs("alice", upstream, "NEWS.md", "alice moves on"); |
| 134 | 143 | const moved = await tip(upstream); |
| @@ -140,8 +149,7 @@ describe("forks", () => { | ||
| 140 | 149 | expect(again.to).toBe(moved!); |
| 141 | 150 | |
| 142 | 151 | // The follower never merges: bob has work of his own and stays where he was. |
| 143 | const bob = getRepo(app.db, "bob", "app")!; | |
| 144 | expect(await tip(bob)).not.toBe(moved); | |
| 152 | expect(await tip(bobOwn)).not.toBe(moved); | |
| 145 | 153 | }); |
| 146 | 154 | |
| 147 | 155 | test("Update from parent merges a diverged fork cleanly, and refuses a conflicting one untouched", async () => { |
| @@ -194,6 +202,9 @@ describe("forks", () => { | ||
| 194 | 202 | }, 30_000); |
| 195 | 203 | |
| 196 | 204 | test("the About rail says how far a fork is from its parent, and offers an update only when one can be taken", async () => { |
| 205 | // Bob has work of his own; upstream then moves once, before dan forks. | |
| 206 | await bobWithWork(); | |
| 207 | await commitAs("alice", upstream, "NEWS.md", "alice moves on"); | |
| 197 | 208 | // Dan forks as upstream stands: level, nothing offered. |
| 198 | 209 | await forkAs("dan", upstream); |
| 199 | 210 | const current = await page("/dan/app", "dan"); |
| @@ -223,6 +234,7 @@ describe("forks", () => { | ||
| 223 | 234 | }); |
| 224 | 235 | |
| 225 | 236 | test("the fork count opens the list, and counts only forks the viewer may read", async () => { |
| 237 | for (const who of ["bob", "carol", "dan"]) await forkAs(who, upstream); | |
| 226 | 238 | const home = await page("/alice/app"); |
| 227 | 239 | expect(home).toContain('href="/alice/app/forks"'); |
| 228 | 240 | expect(home).toContain("3 forks"); |
| @@ -246,6 +258,7 @@ describe("forks", () => { | ||
| 246 | 258 | expect(refused.ok).toBe(false); |
| 247 | 259 | if (!refused.ok) expect(refused.error).toBe("not_found"); |
| 248 | 260 | |
| 261 | await forkAs("bob", upstream); | |
| 249 | 262 | const twice = await forkRepo(app, users["bob"]!, upstream); |
| 250 | 263 | expect(twice.ok).toBe(false); |
| 251 | 264 | if (!twice.ok) expect(twice.error).toBe("already_forked"); |
| @@ -271,7 +284,7 @@ describe("forks", () => { | ||
| 271 | 284 | }); |
| 272 | 285 | |
| 273 | 286 | test("deleting the parent detaches the fork, which survives whole", async () => { |
| 274 | const bob = getRepo(app.db, "bob", "app")!; | |
| 287 | const bob = await bobWithWork(); | |
| 275 | 288 | must(await deleteRepo(app, users["alice"]!, upstream)); |
| 276 | 289 | |
| 277 | 290 | expect( |
test/front.test.ts +9 −3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * MCP alike. Refusals first: a stranger and a plain member never set it, and |
| 6 | 6 | * nothing private is ever shown, pinned or not. |
| 7 | 7 | */ |
| 8 | import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test"; | |
| 8 | import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"; | |
| 9 | 9 | import { mkdirSync, writeFileSync } from "node:fs"; |
| 10 | 10 | import { mkdtemp, rm } from "node:fs/promises"; |
| 11 | 11 | import { tmpdir } from "node:os"; |
| @@ -224,7 +224,8 @@ describe("the front page", () => { | ||
| 224 | 224 | body: JSON.stringify(body), |
| 225 | 225 | }); |
| 226 | 226 | |
| 227 | beforeAll(async () => { | |
| 227 | // A fresh forge for every test: none leans on an app or a pin another made. | |
| 228 | beforeEach(async () => { | |
| 228 | 229 | dataDir = await mkdtemp(join(tmpdir(), "forge-front-")); |
| 229 | 230 | app = createApp({ dataDir, port: 0 }); |
| 230 | 231 | servers = await serve(app); |
| @@ -294,7 +295,7 @@ describe("the front page", () => { | ||
| 294 | 295 | }; |
| 295 | 296 | }, 30_000); |
| 296 | 297 | |
| 297 | afterAll(async () => { | |
| 298 | afterEach(async () => { | |
| 298 | 299 | restore(); |
| 299 | 300 | await runtime.stop(); |
| 300 | 301 | servers.stop(); |
| @@ -467,6 +468,9 @@ describe("the front page", () => { | ||
| 467 | 468 | }); |
| 468 | 469 | |
| 469 | 470 | test("a site admin pins, orders and hides; the first pin a stranger can read is featured, a private pin never shows", async () => { |
| 471 | await make(admin, "two"); | |
| 472 | await make(admin, "three"); | |
| 473 | await make(other, "loved"); | |
| 470 | 474 | // The forge's own repository, still private: pinned first, shown never. |
| 471 | 475 | const own = await createRepo(app, admin, { |
| 472 | 476 | name: "forge", |
| @@ -621,6 +625,7 @@ describe("the front page", () => { | ||
| 621 | 625 | expect(body).not.toContain("A merge nobody outside may read"); |
| 622 | 626 | }); |
| 623 | 627 | test("featured shows the crew at work on it right now, by issue", async () => { |
| 628 | await make(admin, "two"); | |
| 624 | 629 | const issue = openIssue( |
| 625 | 630 | app, |
| 626 | 631 | admin, |
| @@ -653,6 +658,7 @@ describe("the front page", () => { | ||
| 653 | 658 | }); |
| 654 | 659 | |
| 655 | 660 | test("never a letter tile: a pin without a stranger's picture, or one that is down, waits; the sweep wakes a pinned app asleep to picture it", async () => { |
| 661 | await make(admin, "two"); | |
| 656 | 662 | await make(admin, "pinned-bare", { picture: false }); |
| 657 | 663 | const down = await make(admin, "pinned-down"); |
| 658 | 664 | states.set(down.record.id, "failed"); |
test/mcp-releases.test.ts +3 −3
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** `releases` is the /releases page over MCP: the same list, the same gate, no rollback. */ |
| 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 3 | 3 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| @@ -43,7 +43,7 @@ describe("MCP releases", () => { | ||
| 43 | 43 | return body.result.isError === true ? { error: text } : { value: JSON.parse(text) }; |
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | beforeAll(async () => { | |
| 46 | beforeEach(async () => { | |
| 47 | 47 | process.env["FORGE_COMMIT"] = LIVE; |
| 48 | 48 | dataDir = await mkdtemp(join(tmpdir(), "forge-mcp-releases-")); |
| 49 | 49 | app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" }); |
| @@ -65,7 +65,7 @@ describe("MCP releases", () => { | ||
| 65 | 65 | repoId = made.value.id; |
| 66 | 66 | }, 30_000); |
| 67 | 67 | |
| 68 | afterAll(async () => { | |
| 68 | afterEach(async () => { | |
| 69 | 69 | if (saved === undefined) delete process.env["FORGE_COMMIT"]; |
| 70 | 70 | else process.env["FORGE_COMMIT"] = saved; |
| 71 | 71 | servers.stop(); |
test/origins-import-labels.test.ts +7 −3
| @@ -1,4 +1,4 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 1 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 2 | 2 | import { mkdtemp, rm } from "node:fs/promises"; |
| 3 | 3 | import { tmpdir } from "node:os"; |
| 4 | 4 | import { join } from "node:path"; |
| @@ -42,7 +42,7 @@ const newIssue = (title: string) => { | ||
| 42 | 42 | return made.value.id; |
| 43 | 43 | }; |
| 44 | 44 | |
| 45 | beforeAll(async () => { | |
| 45 | beforeEach(async () => { | |
| 46 | 46 | dir = await mkdtemp(join(tmpdir(), "forge-origin-labels-")); |
| 47 | 47 | app = createApp({ dataDir: dir, port: 0 }); |
| 48 | 48 | const admin = await seedAdmin(app, { |
| @@ -57,7 +57,7 @@ beforeAll(async () => { | ||
| 57 | 57 | repoId = repo.value.id; |
| 58 | 58 | }); |
| 59 | 59 | |
| 60 | afterAll(async () => { | |
| 60 | afterEach(async () => { | |
| 61 | 61 | await rm(dir, { recursive: true, force: true }); |
| 62 | 62 | }); |
| 63 | 63 | |
| @@ -73,6 +73,10 @@ describe("importLabels", () => { | ||
| 73 | 73 | }); |
| 74 | 74 | |
| 75 | 75 | test("a re-sync adopts the row by name, case-insensitively, and takes the new colour", () => { |
| 76 | importLabels(app.db, repoId, [ | |
| 77 | { remoteId: "1", name: "bug", color: "d73a4a" }, | |
| 78 | { remoteId: "2", name: "docs", color: "0075ca" }, | |
| 79 | ]); | |
| 76 | 80 | importLabels(app.db, repoId, [{ remoteId: "9", name: "BUG", color: "000000" }]); |
| 77 | 81 | expect(rows()).toEqual(["bug", "docs"]); |
| 78 | 82 | const bug = app.db |
test/perf-jobs-per-forge.test.ts +3 −3
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | * two forges booted in one process, as two test files are, never read each |
| 4 | 4 | * other's jobs or children, and each forge's loop watch reads its own. |
| 5 | 5 | */ |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 7 | 7 | import { mkdtemp, rm } from "node:fs/promises"; |
| 8 | 8 | import { tmpdir } from "node:os"; |
| 9 | 9 | import { join } from "node:path"; |
| @@ -16,13 +16,13 @@ let dirs: string[] = []; | ||
| 16 | 16 | let one: App; |
| 17 | 17 | let other: App; |
| 18 | 18 | |
| 19 | beforeAll(async () => { | |
| 19 | beforeEach(async () => { | |
| 20 | 20 | dirs = [await mkdtemp(join(tmpdir(), "jobs-one-")), await mkdtemp(join(tmpdir(), "jobs-other-"))]; |
| 21 | 21 | one = createApp({ dataDir: dirs[0]!, url: "https://one.test", port: 0 }); |
| 22 | 22 | other = createApp({ dataDir: dirs[1]!, url: "https://other.test", port: 0 }); |
| 23 | 23 | }); |
| 24 | 24 | |
| 25 | afterAll(async () => { | |
| 25 | afterEach(async () => { | |
| 26 | 26 | one?.close(); |
| 27 | 27 | other?.close(); |
| 28 | 28 | for (const d of dirs) await rm(d, { recursive: true, force: true }); |
test/pinned-forge-recovery.test.ts +23 −2
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * all leave a row a retry finishes. The terminal door reaches the same actions. |
| 5 | 5 | */ |
| 6 | 6 | import { BUN_INTEGRITY } from "../src/cloud/bun_install.ts"; |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"; | |
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| @@ -68,6 +68,19 @@ describe("pinned forge recovery", () => { | ||
| 68 | 68 | }; |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | // Every test starts with no pinned forge and no stubbed history; it deploys what it needs. | |
| 72 | beforeEach(() => { | |
| 73 | app.db.run("DELETE FROM pinned_forge"); | |
| 74 | calls.length = 0; | |
| 75 | fail.clear(); | |
| 76 | deleted = new Set(); | |
| 77 | }); | |
| 78 | /** A running acme at V1, as a first deploy leaves it. */ | |
| 79 | const running = async () => { | |
| 80 | expect((await deployPinned(app, admin(), input())).ok).toBe(true); | |
| 81 | calls.length = 0; | |
| 82 | }; | |
| 83 | ||
| 71 | 84 | afterAll(async () => { |
| 72 | 85 | app.close(); |
| 73 | 86 | await rm(dataDir, { recursive: true, force: true }); |
| @@ -89,6 +102,7 @@ describe("pinned forge recovery", () => { | ||
| 89 | 102 | }); |
| 90 | 103 | |
| 91 | 104 | test("an Update whose create fails after the delete can be rolled back or tried again", async () => { |
| 105 | await running(); | |
| 92 | 106 | fail.set("POST /v2/droplets", 500); |
| 93 | 107 | expect((await updatePinned(app, admin(), "acme", { version: V2 })).ok).toBe(false); |
| 94 | 108 | expect(getPinned(app.db, "acme")).toMatchObject({ state: "failed", remote: "", version: V2 }); |
| @@ -101,6 +115,7 @@ describe("pinned forge recovery", () => { | ||
| 101 | 115 | }); |
| 102 | 116 | |
| 103 | 117 | test("a droplet already gone (404) counts as deleted", async () => { |
| 118 | await running(); | |
| 104 | 119 | app.db.run("UPDATE pinned_forge SET remote = '777' WHERE name = 'acme'"); |
| 105 | 120 | deleted.add("/v2/droplets/777"); |
| 106 | 121 | expect((await updatePinned(app, admin(), "acme", { version: V2 })).ok).toBe(true); |
| @@ -108,7 +123,10 @@ describe("pinned forge recovery", () => { | ||
| 108 | 123 | }); |
| 109 | 124 | |
| 110 | 125 | test("a failed forge may be told the version it already has, to finish the replacement", async () => { |
| 111 | app.db.run("UPDATE pinned_forge SET state = 'failed', remote = '' WHERE name = 'acme'"); | |
| 126 | await running(); | |
| 127 | fail.set("POST /v2/droplets", 500); | |
| 128 | expect((await updatePinned(app, admin(), "acme", { version: V2 })).ok).toBe(false); | |
| 129 | expect(getPinned(app.db, "acme")).toMatchObject({ state: "failed", version: V2 }); | |
| 112 | 130 | expect((await updatePinned(app, admin(), "acme", { version: V2 })).ok).toBe(true); |
| 113 | 131 | expect(getPinned(app.db, "acme")?.state).toBe("running"); |
| 114 | 132 | }); |
| @@ -124,6 +142,8 @@ describe("pinned forge recovery", () => { | ||
| 124 | 142 | }); |
| 125 | 143 | |
| 126 | 144 | test("terminal: the palette offers Pinned forges to an admin only; d, u and r reach the actions", async () => { |
| 145 | await running(); | |
| 146 | expect((await updatePinned(app, admin(), "acme", { version: V2 })).ok).toBe(true); | |
| 127 | 147 | const bob = new Session(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: getUserByName(app.db, "bob")! }); |
| 128 | 148 | const alice = new Session(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: admin() }); |
| 129 | 149 | expect(entry.offered(bob)).toBe(false); |
| @@ -147,6 +167,7 @@ describe("pinned forge recovery", () => { | ||
| 147 | 167 | }); |
| 148 | 168 | |
| 149 | 169 | test("terminal: the screen follows the bus while it is on the stack", async () => { |
| 170 | await running(); | |
| 150 | 171 | const alice = new Session(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: admin() }); |
| 151 | 172 | let invalidated = 0; |
| 152 | 173 | const ctx = { push() {}, invalidate: () => invalidated++ } as never; |
test/snapshot-mirror-page.test.ts +4 −3
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * page never shows a value; a blank field keeps what was sealed; clear removes |
| 5 | 5 | * the names and, once the pass settles, the board card. |
| 6 | 6 | */ |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 8 | 8 | import { mkdtempSync, rmSync } from "node:fs"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| @@ -54,7 +54,7 @@ describe("the mirror's admin routes", () => { | ||
| 54 | 54 | ); |
| 55 | 55 | const sealed = () => mirrorSealedSet(app.db).sort(); |
| 56 | 56 | |
| 57 | beforeAll(async () => { | |
| 57 | beforeEach(async () => { | |
| 58 | 58 | root = mkdtempSync(join(tmpdir(), "forge-mirrorpage-")); |
| 59 | 59 | app = createApp({ dataDir: root, port: 0 }); |
| 60 | 60 | for (const [username, password, adminIfFirst] of [ |
| @@ -82,7 +82,7 @@ describe("the mirror's admin routes", () => { | ||
| 82 | 82 | }); |
| 83 | 83 | servers = await serve(app); |
| 84 | 84 | }); |
| 85 | afterAll(async () => { | |
| 85 | afterEach(async () => { | |
| 86 | 86 | servers.stop(); |
| 87 | 87 | await svc.stop(); |
| 88 | 88 | app.close(); |
| @@ -120,6 +120,7 @@ describe("the mirror's admin routes", () => { | ||
| 120 | 120 | |
| 121 | 121 | test("a blank field keeps what was sealed, and a changed target drops the old pass", async () => { |
| 122 | 122 | const alice = await login("alice", "a-good-passphrase"); |
| 123 | expect((await post("/mirror", full, alice)).status).toBe(303); | |
| 123 | 124 | await svc.mirrorFresh(); |
| 124 | 125 | recordMirror(root, { where: "old/bucket", attemptAt: new Date().toISOString(), reachable: true, syncedAt: new Date().toISOString() }); |
| 125 | 126 | expect((await post("/mirror", { ...full, endpoint: "", bucket: "other-bucket", access_key: "", secret_key: "" }, alice)).status).toBe(303); |
test/spawn-upstream.test.ts +11 −5
| @@ -73,9 +73,11 @@ describe("looking upstream", () => { | ||
| 73 | 73 | }); |
| 74 | 74 | |
| 75 | 75 | test("an unreachable upstream keeps its error and what was known", async () => { |
| 76 | const known = await checkUpstream(app, { remote: parent, now: 2500 }); | |
| 77 | expect(known?.error).toBe(""); | |
| 76 | 78 | const s = await checkUpstream(app, { remote: join(dir, "nowhere.git"), now: 3000 }); |
| 77 | 79 | expect(s?.error).not.toBe(""); |
| 78 | expect(s?.behind).toBe(3); | |
| 80 | expect(s?.behind).toBe(known!.behind); | |
| 79 | 81 | expect((await upstreamState(app))?.error).toBe(s!.error); |
| 80 | 82 | }); |
| 81 | 83 | |
| @@ -179,9 +181,13 @@ describe("looking upstream", () => { | ||
| 179 | 181 | }); |
| 180 | 182 | |
| 181 | 183 | test("a severed forge is not checked", async () => { |
| 182 | const doc = await Bun.file(join(app.config.dataDir, "parent.json")).json(); | |
| 183 | doc.forgeCode.severedAt = new Date().toISOString(); | |
| 184 | await Bun.write(join(app.config.dataDir, "parent.json"), JSON.stringify(doc)); | |
| 185 | expect(await checkUpstream(app, { remote: parent })).toBeUndefined(); | |
| 184 | const file = join(app.config.dataDir, "parent.json"); | |
| 185 | const doc = await Bun.file(file).json(); | |
| 186 | try { | |
| 187 | await Bun.write(file, JSON.stringify({ ...doc, forgeCode: { ...doc.forgeCode, severedAt: new Date().toISOString() } })); | |
| 188 | expect(await checkUpstream(app, { remote: parent })).toBeUndefined(); | |
| 189 | } finally { | |
| 190 | await Bun.write(file, JSON.stringify(doc)); | |
| 191 | } | |
| 186 | 192 | }); |
| 187 | 193 | }); |
test/teams-crew.test.ts +18 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | * the org page lists each team's members with their roles, escaped. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"; | |
| 11 | 11 | import { mkdtemp, rm } from "node:fs/promises"; |
| 12 | 12 | import { tmpdir } from "node:os"; |
| 13 | 13 | import { join } from "node:path"; |
| @@ -109,6 +109,15 @@ describe("teams drive the crew", () => { | ||
| 109 | 109 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; |
| 110 | 110 | }); |
| 111 | 111 | |
| 112 | // Every test starts from the same crew: the write team seats sentinel as | |
| 113 | // builder and juniper as reviewer; no one else holds a seat. A test that | |
| 114 | // needs more builds it in its own body. | |
| 115 | beforeEach(() => { | |
| 116 | app.db.query("DELETE FROM team_member WHERE team_id IN (?1, ?2)").run(crewTeam.id, readers.id); | |
| 117 | expect(addTeamMember(app.db, crewTeam, sentinel.id, "builder")).toBe(true); | |
| 118 | expect(addTeamMember(app.db, crewTeam, juniper.id, "reviewer")).toBe(true); | |
| 119 | }); | |
| 120 | ||
| 112 | 121 | afterAll(async () => { |
| 113 | 122 | servers?.stop(); |
| 114 | 123 | await rm(dataDir, { recursive: true, force: true }); |
| @@ -123,6 +132,7 @@ describe("teams drive the crew", () => { | ||
| 123 | 132 | }); |
| 124 | 133 | |
| 125 | 134 | test("with no agent seated by a write team the roster is the crew, unchanged", () => { |
| 135 | app.db.query("DELETE FROM team_member WHERE team_id = ?1").run(crewTeam.id); | |
| 126 | 136 | // An agent on a read team grants nothing. |
| 127 | 137 | expect(addTeamMember(app.db, readers, mason.id, "reviewer")).toBe(true); |
| 128 | 138 | for (const target of [teamed, rostered, personal]) { |
| @@ -135,6 +145,7 @@ describe("teams drive the crew", () => { | ||
| 135 | 145 | }); |
| 136 | 146 | |
| 137 | 147 | test("a write team with a reviewer is the crew: the routing picks its reviewer", () => { |
| 148 | app.db.query("DELETE FROM team_member WHERE team_id = ?1").run(crewTeam.id); | |
| 138 | 149 | expect(addTeamMember(app.db, crewTeam, mason.id, "reviewer")).toBe(true); |
| 139 | 150 | expect(addTeamMember(app.db, crewTeam, sentinel.id, "builder")).toBe(true); |
| 140 | 151 | // Every repository the org owns now reads its crew from the team … |
| @@ -152,7 +163,8 @@ describe("teams drive the crew", () => { | ||
| 152 | 163 | }); |
| 153 | 164 | |
| 154 | 165 | test("a write team without a reviewer leaves the seat empty, not the roster's", () => { |
| 155 | app.db.query("UPDATE team_member SET role = 'planner' WHERE team_id = ?1 AND user_id = ?2").run(crewTeam.id, mason.id); | |
| 166 | app.db.query("DELETE FROM team_member WHERE team_id = ?1 AND user_id = ?2").run(crewTeam.id, juniper.id); | |
| 167 | expect(addTeamMember(app.db, crewTeam, mason.id, "planner")).toBe(true); | |
| 156 | 168 | expect(reviewersOf(app.db, teamed.id)).toEqual([]); |
| 157 | 169 | expect(names(crewWithRole(app.db, [teamed.id], "planner").get(teamed.id))).toEqual(["mason"]); |
| 158 | 170 | expect(reposWithBuilder(app.db, [teamed.id, personal.id])).toEqual(new Set([teamed.id, personal.id])); |
| @@ -160,6 +172,8 @@ describe("teams drive the crew", () => { | ||
| 160 | 172 | }); |
| 161 | 173 | |
| 162 | 174 | test("a plain member of a write team holds no seat, so a membership from before roles changes no crew", async () => { |
| 175 | app.db.query("DELETE FROM team_member WHERE team_id = ?1 AND user_id = ?2").run(crewTeam.id, juniper.id); | |
| 176 | expect(addTeamMember(app.db, crewTeam, mason.id, "planner")).toBe(true); | |
| 163 | 177 | const second = createTeam(app.db, org.id, "Second", "write"); |
| 164 | 178 | if (!second.ok) throw new Error(second.error); |
| 165 | 179 | expect(addTeamMember(app.db, second.value, juniper.id)).toBe(true); |
| @@ -190,6 +204,7 @@ describe("teams drive the crew", () => { | ||
| 190 | 204 | }); |
| 191 | 205 | |
| 192 | 206 | test("POST accepts and validates a role; GET lists it", async () => { |
| 207 | expect(addTeamMember(app.db, crewTeam, mason.id, "planner")).toBe(true); | |
| 193 | 208 | const bad = await api("POST", "", { user: "mason", role: "king" }); |
| 194 | 209 | expect(bad.status).toBe(422); |
| 195 | 210 | expect(((await bad.json()) as { error: string }).error).toBe("bad_role"); |
| @@ -205,6 +220,7 @@ describe("teams drive the crew", () => { | ||
| 205 | 220 | }); |
| 206 | 221 | |
| 207 | 222 | test("DELETE with a role takes that role off and keeps the member; a bad role is refused", async () => { |
| 223 | expect(addTeamMember(app.db, crewTeam, mason.id, "reviewer")).toBe(true); | |
| 208 | 224 | expect((await api("DELETE", "/mason?role=king")).status).toBe(422); |
| 209 | 225 | expect((await api("DELETE", "/mason?role=builder")).status).toBe(404); |
| 210 | 226 | expect((await api("DELETE", "/mason?role=reviewer")).status).toBe(204); |
test/tui-newforge-recipes.test.ts +9 −6
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | * The terminal's New forge screen has the page's recipes (#649): apps with a mode, Save as recipe, |
| 3 | 3 | * and Spawn from recipe, through the same door. |
| 4 | 4 | */ |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 5 | import { afterEach, beforeEach, expect, test } from "bun:test"; | |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 7 | import { tmpdir } from "node:os"; |
| 8 | 8 | import { join } from "node:path"; |
| @@ -23,7 +23,7 @@ let dir: string; | ||
| 23 | 23 | let app: App; |
| 24 | 24 | let admin: User; |
| 25 | 25 | |
| 26 | beforeAll(async () => { | |
| 26 | beforeEach(async () => { | |
| 27 | 27 | dir = await mkdtemp(join(tmpdir(), "forge-tui-newforge-recipes-")); |
| 28 | 28 | app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 }); |
| 29 | 29 | const r = await createUser(app.db, { |
| @@ -35,7 +35,7 @@ beforeAll(async () => { | ||
| 35 | 35 | useProbe(app, () => async () => true); |
| 36 | 36 | usePlacement(app, hostedPlacement({ host: "forge.test" })); |
| 37 | 37 | }); |
| 38 | afterAll(async () => { | |
| 38 | afterEach(async () => { | |
| 39 | 39 | app.db.close(); |
| 40 | 40 | await rm(dir, { recursive: true, force: true }); |
| 41 | 41 | }); |
| @@ -64,10 +64,11 @@ async function open(keys: string): Promise<string> { | ||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | const KEEP_KEYS = | |
| 68 | "zed" + TAB.repeat(3) + "alice/shop:autonomous, alice/old:migration" + TAB.repeat(4) + "20" + TAB.repeat(6) + "client kit" + "\x10"; | |
| 69 | ||
| 67 | 70 | test("Save as recipe keeps the apps with their modes and the budget, with the plan", async () => { |
| 68 | const keys = | |
| 69 | "zed" + TAB.repeat(3) + "alice/shop:autonomous, alice/old:migration" + TAB.repeat(4) + "20" + TAB.repeat(6) + "client kit" + "\x10"; | |
| 70 | const screen = await open(keys); | |
| 71 | const screen = await open(KEEP_KEYS); | |
| 71 | 72 | // Kept before the plan is asked for; the plan itself may refuse apps this forge does not have. |
| 72 | 73 | expect(listRecipes(dir, admin.id).map((r) => r.name)).toEqual(["client kit"]); |
| 73 | 74 | expect(listRecipes(dir, admin.id)[0]!.config).toEqual({ |
| @@ -78,12 +79,14 @@ test("Save as recipe keeps the apps with their modes and the budget, with the pl | ||
| 78 | 79 | }); |
| 79 | 80 | |
| 80 | 81 | test("a bad recipe name is refused beside its field and nothing is kept", async () => { |
| 82 | await open(KEEP_KEYS); | |
| 81 | 83 | const screen = await open("zed" + TAB.repeat(13) + "no/slash!" + "\x10"); |
| 82 | 84 | expect(screen).toContain("recipe name is 1-40 characters"); |
| 83 | 85 | expect(listRecipes(dir, admin.id).map((r) => r.name)).toEqual(["client kit"]); |
| 84 | 86 | }); |
| 85 | 87 | |
| 86 | 88 | test("Spawn from recipe is offered once there is one", async () => { |
| 89 | await open(KEEP_KEYS); | |
| 87 | 90 | const screen = await open(TAB.repeat(14)); |
| 88 | 91 | expect(screen).toContain("Spawn from recipe"); |
| 89 | 92 | }); |
test/tui-signins-password.test.ts +3 −3
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | * account reads as Settings does; the typed text never appears in any frame a |
| 9 | 9 | * run painted; an agent is not offered `p`. |
| 10 | 10 | */ |
| 11 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 11 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 12 | 12 | import { mkdtemp, rm } from "node:fs/promises"; |
| 13 | 13 | import { tmpdir } from "node:os"; |
| 14 | 14 | import { join } from "node:path"; |
| @@ -95,7 +95,7 @@ describe("changing your password from the terminal", () => { | ||
| 95 | 95 | const signsIn = async (username: string, password: string) => |
| 96 | 96 | (await new Session(forge, { sshUsername: "t", remoteAddress: "10.0.0.9" }).signIn(username, password)).ok; |
| 97 | 97 | |
| 98 | beforeAll(async () => { | |
| 98 | beforeEach(async () => { | |
| 99 | 99 | dataDir = await mkdtemp(join(tmpdir(), "forge-tui-signins-password-")); |
| 100 | 100 | forge = createApp({ dataDir, port: 0 }); |
| 101 | 101 | const made = await createUser(forge.db, { |
| @@ -117,7 +117,7 @@ describe("changing your password from the terminal", () => { | ||
| 117 | 117 | }); |
| 118 | 118 | if (!bob.ok) throw new Error(bob.error); |
| 119 | 119 | }); |
| 120 | afterAll(async () => { | |
| 120 | afterEach(async () => { | |
| 121 | 121 | forge.close(); |
| 122 | 122 | await rm(dataDir, { recursive: true, force: true }); |
| 123 | 123 | }); |
test/view-source.test.ts +23 −5
| @@ -1,4 +1,4 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 1 | import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | |
| 2 | 2 | import { mkdtemp, rm } from "node:fs/promises"; |
| 3 | 3 | import { tmpdir } from "node:os"; |
| 4 | 4 | import { join } from "node:path"; |
| @@ -112,7 +112,19 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 112 | 112 | |
| 113 | 113 | const requests = (): number => fake.state.requests.length; |
| 114 | 114 | |
| 115 | beforeAll(async () => { | |
| 115 | /** Mirror octo/widgets and wait for the job to end. */ | |
| 116 | const mirrorWidgets = async (): Promise<void> => { | |
| 117 | const started = await api(`/api/v1/user/origins/${originId}/mirror`, { | |
| 118 | method: "POST", | |
| 119 | body: JSON.stringify({ fullName: "octo/widgets" }), | |
| 120 | }); | |
| 121 | expect(started.status).toBe(202); | |
| 122 | const job = (await read<{ job: { id: string } }>(started)).job; | |
| 123 | expect((await settled(job.id))?.stage).toBe("done"); | |
| 124 | }; | |
| 125 | ||
| 126 | // Two forges and an origin, new for every test: none leans on a mirror or a cache another warmed. | |
| 127 | beforeEach(async () => { | |
| 116 | 128 | dataDir = await mkdtemp(join(tmpdir(), "forge-view-")); |
| 117 | 129 | originDataDir = await mkdtemp(join(tmpdir(), "forge-view-up-")); |
| 118 | 130 | |
| @@ -297,7 +309,7 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 297 | 309 | clearViewCache(); |
| 298 | 310 | }); |
| 299 | 311 | |
| 300 | afterAll(async () => { | |
| 312 | afterEach(async () => { | |
| 301 | 313 | fake.stop(); |
| 302 | 314 | servers.stop(); |
| 303 | 315 | originServers.stop(); |
| @@ -598,7 +610,9 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 598 | 610 | |
| 599 | 611 | test("mirroring busts what the browse cache believed", async () => { |
| 600 | 612 | const source = live("octo/widgets"); |
| 601 | // The mirror above ran after the cache was warmed by earlier reads. | |
| 613 | // The cache is warmed by a read, then the mirror runs. | |
| 614 | await source.tree("main", ""); | |
| 615 | await mirrorWidgets(); | |
| 602 | 616 | const before = requests(); |
| 603 | 617 | await source.tree("main", ""); |
| 604 | 618 | expect(requests()).toBeGreaterThan(before); |
| @@ -669,6 +683,7 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 669 | 683 | // ---- the equivalence that makes the interface worth having ---- |
| 670 | 684 | |
| 671 | 685 | test("the mirror and the origin answer the same questions the same way", async () => { |
| 686 | await mirrorWidgets(); | |
| 672 | 687 | // Compare against the finished mirror: if the test that started it ran |
| 673 | 688 | // out of time on a loaded machine, its import may still be running. |
| 674 | 689 | const importing = runningJob(originId, "octo/widgets"); |
| @@ -821,7 +836,8 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 821 | 836 | // is the answers', not the clock's. |
| 822 | 837 | }, 60_000); |
| 823 | 838 | |
| 824 | test("a local source refuses a repo the viewer cannot read", () => { | |
| 839 | test("a local source refuses a repo the viewer cannot read", async () => { | |
| 840 | await mirrorWidgets(); | |
| 825 | 841 | app.db |
| 826 | 842 | .query("UPDATE repo SET visibility = 'private' WHERE name = 'widgets'") |
| 827 | 843 | .run(); |
| @@ -843,6 +859,7 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 843 | 859 | // ---- the API over it ---- |
| 844 | 860 | |
| 845 | 861 | test("the browse routes answer with the local shapes", async () => { |
| 862 | await mirrorWidgets(); | |
| 846 | 863 | const landing = await read<{ |
| 847 | 864 | source: string; |
| 848 | 865 | fullName: string; |
| @@ -995,6 +1012,7 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 995 | 1012 | }); |
| 996 | 1013 | |
| 997 | 1014 | test("the picker says which rows are already mirrored", async () => { |
| 1015 | await mirrorWidgets(); | |
| 998 | 1016 | const rows = await read< |
| 999 | 1017 | { fullName: string; mirroredAs: { owner: string; name: string } | null }[] |
| 1000 | 1018 | >(await api(`/api/v1/user/origins/${originId}/repos?refresh=1`)); |
new above
offline