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

test/crew-remotes.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10234

Merged opened this

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

Merged

mason/forge:mason/10227-test-crew-remotes-test-ts-runs-in-under → main 1 commit fork

  • Merged. mason/10227-test-crew-remotes-test-ts-runs-in-under was merged into main as 495df99.

Review

Sign in to review this change.
1 file changed +28 −13
test/crew-remotes.test.ts +28 −13
@@ -18,6 +18,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1818 import { createApp, type App } from "../src/app.ts";
1919 import { startCrew, type CrewHandle } from "../src/crew/dispatch.ts";
2020 import { listPulls } from "../src/core/pulls.ts";
21 import type { Issue } from "../src/core/issues.ts";
2122 import type { Repo } from "../src/core/repos.ts";
2223 import { listRuns, type Run } from "../src/core/runs.ts";
2324 import { createUser, type User } from "../src/core/users.ts";
@@ -42,11 +43,11 @@ describe("the remotes an agent is handed", () => {
4243 let remotesFile: string;
4344
4445 async function settled(where: (run: Run) => boolean): Promise<Run> {
45 const deadline = Date.now() + 30_000;
46 const deadline = Date.now() + 4_000;
4647 while (Date.now() < deadline) {
4748 const run = listRuns(app.db, repo.id, { kind: "agent" }).find(where);
4849 if (run && run.state !== "queued" && run.state !== "running") return run;
49 await Bun.sleep(100);
50 await Bun.sleep(20);
5051 }
5152 throw new Error("agent run did not settle");
5253 }
@@ -81,6 +82,8 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
8182 concurrency: 1,
8283 budgetUsd: 1,
8384 runTimeoutMs: 60_000,
85 // The pump's clock: a run queued is taken on the next tick, not 5 s on.
86 tickMs: 20,
8487 });
8588 const a = await createUser(app.db, {
8689 origin: "seed",
@@ -116,18 +119,26 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
116119 await rm(dataDir, { recursive: true, force: true });
117120 });
118121
122 // The issue and its first run, made by the first test; the second visits
123 // the clone that run left.
124 let issue: Issue;
125 let firstRun: Run;
126
119127 // The stand-in runs outside any sandbox, so what this proves is the
120128 // address the agent is handed and that a plain push over it lands — not
121129 // the sandbox's own reach, which is Claude Code's to hold.
122130 test("carry the forge's public URL, fetch from the repository and push to the agent's fork, and a plain push lands", async () => {
131 // Invariant: a fresh clone's fetch and push remotes are the forge's public URL, and a plain `git push` over them opens the pull.
123132 expect(publicUrl).not.toBe(servers.url);
124 const issue = openIssue(app, alice, repo, {
133 const opened = openIssue(app, alice, repo, {
125134 title: "Plant tulips",
126135 body: "Along the fence.",
127136 });
128 if (!issue.ok) throw new Error(String(issue.error));
129 expect(assignIssue(app, alice, repo, issue.value, bot).ok).toBe(true);
130 const run = await settled((r) => r.issueId === issue.value.id);
137 if (!opened.ok) throw new Error(String(opened.error));
138 issue = opened.value;
139 expect(assignIssue(app, alice, repo, issue, bot).ok).toBe(true);
140 const run = await settled((r) => r.issueId === issue.id);
141 firstRun = run;
131142 expect(run.state).toBe("ok");
132143 expect(run.summary).toMatch(/^opened pull #\d+( \([0-9a-f]{7,40}\))?$/);
133144 const [fetchUrl, pushUrl] = readFileSync(remotesFile, "utf8")
@@ -137,16 +148,20 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
137148 expect(pushUrl).toBe(`${publicUrl}/bot/garden.git`);
138149 const pull = listPulls(app.db, repo.id, { state: "open" })[0]!;
139150 expect(pull.headBranch).toBe(run.branch);
151 });
140152
141 // A clone kept from before the forge changed where its remotes point —
142 // a run resumed after a release — is set right again on every visit,
143 // not only when it is first made.
153 // A clone kept from before the forge changed where its remotes point —
154 // a run resumed after a release — is set right again on every visit,
155 // not only when it is first made.
156 test("are set right again on a kept clone whose remotes went stale", async () => {
157 // Invariant: a kept clone's stale remotes are reset to the forge's public URL on every visit, and the next push updates the pull.
158 expect(firstRun?.state).toBe("ok");
144159 const clone = join(
145160 dataDir,
146161 "crew",
147162 "bot",
148163 repo.id,
149 String(issue.value.number),
164 String(issue.number),
150165 );
151166 for (const key of ["remote.origin.url", "remote.origin.pushurl"]) {
152167 const stale = Bun.spawnSync(
@@ -159,12 +174,12 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
159174 app,
160175 alice,
161176 repo,
162 issue.value,
177 issue,
163178 "Also plant daffodils.",
164179 );
165180 if (!said.ok) throw new Error(String(said.error));
166181 const again = await settled(
167 (r) => r.issueId === issue.value.id && r.id !== run.id,
182 (r) => r.issueId === issue.id && r.id !== firstRun.id,
168183 );
169184 expect(again.state).toBe("ok");
170185 expect(again.summary).toMatch(/^updated pull #\d+/);
@@ -173,5 +188,5 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
173188 .split("\n");
174189 expect(fetchAgain).toBe(`${publicUrl}/alice/garden.git`);
175190 expect(pushAgain).toBe(`${publicUrl}/bot/garden.git`);
176 }, 90_000);
191 });
177192 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs