vitest.snapshot.config.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import tsconfigPaths from 'vite-tsconfig-paths'
  2. import { defineConfig } from 'vitest/config'
  3. // Snapshot tests: `pnpm run test:snapshot`, file pattern *.snapshot.ts.
  4. // REPLAY by default — they boot the real acp-agent subprocess against a
  5. // recorded session JSONL fixture (no API key, no network) and diff the
  6. // normalized stdout transcript + re-persisted log against committed goldens.
  7. // `pnpm run test:snapshot:record` (DSH_SNAPSHOT=record + -u) re-records the
  8. // fixtures against the real API and refreshes the goldens.
  9. //
  10. // Replay loads no .env (it must never reach the network — a recorded fixture
  11. // drives the model). Record reads DEEPSEEK_API_KEY from the env or a gitignored
  12. // repo-root .env, so a contributor with a key only in .env can still record.
  13. if (process.env.DSH_SNAPSHOT === 'record') {
  14. try {
  15. process.loadEnvFile(new URL('.env', import.meta.url).pathname)
  16. } catch (error) {
  17. // ENOENT (no .env) is fine — the key may already be in the environment.
  18. // Surface any other failure rather than silently recording with wrong env.
  19. if ((error as NodeJS.ErrnoException | null)?.code !== 'ENOENT') throw error
  20. }
  21. }
  22. export default defineConfig({
  23. // Same resolution note as vitest.config.ts: bare workspace names resolve
  24. // through the root tsconfig paths map; the native option cannot do this.
  25. plugins: [tsconfigPaths({ projects: ['./tsconfig.json'] })],
  26. test: {
  27. include: ['examples/*/tests/**/*.snapshot.ts'],
  28. // Each test boots a subprocess; give it room, and run files one at a time
  29. // (a record run hits the live API, and replay subprocess boot is heavy).
  30. testTimeout: 120_000,
  31. hookTimeout: 30_000,
  32. fileParallelism: false,
  33. },
  34. })