Add Vitest test suite with CI and testability refactors - #26
Conversation
Introduce unit, integration, and CLI smoke tests; extract git parsers, support COMMIT_TOOLS_HOME, and default bare commit to generate.
- Add PR validation concurrency and shared CI environment settings for build and test steps. - Run the built CLI smoke doctor test whenever `dist/` exists. - Return a clear config load error when `config.json` contains invalid JSON. - Document pull request checks and local validation commands in the README.
There was a problem hiding this comment.
Critical finding (fixed on rafaeelricco/critical-correctness-bugs-9c08)
PR #26 adds COMMIT_TOOLS_HOME for isolated Vitest config, but CONFIG_DIR / CONFIG_FILE were computed once at module import time. Vitest sets COMMIT_TOOLS_HOME in beforeEach, which runs after test modules load, so saveConfig() in config.test.ts still wrote to ~/.commit-tools/config.json.
Impact: Running pnpm test could overwrite a developer's real config.json (OAuth tokens, API keys, conventions).
Fix: Resolve config paths on each access; add config-path.test.ts regression coverage.
No other critical correctness issues found in the behavioral diff (git parser extraction, default CLI command, JSON parse errors).
Sent by Cursor Automation: Find critical bugs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66f858abd7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
CONFIG_DIR/CONFIG_FILE were computed at module import, before Vitest's beforeEach set COMMIT_TOOLS_HOME, so `pnpm test` wrote to the real ~/.commit-tools/config.json. Convert them to configDir()/configFile() functions read at call time, update version-check.ts and doctor.ts callers, and move static test env to top-level setup so import-time reads in env.ts see the test values.


Motivation
Add automated test coverage for all existing
commit-toolsfeatures so regressions in the CLI, config persistence, git helpers, and LLM routing are caught in CI instead of during manual release checks.What's New
Testing Infrastructure & CI
vitest.config.ts,test/setup.ts, andpnpm test/test:watchscriptspnpm testin.github/workflows/pr-validate.ymlwith stub OAuth env vars**/*.test.tsandtest/fromtscso test helpers stay Vitest-onlyTestability Refactors
COMMIT_TOOLS_HOMEinstorage/config.tsfor hermetic config testsinfra/git/parsers.tsand slim downrepo.tsisNonFastForwardErrortocli/commit-errors.tstokensChangedanddetectPackageManagerfor focused unit testscommitinvocation togenerate(aligned with README)Unit & Integration Tests
gitCLI Smoke Tests
test/cli-smoke.test.tsfor builtdist/index.js(-v,-h, unknown command;doctorin CI)Test Architecture Flow
graph TD subgraph L1 [Layer 1 - Pure unit] Parser[parser / fuzzy / parsers] Config[config schema] Prompts[prompts / response-parser] end subgraph L2 [Layer 2 - Mocked integration] Router[LLM router] Auth[auth-resolver] CLI[commit / doctor / setup] end subgraph L3 [Layer 3 - Git fixtures] RepoInt[repo.integration] end subgraph L4 [Layer 4 - CLI smoke] Smoke[cli-smoke dist] end L1 --> L2 L2 --> L3 L3 --> L4 CI[pr-validate CI] --> L1 CI --> L2 CI --> L3 CI --> L4Changed Files
vitest.config.ts,test/setup.ts,test/helpers/*package.json,pnpm-lock.yaml.github/workflows/pr-validate.ymlsrc/infra/git/parsers.tssrc/infra/git/repo.tssrc/cli/parser.tsgeneratesrc/infra/storage/config.tsCOMMIT_TOOLS_HOMEoverridesrc/cli/commit-errors.tssrc/**/*.test.ts,test/cli-smoke.test.ts.env.example,tsconfig.jsontscAdditional for Run Locally
gitrequired forrepo.integration.test.tsdist/before smoke tests (pnpm buildwithGOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRETset, same as CI)Testing & Feedback
pnpm test,pnpm typecheck, andpnpm lintpass locallycommit,setup,doctor) for realistic mock coveragecommit→generatematches expected product behaviorIf you find any bugs or have recommendations for improvements, please open an issue and assign it to me.