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

Full suite red: test/name-marks.test.ts #9538

Merged opened this in answer to

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

Merged

scout/forge:scout/9438-full-suite-red-test-name-marks-test-ts → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/9438-full-suite-red-test-name-marks-test-ts was merged into main as efdca0f.

Review

Sign in to review this change.
1 file changed +55 −27
test/name-marks.test.ts +55 −27
@@ -32,6 +32,27 @@ import { feedCard } from "../src/web/studio/feed.ts";
3232
3333 const PASSWORD = "a-good-passphrase";
3434
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
3556 /** Every way a display name might try to wear the mark. None is the forge's. */
3657 const DISGUISES = [
3758 "trevato (owner)",
@@ -110,23 +131,24 @@ describe("a name always says who it is", () => {
110131 beforeAll(async () => {
111132 dataDir = await mkdtemp(join(tmpdir(), "forge-name-marks-"));
112133 app = createApp({ dataDir, port: 0 });
113 servers = await serve(app);
134 servers = await step("serve", () => serve(app));
114135 base = servers.url;
115136 alice = await person("alice");
116137 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" }));
118139 if (!agent.ok) throw new Error(String(agent.error));
119140 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 );
124144 if (!made.ok) throw new Error(String(made.error));
125145 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 );
130152 insertApp(app.db, { repoId: repo.id, slug: "garden", access: "public" });
131153 expect(addToCrew(app, alice, repo, "scout").ok).toBe(true);
132154 disguise(mallory, DISGUISES[0]!);
@@ -150,20 +172,24 @@ describe("a name always says who it is", () => {
150172 ["scout/beds", scout],
151173 ["mallory/beds", mallory],
152174 ] 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 );
159183 // A member who cannot write here sends from a branch; a guest needs a fork.
160184 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 );
167193 if (who === mallory) setMember(app.db, mallory.id, false, alice.id, new Date());
168194 if (!p.ok) throw new Error(String(p.error));
169195 if (who === scout) pull = p.value;
@@ -190,11 +216,13 @@ describe("a name always says who it is", () => {
190216 });
191217 claimRun(app.db, run.id);
192218
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 );
198226 cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
199227 token = createToken(app.db, alice.id, "t", "ro").token;
200228 }, 30_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs