End-to-end tests: apply the database migrations once per run, not once per test file (#235)
* End-to-end tests: apply the database migrations once per run, not once per test file
16 files changed+68−16
Files (16)
- apps/diffinery/test/e2e/accounts.test.mjs+2−1
- apps/diffinery/test/e2e/agentic.test.mjs+2−1
- apps/diffinery/test/e2e/agents-harness.mjs+2−1
- apps/diffinery/test/e2e/d1-state.mjs+37−0
- apps/diffinery/test/e2e/e2e.test.mjs+2−1
- apps/diffinery/test/e2e/early-access.test.mjs+2−1
- apps/diffinery/test/e2e/email.test.mjs+2−1
- apps/diffinery/test/e2e/graphql.test.mjs+2−1
- apps/diffinery/test/e2e/moderation.test.mjs+2−1
- apps/diffinery/test/e2e/oauth.test.mjs+2−1
- apps/diffinery/test/e2e/passkeys.test.mjs+3−2
- apps/diffinery/test/e2e/registry.test.mjs+2−1
- apps/diffinery/test/e2e/review.test.mjs+2−1
- apps/diffinery/test/e2e/security-txt.test.mjs+2−1
- apps/diffinery/test/e2e/security.test.mjs+2−1
- apps/diffinery/test/e2e/status.test.mjs+2−1
modifiedapps/diffinery/test/e2e/accounts.test.mjs+2−1View file
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | import { createServer } from "node:net"; |
| 17 | 17 | import { test, before, after } from "node:test"; |
| 18 | 18 | import assert from "node:assert/strict"; |
| 19 | +import { migratedState } from "./d1-state.mjs"; | |
| 19 | 20 | |
| 20 | 21 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 21 | 22 | const work = mkdtempSync(join(tmpdir(), "diffinery-accounts-")); |
| @@ -128,7 +129,7 @@ | ||
| 128 | 129 | base = `http://127.0.0.1:${port}`; |
| 129 | 130 | const persist = join(work, "state"); |
| 130 | 131 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 131 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 132 | + migratedState(APP, persist); | |
| 132 | 133 | const at = new Date().toISOString(); |
| 133 | 134 | const hoursAgo = (h) => new Date(Date.now() - h * 3600_000).toISOString(); |
| 134 | 135 | const later = new Date(Date.now() + 30 * 86400_000).toISOString(); |
modifiedapps/diffinery/test/e2e/agentic.test.mjs+2−1View file
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | import { createServer } from "node:net"; |
| 16 | 16 | import { test, before, after } from "node:test"; |
| 17 | 17 | import assert from "node:assert/strict"; |
| 18 | +import { migratedState } from "./d1-state.mjs"; | |
| 18 | 19 | |
| 19 | 20 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 20 | 21 | const work = mkdtempSync(join(tmpdir(), "diffinery-agentic-e2e-")); |
| @@ -86,7 +87,7 @@ | ||
| 86 | 87 | const port = await freePort(); |
| 87 | 88 | base = `http://127.0.0.1:${port}`; |
| 88 | 89 | const persist = join(work, "state"); |
| 89 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 90 | + migratedState(APP, persist); | |
| 90 | 91 | dev = spawn("pnpm", ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--var", `MASTER_KEY:${randomBytes(32).toString("base64")}`, "--show-interactive-dev-session=false"], { |
| 91 | 92 | cwd: APP, |
| 92 | 93 | env: { ...process.env, CI: "1", WRANGLER_SEND_METRICS: "false" }, |
modifiedapps/diffinery/test/e2e/agents-harness.mjs+2−1View file
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | import { createServer as httpServer } from "node:http"; |
| 13 | 13 | import { before, after } from "node:test"; |
| 14 | 14 | import assert from "node:assert/strict"; |
| 15 | +import { migratedState } from "./d1-state.mjs"; | |
| 15 | 16 | |
| 16 | 17 | export const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 17 | 18 | export const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| @@ -190,7 +191,7 @@ | ||
| 190 | 191 | const port = await freePort(); |
| 191 | 192 | base = `http://127.0.0.1:${port}`; |
| 192 | 193 | const persist = join(work, "state"); |
| 193 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 194 | + migratedState(APP, persist); | |
| 194 | 195 | // A second person, signed in with a session: not the terminal's opener, whatever their role. |
| 195 | 196 | { |
| 196 | 197 | const at = new Date().toISOString(); |
addedapps/diffinery/test/e2e/d1-state.mjs+37−0View file
| @@ -1,0 +1,37 @@ | ||
| 1 | +// A fresh local database for an end-to-end test's `wrangler dev --persist-to` directory, with | |
| 2 | +// every migration applied. | |
| 3 | +// | |
| 4 | +// `wrangler d1 migrations apply --local` takes about 20 s (most of a test file's start), and | |
| 5 | +// every file used to pay it. The first call in a run applies the migrations once, the same way, | |
| 6 | +// into a template in the OS temp directory; every call then copies that template, which takes | |
| 7 | +// milliseconds. The template's name carries a hash of the migrations, the Wrangler config and | |
| 8 | +// Wrangler's version, so a change to any of them builds a new one. It is built in a directory | |
| 9 | +// of its own and renamed into place, so test files starting side by side never copy half of one. | |
| 10 | +import { execFileSync } from "node:child_process"; | |
| 11 | +import { cpSync, existsSync, readdirSync, readFileSync, renameSync, rmSync } from "node:fs"; | |
| 12 | +import { tmpdir } from "node:os"; | |
| 13 | +import { createHash, randomBytes } from "node:crypto"; | |
| 14 | +import { createRequire } from "node:module"; | |
| 15 | +import { join } from "node:path"; | |
| 16 | + | |
| 17 | +/** Copies a database with every migration applied into `persist` (the `--persist-to` directory). */ | |
| 18 | +export function migratedState(app, persist) { | |
| 19 | + const migrations = join(app, "migrations"); | |
| 20 | + const hash = createHash("sha256"); | |
| 21 | + for (const name of readdirSync(migrations).sort()) hash.update(`${name}\0`).update(readFileSync(join(migrations, name))).update("\0"); | |
| 22 | + hash.update(readFileSync(join(app, "wrangler.jsonc"))); | |
| 23 | + hash.update(createRequire(join(app, "package.json"))("wrangler/package.json").version); | |
| 24 | + const template = join(tmpdir(), `diffinery-e2e-d1-${hash.digest("hex").slice(0, 16)}`); | |
| 25 | + if (!existsSync(template)) { | |
| 26 | + const building = `${template}.building-${process.pid}-${randomBytes(4).toString("hex")}`; | |
| 27 | + execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", building], { cwd: app, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 28 | + try { | |
| 29 | + renameSync(building, template); | |
| 30 | + } catch (e) { | |
| 31 | + // Another test file finished the same template first. | |
| 32 | + if (!existsSync(template)) throw e; | |
| 33 | + rmSync(building, { recursive: true, force: true }); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + cpSync(template, persist, { recursive: true }); | |
| 37 | +} |
modifiedapps/diffinery/test/e2e/e2e.test.mjs+2−1View file
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | import { test, before, after } from "node:test"; |
| 20 | 20 | import assert from "node:assert/strict"; |
| 21 | 21 | import { fakeGitHub, lfsObject } from "./fake-github.mjs"; |
| 22 | +import { migratedState } from "./d1-state.mjs"; | |
| 22 | 23 | |
| 23 | 24 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 24 | 25 | const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| @@ -178,7 +179,7 @@ | ||
| 178 | 179 | const port = await freePort(); |
| 179 | 180 | base = `http://127.0.0.1:${port}`; |
| 180 | 181 | const persist = join(work, "state"); |
| 181 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 182 | + migratedState(APP, persist); | |
| 182 | 183 | // Until the web UI exists, run the same app through the API-only entry. |
| 183 | 184 | const entry = existsSync(join(APP, "src/web/routes.tsx")) ? [] : ["test/e2e/entry.ts"]; |
| 184 | 185 | const out = openSync(devLogFile, "a"); |
modifiedapps/diffinery/test/e2e/early-access.test.mjs+2−1View file
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | import { request as httpRequest } from "node:http"; |
| 21 | 21 | import { test, after } from "node:test"; |
| 22 | 22 | import assert from "node:assert/strict"; |
| 23 | +import { migratedState } from "./d1-state.mjs"; | |
| 23 | 24 | |
| 24 | 25 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 25 | 26 | const work = mkdtempSync(join(tmpdir(), "diffinery-early-access-e2e-")); |
| @@ -92,7 +93,7 @@ | ||
| 92 | 93 | const session = (account, cookie) => `INSERT INTO sessions (id, account_id, method, created_at, last_seen_at, expires_at) VALUES ('${hash(cookie)}', '${account}', 'passkey', '${at}', '${at}', '${later}')`; |
| 93 | 94 | const seed = [person("u-root", "root", "root@example.com", 1), person("u-ann", "ann", "ann@example.com", 0), token("t-root", "u-root", T.root), token("t-ann", "u-ann", T.ann), session("u-root", S.root), session("u-ann", S.ann)]; |
| 94 | 95 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 95 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 96 | + migratedState(APP, persist); | |
| 96 | 97 | wrangler("d1", "execute", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist, "--command", seed.join("; ")); |
| 97 | 98 | const args = ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--show-interactive-dev-session=false"]; |
| 98 | 99 | const dev = spawn("pnpm", args, { cwd: APP, env: { ...process.env, CI: "1", WRANGLER_SEND_METRICS: "false" }, stdio: ["ignore", "pipe", "pipe"], detached: true }); |
modifiedapps/diffinery/test/e2e/email.test.mjs+2−1View file
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import { test, before, after } from "node:test"; |
| 22 | 22 | import assert from "node:assert/strict"; |
| 23 | 23 | import { chromium } from "playwright"; |
| 24 | +import { migratedState } from "./d1-state.mjs"; | |
| 24 | 25 | |
| 25 | 26 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 26 | 27 | const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| @@ -128,7 +129,7 @@ | ||
| 128 | 129 | const port = await freePort(); |
| 129 | 130 | base = `http://127.0.0.1:${port}`; |
| 130 | 131 | const persist = join(work, "state"); |
| 131 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 132 | + migratedState(APP, persist); | |
| 132 | 133 | dev = spawn("pnpm", ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--var", `MASTER_KEY:${randomBytes(32).toString("base64")}`, "--var", `MAIL_EVENTS_SECRET:${eventsSecret}`, "--show-interactive-dev-session=false"], { |
| 133 | 134 | cwd: APP, |
| 134 | 135 | env: { ...process.env, CI: "1", WRANGLER_SEND_METRICS: "false" }, |
modifiedapps/diffinery/test/e2e/graphql.test.mjs+2−1View file
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | import { createServer } from "node:net"; |
| 16 | 16 | import { test, before, after } from "node:test"; |
| 17 | 17 | import assert from "node:assert/strict"; |
| 18 | +import { migratedState } from "./d1-state.mjs"; | |
| 18 | 19 | |
| 19 | 20 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 20 | 21 | const work = mkdtempSync(join(tmpdir(), "diffinery-graphql-e2e-")); |
| @@ -43,7 +44,7 @@ | ||
| 43 | 44 | const later = new Date(Date.now() + 30 * 86400_000).toISOString(); |
| 44 | 45 | const person = (id, login) => `INSERT INTO accounts (id, login, kind, name, email, status, site_admin, created_at) VALUES ('${id}', '${login}', 'user', '${login}', '${login}@example.com', 'active', 0, '${at}')`; |
| 45 | 46 | const token = (id, account, t, scope) => `INSERT INTO tokens (id, account_id, name, token_hash, prefix, scopes, expires_at, created_at) VALUES ('${id}', '${account}', 'e2e', '${hash(t)}', '${t.slice(0, 10)}', '["${scope}"]', '${later}', '${at}')`; |
| 46 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 47 | + migratedState(APP, persist); | |
| 47 | 48 | wrangler("d1", "execute", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist, "--command", [person("u-ann", "ann"), person("u-bob", "bob"), token("t-ann", "u-ann", T.ann, "admin"), token("t-anr", "u-ann", T.annRead, "read"), token("t-bob", "u-bob", T.bob, "admin")].join("; ")); |
| 48 | 49 | // No fixed dev identity (DEV_AUTH empty), so a request without a token is anonymous. |
| 49 | 50 | dev = spawn("pnpm", ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--var", "DEV_AUTH:", "--show-interactive-dev-session=false"], { |
modifiedapps/diffinery/test/e2e/moderation.test.mjs+2−1View file
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | import { createServer } from "node:net"; |
| 18 | 18 | import { test, before, after } from "node:test"; |
| 19 | 19 | import assert from "node:assert/strict"; |
| 20 | +import { migratedState } from "./d1-state.mjs"; | |
| 20 | 21 | |
| 21 | 22 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 22 | 23 | const work = mkdtempSync(join(tmpdir(), "diffinery-moderation-")); |
| @@ -89,7 +90,7 @@ | ||
| 89 | 90 | base = `http://127.0.0.1:${port}`; |
| 90 | 91 | const persist = join(work, "state"); |
| 91 | 92 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 92 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 93 | + migratedState(APP, persist); | |
| 93 | 94 | const at = new Date().toISOString(); |
| 94 | 95 | const later = new Date(Date.now() + 30 * 86400_000).toISOString(); |
| 95 | 96 | const account = (id, login, kind) => `INSERT INTO accounts (id, login, kind, name, status, created_at) VALUES ('${id}', '${login}', '${kind}', '${login}', 'active', '${at}')`; |
modifiedapps/diffinery/test/e2e/oauth.test.mjs+2−1View file
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import { test, before, after } from "node:test"; |
| 19 | 19 | import assert from "node:assert/strict"; |
| 20 | 20 | import { chromium } from "playwright"; |
| 21 | +import { migratedState } from "./d1-state.mjs"; | |
| 21 | 22 | |
| 22 | 23 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 23 | 24 | const work = mkdtempSync(join(tmpdir(), "diffinery-oauth-")); |
| @@ -58,7 +59,7 @@ | ||
| 58 | 59 | const port = await freePort(); |
| 59 | 60 | base = `http://localhost:${port}`; |
| 60 | 61 | persist = join(work, "state"); |
| 61 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 62 | + migratedState(APP, persist); | |
| 62 | 63 | const at = new Date().toISOString(); |
| 63 | 64 | const later = new Date(Date.now() + 86400_000).toISOString(); |
| 64 | 65 | sql( |
modifiedapps/diffinery/test/e2e/passkeys.test.mjs+3−2View file
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import { test, before, after } from "node:test"; |
| 22 | 22 | import assert from "node:assert/strict"; |
| 23 | 23 | import { chromium } from "playwright"; |
| 24 | +import { migratedState } from "./d1-state.mjs"; | |
| 24 | 25 | |
| 25 | 26 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 26 | 27 | const work = mkdtempSync(join(tmpdir(), "diffinery-passkeys-")); |
| @@ -97,7 +98,7 @@ | ||
| 97 | 98 | base = `http://localhost:${port}`; |
| 98 | 99 | const persist = join(work, "state"); |
| 99 | 100 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 100 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 101 | + migratedState(APP, persist); | |
| 101 | 102 | const at = new Date().toISOString(); |
| 102 | 103 | const later = new Date(Date.now() + 86400_000).toISOString(); |
| 103 | 104 | wrangler( |
| @@ -462,7 +463,7 @@ | ||
| 462 | 463 | const port = await freePort(); |
| 463 | 464 | const site = `http://localhost:${port}`; |
| 464 | 465 | const persist = join(work, "signup-state"); |
| 465 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 466 | + migratedState(APP, persist); | |
| 466 | 467 | const open = spawn( |
| 467 | 468 | "pnpm", |
| 468 | 469 | ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${site}`, "--var", `MASTER_KEY:${MASTER_KEY}`, "--var", "SIGNUP:open", "--show-interactive-dev-session=false"], |
modifiedapps/diffinery/test/e2e/registry.test.mjs+2−1View file
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | import { createServer } from "node:net"; |
| 18 | 18 | import { test, before, after } from "node:test"; |
| 19 | 19 | import assert from "node:assert/strict"; |
| 20 | +import { migratedState } from "./d1-state.mjs"; | |
| 20 | 21 | |
| 21 | 22 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 22 | 23 | const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| @@ -134,7 +135,7 @@ | ||
| 134 | 135 | base = `http://127.0.0.1:${port}`; |
| 135 | 136 | host = `127.0.0.1:${port}`; |
| 136 | 137 | const persist = join(work, "state"); |
| 137 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 138 | + migratedState(APP, persist); | |
| 138 | 139 | const at = new Date().toISOString(); |
| 139 | 140 | const later = new Date(Date.now() + 30 * 86400_000).toISOString(); |
| 140 | 141 | const seed = [ |
modifiedapps/diffinery/test/e2e/review.test.mjs+2−1View file
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | import { createServer as httpServer } from "node:http"; |
| 20 | 20 | import { test, before, after } from "node:test"; |
| 21 | 21 | import assert from "node:assert/strict"; |
| 22 | +import { migratedState } from "./d1-state.mjs"; | |
| 22 | 23 | |
| 23 | 24 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 24 | 25 | const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| @@ -156,7 +157,7 @@ | ||
| 156 | 157 | const port = await freePort(); |
| 157 | 158 | base = `http://127.0.0.1:${port}`; |
| 158 | 159 | const persist = join(work, "state"); |
| 159 | - execFileSync("pnpm", ["exec", "wrangler", "d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); | |
| 160 | + migratedState(APP, persist); | |
| 160 | 161 | const vars = { PUBLIC_URL: base, MASTER_KEY: randomBytes(32).toString("base64"), SANDBOX_POOL_URL: `http://127.0.0.1:${poolPort}`, SANDBOX_POOL_SECRET: poolSecret, MODEL_UPSTREAM_ANTHROPIC: upstreamUrl, MODEL_UPSTREAM_OPENAI: upstreamUrl, MODEL_UPSTREAM_OPENROUTER: upstreamUrl }; |
| 161 | 162 | dev = spawn("pnpm", ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, ...Object.entries(vars).flatMap(([k, v]) => ["--var", `${k}:${v}`]), "--show-interactive-dev-session=false"], { |
| 162 | 163 | cwd: APP, |
modifiedapps/diffinery/test/e2e/security-txt.test.mjs+2−1View file
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | import { createServer } from "node:net"; |
| 15 | 15 | import { test, after } from "node:test"; |
| 16 | 16 | import assert from "node:assert/strict"; |
| 17 | +import { migratedState } from "./d1-state.mjs"; | |
| 17 | 18 | |
| 18 | 19 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 19 | 20 | const work = mkdtempSync(join(tmpdir(), "diffinery-securitytxt-e2e-")); |
| @@ -34,7 +35,7 @@ | ||
| 34 | 35 | const base = `http://127.0.0.1:${port}`; |
| 35 | 36 | const persist = join(work, name); |
| 36 | 37 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 37 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 38 | + migratedState(APP, persist); | |
| 38 | 39 | if (seed.length) wrangler("d1", "execute", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist, "--command", seed.join("; ")); |
| 39 | 40 | const args = ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--show-interactive-dev-session=false"]; |
| 40 | 41 | for (const [k, v] of Object.entries(vars)) args.push("--var", `${k}:${v}`); |
modifiedapps/diffinery/test/e2e/security.test.mjs+2−1View file
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | import { createServer as createHttpServer } from "node:http"; |
| 35 | 35 | import { test, before, after } from "node:test"; |
| 36 | 36 | import assert from "node:assert/strict"; |
| 37 | +import { migratedState } from "./d1-state.mjs"; | |
| 37 | 38 | |
| 38 | 39 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 39 | 40 | const work = mkdtempSync(join(tmpdir(), "diffinery-security-")); |
| @@ -135,7 +136,7 @@ | ||
| 135 | 136 | base = `http://127.0.0.1:${port}`; |
| 136 | 137 | const persist = join(work, "state"); |
| 137 | 138 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 138 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 139 | + migratedState(APP, persist); | |
| 139 | 140 | const at = new Date().toISOString(); |
| 140 | 141 | const later = new Date(Date.now() + 30 * 86400_000).toISOString(); |
| 141 | 142 | const account = (id, login, kind, status, owner = null) => `INSERT INTO accounts (id, login, kind, name, status, owner_id, created_at) VALUES ('${id}', '${login}', '${kind}', '${login}', '${status}', ${owner ? `'${owner}'` : "NULL"}, '${at}')`; |
modifiedapps/diffinery/test/e2e/status.test.mjs+2−1View file
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | import { createServer } from "node:net"; |
| 14 | 14 | import { test, after } from "node:test"; |
| 15 | 15 | import assert from "node:assert/strict"; |
| 16 | +import { migratedState } from "./d1-state.mjs"; | |
| 16 | 17 | |
| 17 | 18 | const APP = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); |
| 18 | 19 | const work = mkdtempSync(join(tmpdir(), "diffinery-status-e2e-")); |
| @@ -33,7 +34,7 @@ | ||
| 33 | 34 | const base = `http://127.0.0.1:${port}`; |
| 34 | 35 | const persist = join(work, name); |
| 35 | 36 | const wrangler = (...args) => execFileSync("pnpm", ["exec", "wrangler", ...args], { cwd: APP, stdio: "pipe", env: { ...process.env, CI: "1" } }); |
| 36 | - wrangler("d1", "migrations", "apply", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist); | |
| 37 | + migratedState(APP, persist); | |
| 37 | 38 | if (seed.length) wrangler("d1", "execute", "diffinery-dev", "--local", "-e", "dev", "--persist-to", persist, "--command", seed.join("; ")); |
| 38 | 39 | const args = ["exec", "wrangler", "dev", "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${base}`, "--show-interactive-dev-session=false"]; |
| 39 | 40 | for (const [k, v] of Object.entries(vars)) args.push("--var", `${k}:${v}`); |