Skip to content

test: integration tests for validate_and_load and state lifecycle#261

Merged
snipcodeit merged 1 commit intomainfrom
issue/250-write-integration-tests-for-validate-and
Mar 6, 2026
Merged

test: integration tests for validate_and_load and state lifecycle#261
snipcodeit merged 1 commit intomainfrom
issue/250-write-integration-tests-for-validate-and

Conversation

@snipcodeit
Copy link
Owner

Summary

Closes #250

Milestone Context

Changes

New Files

  • test/validate-and-load.test.js — 23 vitest integration tests (5 groups)
  • test/fixtures/github/ — 16 fixture JSON files for mock-github.cjs activation
  • test/setup.js — Vitest global setup with mock auto-activation
  • test/loadFixture.js — Fixture loader helper
  • vitest.config.js — Vitest config targeting .test.js / .spec.js
  • lib/mock-github.cjs — GitHub API interceptor for tests

Modified Files

  • package.json — Added vitest devDependency and test scripts (test, test:watch, test:node)

Test Groups

Group Tests Coverage
1: Fresh .mgw/ init 5 getMgwDir, writeProjectState, storeDependencies, gitignore idempotency
2: migrateProjectState idempotency 5 field injection, double-run safety, milestone sub-fields, active file fields
3: loadActiveIssue lifecycle 4 null returns, prefix pattern, string coercion
4: Staleness (mock-github) 4 execSync interception, comment count comparison, call log
5: loadCrossRefs validation 5 absent file, valid parse, invalid links, malformed JSON
Total 23 All passing

Test Plan

  • vitest run test/validate-and-load.test.js — 23/23 tests pass
  • No real .mgw/ directories created outside tmp dirs
  • process.cwd() restored in afterEach for all describe blocks
  • migrateProjectState() called twice — state unchanged on second run
  • mock-github.cjs intercepts child_process.execSync correctly
  • Group 4 tests degrade gracefully when mock-github.cjs absent (conditional require)
  • All fixture files present in test/fixtures/github/ for mock activation
GSD Progress
Stage Status
Triage
Planning
Execution ✓ (23 tests created, all passing)
Verification
PR Creation

@github-actions github-actions bot added the core Changes to core library label Mar 6, 2026
@snipcodeit
Copy link
Owner Author

Testing Procedures

Prerequisites

  • Node.js 18+
  • vitest devDependency installed (npm install)
  • The test/fixtures/github/ directory must exist (included in this PR)

Running Tests

# Run the new integration tests only
npx vitest run test/validate-and-load.test.js

# Run all vitest tests
npm run test

# Run in watch mode
npm run test:watch

# Run legacy node:test suite (not affected by this PR)
npm run test:node

Expected Output

 RUN  v2.x.x ...
 ✓ test/validate-and-load.test.js (23 tests)
 Test Files  1 passed (1)
       Tests  23 passed (23)

Manual Verification

To verify tmp directory isolation:

# Run tests and confirm no .mgw/ was created in repo root
npx vitest run test/validate-and-load.test.js
ls .mgw/  # should still only contain existing state files, none from tests

What Each Group Tests

  1. Group 1 (T1.1–T1.5): Run and verify fresh .mgw/ init works in isolated tmp dir
  2. Group 2 (T2.1–T2.5): Call migrateProjectState() twice — state should be identical both times
  3. Group 3 (T3.1–T3.4): Verify loadActiveIssue() prefix pattern matching
  4. Group 4 (T4.1–T4.4): Verify mock-github.cjs intercepts child_process.execSync
  5. Group 5 (T5.1–T5.5): Verify loadCrossRefs() handles edge cases with warnings

…cycle (#250)

Adds test/validate-and-load.test.js with 23 vitest integration tests (5 groups)
covering fresh .mgw/ init, migrateProjectState() idempotency, loadActiveIssue()
prefix pattern, staleness detection via mock-github.cjs, and loadCrossRefs()
validation — all isolated in tmp directories via process.cwd() override.

Also includes vitest infrastructure (vitest.config.js, test/setup.js,
test/loadFixture.js, test/fixtures/github/) from PRs #247 and #260 required
to run the test suite.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@snipcodeit snipcodeit force-pushed the issue/250-write-integration-tests-for-validate-and branch from 0e28748 to 7d2521e Compare March 6, 2026 11:20
@snipcodeit snipcodeit merged commit 1754034 into main Mar 6, 2026
@snipcodeit snipcodeit deleted the issue/250-write-integration-tests-for-validate-and branch March 6, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write integration tests for validate_and_load and state file lifecycle

1 participant