Skip to content

feat: add lib/mock-github.cjs with GitHub API interceptors for tests#258

Merged
snipcodeit merged 3 commits intomainfrom
issue/247-create-lib-mock-github-cjs-with-github-ap
Mar 6, 2026
Merged

feat: add lib/mock-github.cjs with GitHub API interceptors for tests#258
snipcodeit merged 3 commits intomainfrom
issue/247-create-lib-mock-github-cjs-with-github-ap

Conversation

@snipcodeit
Copy link
Owner

Summary

  • Implements lib/mock-github.cjs — a configurable execSync interceptor that routes gh CLI commands to fixture-based responses during tests
  • Creates test/fixtures/github/ with 16 JSON fixtures covering all five operation categories: issue CRUD, milestone CRUD, label operations, PR creation, and GraphQL board mutations
  • Provides activate/deactivate lifecycle, scenario-based fixture overrides, inline setResponse() overrides, and a call log for assertion in tests

Closes #247

Milestone Context

Milestone: v6 — Local Testing & Simulation Framework
Phase: 47 — Mock Infrastructure
Position: 1 of 11 in milestone execution order

This is the foundational mock layer that downstream issues (#248#255) depend on to write integration and scenario tests without real gh CLI network calls.

Changes

New files

File Purpose
lib/mock-github.cjs Mock layer — intercepts execSync, routes gh commands to fixtures
test/fixtures/github/issue-view.json Single issue object (gh issue view shape)
test/fixtures/github/issue-list.json Array of issues (gh issue list shape)
test/fixtures/github/issue-comment.json Empty string (comment creation)
test/fixtures/github/issue-edit.json Issue URL string (edit result)
test/fixtures/github/milestone-view.json Milestone with open state
test/fixtures/github/milestone-create.json Created milestone
test/fixtures/github/milestone-close.json Milestone with closed state
test/fixtures/github/label-create.json Empty string (label creation)
test/fixtures/github/label-list.json Array of label objects
test/fixtures/github/pr-create.json PR URL string
test/fixtures/github/pr-view.json PR object
test/fixtures/github/rate-limit.json Rate limit API response
test/fixtures/github/board-item.json Project item ID string
test/fixtures/github/graphql-board-mutation.json updateProjectV2ItemFieldValue response
test/fixtures/github/repo-meta.json Repository with discussionCategories
test/fixtures/github/discussion-create.json createDiscussion URL response

API

const mockGitHub = require('./lib/mock-github.cjs');

mockGitHub.activate();              // base fixtures only
mockGitHub.activate('pr-error');    // scenario override from test/fixtures/github/pr-error/
mockGitHub.setResponse('gh pr create', 'https://...'); // inline override
mockGitHub.getCallLog();            // [{ cmd, fixture, returnValue, timestamp }, ...]
mockGitHub.clearCallLog();          // reset between sub-scenarios
mockGitHub.deactivate();            // restore real execSync

Test Plan

  • All 10 verification checks pass (node verify-247.cjs)
  • All 64 existing test/github.test.cjs tests pass with 0 regressions
  • Smoke tests verified: activate/deactivate lifecycle, builtin routing, fixture routing, inline overrides, call log, milestone routing, PR create routing
  • No real gh CLI calls made when mock is active
  • Works with Node's built-in node:test framework (no vitest dependency required)

🤖 Generated with Claude Code

Stephen Miller and others added 2 commits March 6, 2026 03:03
Implements the mock GitHub API layer for the v6 Local Testing & Simulation
Framework milestone (Phase 47: Mock Infrastructure).

- lib/mock-github.cjs: configurable execSync interceptor with fixture-based
  routing, scenario support, inline overrides, and call log
- test/fixtures/github/: 16 fixture files covering issue CRUD, milestone CRUD,
  label operations, PR creation, and GraphQL board mutations

All 64 existing github.test.cjs tests pass. No real gh CLI calls made when mock
is active.

Closes #247

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions github-actions bot added the core Changes to core library label Mar 6, 2026
snipcodeit pushed a commit that referenced this pull request Mar 6, 2026
Implements a fake GSD agent runner for offline MGW pipeline testing.
The module intercepts Task() spawns, returns configurable fixture outputs,
and records spawn calls for assertion.

- lib/mock-gsd-agent.cjs: core mock module with activate/deactivate/
  spawnStub/getCallLog/setResponse/isActive/getSpawnCount/assertSpawned API
- test/fixtures/agents/: base fixture files for all 5 agent types
  (gsd-planner, gsd-executor, gsd-verifier, gsd-plan-checker, general-purpose)

API mirrors lib/mock-github.cjs (PR #258) for consistency:
- Same activate/deactivate/setResponse/getCallLog/isActive pattern
- Scenario support: test/fixtures/agents/<scenario>/ overrides base fixtures
- Inline overrides have highest precedence

Closes #248

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
snipcodeit pushed a commit that referenced this pull request Mar 6, 2026
Configures vitest as the primary test runner for the v6 Local Testing
& Simulation Framework (Phase 47: Mock Infrastructure, issue #249).

Changes:
- package.json: add vitest ^2.0.0 devDependency; npm test → vitest run;
  npm run test:watch → vitest; npm run test:node preserves existing
  node --test runner for .test.cjs files
- vitest.config.js: node environment, setupFiles: ['./test/setup.js'],
  includes .test.js/.spec.js, excludes .test.cjs (node:test incompatible)
- test/setup.js: auto-activates mock-github and mock-gsd-agent in
  beforeEach/afterEach; conditional require — works when PRs #258/#259
  are not yet merged to main; exports mockGitHub/mockGsdAgent
- test/loadFixture.js: loadFixture(name) helper that reads from
  test/fixtures/; supports namespaced paths (e.g. 'github/issue-view');
  throws descriptive errors on missing/invalid fixtures

Closes #249

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@snipcodeit snipcodeit merged commit 276e647 into main Mar 6, 2026
4 of 5 checks passed
@snipcodeit snipcodeit deleted the issue/247-create-lib-mock-github-cjs-with-github-ap branch March 6, 2026 11:18
snipcodeit added a commit that referenced this pull request Mar 6, 2026
Implements a fake GSD agent runner for offline MGW pipeline testing.
The module intercepts Task() spawns, returns configurable fixture outputs,
and records spawn calls for assertion.

- lib/mock-gsd-agent.cjs: core mock module with activate/deactivate/
  spawnStub/getCallLog/setResponse/isActive/getSpawnCount/assertSpawned API
- test/fixtures/agents/: base fixture files for all 5 agent types
  (gsd-planner, gsd-executor, gsd-verifier, gsd-plan-checker, general-purpose)

API mirrors lib/mock-github.cjs (PR #258) for consistency:
- Same activate/deactivate/setResponse/getCallLog/isActive pattern
- Scenario support: test/fixtures/agents/<scenario>/ overrides base fixtures
- Inline overrides have highest precedence

Closes #248

Co-authored-by: Stephen Miller <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
snipcodeit added a commit that referenced this pull request Mar 6, 2026
…260)

Configures vitest as the primary test runner for the v6 Local Testing
& Simulation Framework (Phase 47: Mock Infrastructure, issue #249).

Changes:
- package.json: add vitest ^2.0.0 devDependency; npm test → vitest run;
  npm run test:watch → vitest; npm run test:node preserves existing
  node --test runner for .test.cjs files
- vitest.config.js: node environment, setupFiles: ['./test/setup.js'],
  includes .test.js/.spec.js, excludes .test.cjs (node:test incompatible)
- test/setup.js: auto-activates mock-github and mock-gsd-agent in
  beforeEach/afterEach; conditional require — works when PRs #258/#259
  are not yet merged to main; exports mockGitHub/mockGsdAgent
- test/loadFixture.js: loadFixture(name) helper that reads from
  test/fixtures/; supports namespaced paths (e.g. 'github/issue-view');
  throws descriptive errors on missing/invalid fixtures

Closes #249

Co-authored-by: Stephen Miller <[email protected]>
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

core Changes to core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create lib/mock-github.cjs with GitHub API interceptors for tests

1 participant