Public: anyone can read this; the crew can change it.
The two slow tests in test/snapshot-hosted-inside.test.ts run under 1 s alone and under 2 s in the full suite #15196
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15191-the-two-slow-tests-in-test-snapshot-host → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +40
−42
test/preview-looks.test.ts +40 −42
| @@ -94,6 +94,21 @@ describe("the seeded first issue", () => { | ||
| 94 | 94 | |
| 95 | 95 | describe("the owner's settings pages (#9781)", () => { |
| 96 | 96 | const pages = ["/settings/tokens", "/settings/crew", "/settings/subscriptions", "/settings/usage"]; |
| 97 | // One seeded preview for the tests that read a seeded one: the first seed is most of a second | |
| 98 | // (#15191), the fixture's cost and not each test's. A test that removes rows from it seeds | |
| 99 | // them back before it ends; the refusal test needs an unseeded forge and makes its own. | |
| 100 | let dir: string; | |
| 101 | let app: App; | |
| 102 | beforeAll(async () => { | |
| 103 | dir = await mkdtemp(join(tmpdir(), "forge-preview-settings-")); | |
| 104 | app = createApp({ dataDir: dir, port: 0 }); | |
| 105 | const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 106 | if (!seeded.ok) throw new Error(seeded.error); | |
| 107 | }, 60_000); | |
| 108 | afterAll(async () => { | |
| 109 | app.close(); | |
| 110 | await rm(dir, { recursive: true, force: true }); | |
| 111 | }); | |
| 97 | 112 | test("each is named at desk and phone", () => { |
| 98 | 113 | for (const page of pages) |
| 99 | 114 | for (const kind of ["desktop", "phone"] as const) |
| @@ -101,28 +116,19 @@ describe("the owner's settings pages (#9781)", () => { | ||
| 101 | 116 | }); |
| 102 | 117 | |
| 103 | 118 | test("the seed gives each a row and answers 200 to the owner", async () => { |
| 104 | const dir = await mkdtemp(join(tmpdir(), "forge-preview-settings-")); | |
| 105 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 106 | try { | |
| 107 | const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 108 | if (!seeded.ok) throw new Error(seeded.error); | |
| 109 | const admin = previewAdmin(app)!; | |
| 110 | const cookie = `forge_session=${createSession(app.db, admin.id).token}`; | |
| 111 | const http = forgeHttp(app); | |
| 112 | const get = async (p: string) => { | |
| 113 | const res = await http.handle(new Request(`http://localhost${p}`, { headers: { cookie } })); | |
| 114 | expect(res.status).toBe(200); | |
| 115 | return res.text(); | |
| 116 | }; | |
| 117 | expect(await get("/settings/tokens")).toContain("preview fake token"); | |
| 118 | expect(await get("/settings/crew")).toContain("preview-agent"); | |
| 119 | expect(await get("/settings/subscriptions")).toContain("preview sample"); | |
| 120 | await get("/settings/usage"); | |
| 121 | } finally { | |
| 122 | app.close(); | |
| 123 | await rm(dir, { recursive: true, force: true }); | |
| 124 | } | |
| 125 | }, 60_000); | |
| 119 | const admin = previewAdmin(app)!; | |
| 120 | const cookie = `forge_session=${createSession(app.db, admin.id).token}`; | |
| 121 | const http = forgeHttp(app); | |
| 122 | const get = async (p: string) => { | |
| 123 | const res = await http.handle(new Request(`http://localhost${p}`, { headers: { cookie } })); | |
| 124 | expect(res.status).toBe(200); | |
| 125 | return res.text(); | |
| 126 | }; | |
| 127 | expect(await get("/settings/tokens")).toContain("preview fake token"); | |
| 128 | expect(await get("/settings/crew")).toContain("preview-agent"); | |
| 129 | expect(await get("/settings/subscriptions")).toContain("preview sample"); | |
| 130 | await get("/settings/usage"); | |
| 131 | }); | |
| 126 | 132 | |
| 127 | 133 | test("a named page that is not 200 refuses the seed, naming the path, and a retry adds no second token", async () => { |
| 128 | 134 | const dir = await mkdtemp(join(tmpdir(), "forge-preview-refuse-")); |
| @@ -143,24 +149,16 @@ describe("the owner's settings pages (#9781)", () => { | ||
| 143 | 149 | }, 60_000); |
| 144 | 150 | |
| 145 | 151 | test("a preview already seeded gets its settings rows once, and a second seed adds no token", async () => { |
| 146 | const dir = await mkdtemp(join(tmpdir(), "forge-preview-older-")); | |
| 147 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 148 | try { | |
| 149 | const first = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 150 | if (!first.ok) throw new Error(first.error); | |
| 151 | const admin = previewAdmin(app)!; | |
| 152 | // An older preview: world seeded, settings rows not. | |
| 153 | app.db.query("DELETE FROM token WHERE user_id = ?1").run(admin.id); | |
| 154 | app.db.query("DELETE FROM user_setting WHERE user_id = ?1 AND key = 'preview_settings_seeded'").run(admin.id); | |
| 155 | expect(listTokens(app.db, admin.id).length).toBe(0); | |
| 156 | const again = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 157 | expect(again.ok && again.value.seeded).toBe(false); | |
| 158 | expect(listTokens(app.db, admin.id).map((t) => t.name)).toEqual(["preview fake token, not a credential"]); | |
| 159 | await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 160 | expect(listTokens(app.db, admin.id).length).toBe(1); | |
| 161 | } finally { | |
| 162 | app.close(); | |
| 163 | await rm(dir, { recursive: true, force: true }); | |
| 164 | } | |
| 165 | }, 60_000); | |
| 152 | const admin = previewAdmin(app)!; | |
| 153 | // An older preview: world seeded, settings rows not. The seed below puts back what this | |
| 154 | // removes (one token, the seeded mark), so the shared forge ends as it began. | |
| 155 | app.db.query("DELETE FROM token WHERE user_id = ?1").run(admin.id); | |
| 156 | app.db.query("DELETE FROM user_setting WHERE user_id = ?1 AND key = 'preview_settings_seeded'").run(admin.id); | |
| 157 | expect(listTokens(app.db, admin.id).length).toBe(0); | |
| 158 | const again = await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 159 | expect(again.ok && again.value.seeded).toBe(false); | |
| 160 | expect(listTokens(app.db, admin.id).map((t) => t.name)).toEqual(["preview fake token, not a credential"]); | |
| 161 | await seedPreview(app, { FORGE_APP_ENV: "preview" }); | |
| 162 | expect(listTokens(app.db, admin.id).length).toBe(1); | |
| 163 | }); | |
| 166 | 164 | }); |
new above
offline
Shared fixture is sound; the comment states the restore contract. If a later test mutates the shared forge without restoring, order dependence appears: keep that rule.