import { fileURLToPath } from "node:url"; import { AgentPlugin, DefaultDiscoverStrategy } from "@vitest-agent/plugin"; import { defineConfig } from "vitest/config"; export default async () => { // Scratchpad is a local-only probe venue: discovered as a normal project on // dev machines, invisible to ci:test. const strategy = new DefaultDiscoverStrategy().extend({ buildProject: async (input, inherited) => { if (input.name === "scratchpad" && process.env.CI) return null; if (inherited === null) return null; const test = { ...inherited.test, env: { ...inherited.test?.env, // pnpm sets this for the bootstrap, resolved from each process's cwd, so a child a test starts in a scratch // directory dies on it. A test that runs sibling source in a child loads tsx itself. NODE_OPTIONS: "", // Linked source has no bundler define, and its 0.0.0 fallback makes the version comparison skip itself. __PACKAGE_VERSION__: "0.0.0-source", }, }; // @effected/cli-kit registers its own snapshot serializer the way a consumer does: through the config, by the // module whose default export it is, never with expect.addSnapshotSerializer (effected#909). if (input.name === "@effected/cli-kit") { return { ...inherited, test: { ...test, snapshotSerializers: [ fileURLToPath(new URL("packages/cli-kit/src/ui-testing-serializer.ts", import.meta.url)), ], }, }; } return { ...inherited, test }; }, }); const { projects, tags } = await AgentPlugin.discover(strategy); return defineConfig({ plugins: [ AgentPlugin({ console: { human: "stream", agent: "agent", }, coverageTargets: AgentPlugin.COVERAGE_LEVELS.basic.coverageTargets, // CI runners are ephemeral: nothing reads the SQLite history there, and persisting it plus the // follow-on scan cost about 24 s per run (vitest-agent#568). `persist` is opt-out by design and // never reads CI itself, so the decision lives here. Console summary, job summary, coverage // analysis and the exit code are unchanged; VITEST_AGENT_PERSIST still overrides either way. ...(process.env.CI ? { persist: false } : {}), }), ], test: { ...(projects ? { projects } : {}), tags, pool: "forks", // Resolved against THIS file, not the cwd. A bare relative path here // resolves against wherever vitest was invoked, so a run from inside a // package that points `--config` here dies with // `Failed to load url .../packages//vitest.setup.ts` // — an error that reads as a missing file you were meant to create, // whose tempting "fix" is to create a per-package setup and fork it // permanently (effected#455). // // Vitest does NOT walk up to this config: run from inside a package it // uses that directory as its root with no repo config. Measured from // inside `packages/lockfiles`: // vitest run -> that package only, default reporter, exit 0 // vitest run --project @effected/lockfiles -> "No projects matched the filter", exit 1 // vitest run packages/lockfiles -> "No test files found", exit 1 // From the repo root, `--project ` selects one project, and a // POSITIONAL filter is a substring of each test file's path (`ckfiles` // selects lockfiles). Run from the root; prefer `--project `. globalSetup: [fileURLToPath(new URL("vitest.setup.ts", import.meta.url))], coverage: { enabled: true, provider: "v8", thresholds: AgentPlugin.COVERAGE_LEVELS.basic.thresholds, // Our own sources only. Without an include, the coverage-target scan listed dependency files // (node_modules/.pnpm/...) as "below target" (effected#945). include: ["packages/*/src/**/*.{ts,tsx,mts,cts}", "lib/scripts/**/*.ts"], // The catalog plugin's source imports rolldown-pnpm-config's build-only virtual modules, // so no test can load it; its suite exercises the built pnpmfile instead. exclude: ["scratchpad/**", "packages/pnpm-plugin-effected/src/**"], }, }, }); };