Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

The refactored campaign_discovery.cjs (PR #11518) lacked test coverage for the newly extracted searchItems helper and buildScopeParts utility, plus critical edge cases in the discovery logic.

Added Tests (17 new, 34 total)

buildScopeParts (6 tests)

  • Repo-only, org-only, and combined scope generation
  • Null/undefined handling for repos and orgs parameters

searchItems helper (8 tests)

  • Budget enforcement (maxItems, maxPages)
  • Cursor-based pagination resumption
  • Content type detection (issue vs pull_request)
  • Early termination on partial results (<100 items)

discover edge cases (3 tests)

  • Budget exhaustion reasons (items vs pages)
  • Cross-search item deduplication by URL
  • Tracker label fallback when primary searches return empty

Example Test

it("should deduplicate items found across multiple searches", async () => {
  const duplicateItem = { html_url: "https://github.com/owner/repo/issues/1", ... };
  const uniqueItem = { html_url: "https://github.com/owner/repo/issues/2", ... };

  const mockOctokit = {
    rest: { search: { issuesAndPullRequests: vi.fn()
      .mockResolvedValueOnce({ data: { items: [duplicateItem] } })      // Campaign label
      .mockResolvedValueOnce({ data: { items: [duplicateItem, uniqueItem] } }) // Generic label
    }}
  };

  const manifest = await discover(config);
  expect(manifest.discovery.total_items).toBe(2); // Deduplicated by URL
});

All 34 tests pass.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added 17 new tests (34 total, doubled from 17)
- Added tests for buildScopeParts helper function (6 tests)
- Added tests for searchItems helper function (8 tests)
- Added tests for discover edge cases (3 tests):
  * Budget exhaustion (items and pages)
  * Item deduplication across searches
  * Tracker label fallback behavior

All tests pass ✓
Formatting validated ✓
Linting validated ✓
Type checking validated ✓

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Clean campaign_discovery.cjs for improved code reuse Add comprehensive test coverage for campaign_discovery.cjs Jan 23, 2026
Copilot AI requested a review from pelikhan January 23, 2026 19:48
@pelikhan pelikhan marked this pull request as ready for review January 23, 2026 19:49
@pelikhan pelikhan merged commit 4126327 into jsweep-campaign-discovery-2026-01-23-01ec0b0064ef6ac0 Jan 23, 2026
117 checks passed
@pelikhan pelikhan deleted the copilot/sub-pr-11518 branch January 23, 2026 19:50
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