Skip to content

refactor: extract preflight_check helpers + 20 tests + dotfile bug fix - #29

Closed
TerminalGravity wants to merge 3 commits into
mainfrom
refactor/extract-preflight-helpers-v2
Closed

refactor: extract preflight_check helpers + 20 tests + dotfile bug fix#29
TerminalGravity wants to merge 3 commits into
mainfrom
refactor/extract-preflight-helpers-v2

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

What

  • Extracted 4 pure helper functions from preflight-check.ts into src/lib/preflight.ts for testability
  • Added 20 new tests in tests/lib/preflight.test.ts (80 total, all passing)
  • Fixed bug: extractFilePaths now detects dotfiles like .env and .gitignore

Why

preflight_check is the most complex tool in the project and had zero direct test coverage. The helper functions were private/inline, making them untestable. This refactor makes them importable and well-tested.

Functions extracted

Function Purpose
extractFilePaths Parse file references from prompt text
detectAmbiguity Flag vague pronouns, verbs, short prompts
estimateComplexity SMALL/MEDIUM/LARGE from file count + dir spread
splitSubtasks Break multi-step prompts into risk-tagged tasks

… and contracts

The README references .preflight/ config extensively but there were no
concrete example files to copy. This adds a ready-to-use examples/.preflight/
directory with annotated config.yml, triage.yml, and contracts/api.yml,
plus a README explaining how to use them.
- Add 17 tests covering config loading from .preflight/, env var
  overrides, caching, malformed YAML handling, and helper functions
- Export resetConfig() to clear cached config (needed for tests and
  potential config hot-reload)
- All 60 tests passing
…tests + fix dotfile bug

- Extract extractFilePaths, detectAmbiguity, estimateComplexity, splitSubtasks into src/lib/preflight.ts
- Add comprehensive test suite (tests/lib/preflight.test.ts) — 20 new tests
- Fix bug: extractFilePaths now correctly detects dotfiles (.env, .gitignore)
- preflight-check.ts imports from lib instead of inline definitions
- All 80 tests pass

@TerminalGravity TerminalGravity left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clean extraction — the four helpers are well-scoped and the tests are thorough. The dotfile fix in extractFilePaths is a good catch.

One minor thought: estimateComplexity uses the first path segment for directory spread, which works for typical layouts but would undercount monorepo paths like packages/foo/src/bar.ts — might be worth using path.dirname instead of split('/')[0] at some point. Not blocking.

This supersedes #23 and #24 — let's close those once this merges.

Also noticed this PR includes the example configs from #26 (the .preflight/ examples). Was that intentional or a rebase artifact? The examples look great either way.

@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

Superseded by newer PRs.

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