Skip to content

refactor(cli): one DNS seam under vet_addresses, with a fake #3752

Description

@dan-petty

Problem

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

The DNS lookup of the egress check is not injectable. vet_addresses calls socket.getaddrinfo, and avet_addresses calls anyio.getaddrinfo [code: src/devops_cli/http/egress.py:133, :146]. A test that needs a name to resolve patches socket.getaddrinfo itself, through public_dns [code: tests/support/web.py:37] or scripted_resolver [code: tests/web_fakes.py:196]. #2437 deleted _resolve_host_ips, so every lookup of the egress check now passes through these two functions.

Expected

  • One resolver seam sits under vet_addresses and avet_addresses in http/egress.py. It has a Protocol, one place that supplies the real lookup, and a hook that installs another resolver.
  • One fake, one fixture and one contract suite hold the seam to the real lookup.

Acceptance criteria

  • http/egress.py exposes a resolver Protocol that resolves a host and port to getaddrinfo answers, sync and async, within a timeout for the async lookup. The real resolver calls socket.getaddrinfo and anyio.getaddrinfo. A hook installs another resolver and returns the previous one, and a reset restores the real one. vet_addresses and avet_addresses resolve only through it.
  • tests/support/fakes/dns.py maps names to addresses, can answer every name with one public address as public_dns does, can script the answers of a name per lookup, can time out a name, and fails an unknown name with the socket.gaierror the real lookup raises. It records each lookup.
  • A dns fixture installs the fake through the hook, removes it at teardown and returns it. The root conftest registers it once, and the process-state reset restores the real resolver. Until the direct socket.getaddrinfo callers are routed, the fixture also answers socket.getaddrinfo from the same fake, the stdlib fallback that docs/TESTING.md allows for stdlib edges.
  • tests/http/, the mirror directory of http/egress.py, holds the DNS contract suite. It runs each case against the fake and the real resolver. The real side resolves only localhost and IP literals, which the hermetic floor lets through. Cases: a loopback name, an IP literal, an unknown name and a timeout.
  • ARCHITECTURE.md names the resolver seam.
  • 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, no tool found. A Protocol with one real implementation and one hook follows the keyring seam (config/os_keyring.py) and needs no new library.

Related

Parent: #1314. Part 2 is the HTTP entry point and fake; part 3 is the caller migration. The 44 test files that request public_dns and the 29 that use scripted_resolver move to the dns fixture with their packages in part 3, which then deletes public_dns and ScriptedResolver.

Activity

  1. added
    source/agent
    type/refactor
    scope/cli
    status/new
    value/medium
    effort/medium
    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. It is a prerequisite for testing the egress security system but does not itself fix a vulnerability or block a release.
    • Value: Medium. It makes the egress DNS check testable in isolation, which improves confidence in the security fix of #898.
    • Effort: Medium. It adds a Protocol, a fake, a fixture, a contract suite, and a docs line across several files, but the scope is bounded.
    • Related: fix(security): the pre-flight resolve paths go, the kept pre-flight checks call vet_addresses, and the docs say every http client is checked at the connect #2437, which asks for a different change. Both touch the vet_addresses path in http/egress.py, but #2437 deletes pre-flight resolve paths while the candidate adds an injectable DNS seam and fake for testing.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    owner/agent
    on Nov 6, 2026
  5. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Answer from project standards, under the owner's instruction of 2026-11-05.

    Question: Where does the DNS contract suite live? #1314 said tests/core/.

    Answer: In tests/http/test_dns_contract.py. The seam is in http/egress.py since #2437 removed the DNS code of core/validation.py, and docs/TESTING.md (Layout) says tests/ mirrors the package tree. I changed the criterion in the body.

    Question: Do the users of public_dns and scripted_resolver move in this item?

    Answer: No. They still patch socket.getaddrinfo and httpcore2 dials, and they move with their packages in #3758, which deletes both fixtures. The dns fixture does what they do, and the two sets coexist until then.

    Rule: docs/TESTING.md (Layout; Until the migration ends) and the split of #1314.

  6. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 6, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 6, 2026
  8. added a commit that references this issue on Nov 6, 2026
  9. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 08:16 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/mediumpriority/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