Skip to content

refactor(api): move the Query API into client/query.rs (#1173) - #1176

Open
sdairs wants to merge 4 commits into
feat/1164-cloud-service-dotenvfrom
claude/1173-api-client-query
Open

sdairs wants to merge 4 commits into
feat/1164-cloud-service-dotenvfrom
claude/1173-api-client-query

Conversation

@sdairs

@sdairs sdairs commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Part of #1173 (1 of 6: client/query.rs). Stacked on #1167.

Summary

This moves the Query API out of crates/clickhouse-cloud-api/src/client.rs into a new private module, src/client/query.rs. Behaviour and the public surface are unchanged. client.rs keeps Client (including its query_host field), Auth, the constructors, set_bearer_token and request().

File Lines Contents
src/client.rs 138 (was 646) Client, Auth, constructors, set_bearer_token, request()
src/client/query.rs 511 (new) QueryAuth, derive_query_host, query_api_sql_error / query_api_error / query_api_reports_timeout / query_api_reports_stopped_service, impl Client { with_query_host, configured_query_host, resolved_query_host, run_query, run_query_bearer, run_query_with }, and the 14 unit tests that exercise them

client/query.rs now maps to the service Cloud integration suite only. Before, any Query API change touched client.rs, which maps to all four suites.

Commits

  1. Moves only. The code is cut by line range, so the text is byte-identical. The only new or changed lines are the use super::{Auth, Client}; header in query.rs, mod query; in client.rs, the two pub(super) widenings below, and client/postgres.rs's import of query_api_error. Review it with git show --color-moved=dimmed-zebra.
  2. Classifier. scripts/classify-cloud-integration.py maps src/client/query.rs to {"service"}, and the source-mapping fixture in scripts/tests/test_classify_cloud_integration.py lists it.
    • The service suite exercises the Query API live in two places: integration_test calls Client::run_query, and service_query_key_cli_test spawns clickhousectl cloud service query.
    • No other live suite calls run_query, run_query_bearer or run_postgres_query_bearer, or spawns a query command. The ClickPipes CDC test reads rows through its own direct HTTPS helper.
    • client.rs stays ALL_SUITES.
    • The install classifier needs no entry, because API-crate paths are not installer candidates.
  3. .git-blame-ignore-revs entry for commit 1. This SHA must be updated if the stack is rebased before merge.
  4. Docs. The Layout section of crates/clickhouse-cloud-api/AGENTS.md names src/client/query.rs. The stale "Auto-generated from the OpenAPI specification." line is removed from the client.rs module doc.

Visibility widenings

  • query_api_error and Client::resolved_query_host are now pub(super), because client/postgres.rs (run_postgres_query_bearer) shares them. postgres.rs imports query_api_error from super::query.

Tests

  • Counts match before and after: 916 tests in clickhouse-cloud-api and clickhouse-openapi-analyzer (887 passed, 29 ignored). Test names match once module paths are stripped. Only the 14 moved unit tests change path, from client::tests:: to client::query::tests::.
  • spec_coverage_test and model_facade_test pass untouched. python3 scripts/check-openapi-drift.py --dry-run gives the same output before and after (0 actionable drift).
  • All gates pass:
    • cargo fmt --all
    • API and analyzer clippy with --all-targets -D warnings
    • clickhousectl clippy in both configurations
    • cargo check -p clickhousectl --no-default-features
    • cargo check --workspace --all-features
    • cargo test -p clickhouse-cloud-api -p clickhouse-openapi-analyzer
    • the Python classifier tests (113 OK)

Merge with a merge commit, not a squash. The .git-blame-ignore-revs entry names this PR's move commit. A squash merge would leave it pointing at a commit that isn't on main, and git would silently ignore it.

🤖 Generated with Claude Code


Note

Low Risk
Mechanical module split with byte-identical logic and no public API changes; only wiring, visibility, docs, and integration-test classifier mappings.

Overview
Extracts all Query API client logic from client.rs into a new private module client/query.rs, including host resolution (with_query_host, derive_query_host), run_query / run_query_bearer, shared error classification (query_api_error, idle/stopped/timeout handling), and the 14 unit tests that covered those helpers. client.rs now only wires mod query and keeps Client, auth, constructors, and the management request() helper; public behavior and APIs are unchanged.

client/postgres.rs now imports query_api_error from super::query and relies on pub(super) on query_api_error and resolved_query_host so Postgres Query API paths share the same helpers.

CI path classification maps client/query.rs to the service integration suite only (so Query API edits no longer force all four suites via client.rs). AGENTS.md documents the new layout; .git-blame-ignore-revs adds the move commit for blame hygiene.

Reviewed by Cursor Bugbot for commit 96696c6. Bugbot is set up for automated code reviews on this repo. Configure here.

sdairs and others added 4 commits October 30, 2026 19:30
Move QueryAuth, derive_query_host, the query_api_* error helpers, the
query-host methods (with_query_host, configured_query_host,
resolved_query_host), run_query, run_query_bearer and run_query_with,
plus their unit tests, out of client.rs into the private
src/client/query.rs. Code is moved verbatim; only mod/use lines and
visibility change: query_api_error and resolved_query_host become
pub(super) because client/postgres.rs's run_postgres_query_bearer
shares them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Query API (run_query, run_query_bearer) is exercised live only by the
service suite: integration_test calls Client::run_query and
service_query_key_cli_test spawns `clickhousectl cloud service query`.
client.rs stays ALL_SUITES for the shared HTTP machinery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… doc line (#1173)

client.rs has not been generated from the OpenAPI spec for a long time;
remove the "Auto-generated" line from its module doc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sdairs sdairs added enhancement New feature or request client Affects the HTTP client rust Pull requests that update rust code labels Oct 30, 2026
@sdairs
sdairs requested a review from iskakaushik as a code owner October 30, 2026 19:57
@sdairs
sdairs added this pull request to stack #1153 October 30, 2026 19:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Affects the HTTP client enhancement New feature or request rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant