Files
LobsterAI/vitest.config.ts
Dylan c202b951dd feat(logger): daily rotation, 80 MB limit, 7-day retention, and log export
Overhaul the main-process logger and introduce a co-located unit test
  suite powered by Vitest.

  ### Logger changes (src/main/logger.ts)

  - Switch from a single main.log to daily files named main-YYYY-MM-DD.log
    via electron-log's resolvePathFn.
  - Raise per-file size limit from 10 MB to 80 MB before overflow rotation.
  - Add pruneOldLogs(): on every startup, delete main-*.log and
    main-*.old.log files whose mtime is older than 7 days.
  - Add getRecentMainLogEntries(): returns {archiveName, filePath}[] for
    all daily log files within the retention window, sorted alphabetically.
    Used by the log:exportZip IPC handler to bundle all recent logs.

  ### Log export (src/main/main.ts)

  - Import getRecentMainLogEntries alongside getLogFilePath.
  - log:exportZip now spreads getRecentMainLogEntries() instead of the
    single hardcoded main.log entry, so exported zips contain up to 7
    days of main-process logs.

  ### Testing infrastructure

  - Add Vitest (^4.1.0) as a dev dependency.
  - Add vitest.config.ts: includes src/**/*.test.ts, environment: node.
  - Replace the scattered test:memory / test:logger scripts with a single
    "test": "vitest run" command. Filter by module: npm test -- <name>.
  - Add electron-tsconfig.json exclude for src/**/*.test.* and
    src/**/*.spec.* so tsc never compiles test files.
  - Add src/main/logger.test.ts (co-located, 24 tests) covering:
    - filename pattern validation (daily + .old variants, rejection cases)
    - pruneOldLogs boundary behavior (retention cutoff, mixed files)
    - getRecentMainLogEntries filtering, ordering, and 7-day window

  ### Conventions and documentation

  - AGENTS.md / CLAUDE.md: rewrite Testing Guidelines — co-location
    required, .test.ts is the only accepted extension, Vitest imports only.
  - README.md / README_zh.md: add Testing section with run commands,
    directory layout, and a minimal example; both English and Chinese.

Signed-off-by: Dylan <[email protected]>
2026-03-20 15:22:06 +08:00

9 lines
156 B
TypeScript

import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['src/**/*.test.ts'],
environment: 'node',
},
});