Repository navigation
Description
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-681and: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,:746and:782. :312: the client builds its ownhttpx2.Clientfor 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
-
CloudflareClienttakes 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 ithttpx2.MockTransportor refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP fake and patches nohttpx2ordevops_cliname. - 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_recordsthat 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_messagetakes 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.pyin CI goes up from 66%. The pull request gives the new figure. -
uv run devops cipasses.
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
- How should the HTTP transport be injected into CloudflareClient?: Add a transport parameter to CloudflareClient.init. If refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP seam has landed, use that instead. The body states both options and the primary is the constructor parameter. (proposed)
- Are fix(infra): cloudflare access sync reads every page of applications and policies and retries rate-limited requests #1436's pagination and retry tests in scope for this item?: No. The body states that fix(infra): cloudflare access sync reads every page of applications and policies and retries rate-limited requests #1436 owns the pagination of the Access listings and the retries, so this item does not test them. fix(infra): cloudflare access sync reads every page of applications and policies and retries rate-limited requests #1436 is already archived. (proposed)
- What is the status of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's HTTP seam?: The body says "or from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam if that has landed", implying it may or may not be done. The work proceeds with a constructor parameter if refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 is not yet available. [sources: src/devops_cli/cloudflare/client.py:312]
- What happens to _extract_policy_include_email?: refactor: Delete unused functions after manual caller check #1910 deletes it. This item does not test it. [sources: src/devops_cli/cloudflare/client.py:228]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 24, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate proposes adding tests for the Cloudflare client's write and error paths.The candidate addresses test coverage and code quality, which are important for maintaining a stable product.Improving test coverage helps prevent regressions and increases confidence in the Cloudflare client functionality.Adding comprehensive tests for multiple write and error paths requires significant development effort.dan-petty commentedon Oct 27, 2026
Status set to Ready at 0abf552 (see proposed design in issue body).