Skip to content

test: add 15 unit tests for lib/state.ts - #263

Open
TerminalGravity wants to merge 4 commits into
mainfrom
test/state-lib-tests-mar16
Open

test: add 15 unit tests for lib/state.ts#263
TerminalGravity wants to merge 4 commits into
mainfrom
test/state-lib-tests-mar16

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

Adds comprehensive test coverage for src/lib/state.ts — the state persistence layer used by checkpoint, session-health, and most tools.

15 tests covering:

  • loadState: missing file, valid JSON, corrupt JSON
  • saveState: creates dir, writes JSON, overwrites existing
  • appendLog: creates file, appends JSONL, multiple entries, log rotation at 5MB
  • readLog: missing file, all entries, lastN slicing, corrupt line skipping, empty file
  • now: valid ISO format, timestamp accuracy

All tests use temp directories — no side effects on the real workspace.

Shows 4 concrete scenarios: vague prompt clarification, multi-step
scoping, correction pattern matching, and cross-service awareness.
Each example includes the prompt, triage classification, and the
actual output users can expect.
The README and examples/README.md referenced examples/.preflight/
but the actual config files didn't exist. Added:

- config.yml — profile, related projects, thresholds, embeddings
- triage.yml — keyword rules and strictness settings
- contracts/api.yml — manual contract definition examples

All files are heavily commented so users can copy them into their
project root and customize without needing to reference the docs.
The init wizard resolved the templates directory relative to dist/cli/,
which pointed to dist/templates/ — a path that doesn't exist. Templates
live in src/templates/ and ship in the npm tarball via the 'files' field.

Fixed by going up three levels (dist/cli/init.js → package root) instead
of two, then into src/templates/.
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