Repository navigation
Description
Problem or Motivation
Part 6 of 6 of #1335. It waits for #1314, the HTTP and DNS seams. That block is a proposal. See "Why #1314 first" below.
Argo CD, Argo Rollouts, Prometheus and Grafana code builds its HTTP clients with new_http_client(level=...). A test cannot inject a transport into that client. The only shared double is stub_web, which swaps the httpx2.Client class, and #1314 deletes it. Measured at origin/main 29309f0, with the counting rules of #1335:
| File | Lines | Tests | Patch sites | Private imports |
|---|---|---|---|---|
tests/argo/test_argo_fleet.py |
621 | 32 | 41 | 5 |
tests/argo/test_argo_gitops.py |
589 | 22 | 15 | 0 |
tests/commands/test_promql_analysis.py |
476 | 29 | 5 | 0 |
| Total | 1,686 | 83 | 61 | 5 |
The sites patch:
httpx2.Clientandhttpx2.Client.post(10 in all, 3 of them throughcommands.prometheus).load_settings(12) andget_argocd_token(4).argo.rollouts.abort_rollout(6),_fetch_metric_value(5),argo.fleet.sync_fleet(3) andArgoCRDService._api(3).ai.mcp.server._run_mcp_cmd(4) andargo.gitops.run_subprocess(3).
The catch-all test_fetch_metric_value_branches (test_argo_fleet.py:400) checks three cases in one test with MagicMock settings. CliRunner() is built at module level in test_argo_fleet.py:19, test_argo_gitops.py:20 and test_promql_analysis.py:28.
Why #1314 first
- The HTTP fake (
web) and the entry point that takes a transport are the work of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314. Its caller-migration part moves callers of the factories to that entry point. It moves their tests to the fixtures. If this part ran first, refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 would edit the same lines again. - refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 is open with
status/new. Nobody has split it. A split into three parts is proposed in its comments (2026-11-05). Part 3 is "caller migration by package", and it names "k8s and argo" and "commands and the rest". - The text of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 has two readings. Its criteria say that package items migrate the "inline builders" and DNS bypasses, and they name test(infra): infrastructure tests run on edge fakes #1335 for three DNS sites. Those DNS sites now call
vet_addresses. The callers in this part use the factorynew_http_client, which is not an inline builder. So part 3 of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 owns them. - If the split of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 gives these callers to the package items, remove the block. Then refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 waits for this part. Until the split, the block is not proven.
Three Q19 rules still sit in commands/, each with HTTP:
- PromQL client.
commands/prometheus.pybuilds a client (_client, line 71) and calls the Prometheus API in five commands (lines 174, 240, 330, 398, 453)._validate_expr,_parse_durationand_read_jsonsit beside them.argo/rollouts.py:78(_fetch_metric_value) holds a second copy of the instant query. - Grafana dashboard calls.
commands/grafana.py:289-350holds_is_provisioned,_post_dashboardand_sync_dashboard_file. They hold the rule that a refused save of a provisioned dashboard is a skip. - Argo CD client.
commands/argo.py:179-208(_argocd,_argocd_client) resolves the URL and the token.argo/fleet.py:50-61repeats the token and header steps.commands/argo.py:396-405(_check_image_pins) builds a public client to check image pins.
Proposed Solution & Architectural Design
- Wait until the blocker is settled. Then rebase on origin/main and check what the files look like.
- Add
prometheus/client.pywith a public client. It takes a base URL, the egress level and a client from the entry point. It hasquery,query_range,labels,rulesandalerts. Move the validation of the expression and the duration parsing next to it. The command prints.argo/rollouts.pycalls the samequery. This removes the second copy. - Add the Grafana dashboard calls to
grafana/as public functions. The command prints and counts. - Add
argo/client.py. It resolves the URL and the token once and builds the headers.fleet.py,gitops.pyand the command use it. Move_check_image_pinsintoargo/image_pins.py, which already hascheck_pins(pins, client, *, timeout). - Tests install the
webfixture (refactor(cli): Unify HTTP and DNS seams with shared fakes #1314) and the keyring fake. They patch no name and set noMagicMocksettings. They use theconfigfixture. Dissolvetest_fetch_metric_value_branchesinto tests named after the behaviour: no URL means no value, a value is read, a refused address means no value. - Move the cases that test the moved rule from
tests/commands/test_prometheus.py,test_grafana.pyandtest_argo.pytotests/prometheus/,tests/grafana/andtests/argo/. The command tests keep wiring only. Do not touch their other patch sites. They belong to the finish of test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327. - Replace the
abort_rollout,sync_fleetandArgoCRDService._apipatches withFakeClusterand thewebfixture. Use theclifixture.
Acceptance criteria
- A test first for each moved function. The Prometheus client has an instant query, a range query, a non-JSON answer and a refused address. The Grafana calls have a save, a refused save of a provisioned dashboard (skip) and a refused save of another kind (failure). The Argo CD client has a missing URL and a missing token.
- The three files hold no patch site and no private import. The pull request comment gives the counts before (61 and 5) and after.
-
git grep -n "new_http_client\|httpx2.Client(" -- src/devops_cli/commands/prometheus.py src/devops_cli/commands/grafana.py src/devops_cli/commands/argo.pyprints nothing. -
argo/rollouts.pyholds no copy of the PromQL query. -
test_fetch_metric_value_branchesis gone. The three files hold no module-levelCliRunner(). -
uv run devops cipasses. The changed lines are covered at 90 percent.
Target Subsystem
Kubernetes & Minikube Automation
Existing Tool Considered
Open client packages exist. The wheel sources were read on 2026-11-06.
prometheus-api-client0.7.2 (released 2026-04-13) depends onrequestsanddateparser.pyproject.tomlhas norequests. The client takes an optionalrequests.Session(prometheus_connect.py:55, 87-90), so a session can be injected. It has no call for rules or alerts. Its transport is nothttpx2, so the egress check ofvet_addressesand the one HTTP fake do not reach it. Rejected.grafana-client5.1.4 (released 2026-10-20) depends onniquests. It creates its ownniquests.Session(client.py:105) and has no session parameter. The egress check and the HTTP fake do not reach it. Rejected.- Argo CD: PyPI holds
argocd-python-client1.0.2 (2021-10-13, generated code onurllib3) andargocd0.5.0 (2022-10-15, pinsrequests==2.28.1). Neither is maintained. The project rule allows only reputable, maintained dependencies. Rejected.
The project sends every request through http/, where vet_addresses checks the address at the connect (http/egress.py). A package that dials by itself skips that check. So the clients stay in the repository, on httpx2. The cost to build is about 400,000 tokens. It costs about 25,000 tokens a year to keep. The work takes about 2 days after the blocker is settled.
Strategic alignment: child of #1335. Parent #1307. Depends on: #1314 (proposed, not proven). Related: #1327 (closed), #1336.
Activity
dan-petty commentedon Nov 6, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
testprefix of the title gives the type.(infra)scope of the title gives the scope.It is the sixth and final part of #1335, blocked on open issue #1314, and changes only test code.It removes 61 fragile patch sites and makes 83 tests use one shared fake, improving long-term test stability.It spans 1,686 lines in three files, 61 patch sites, and adds three new client modules.Both concern the shared HTTP fake for Argo CD, Prometheus and Grafana, but #1314 builds the seam and the candidate migrates 83 tests to use it.test(infra): infrastructure tests run on edge fakes (#4283)