Skip to content

test(#154): mock gh in test sandboxes to remove live-tracker dependency#156

Merged
atlas-apex merged 1 commit into
me2resh:devfrom
atlas-apex:feature/GH-154-test-sandbox-mock-gh
May 3, 2026
Merged

test(#154): mock gh in test sandboxes to remove live-tracker dependency#156
atlas-apex merged 1 commit into
me2resh:devfrom
atlas-apex:feature/GH-154-test-sandbox-mock-gh

Conversation

@atlas-apex

Copy link
Copy Markdown
Collaborator

Summary

  • Adds .claude/hooks/tests/_lib-mock-gh.sh — a tiny gh-shim helper that intercepts gh issue view <N> ... --json ... calls inside hook test sandboxes and returns synthetic {"number":N,"state":"OPEN"}. Pass-through for any gh call it doesn't intercept.
  • Wires the shim into test_single_closes_per_pr.sh and test_validate_pr_required_sections.sh. Both previously failed every case (0/13 and 0/8) because their PR titles reference #114 / #113, which validate-pr-create.sh rejects when those issues are CLOSED — and they are now closed upstream.
  • The shim's mock_gh_set_state <sb> <num> <state> helper is available for future tests that need to exercise the CLOSED-issue branch of the validator. Not used in this PR — neither test was scoped to that branch originally.

Closes #154.

Testing

bash .claude/hooks/tests/test_single_closes_per_pr.sh
# PASS: 13   FAIL: 0

bash .claude/hooks/tests/test_validate_pr_required_sections.sh
# PASS: 8    FAIL: 0

# Full suite — all 12 test files green
for t in .claude/hooks/tests/test_*.sh; do bash "$t" 2>&1 | tail -2; done

To trace intercepted shim calls during debug: MOCK_GH_TRACE=1 bash .claude/hooks/tests/test_single_closes_per_pr.sh.

Glossary

Term Definition
gh-shim A fake gh binary placed on PATH that intercepts a known subset of subcommands and returns synthetic responses. Real gh is exec'd for everything not intercepted.
Live-tracker dependency A test that calls a real network API (here, GitHub Issues) and so changes pass/fail status when the remote state changes — even though no test code or system-under-test code changed.
Sandbox A mktemp'd directory each test case populates with a minimal git repo, the hook under test, and supporting libs, then runs the hook against. Isolates filesystem state between cases.
validate-pr-create.sh Hook that runs on PreToolUse for gh pr create and refuses when the PR title references an issue that doesn't exist OR is CLOSED in the tracker repo.

Loading
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.

2 participants