Skip to content

test: write unit tests for lib/state.cjs (#133)#148

Merged
snipcodeit merged 2 commits intomainfrom
issue/133-write-unit-tests-for-lib-state-cjs
Mar 2, 2026
Merged

test: write unit tests for lib/state.cjs (#133)#148
snipcodeit merged 2 commits intomainfrom
issue/133-write-unit-tests-for-lib-state-cjs

Conversation

@snipcodeit
Copy link
Owner

Summary

  • Adds test/state.test.cjs with 44 unit tests covering all 9 exported functions in lib/state.cjs — the most critical module in MGW (every command reads/writes project state through it)
  • Uses node:test + node:assert/strict (zero new dependencies), consistent with the existing test suite pattern in test/mgw.test.cjs and test/github.test.cjs
  • Isolation strategy: fs.mkdtempSync() real temp dirs + process.cwd() override per describe block; afterEach cleans .mgw/ between tests

Closes #133

Milestone Context

  • Milestone: v3.5 — Foundation Hardening
  • Phase: 32 — Test Coverage
  • Issue: 2 of 9 in milestone

Changes

  • test/state.test.cjs (new, 546 lines) — 44 tests across 7 describe blocks:
    • getMgwDir / getActiveDir / getCompletedDir (4 tests) — path derivation from cwd
    • loadProjectState / writeProjectState (7 tests) — null on missing/invalid, round-trip, overwrite, auto-mkdir
    • loadActiveIssue (6 tests) — prefix matching, superset-prefix guard, invalid JSON, string vs number arg
    • mergeProjectState (7 tests) — throws on no state, milestone append, phase_map merge (no overwrite), new and legacy active pointer fields, disk persistence
    • migrateProjectState (8 tests) — null on no state, adds missing fields, does not overwrite existing values, idempotency, disk persistence, empty milestones edge case
    • resolveActiveMilestoneIndex (10 tests) — null/undefined state, new schema precedence, dangling reference returns -1, legacy conversion, neither field set, empty/missing milestones array

Test Plan

# Run full test suite — all 92 tests should pass
npm test

# Verify state tests in isolation
node --test test/state.test.cjs

# Confirm github and mgw tests are unaffected
node --test test/github.test.cjs test/mgw.test.cjs

Stephen Miller and others added 2 commits March 1, 2026 22:28
Add comprehensive unit tests for all 10 exported functions in
lib/github.cjs using node:test built-in runner with execSync mocked
via module cache invalidation — no real gh CLI calls made.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds test/state.test.cjs with 44 unit tests covering all 9 exported
functions in lib/state.cjs using node:test + node:assert/strict (zero
new dependencies). Critical schema-evolution paths — migrateProjectState
idempotency and resolveActiveMilestoneIndex new-vs-legacy schema
precedence — are tested first.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.

Write unit tests for lib/state.cjs

1 participant