diff --git a/tests/boundary/cli/developmentTests.test.ts b/tests/boundary/cli/developmentTests.test.ts index 21d8c5127..2987206c8 100644 --- a/tests/boundary/cli/developmentTests.test.ts +++ b/tests/boundary/cli/developmentTests.test.ts @@ -1,100 +1,175 @@ -import { execFile } from "node:child_process"; -import { mkdir, symlink, writeFile } from "node:fs/promises"; -import { join, resolve } from "node:path"; -import { promisify } from "node:util"; +import { + copyFile, + mkdir, + readFile, + symlink, + writeFile, +} from "node:fs/promises"; +import { join } from "node:path"; import { describe, expect, it } from "vitest"; +import { execFileOutput } from "../../../src/process/ExecFileOutput.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; -const execute = promisify(execFile); -const runner = resolve("scripts/run-development-tests.mjs"); - -describe("development test runner", () => { - it("rejects nonexistent explicit paths instead of returning a zero-test success", async () => { - await expect( - execute(process.execPath, [ - runner, - "focused", - "src/missing.test.ts", - "--dry-run", - ]), - ).rejects.toMatchObject({ code: 1 }); +const run = (root: string, command: string, arguments_: readonly string[]) => + execFileOutput(command, arguments_, { + cwd: root, + stopSignal: "SIGTERM", + timeout: 30_000, + maxBuffer: 1024 * 1024, }); - it("reports actionable remediation when the comparison base is unavailable", async () => { - await expect( - execute(process.execPath, [ - runner, - "changed", - "--base", - "missing-test-base", - "--dry-run", +const git = (root: string, ...arguments_: string[]) => + run(root, "git", arguments_); + +const commit = (root: string, message: string) => + git( + root, + "-c", + "user.name=REA fixture", + "-c", + "user.email=fixture@example.test", + "-c", + "commit.gpgSign=false", + "commit", + "--quiet", + "-m", + message, + ); + +const fixture = async () => { + const root = await createTestTempDirectory("rea-development-tests-"); + await mkdir(join(root, "scripts", "lib"), { recursive: true }); + await mkdir(join(root, "src")); + for (const path of [ + "scripts/run-development-tests.mjs", + "scripts/lib/development-tests.mjs", + ]) + await copyFile(join(process.cwd(), path), join(root, path)); + await symlink( + join(process.cwd(), "node_modules"), + join(root, "node_modules"), + process.platform === "win32" ? "junction" : undefined, + ); + await writeFile(join(root, "package.json"), '{"type":"module"}\n'); + await writeFile(join(root, ".gitignore"), "node_modules\nselected.txt\n"); + await writeFile( + join(root, "vitest.config.mjs"), + 'export default { test: { projects: [{ test: { name: "domain", include: ["src/**/*.test.ts"] } }] } };\n', + ); + await writeFile(join(root, "src/value.ts"), "export const value = 1;\n"); + await writeFile( + join(root, "src/value.test.ts"), + 'import { expect, it } from "vitest"; import { writeFileSync } from "node:fs"; import { value } from "./value.js"; it("checks the selected source", () => { expect(value).toBe(1); writeFileSync("selected.txt", String(value)); });\n', + ); + await git(root, "init", "--quiet", "-b", "main"); + await git(root, "add", "."); + await commit(root, "fixture"); + return root; +}; + +const testCommand = (root: string, ...arguments_: string[]) => + run(root, process.execPath, [ + "scripts/run-development-tests.mjs", + ...arguments_, + ]); + +describe("development test runner public CLI", () => { + it("runs an explicitly selected source test on a clean tree without build artifacts", async () => { + const root = await fixture(); + const { stdout: status } = await git(root, "status", "--porcelain"); + expect(status).toBe(""); + await testCommand(root, "local", "src/value.test.ts"); + expect(await readFile(join(root, "selected.txt"), "utf8")).toBe("1"); + }); + + it("plans an exact local test without building", async () => { + const root = await fixture(); + const { stdout } = await testCommand( + root, + "local", + "src/value.test.ts", + "--dry-run", + ); + expect(JSON.parse(stdout)).toMatchObject({ + needsBuild: false, + artifactTasks: [], + vitestArguments: expect.arrayContaining([ + "run", + "--project", + "domain", + "--project", + "services", + "--project", + "adapters", + "--project", + "composition", + "--project", + "conformance", + "--project", + "evaluation", + "src/value.test.ts", ]), + }); + }); + + it("uses committed dependency changes to select source tests and reports failures", async () => { + const root = await fixture(); + const { stdout: base } = await git(root, "rev-parse", "HEAD"); + await writeFile(join(root, "src/value.ts"), "export const value = 2;\n"); + await git(root, "add", "src/value.ts"); + await commit(root, "change dependency"); + await expect( + testCommand(root, "changed", "--base", base.trim()), + ).rejects.toMatchObject({ + code: 1, + stdout: expect.stringContaining("src/value.test.ts"), + stderr: expect.stringContaining("expected 2 to be 1"), + }); + }); + + it("runs changed and focused tests from a committed branch regression", async () => { + const root = await fixture(); + const { stdout: baseline } = await git(root, "rev-parse", "HEAD"); + await git(root, "update-ref", "refs/remotes/origin/main", baseline.trim()); + await git(root, "switch", "--quiet", "-c", "regression"); + await writeFile(join(root, "src/value.ts"), "export const value = 2;\n"); + await writeFile( + join(root, "src/value.test.ts"), + 'import { expect, it } from "vitest"; import { value } from "./value.js"; it("checks current source", () => expect(value).toBe(2));\n', + ); + await git(root, "add", "src"); + await commit(root, "regression fix"); + expect((await git(root, "status", "--porcelain")).stdout).toBe(""); + + const changed = await testCommand(root, "changed"); + expect(changed.stdout).toContain("1 passed"); + const focused = await testCommand(root, "focused", "src/value.test.ts"); + expect(focused.stdout).toContain("1 passed"); + }, 60_000); + + it("reports a missing comparison base and rejects missing or compiled-boundary paths", async () => { + const root = await fixture(); + await expect( + testCommand(root, "changed", "--base", "missing-test-base", "--dry-run"), ).rejects.toMatchObject({ code: 1, stderr: expect.stringContaining( "Fetch origin/main or pass --base REVISION", ), }); - }); - - it("runs a committed branch regression through real Git and Vitest without dist", async () => { - const root = await createTestTempDirectory("rea-development-tests-"); - await mkdir(join(root, "src")); - await symlink( - resolve("node_modules"), - join(root, "node_modules"), - "junction", - ); - await writeFile( - join(root, "package.json"), - JSON.stringify({ type: "module" }), - ); - await writeFile(join(root, ".gitignore"), "node_modules\n"); - await writeFile( - join(root, "vitest.config.ts"), - `export default { test: { projects: [{ test: { name: "domain", include: ["src/**/*.test.ts"] } }] } };`, - ); - await writeFile(join(root, "src/value.ts"), "export const value = 1;\n"); - await writeFile( - join(root, "src/value.test.ts"), - `import { it, expect } from "vitest"; import { value } from "./value"; it("checks current source", () => expect(value).toBe(1));\n`, - ); - const git = (arguments_: string[]) => - execute("git", arguments_, { cwd: root }); - await git(["init", "-b", "main"]); - await git(["add", ".gitignore", "package.json", "vitest.config.ts", "src"]); - const commit = [ - "-c", - "user.name=REA fixture", - "-c", - "user.email=fixture@example.test", - "commit", - "-m", - "fixture", - ]; - await git(commit); - const { stdout: baseline } = await git(["rev-parse", "HEAD"]); - await git(["update-ref", "refs/remotes/origin/main", baseline.trim()]); - await git(["switch", "-c", "regression"]); - await writeFile(join(root, "src/value.ts"), "export const value = 2;\n"); - await writeFile( - join(root, "src/value.test.ts"), - `import { it, expect } from "vitest"; import { value } from "./value"; it("checks current source", () => expect(value).toBe(2));\n`, - ); - await git(["add", "src"]); - await git(commit); - expect((await git(["status", "--porcelain"])).stdout).toBe(""); - const { stdout } = await execute(process.execPath, [runner, "changed"], { - cwd: root, + await expect( + testCommand(root, "focused", "src/missing.test.ts"), + ).rejects.toMatchObject({ + code: 1, + stderr: expect.stringContaining("ENOENT"), }); - expect(stdout).toContain("1 passed"); - const explicit = await execute( - process.execPath, - [runner, "focused", "src/value.test.ts"], - { cwd: root }, - ); - expect(explicit.stdout).toContain("1 passed"); - }, 30_000); + await expect( + testCommand(root, "local", "tests/acceptance/runtime.test.ts"), + ).rejects.toMatchObject({ + code: 1, + stderr: expect.stringContaining("Use test:focused"), + }); + }); }); diff --git a/tests/boundary/filesystem/developmentTests.test.ts b/tests/boundary/filesystem/developmentTests.test.ts deleted file mode 100644 index 1b52bb475..000000000 --- a/tests/boundary/filesystem/developmentTests.test.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { - copyFile, - mkdir, - readFile, - symlink, - writeFile, -} from "node:fs/promises"; -import { join } from "node:path"; - -import { expect, it } from "vitest"; - -import { execFileOutput } from "../../../src/process/ExecFileOutput.js"; -import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; - -const run = (root: string, command: string, arguments_: readonly string[]) => - execFileOutput(command, arguments_, { - cwd: root, - stopSignal: "SIGTERM", - timeout: 20_000, - }); - -const commit = (root: string, message: string) => - run(root, "git", [ - "-c", - "user.name=REA fixture", - "-c", - "user.email=fixture@example.invalid", - "-c", - "commit.gpgSign=false", - "commit", - "--quiet", - "-m", - message, - ]); - -const fixture = async () => { - const root = await createTestTempDirectory("rea-development-tests-"); - await mkdir(join(root, "scripts", "lib"), { recursive: true }); - await mkdir(join(root, "src")); - for (const path of [ - "scripts/run-development-tests.mjs", - "scripts/lib/development-tests.mjs", - ]) - await copyFile(join(process.cwd(), path), join(root, path)); - await symlink( - join(process.cwd(), "node_modules"), - join(root, "node_modules"), - process.platform === "win32" ? "junction" : undefined, - ); - await writeFile(join(root, "package.json"), '{"type":"module"}\n'); - await writeFile(join(root, ".gitignore"), "node_modules\nselected.txt\n"); - await writeFile( - join(root, "vitest.config.mjs"), - 'export default { test: { projects: [{ test: { name: "domain", include: ["src/**/*.test.ts"] } }] } };\n', - ); - await writeFile(join(root, "src", "value.ts"), "export const value = 1;\n"); - await writeFile( - join(root, "src", "value.test.ts"), - 'import { expect, it } from "vitest"; import { writeFileSync } from "node:fs"; import { value } from "./value.js"; it("checks the selected source", () => { expect(value).toBe(1); writeFileSync("selected.txt", String(value)); });\n', - ); - await run(root, "git", ["init", "--quiet"]); - await run(root, "git", ["add", "."]); - await commit(root, "fixture"); - return root; -}; - -const testCommand = (root: string, ...arguments_: string[]) => - run(root, process.execPath, [ - "scripts/run-development-tests.mjs", - ...arguments_, - ]); - -it("executes an explicitly selected source test on a clean tree without build artifacts", async () => { - const root = await fixture(); - const { stdout: status } = await run(root, "git", ["status", "--porcelain"]); - expect(status).toBe(""); - await testCommand(root, "local", "src/value.test.ts"); - expect(await readFile(join(root, "selected.txt"), "utf8")).toBe("1"); -}); - -it("uses committed dependency changes since the requested Git base to select source tests", async () => { - const root = await fixture(); - const { stdout: base } = await run(root, "git", ["rev-parse", "HEAD"]); - await writeFile(join(root, "src", "value.ts"), "export const value = 2;\n"); - await run(root, "git", ["add", "src/value.ts"]); - await commit(root, "change dependency"); - await expect( - testCommand(root, "changed", "--base", base.trim()), - ).rejects.toMatchObject({ - code: 1, - stdout: expect.stringContaining("src/value.test.ts"), - stderr: expect.stringContaining("expected 2 to be 1"), - }); -}); - -it("rejects a compiled boundary in the source-only command and a missing exact test", async () => { - const root = await fixture(); - await expect( - testCommand(root, "local", "tests/acceptance/runtime.test.ts"), - ).rejects.toMatchObject({ - code: 1, - stderr: expect.stringContaining("Use test:focused"), - }); - await expect( - testCommand(root, "local", "src/missing.test.ts"), - ).rejects.toMatchObject({ - code: 1, - stderr: expect.stringContaining("ENOENT"), - }); -});