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

signup-fresh: main.ts's part is the seedSignup option, read from its createApp call, not a boot timed against a clock #17198

opened this

Merged 47h 1m ago, live in production

fix/signup-fresh-boot → main 0 commits

  • Merged. fix/signup-fresh-boot was merged into main as f264c2b.

Review

Sign in to review this change.
2 files changed +12 −29
scripts/test-honesty-allow.json −1
@@ -368,7 +368,6 @@
368368 "test/signin-page.test.ts": {"wait":1},
369369 "test/signin-password-doors.test.ts": {"wait":1},
370370 "test/signins.test.ts": {"wait":5},
371 "test/signup-fresh.test.ts": {"wait":1},
372371 "test/snapshot-destination.test.ts": {"wait":2},
373372 "test/snapshot-drill-page.test.ts": {"wait":2},
374373 "test/snapshot-one-core.test.ts": {"wait":2},
test/signup-fresh.test.ts +12 −28
@@ -4,10 +4,9 @@
44 */
55
66 import { describe, expect, test } from "bun:test";
7 import { mkdtempSync } from "node:fs";
7 import { mkdtempSync, readFileSync } from "node:fs";
88 import { tmpdir } from "node:os";
99 import { join } from "node:path";
10 import { Database } from "bun:sqlite";
1110 import { createApp } from "../src/app.ts";
1211 import { getSignup, seedSignup, setSignup, signupChanges } from "../src/settings/signup.ts";
1312
@@ -69,30 +68,15 @@ describe("createApp with seedSignup", () => {
6968 });
7069
7170 describe("main.ts", () => {
72 test("booting on an empty data directory stores invite", async () => {
73 const dir = mkdtempSync(join(tmpdir(), "fresh-"));
74 const proc = Bun.spawn(["bun", "run", join(import.meta.dir, "../src/main.ts")], {
75 env: { ...process.env, FORGE_DATA: dir, FORGE_APP_DATA: "", FORGE_SIGNUP: "", PORT: "0", FORGE_PORT: "0" },
76 stdout: "ignore",
77 stderr: "ignore",
78 });
79 try {
80 // A wall-clock deadline, not a count of tries: a loaded check box has booted main.ts in
81 // 11.8 s (the gate box's usual is 3.1 s), and what this asserts is the stored value.
82 const deadline = Date.now() + 40_000;
83 let value: string | undefined;
84 while (value === undefined && Date.now() < deadline) {
85 await Bun.sleep(100);
86 try {
87 const db = new Database(join(dir, "forge.db"), { readonly: true });
88 value = db.query<{ value: string }, []>("SELECT value FROM forge_setting WHERE key = 'signup'").get()?.value;
89 db.close();
90 } catch {}
91 }
92 expect(value).toBe("invite");
93 } finally {
94 proc.kill();
95 await proc.exited;
96 }
97 }, 60_000);
71 // The forge's own boot asks createApp to seed (the tests above show what that stores). Booting
72 // main.ts to read it back timed a whole boot, every migration from nothing, against a clock: on a
73 // loaded runner that took 10.5 to 11.8 s against a 10 s wait (06:25, 11:10, 14:59 on 2026-12-01),
74 // and raising the wait only moves the line. What main.ts adds is this one option, read here.
75 test("the forge's boot asks createApp to seed signup = invite on an empty data directory", () => {
76 const main = readFileSync(join(import.meta.dir, "../src/main.ts"), "utf8");
77 const start = main.indexOf("const app = createApp({");
78 expect(start).toBeGreaterThan(-1);
79 const call = main.slice(start, main.indexOf("\n});", start));
80 expect(call).toMatch(/^\s*seedSignup: true,$/m);
81 });
9882 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs