Skip to content

test(github): backfill coverage for issue/PR/label helpers (#511)#539

Merged
joryirving merged 2 commits into
mainfrom
test/github-coverage
Jul 2, 2026
Merged

test(github): backfill coverage for issue/PR/label helpers (#511)#539
joryirving merged 2 commits into
mainfrom
test/github-coverage

Conversation

@joryirving

Copy link
Copy Markdown
Contributor

Summary

Covered behaviors (not thin fetchPaginated passthroughs, which are already tested):

  • fetchIssues PR filtering + state=open|all
  • fetchIssue PR-vs-issue guard + error path
  • fetchIssueComments per_page clamp + slice-to-max + non-array guard
  • label mutations, incl. removeIssueLabel 404 tolerance vs. other errors
  • syncStatusLabels remove-then-add ordering (the closed⇒done writer from feat(sync): closed issues always move to status/done #521)
  • validateGitHubToken ok/not-ok/throws
  • fetchPullRequestHealthSignalsderiveReviewDecision (CHANGES_REQUESTED precedence, latest-per-reviewer, ignores COMMENTED)
  • fetchPullRequestCheckFailures failure-conclusion filter + graceful [] on error
  • fetchLinkedPrHealthInput merged/closed/open state mapping

Verification

  • npx vitest run src/lib/github.test.ts → 61 passed (was 29)
  • tsc --noEmit clean; eslint clean

Characterize the logic-bearing github.ts functions that lacked tests:
issue fetch/PR-filtering, PR-vs-issue guard, comment clamp/slice,
label mutations (incl. removeIssueLabel 404 tolerance), syncStatusLabels
ordering, token validation, review-decision derivation, check-failure
filtering, and PR-health state mapping.

Closes the deferred half of #511.

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Automated Review

Full PR review.

Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — escalated (fast_low_confidence)

PR Review: test(github): backfill coverage for issue/PR/label helpers (PR 539)

Recommendation: Approve

This is a pure test-coverage backfill PR adding 426 lines of unit tests for src/lib/github.ts functions that previously had no test coverage. All CI checks passed, and the implementation is straightforward, well-structured, and follows repository conventions.


Change-by-Change Findings

src/lib/github.test.ts — Backfill coverage for 9 function groups (+426 lines)

1. fetchIssues tests

  • Verifies PRs are filtered out from the issues endpoint (GitHub returns both)
  • Confirms state=open is the default; state=all used when includeClosed: true

2. fetchIssue tests

  • Happy path returns the issue object
  • Guard correctly rejects items with pull_request property
  • Non-ok responses throw with formatted error message

3. fetchIssueComments tests

  • per_page clamped to 100 (verified via URL inspection)
  • Response sliced to maxComments
  • Non-array payload throws "expected comments array"
  • HTTP errors propagate correctly

4. Issue mutation tests

  • updateIssueLabels → PUT with full label array
  • addIssueLabel → POST with single-label array
  • updateIssueTitleAndBody → PATCH with partial body
  • closeIssue → PATCH with state: closed
  • removeIssueLabel → DELETE with URL-encoded label
  • 404 tolerance verified: removeIssueLabel returns void on 404 (label already absent), throws on other errors

5. syncStatusLabels tests

  • Confirms delete-then-add ordering (removes happen before adds)
  • No-op when both lists are empty

6. validateGitHubToken tests

  • Returns true on ok response
  • Returns false on 401
  • Returns false on network errors

7. fetchPullRequestHealthSignals / deriveReviewDecision tests

  • Returns mergeStateStatus and reviewDecision
  • CHANGES_REQUESTED takes precedence over APPROVED (later timestamp wins)
  • Latest review per reviewer used (earlier CHANGES_REQUESTED ignored when APPROVED follows)
  • COMMENTED reviews produce null reviewDecision
  • Merge state degrades to null on HTTP errors (reviews still returned)

8. fetchPullRequestCheckFailures tests

  • Filters to completed runs with failure or timed_out conclusions
  • pending (null conclusion) runs excluded
  • Ref URL-encoded for branch names with slashes
  • Returns [] gracefully on HTTP errors and network failures

9. fetchLinkedPrHealthInput tests

  • merged_at present → state merged
  • state: closed + no merged_at → state closed
  • state: open → state open
  • Assembles all signals (review decision, merge state, check failures) correctly

Standards Compliance

Standard Status
Test patterns Uses beforeEach, describe, it, expect with vi.fn() stubs
Error handling coverage Both happy and sad paths tested for all functions
No secrets committed Only test fixtures used; no real credentials
TypeScript Type imports verified; toMatchObject used appropriately
Naming conventions Matches repository test file conventions

Linked Issue Fit

The PR body references PR 511 (the parent issue for GitHub helper test coverage). From git history:

  • PR 511 is the parent tracking issue
  • PR 524 was the agent-queue test backfill (already merged)
  • This PR closes the deferred half of PR 511 (the github.ts helper coverage)

The PR description accurately lists all covered behaviors and matches the diff content.


Evidence Provider Findings

No evidence providers were configured for this PR.


Tool Harness Findings

All 4 tool reads of the test file succeeded:

  • Imports and mock setup verified
  • Existing fetchPaginated, fetchRepositoryMetadata, searchRepositoryCode, addIssueComment tests confirmed
  • New test blocks for all 9 function groups confirmed in their expected positions
  • The routeByUrl mock helper correctly handles parallel Promise.all fetches in fetchLinkedPrHealthInput

Unknowns / Needs Verification

None. The diff, tool harness reads, and CI results are complete and consistent.


Final Assessment

This is a well-executed test coverage backfill:

  • ✅ All functions listed in the PR description have corresponding tests
  • ✅ Both success and error paths covered
  • ✅ Edge cases tested (404 tolerance, empty arrays, parallel fetches)
  • ✅ CI passes (61 tests, up from 29)
  • ✅ No modifications to production code
  • ✅ Follows existing test file conventions

No changes requested.

@joryirving joryirving enabled auto-merge (squash) July 2, 2026 03:16
@joryirving joryirving merged commit 342a8db into main Jul 2, 2026
6 checks passed
@joryirving joryirving deleted the test/github-coverage branch July 2, 2026 03:19
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.

1 participant