Skip to content

test(github): github/ is tested through its public interface over the gh process and session fakes, with no internal patches or private imports #1321

Closed

Description

@dan-petty

Problem

Counts come from one AST pass over tests/test_*.py at 5c45b1e, the head of release/v0.2.28, and [code: …] lines are at the same commit. A file belongs to the package it references most, as in the census. Patch sites are patch, patch.object, patch.dict, mocker.patch and monkeypatch.setattr/setitem/delattr calls aimed at devops_cli. Private imports are _-prefixed names imported from devops_cli.

  • Files. 20 test files have github/ as their primary package: 9,368 lines and 413 tests [measured: AST pass at 5c45b1e]. They are test_gh_issue_closure, test_gh_issues_milestones, test_gh_project_workflows, test_github_branch_protection, test_github_client, test_github_issues, test_github_labels, test_github_metrics, test_github_pages, test_github_pr_monitor, test_github_pr_threads, test_github_projects, test_github_projects_reconcile, test_github_rate_limiter, test_github_secrets, test_github_session, test_github_ssh, test_pr_check_runs, test_pr_check_verdict and test_release_notes_sync. test_pr_cmd.py also references github/ most, but its subject is devops pr, so test(cli): devops pr, gh and repos are thin adapters tested over edge fakes, and merge readiness is tested in its package #1324 names it. feat(release): release-please makes every release from main #1952 deleted test_gh_issue_closure and test_release_notes_sync with the release code that they tested, so this item does not own them now.
  • Coupling. These files hold 343 patch sites aimed at devops_cli internals, in 17 files, and 92 private imports, in 13 files [measured].
    • 101 of the patches replace run_gh in 11 modules: projects 24, pr_monitor 14, ssh 13, issues 11, pr_threads 11, secrets 7, release_notes 7 and four others.
    • 24 more replace run_subprocess (17 in rate_limiter, 1 in pr_monitor) or _burst_protected_subprocess (6).
    • Most of the rest patch github's own functions. test_github_pr_monitor.py alone patches pr_monitor 50 times, and _detect_copilot_status is imported privately 8 times.
    • test_github_session.py:49 and :87 set the private core.process._github_token.
  • Hand-rolled doubles.
    • _FakeGithub is defined 4 times in test_github_client.py (:126, :168, :197, :236).
    • Single copies: _RecordedGithub at test_github_session.py:33 and _mock_proc at test_gh_project_workflows.py:28.
    • The files also make 34 CompletedProcess( calls and 193 MagicMock( calls, and 6 of them build a module-level runner = CliRunner().
  • Edges reached outside a seam.
  • Files and names.
    • Three files each mix several behaviours: test_github_rate_limiter.py (1,642 lines, 73 tests), test_github_pr_monitor.py (1,238) and test_github_projects.py (1,169).
    • Catch-alls: test_github_rate_limiter.py:291, :527, :551, :614, test_github_projects.py:817 and test_github_issues.py:245.
    • 36 test names end in _success, _failure, _basic or _command.

Acceptance criteria

Key questions

Strategic alignment

Proposed design

Problem statement

The 18 test files that test the github/ package use 343 patch sites aimed at devops_cli internals and 92 private imports. They also use hand-rolled doubles, patch time.sleep and time.time at 18 sites, and contain catch-all test names. The tests must go through public seams (process fake, session fake, SecretProvider, OTLP fake, clock fixture) with zero internal patches or private imports. Three large files must be deleted and replaced with behaviour-named files. Source code in github/metrics.py must call git through the process runner instead of subprocess.run.

Acceptance criteria

Key questions

Fit

Needs splitting into 4 items:

  1. Source: github/metrics.py runs git through the process runner instead of subprocess.run or subprocess.Popen
  2. Tests: remove all 343 internal patch sites and 92 private imports from the 18 github test files, route every edge through the shared fakes from refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(github): the github session owns transport, ledger, error classes and link pagination #983, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318, refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, and refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320
  3. Tests: replace hand-rolled doubles with shared fakes, rename 36 test names to behaviour terms, split 6 catch-all tests, delete 3 large files and create behaviour-named files, add CLI tests under tests/commands/
  4. Tests: remove stub_web usage from test_github_client.py, delete unreachable code in github/, pass the 90% coverage gate and uv run devops ci

Suspected block

None.

Dependencies

#1313, #1318, #1319

Alternatives check of 2026-10-29: not-applicable.
Tool: none found.

Activity

  1. added
    type/test
    scope/github
    priority/p2-medium
    on Oct 7, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. A large structural test improvement that reduces coupling but does not fix a user-facing defect or block a release.
    • Value: High. Eliminating 343 internal patch sites and 92 private imports across 20 files makes the github/ suite far more maintainable and resilient to internal refactors.
    • Effort: High. Twenty test files totalling 9,368 lines and 413 tests must be rewritten to use gh-process and session fakes, replacing hundreds of patch sites and hand-rolled doubles.
  3. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

  4. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    The proposal at 69636b6 needs splitting into 4 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. Source: github/metrics.py runs git through the process runner instead of subprocess.run or subprocess.Popen
    2. Tests: remove all 343 internal patch sites and 92 private imports from the 18 github test files, route every edge through the shared fakes from refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(github): the github session owns transport, ledger, error classes and link pagination #983, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318, refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, and refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320
    3. Tests: replace hand-rolled doubles with shared fakes, rename 36 test names to behaviour terms, split 6 catch-all tests, delete 3 large files and create behaviour-named files, add CLI tests under tests/commands/
    4. Tests: remove stub_web usage from test_github_client.py, delete unreachable code in github/, pass the 90% coverage gate and uv run devops ci
  5. added
    status/new
    effort/medium
    value/high
    on Oct 28, 2026
  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Tool: none found

    Checked on 2026-10-29. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/in-progress
    and removed
    status/new
    on Oct 31, 2026
  8. added
    status/in-review
    and removed
    status/in-progress
    on Oct 31, 2026
  9. removed
    status/in-review
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/githubtype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions