Public: anyone can read this; the crew can change it.
Full suite red: test/name-marks.test.ts #9538
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/9438-full-suite-red-test-name-marks-test-ts → main 2 commits fork 1 thread · 1 unresolved
1 file
changed +55
−27
test/name-marks.test.ts +55 −27
| @@ -32,6 +32,27 @@ import { feedCard } from "../src/web/studio/feed.ts"; | ||
| 32 | 32 | |
| 33 | 33 | const PASSWORD = "a-good-passphrase"; |
| 34 | 34 | |
| 35 | /** | |
| 36 | * One slow step of the setup under its own short deadline, named when it | |
| 37 | * fails: a hang or a throw in a hook shows up as bun's `(unnamed)`, which | |
| 38 | * says nothing (#9438). Setup takes ~2 s whole, so 10 s is a hang. | |
| 39 | */ | |
| 40 | const step = async <T>(label: string, run: () => Promise<T> | T): Promise<T> => { | |
| 41 | let timer: ReturnType<typeof setTimeout> | undefined; | |
| 42 | try { | |
| 43 | return await Promise.race([ | |
| 44 | Promise.resolve().then(run), | |
| 45 | new Promise<never>((_, reject) => { | |
| 46 | timer = setTimeout(() => reject(new Error(`setup step "${label}" took over 10 s`)), 10_000); | |
| 47 | }), | |
| 48 | ]); | |
| 49 | } catch (e) { | |
| 50 | throw new Error(`setup step "${label}" failed: ${e instanceof Error ? e.message : String(e)}`); | |
| 51 | } finally { | |
| 52 | clearTimeout(timer); | |
| 53 | } | |
| 54 | }; | |
| 55 | ||
| 35 | 56 | /** Every way a display name might try to wear the mark. None is the forge's. */ |
| 36 | 57 | const DISGUISES = [ |
| 37 | 58 | "trevato (owner)", |
| @@ -110,23 +131,24 @@ describe("a name always says who it is", () => { | ||
| 110 | 131 | beforeAll(async () => { |
| 111 | 132 | dataDir = await mkdtemp(join(tmpdir(), "forge-name-marks-")); |
| 112 | 133 | app = createApp({ dataDir, port: 0 }); |
| 113 | servers = await serve(app); | |
| 134 | servers = await step("serve", () => serve(app)); | |
| 114 | 135 | base = servers.url; |
| 115 | 136 | alice = await person("alice"); |
| 116 | 137 | mallory = await person("mallory"); |
| 117 | const agent = await createAgent(app, alice, { username: "scout" }); | |
| 138 | const agent = await step("create agent", () => createAgent(app, alice, { username: "scout" })); | |
| 118 | 139 | if (!agent.ok) throw new Error(String(agent.error)); |
| 119 | 140 | scout = agent.value.user; |
| 120 | const made = await createRepo(app, alice, { | |
| 121 | name: "garden", | |
| 122 | visibility: "public", | |
| 123 | }); | |
| 141 | const made = await step("create repo", () => | |
| 142 | createRepo(app, alice, { name: "garden", visibility: "public" }), | |
| 143 | ); | |
| 124 | 144 | if (!made.ok) throw new Error(String(made.error)); |
| 125 | 145 | repo = made.value; |
| 126 | await commitToBranch(app, alice, repo, { | |
| 127 | message: "seed", | |
| 128 | files: [{ path: "README.md", content: "# garden\n" }], | |
| 129 | }); | |
| 146 | await step("seed commit", () => | |
| 147 | commitToBranch(app, alice, repo, { | |
| 148 | message: "seed", | |
| 149 | files: [{ path: "README.md", content: "# garden\n" }], | |
| 150 | }), | |
| 151 | ); | |
| 130 | 152 | insertApp(app.db, { repoId: repo.id, slug: "garden", access: "public" }); |
| 131 | 153 | expect(addToCrew(app, alice, repo, "scout").ok).toBe(true); |
| 132 | 154 | disguise(mallory, DISGUISES[0]!); |
| @@ -150,20 +172,24 @@ describe("a name always says who it is", () => { | ||
| 150 | 172 | ["scout/beds", scout], |
| 151 | 173 | ["mallory/beds", mallory], |
| 152 | 174 | ] as const) { |
| 153 | await commitToBranch(app, alice, repo, { | |
| 154 | branch, | |
| 155 | base: "main", | |
| 156 | message: branch, | |
| 157 | files: [{ path: `${branch.replace("/", "-")}.md`, content: "x\n" }], | |
| 158 | }); | |
| 175 | await step(`commit ${branch}`, () => | |
| 176 | commitToBranch(app, alice, repo, { | |
| 177 | branch, | |
| 178 | base: "main", | |
| 179 | message: branch, | |
| 180 | files: [{ path: `${branch.replace("/", "-")}.md`, content: "x\n" }], | |
| 181 | }), | |
| 182 | ); | |
| 159 | 183 | // A member who cannot write here sends from a branch; a guest needs a fork. |
| 160 | 184 | if (who === mallory) setMember(app.db, mallory.id, true, alice.id, new Date()); |
| 161 | const p = await openPull(app, who, repo, { | |
| 162 | title: `Beds by ${who.username}`, | |
| 163 | body: `Closes #${issueNumber}`, | |
| 164 | baseBranch: "main", | |
| 165 | headBranch: branch, | |
| 166 | }); | |
| 185 | const p = await step(`open pull ${branch}`, () => | |
| 186 | openPull(app, who, repo, { | |
| 187 | title: `Beds by ${who.username}`, | |
| 188 | body: `Closes #${issueNumber}`, | |
| 189 | baseBranch: "main", | |
| 190 | headBranch: branch, | |
| 191 | }), | |
| 192 | ); | |
| 167 | 193 | if (who === mallory) setMember(app.db, mallory.id, false, alice.id, new Date()); |
| 168 | 194 | if (!p.ok) throw new Error(String(p.error)); |
| 169 | 195 | if (who === scout) pull = p.value; |
| @@ -190,11 +216,13 @@ describe("a name always says who it is", () => { | ||
| 190 | 216 | }); |
| 191 | 217 | claimRun(app.db, run.id); |
| 192 | 218 | |
| 193 | const signin = await fetch(`${base}/signin`, { | |
| 194 | method: "POST", | |
| 195 | body: new URLSearchParams({ username: "alice", password: PASSWORD }), | |
| 196 | redirect: "manual", | |
| 197 | }); | |
| 219 | const signin = await step("sign in", () => | |
| 220 | fetch(`${base}/signin`, { | |
| 221 | method: "POST", | |
| 222 | body: new URLSearchParams({ username: "alice", password: PASSWORD }), | |
| 223 | redirect: "manual", | |
| 224 | }), | |
| 225 | ); | |
| 198 | 226 | cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; |
| 199 | 227 | token = createToken(app.db, alice.id, "t", "ro").token; |
| 200 | 228 | }, 30_000); |
new above
offline