Skip to content

test(infra): Argo CD, PromQL and Grafana use the HTTP fake #3754

Closed

Description

@dan-petty

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.Client and httpx2.Client.post (10 in all, 3 of them through commands.prometheus).
  • load_settings (12) and get_argocd_token (4).
  • argo.rollouts.abort_rollout (6), _fetch_metric_value (5), argo.fleet.sync_fleet (3) and ArgoCRDService._api (3).
  • ai.mcp.server._run_mcp_cmd (4) and argo.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

Three Q19 rules still sit in commands/, each with HTTP:

  • PromQL client. commands/prometheus.py builds a client (_client, line 71) and calls the Prometheus API in five commands (lines 174, 240, 330, 398, 453). _validate_expr, _parse_duration and _read_json sit beside them. argo/rollouts.py:78 (_fetch_metric_value) holds a second copy of the instant query.
  • Grafana dashboard calls. commands/grafana.py:289-350 holds _is_provisioned, _post_dashboard and _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-61 repeats 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

  1. Wait until the blocker is settled. Then rebase on origin/main and check what the files look like.
  2. Add prometheus/client.py with a public client. It takes a base URL, the egress level and a client from the entry point. It has query, query_range, labels, rules and alerts. Move the validation of the expression and the duration parsing next to it. The command prints. argo/rollouts.py calls the same query. This removes the second copy.
  3. Add the Grafana dashboard calls to grafana/ as public functions. The command prints and counts.
  4. Add argo/client.py. It resolves the URL and the token once and builds the headers. fleet.py, gitops.py and the command use it. Move _check_image_pins into argo/image_pins.py, which already has check_pins(pins, client, *, timeout).
  5. Tests install the web fixture (refactor(cli): Unify HTTP and DNS seams with shared fakes #1314) and the keyring fake. They patch no name and set no MagicMock settings. They use the config fixture. Dissolve test_fetch_metric_value_branches into tests named after the behaviour: no URL means no value, a value is read, a refused address means no value.
  6. Move the cases that test the moved rule from tests/commands/test_prometheus.py, test_grafana.py and test_argo.py to tests/prometheus/, tests/grafana/ and tests/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.
  7. Replace the abort_rollout, sync_fleet and ArgoCRDService._api patches with FakeCluster and the web fixture. Use the cli fixture.

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.py prints nothing.
  • argo/rollouts.py holds no copy of the PromQL query.
  • test_fetch_metric_value_branches is gone. The three files hold no module-level CliRunner().
  • uv run devops ci passes. 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-client 0.7.2 (released 2026-04-13) depends on requests and dateparser. pyproject.toml has no requests. The client takes an optional requests.Session (prometheus_connect.py:55, 87-90), so a session can be injected. It has no call for rules or alerts. Its transport is not httpx2, so the egress check of vet_addresses and the one HTTP fake do not reach it. Rejected.
  • grafana-client 5.1.4 (released 2026-10-20) depends on niquests. It creates its own niquests.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-client 1.0.2 (2021-10-13, generated code on urllib3) and argocd 0.5.0 (2022-10-15, pins requests==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

  1. added
    source/agent
    type/test
    scope/infra
    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/test. The test prefix of the title gives the type.
    • Scope: scope/infra. The (infra) scope of the title gives the scope.
    • Priority: P3-Low. It is the sixth and final part of #1335, blocked on open issue #1314, and changes only test code.
    • Value: Medium. It removes 61 fragile patch sites and makes 83 tests use one shared fake, improving long-term test stability.
    • Effort: High. It spans 1,686 lines in three files, 61 patch sites, and adds three new client modules.
    • Related: refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, which asks for a different change. 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.
  3. added
    priority/p3-low
    on Nov 6, 2026
  4. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 7, 2026
  5. removed
    status/in-review
    on Nov 7, 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/p3-lowscope/infrasource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions