diff --git a/packages/server/CLAUDE.md b/packages/server/CLAUDE.md index 47114388..7ab56b64 100644 --- a/packages/server/CLAUDE.md +++ b/packages/server/CLAUDE.md @@ -108,6 +108,6 @@ for Cloudflare bindings. bindings (`secrets: { TOKEN_SIGNING_KEY, … }` in the `phase*` integration tests), and `env.test.ts` drives `loadDwkEnv({ cwd })` against temp dirs, so no secret file is needed locally or in CI. Add a new test's secrets inline - the same way. One leak: `cli.test.ts` calls `main()`, whose `loadDwkEnv()` - reads `.env`/`.env` from the working directory, so a local `.env` - there lands in `process.env` during that file. + the same way. `main()` calls `loadDwkEnv()` against `process.cwd()`, so + `cli.test.ts` runs every `main` case from an empty temp dir; keep new `main` + tests inside that `describe`. diff --git a/packages/server/src/cli.test.ts b/packages/server/src/cli.test.ts index bcc00380..6567b882 100644 --- a/packages/server/src/cli.test.ts +++ b/packages/server/src/cli.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, afterAll } from "vitest"; +import { describe, it, expect, afterAll, beforeEach, afterEach } from "vitest"; import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -150,6 +150,17 @@ describe("dwk-serve CLI", () => { }); describe("main", () => { + // main() calls loadDwkEnv() against process.cwd(); run every case from an + // empty temp dir so a developer's local .env never reaches these tests. + let prevCwd: string; + beforeEach(() => { + prevCwd = process.cwd(); + process.chdir(workdir()); + }); + afterEach(() => { + process.chdir(prevCwd); + }); + it("parses args, loads the config path, and starts listening", async () => { const path = configFile(pingConfig()); const cap = capture();