Skip to content

Add Vitest test suite with CI and testability refactors - #26

Merged
rafaeelricco merged 3 commits into
mainfrom
rafaeelricco/add-vitest-test-suite
May 22, 2026
Merged

Add Vitest test suite with CI and testability refactors#26
rafaeelricco merged 3 commits into
mainfrom
rafaeelricco/add-vitest-test-suite

Conversation

@rafaeelricco

Copy link
Copy Markdown
Owner

Motivation

Add automated test coverage for all existing commit-tools features 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

  • Add Vitest with vitest.config.ts, test/setup.ts, and pnpm test / test:watch scripts
  • Run pnpm test in .github/workflows/pr-validate.yml with stub OAuth env vars
  • Exclude **/*.test.ts and test/ from tsc so test helpers stay Vitest-only

Testability Refactors

  • Support COMMIT_TOOLS_HOME in storage/config.ts for hermetic config tests
  • Extract pure git logic to infra/git/parsers.ts and slim down repo.ts
  • Move isNonFastForwardError to cli/commit-errors.ts
  • Export tokensChanged and detectPackageManager for focused unit tests
  • Default bare commit invocation to generate (aligned with README)

Unit & Integration Tests

  • CLI: parser matrix, commit/doctor/setup/model/effort/update flows (mocked prompts, git, LLM)
  • Domain: config schema round-trip, prompts, response-parser, auth-resolver, LLM router
  • Infra: fuzzy search, version compare, git parsers, config storage, GitHub PR lookup
  • Integration: temp-repo tests for staged diff, commit, and metadata via real git

CLI Smoke Tests

  • Add test/cli-smoke.test.ts for built dist/index.js (-v, -h, unknown command; doctor in 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 --> L4
Loading

Changed Files

File Change Type Summary
vitest.config.ts, test/setup.ts, test/helpers/* Added Vitest scaffold and shared test helpers
package.json, pnpm-lock.yaml Modified Vitest dependencies and test scripts
.github/workflows/pr-validate.yml Modified CI test step
src/infra/git/parsers.ts Added Extracted pure git parsers
src/infra/git/repo.ts Modified Use parsers module
src/cli/parser.ts Modified Default bare CLI to generate
src/infra/storage/config.ts Modified COMMIT_TOOLS_HOME override
src/cli/commit-errors.ts Added Push error helper
src/**/*.test.ts, test/cli-smoke.test.ts Added Unit, integration, and smoke tests
.env.example, tsconfig.json Modified Test env docs; exclude tests from tsc

Additional for Run Locally

  • git required for repo.integration.test.ts
  • Optional: build dist/ before smoke tests (pnpm build with GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET set, same as CI)

Testing & Feedback

  • Confirm pnpm test, pnpm typecheck, and pnpm lint pass locally
  • Skim mocked CLI tests (commit, setup, doctor) for realistic mock coverage
  • Verify default commitgenerate matches expected product behavior
  • Check CI after push (OAuth stubs, git on ubuntu-latest)

If you find any bugs or have recommendations for improvements, please open an issue and assign it to me.

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.
@rafaeelricco rafaeelricco self-assigned this May 22, 2026
@rafaeelricco
rafaeelricco marked this pull request as ready for review May 22, 2026 19:39

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Open in Web View Automation 

Sent by Cursor Automation: Find critical bugs

Comment thread src/infra/storage/config.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread test/setup.ts
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.
@rafaeelricco
rafaeelricco merged commit 3f777b8 into main May 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant