Files
kandev/docs/plans/github-pr-discovery-health/task-01-valid-pr-discovery.md
T
2026-09-11 18:13:12 +01:00

3.6 KiB

id, title, status, wave, depends_on, plan, requirements, acceptance_criteria, system_design
id title status wave depends_on plan requirements acceptance_criteria system_design
01-valid-pr-discovery Restore valid PR discovery done 1
plan.md
REQ-INTEGRATIONS-GITHUB-PR-DISCOVERY-001
AC-INTEGRATIONS-GITHUB-PR-DISCOVERY-001.1
AC-INTEGRATIONS-GITHUB-PR-DISCOVERY-001.2
AC-INTEGRATIONS-GITHUB-PR-DISCOVERY-001.3
../../specs/integrations/system-design/github-pr-discovery-health.md

Task 01: Restore valid PR discovery

Summary

Correct the shared GraphQL PR selection and prove discovery writes the expected association. Keep same-repository, fork, and missing-head identity behavior explicit.

In scope

  • First add TestPRDiscoveryQueryContract in the proposed graphql_pr_discovery_contract_test.go. Validate the generated Repository selection against a checked field contract; run it red on cloneUrl.
  • Replace the selection with url; map the decoded URL to the clone identity. Reuse shared conversion where applicable without conflating CLI JSON and GraphQL.
  • Add TestPRDiscoveryHeadIdentity for normal, fork, null, and missing head data.
  • Add TestPRDiscoveryAssociationRecovery using the real service and store: rejected query creates no association; corrected successful query discovers one eligible PR, persists it once, and publishes the scoped task PR event.
  • Exercise both branch and known-PR batch builders. Keep definitive empty, ambiguity, tombstones, and fork-network call-count coverage green.

Out of scope

Retry policy, health projection, UI, credential selection, and live task repair.

Acceptance

  1. The contract regression fails on the current invalid selection and passes with supported fields; no live GitHub credential is required by tests.
  2. Head and target identities remain distinct and correct, including null data.
  3. Persistence and publication use existing writers and retain unlink protection.

Verification

Run from repository root. Record red output before implementation, then green results.

(cd apps/backend && go test ./internal/github -run 'TestPRDiscovery' -count=1)
(cd apps/backend && go test -race ./internal/github -count=1)
git diff --check

Files likely touched

  • apps/backend/internal/github/graphql.go
  • apps/backend/internal/github/gh_client.go (shared repository decoding only)
  • apps/backend/internal/github/graphql_pr_discovery_contract_test.go (new)
  • apps/backend/internal/github/graphql_test.go
  • apps/backend/internal/github/service_pr_watch_batched_budget_test.go

Dependencies

None.

Risks

Do not obtain a clone URL by using the PR target when the head is a fork. Validate the schema fixture against the upstream source linked in the design; do not merely snapshot today's production query.

Parallelism

sequential

Inputs

  • Requirements, discovery criteria.
  • Design, query validation and association.
  • apps/backend/internal/github/AGENTS.md and existing GraphQL/service test patterns.

Results

  • Replaced the invalid GraphQL headRepository.cloneUrl selection with the supported url field in both batched PR query builders.
  • Derived HTTPS clone identity from the GraphQL repository URL while keeping target and head repository identities distinct, including nullable head data.
  • Added query-contract, identity, and query-recovery association/event tests.
  • TDD verification passed: go test ./internal/github -run 'TestPRDiscovery(HeadIdentity|QueryContract|AssociationAfterQueryRecovery)' -count=1.