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

test/credentials.test.ts runs in under 10 s, every test under 1 s, proving what it proves today #10232

Merged opened this

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

Merged

mason/forge:mason/10228-test-credentials-test-ts-runs-in-under-1 → main 1 commit fork

  • Merged. mason/10228-test-credentials-test-ts-runs-in-under-1 was merged into main as ae45264.

Review

Sign in to review this change.
1 file changed +11 −2
test/credentials.test.ts +11 −2
@@ -56,7 +56,7 @@ async function until<T>(read: () => T | undefined): Promise<T> {
5656 while (Date.now() < deadline) {
5757 const value = read();
5858 if (value !== undefined) return value;
59 await Bun.sleep(50);
59 await Bun.sleep(10);
6060 }
6161 throw new Error("did not happen in time");
6262 }
@@ -80,7 +80,7 @@ if [ "$CLAUDE_CODE_OAUTH_TOKEN" = "${WORK}" ]; then echo "work token used" >&2;
8080 echo '{"type":"system","subtype":"init","session_id":"fake-1","model":"fake"}'
8181 echo '{"type":"assistant","session_id":"fake-1","message":{"id":"msg_1","content":[{"type":"text","text":"working"}],"usage":{"input_tokens":100,"cache_read_input_tokens":900,"output_tokens":50}}}'
8282 if [ -f "${gateDir}/hold" ]; then
83 while [ ! -f "${gateDir}/open" ]; do sleep 0.1; done
83 while [ ! -f "${gateDir}/open" ]; do sleep 0.02; done
8484 fi
8585 echo "work by the crew" >> CREW.md
8686 git add -A && git commit -qm "crew work" && git push -q -u origin HEAD
@@ -95,6 +95,9 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Added CREW
9595 concurrency: 1,
9696 budgetUsd: 2,
9797 runTimeoutMs: 60_000,
98 // The pump picks queued runs on a tick; 5 s by default, 20 ms here, so
99 // the assigned issue's run starts at once rather than on the next tick.
100 tickMs: 20,
98101 });
99102 const a = await createUser(app.db, { origin: "seed", trusted: true,
100103 username: "alice",
@@ -130,6 +133,7 @@ afterAll(async () => {
130133
131134 describe("the platform credential", () => {
132135 test("is a row of its own: listed first, never in the grantable pool, never removed", () => {
136 // Invariant: platform (env) is listed first, is not in the grantable pool, cannot be deleted, and granting it records nothing.
133137 expect(listCredentials(app.db).map((c) => c.name)).toEqual([
134138 "platform (env)",
135139 "trevato-espo",
@@ -145,6 +149,7 @@ describe("the platform credential", () => {
145149
146150 describe("a subscription's scope", () => {
147151 test("one granted nowhere is never picked; one granted elsewhere is not picked here", () => {
152 // Invariant: a subscription is picked for a repository only when granted there; elsewhere the pick falls back to env.
148153 const espo = listSubscriptions(app.db)[0]!;
149154 const scope = { repoId: repo.id, ownerId: alice.id, agentId: bot.id };
150155 expect(pickSubscription(app.db, dataDir, scope, new Date()).kind).toBe("env");
@@ -168,6 +173,7 @@ describe("a subscription's scope", () => {
168173
169174 describe("a repository whose owner is not a forge admin", () => {
170175 test("gets none without a grant and the subscription once granted; an admin's still gets env", async () => {
176 // Invariant: a non-admin owner's repository gets no credential without a grant, the subscription with one; an admin's gets env.
171177 const b = await createUser(app.db, {
172178 origin: "seed",
173179 trusted: true,
@@ -190,6 +196,7 @@ describe("a repository whose owner is not a forge admin", () => {
190196
191197 describe("a crew run on the platform's token", () => {
192198 test("is counted under platform (env), moving while it runs", async () => {
199 // Invariant: a crew run on the platform token is a running ledger line and a usage.delta mid-run, replaced by its result, read the same over the API without the work token.
193200 writeFileSync(join(gateDir, "hold"), "");
194201 const issue = openIssue(app, alice, repo, { title: "Plant tulips", body: "" });
195202 if (!issue.ok) throw new Error(String(issue.error));
@@ -260,6 +267,7 @@ describe("a crew run on the platform's token", () => {
260267
261268 describe("the breakdown", () => {
262269 test("sums by kind and span as a hand would, the costliest runs first", () => {
270 // Invariant: spend sums by span and kind as a hand would, and the top runs are ordered costliest first.
263271 const now = new Date("2026-06-02T12:00:00.000Z");
264272 const line = (runId: string, at: string, costUsd: number, kind: "plan" | "review") =>
265273 recordUsage(app.db, {
@@ -307,6 +315,7 @@ describe("the breakdown", () => {
307315
308316 describe("the board", () => {
309317 test("puts the crew's credentials first and the unscoped account apart, with the spend", async () => {
318 // Invariant: the board and settings pages show the crew's credentials apart from the unscoped account, with the spend views.
310319 const cookie = (
311320 (
312321 await fetch(`${servers.url}/signin`, {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs