Public: anyone can read this; the crew can change it.
Full suite red: test/stranger-first-ask-journey.test.ts #12675
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12654-full-suite-red-test-stranger-first-ask-j → main 6 commits fork
1 file
changed +29
−15
test/stranger-first-ask-journey.test.ts +29 −15
| @@ -24,7 +24,7 @@ import { listAgents } from "../src/core/agents.ts"; | ||
| 24 | 24 | import { startCrew, type CrewHandle } from "../src/crew/dispatch.ts"; |
| 25 | 25 | import { useProbe } from "../src/spawn/door.ts"; |
| 26 | 26 | import { firstBoot } from "../src/spawn/first-boot.ts"; |
| 27 | import { writeStandInClaude } from "./helpers/crew-standin.ts"; | |
| 27 | import { STAND_IN_TICK_MS, writeStandInClaude } from "./helpers/crew-standin.ts"; | |
| 28 | 28 | import { quietLogs } from "./helpers/globals.ts"; |
| 29 | 29 | |
| 30 | 30 | quietLogs(); |
| @@ -125,18 +125,25 @@ const since = (t0: number) => Math.ceil((performance.now() - t0) / 1000); | ||
| 125 | 125 | let ask = ""; |
| 126 | 126 | let homeHtml = ""; |
| 127 | 127 | |
| 128 | test("the walk: link, first screen, one sentence, the crew at work", async () => { | |
| 128 | const record = async (name: string, res: Response, counted: boolean) => { | |
| 129 | const html = res.headers.get("content-type")?.includes("html") ? await res.text() : ""; | |
| 130 | screens.push({ name, status: res.status, html, counted }); | |
| 131 | return html; | |
| 132 | }; | |
| 133 | let t0 = 0; | |
| 134 | let t1 = 0; | |
| 135 | let cookie = ""; | |
| 136 | let homeUrl = ""; | |
| 137 | ||
| 138 | // The walk is two tests, each inside the 2 s test budget: the stranger's path | |
| 139 | // to the ask, then the crew's answer. The second says so when the first failed. | |
| 140 | test("the walk: link, first screen, one sentence, the crew standing by", async () => { | |
| 129 | 141 | up = true; |
| 130 | const record = async (name: string, res: Response, counted: boolean) => { | |
| 131 | const html = res.headers.get("content-type")?.includes("html") ? await res.text() : ""; | |
| 132 | screens.push({ name, status: res.status, html, counted }); | |
| 133 | return html; | |
| 134 | }; | |
| 135 | 142 | |
| 136 | 143 | // Screen 1: the home page, no cookies; the name goes in the form it carries. |
| 137 | 144 | const home = await fetch(`${parentServers.url}/`); |
| 138 | 145 | expect(await record("home", home, true)).toContain('id="start-forge"'); |
| 139 | const t0 = performance.now(); | |
| 146 | t0 = performance.now(); | |
| 140 | 147 | const started = await fetch(`${parentServers.url}/forges/start`, { |
| 141 | 148 | method: "POST", |
| 142 | 149 | headers: { "content-type": "application/x-www-form-urlencoded" }, |
| @@ -171,7 +178,7 @@ test("the walk: link, first screen, one sentence, the crew at work", async () => | ||
| 171 | 178 | redirect: "manual", |
| 172 | 179 | }); |
| 173 | 180 | expect(claimed.status).toBe(303); |
| 174 | const cookie = (claimed.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; | |
| 181 | cookie = (claimed.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; | |
| 175 | 182 | expect(cookie).not.toBe(""); |
| 176 | 183 | |
| 177 | 184 | // Screen 3: the forge's first screen. One sentence through its own form. |
| @@ -179,7 +186,7 @@ test("the walk: link, first screen, one sentence, the crew at work", async () => | ||
| 179 | 186 | const landing = await fetch(landed, { headers: { cookie } }); |
| 180 | 187 | expect(landing.status).toBe(200); |
| 181 | 188 | const first = await record("forge", landing, true); |
| 182 | const t1 = performance.now(); | |
| 189 | t1 = performance.now(); | |
| 183 | 190 | const formTag = /<form[^>]*action="\/tell"[^>]*>([\s\S]*?)<\/form>/.exec(first); |
| 184 | 191 | expect(formTag).not.toBeNull(); |
| 185 | 192 | const fields = new URLSearchParams(); |
| @@ -204,15 +211,16 @@ test("the walk: link, first screen, one sentence, the crew at work", async () => | ||
| 204 | 211 | // row on the forge's home, polled until it shows and timed from the post. |
| 205 | 212 | // The row's "Waiting for the crew." is the forge's echo of the ask, drawn by |
| 206 | 213 | // the same request that stores it, so it is not counted. |
| 207 | const homeUrl = `${childServers.url}${posted.headers.get("location") ?? "/"}`; | |
| 214 | homeUrl = `${childServers.url}${posted.headers.get("location") ?? "/"}`; | |
| 208 | 215 | // The page the post lands on, before any crew run: the forge's echo of the |
| 209 | 216 | // ask, checked like every screen. |
| 210 | 217 | const echoed = await fetch(homeUrl, { headers: { cookie } }); |
| 211 | 218 | const echoHtml = await record("forge after the ask", echoed, false); |
| 212 | 219 | expect(echoHtml).toContain("Waiting for the crew."); |
| 213 | 220 | expect(crewRow(echoHtml)).toBe(false); |
| 214 | // Then the child's crew, as `main.ts` starts it, with the stand-in for | |
| 215 | // Claude Code: started after the post, so its timing only grows stricter. | |
| 221 | // The child's crew, as `main.ts` starts it, with the stand-in for Claude Code, | |
| 222 | // started after the echo is checked (it would answer the echo away) and | |
| 223 | // inside the first test, so its start is not spent in the answer's own test. | |
| 216 | 224 | crew = await startCrew(child, { |
| 217 | 225 | forgeUrl: childServers.url, |
| 218 | 226 | localUrl: childServers.url, |
| @@ -221,13 +229,19 @@ test("the walk: link, first screen, one sentence, the crew at work", async () => | ||
| 221 | 229 | budgetUsd: 1, |
| 222 | 230 | runTimeoutMs: 60_000, |
| 223 | 231 | networkRetryScale: 0, |
| 224 | tickMs: 200, | |
| 232 | tickMs: STAND_IN_TICK_MS, | |
| 225 | 233 | }); |
| 234 | }); | |
| 235 | ||
| 236 | test("the walk: the crew answers", async () => { | |
| 237 | if (child === undefined || homeUrl === "") { | |
| 238 | throw new Error("the walk above did not reach the ask; fix that failure first"); | |
| 239 | } | |
| 226 | 240 | const deadline = performance.now() + FIRST_FIVE_MINUTES.firstCrewActivitySeconds * 1000; |
| 227 | 241 | let back = await fetch(homeUrl, { headers: { cookie } }); |
| 228 | 242 | homeHtml = await back.text(); |
| 229 | 243 | while (!crewRow(homeHtml) && performance.now() < deadline) { |
| 230 | await Bun.sleep(100); | |
| 244 | await Bun.sleep(25); // real-timer: polls a real crew run in a child process | |
| 231 | 245 | back = await fetch(homeUrl, { headers: { cookie } }); |
| 232 | 246 | homeHtml = await back.text(); |
| 233 | 247 | } |
new above
offline