Skip to content

refactor(cli): one HTTP entry point with a transport hook #3755

Description

@dan-petty

Problem

Part 2 of #1314, which is too large for one pull request (comment of 2026-11-05).

The HTTP clients come from seven factory and broker names: new_http_client, new_async_http_client, get_shared_client, get_shared_async_client, HttpClientBroker, get_broker and DEFAULT_HTTP_BROKER. Tests patch httpx2 itself, and the only shared double, StubWeb, swaps the httpx2 client classes. create_retry_transport defaults wrapped to a plain httpx2.HTTPTransport(), which has no egress check [code: ai/retries/init.py]. The user agent is a fixed devops-cli/0.2.9 [code: http/broker.py].

Expected

One entry point in http/ builds httpx2 clients, and its transport is the seam. A hook, a fake, a fixture and a contract suite let a test replace the transport with no patch.

Acceptance criteria

  • One entry point in http/ builds httpx2 clients, sync and async, pooled and unpooled. Every client it builds takes its transport from the seam, typed httpx2.BaseTransport and httpx2.AsyncBaseTransport. HttpClientBroker, get_broker and DEFAULT_HTTP_BROKER are deleted, and the eight modules that call them build their clients through the entry point. Each keeps its timeouts, limits, redirect rules, SSRF validation and traceparent header. telemetry/memory_profiler.py hands its ASGI transport to the entry point and sets no private _transport. The four factory functions stay until part 3 deletes them, because their callers are still there.
  • A hook installs a transport for a test. Installing or removing one closes the pooled clients first. The pool keeps its public reset and its atexit close.
  • create_retry_transport takes wrapped as a required argument. No import httpx fallback remains in http/ or telemetry/memory_profiler.py. The sites that build a network transport themselves wrap the seam's transport.
  • The user agent comes from importlib.metadata.version("devops-cli").
  • Nothing in http/ builds a client or reads a setting at import.
  • tests/support/fakes/http.py promotes StubWeb. It answers by method and URL with status, headers and body (JSON included), lets the client follow redirects by its own rules, raises httpx2's connect and timeout errors when told to, vets hosts with vet_addresses, and records each request. A web fixture installs it through the hook, removes it at teardown and returns it. The root conftest registers it once.
  • The HTTP contract suite in tests/http/ runs each case against the fake and the real transport, the real side talking to a loopback server the test owns. Cases: status, headers and body; JSON; redirects and the redirect limit; connection refused; read timeout; and a destination that SSRF validation refuses, failing before any request is sent.
  • The tests of http/ use the fake or the contract suite, and patch no devops_cli name, no httpx2 class and not socket.getaddrinfo.
  • ARCHITECTURE.md describes the one seam instead of the broker and the pool.
  • Each new test runs offline in under 1 s. uv run devops ci passes.

Existing tool considered

Alternatives check of #1314 (2026-10-29): not-applicable. httpx2.MockTransport implements the transport interface, so the fake runs on it.

Related

Parent: #1314. Part 1 is the DNS seam (it gives the fake its dns fixture). Part 3 is the caller migration. The old names stay until part 3 ends: each has callers that the later pull requests remove. This is a planned order, not a shim.

Activity

  1. added
    source/agent
    type/refactor
    scope/cli
    status/new
    value/medium
    effort/high
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

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

    • Type: type/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/cli. The (cli) scope of the title gives the scope.
    • Priority: P2-Medium. Planned architecture work with no production incident or security gap it closes directly.
    • Value: Medium. Reduces test fragility and simplifies the HTTP layer, but the current system still functions.
    • Effort: High. Seven acceptance criteria span multiple modules, a new fake, a contract suite, and deletion of the broker.
    • Related: refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, which asks for a different change. Both redesign the HTTP client seam; the candidate covers only the transport hook and fake, while #1314 spans the full HTTP and DNS seam.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 6, 2026
  5. removed
    status/in-review
    on Nov 6, 2026
  6. added a commit that references this issue on Nov 6, 2026
  7. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 13:25 UTC

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/highpriority/p2-mediumscope/clisource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions