test: write unit tests for lib/state.cjs (#133)#148
Merged
snipcodeit merged 2 commits intomainfrom Mar 2, 2026
Merged
Conversation
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]>
This was referenced Mar 2, 2026
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test/state.test.cjswith 44 unit tests covering all 9 exported functions inlib/state.cjs— the most critical module in MGW (every command reads/writes project state through it)node:test+node:assert/strict(zero new dependencies), consistent with the existing test suite pattern intest/mgw.test.cjsandtest/github.test.cjsfs.mkdtempSync()real temp dirs +process.cwd()override per describe block;afterEachcleans.mgw/between testsCloses #133
Milestone Context
Changes
test/state.test.cjs(new, 546 lines) — 44 tests across 7 describe blocks:getMgwDir / getActiveDir / getCompletedDir(4 tests) — path derivation from cwdloadProjectState / writeProjectState(7 tests) — null on missing/invalid, round-trip, overwrite, auto-mkdirloadActiveIssue(6 tests) — prefix matching, superset-prefix guard, invalid JSON, string vs number argmergeProjectState(7 tests) — throws on no state, milestone append, phase_map merge (no overwrite), new and legacy active pointer fields, disk persistencemigrateProjectState(8 tests) — null on no state, adds missing fields, does not overwrite existing values, idempotency, disk persistence, empty milestones edge caseresolveActiveMilestoneIndex(10 tests) — null/undefined state, new schema precedence, dangling reference returns -1, legacy conversion, neither field set, empty/missing milestones arrayTest Plan