Skip to content

test(cloudflare): the access policy, include-rule, dns and tunnel write paths of the cloudflare client are tested at the http edge #2153

Closed

Description

@dan-petty

What happened

cloudflare/client.py is at 66% line coverage in CI at f4d7066, 120 of 351 statements missed. Its write paths have no test:

  • the Zero Trust Access application create and the policy create and update (create_access_application, create_or_update_access_policy);
  • the include-rule builder and parsers for allowed e-mails and bypass IP addresses (_build_policy_include_rules, _extract_policy_include_rule, _parse_access_policy);
  • the DNS record create, update and delete, and the reconcile step of sync_dns_records (_reconcile_dns_record);
  • the tunnel reads and writes (resolve_tunnel_id, get_tunnel_configuration, update_tunnel_configuration);
  • the error paths: an HTTP error, a non-success answer and its message (_request, _handle_response, _extract_error_message), and the 14 "Account ID is required" and "Zone ID is required" checks.

Only tests/test_cloudflare_commands.py reaches the module. It patches httpx2.Client.request and CloudflareClient methods, which docs/TESTING.md does not allow.

What should happen

Each write path and each error path has a test that sends the request through the client's real code to an HTTP double, and checks the recorded requests and the result as whole values.

Evidence

At b170358:

  • src/devops_cli/cloudflare/client.py:202-254 (rule builder and parsers), :414-475 (DNS writes), :477-529 (tunnel), :582-609 (reconcile), :662-681 and :733-767 (Access writes), :298-352 (request and errors).
  • The account and zone checks repeat at :375, :396, :428, :456, :473, :487, :514, :529, :622, :656, :673, :689, :746 and :782.
  • :312: the client builds its own httpx2.Client for each request, so no test can give it a transport without a patch.
  • tests/test_cloudflare_commands.py:50-131: patch("httpx2.Client.request", ...).

Acceptance criteria

  • CloudflareClient takes its HTTP client or transport from its caller, or from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam if that has landed. A test gives it httpx2.MockTransport or refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake and patches no httpx2 or devops_cli name.
  • Tests cover: the Access application create; the policy create and the policy update with allowed e-mails and bypass CIDRs; a refused CIDR; the DNS create, update and delete; sync_dns_records that creates, updates and leaves a record alone; the tunnel configuration read and write; an HTTP error; a 4xx and a non-success answer, with the message that _extract_error_message takes from the answer.
  • The account check and the zone check are each one helper. One parametrized test covers every public method that needs an account or a zone ID.
  • Each test checks the requests that the double received and the result as whole values. Hosts are example.com.
  • The coverage of cloudflare/client.py in CI goes up from 66%. The pull request gives the new figure.
  • uv run devops ci passes.

Related: #1436 owns the pagination of the Access listings and the retries, so this item does not test them. #1335 moves Cloudflare record matching out of commands/cloudflare.py. #1381 moves this client onto the egress-checked factory. _extract_policy_include_email has no caller, and #1910 deletes it.

Source: #1436

Proposed design

Problem statement

The Cloudflare client's write paths and error paths have no test that exercises the real HTTP code. The existing tests patch httpx2.Client.request, which docs/TESTING.md prohibits. The client builds its own httpx2.Client per request, so no test can inject a transport without a code change to the client. This leaves 120 of 351 statements untested at 66% line coverage.

Acceptance criteria

  • Criterion 1: CloudflareClient accepts an HTTP transport or client from its caller. A test gives it httpx2.MockTransport and patches no httpx2 or devops_cli name.
    Verification: Run the new tests. Confirm no test file contains patch("httpx2" or patch("devops_cli. Confirm the transport is passed via a constructor parameter or refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam.
  • Criterion 2: Tests cover: Access application create; policy create and update with allowed e-mails and bypass CIDRs; a refused CIDR; DNS create, update and delete; sync_dns_records that creates, updates and leaves a record alone; tunnel configuration read and write; an HTTP error; a 4xx and a non-success answer with the message from _extract_error_message.
    Verification: Run uv run pytest on the new test file. Confirm each listed path has at least one test. Confirm the tests check the recorded requests and the result as whole values.
  • Criterion 3: The account check and the zone check are each one helper. One parametrized test covers every public method that needs an account or a zone ID.
    Verification: Inspect the client source for a single _require_account and _require_zone helper. Run the parametrized test and confirm it covers all 14 check sites.
  • Criterion 4: Each test checks the requests the double received and the result as whole values. Hosts are example.com.
    Verification: Review each test assertion. Confirm it compares the full request list and the full result object. Confirm all hostnames are example.com.
  • Criterion 5: The coverage of cloudflare/client.py in CI goes up from 66%. The pull request states the new figure.
    Verification: Run uv run devops ci and read the coverage report for src/devops_cli/cloudflare/client.py. Confirm the figure exceeds 66%.
  • Criterion 6: uv run devops ci passes.
    Verification: Run uv run devops ci in a clean checkout with the changes applied. Confirm all checks pass.

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 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.

    • Type: type/test. The candidate proposes adding tests for the Cloudflare client's write and error paths.
    • Priority: P1-High. The candidate addresses test coverage and code quality, which are important for maintaining a stable product.
    • Value: High. Improving test coverage helps prevent regressions and increases confidence in the Cloudflare client functionality.
    • Effort: High. Adding comprehensive tests for multiple write and error paths requires significant development effort.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 0abf552 (see proposed design in issue body).

  4. added
    priority/p1-high
    status/ready
    effort/high
    value/high
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Oct 28, 2026
  5. 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/highpriority/p1-highsource/agenttype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions