Skip to content

Derive CLI value lists from library enums with analyzer drift guard#300

Merged
sdairs merged 2 commits into
fix/openapi-drift-298from
issue-291-cli-known-values-drift-guard
Jul 17, 2026
Merged

Derive CLI value lists from library enums with analyzer drift guard#300
sdairs merged 2 commits into
fix/openapi-drift-298from
issue-291-cli-known-values-drift-guard

Conversation

@sdairs

@sdairs sdairs commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #291.

Summary

Replace eight hand-maintained KNOWN_* constant lists in the CLI with pub const VALUES on the library enums they validate against. The analyzer now verifies that any enum declaring a VALUES const has it exactly equal (as a set) to its non-catch-all wire values, producing FindingKind::EnumValuesMismatch on mismatch.

This closes the drift chain: spec ↔ enum variants (guarded since #290) and enum variants ↔ VALUES (new check), so VALUES is transitively spec-accurate. A spec drift remediation that adds an enum value now flows automatically: spec → analyzer finding → models.rs variant + VALUES (analyzer fails CI if VALUES is not updated) → CLI validation, error messages, and --help update with zero CLI edits.

Changes

Library (models.rs)

  • Add pub const VALUES: &'static [&'static str] to 9 enums: PgHaType, PgProvider, PgVersion, ServicePatchRequestReleasechannel, ServicePostRequestCompliancetype, ServicePostRequestProfile, ServicePostRequestProvider, ServicePostRequestRegion, ServicePostRequestReleasechannel.
  • VALUES on ServicePostRequestRegion includes europe-west2 and ca-central-1, fixing existing drift where the CLI rejected valid regions.

Analyzer (clickhouse-openapi-analyzer)

  • rust_inventory.rs: Parse Item::Impl blocks in models.rs to extract VALUES const string literals into EnumInfo.values_const. 4 new inventory tests.
  • report.rs: Add FindingKind::EnumValuesMismatch, bump REPORT_SCHEMA_VERSION from 1 to 2.
  • compare.rs: compare_enum_values_consts checks every enum with a VALUES const against its wire values (set equality); emits EnumValuesMismatch with details[missing] and details[extra]. 4 focused comparison tests.

Python issue rendering

  • check-openapi-drift.py: Schema version check → 2, summary table row and simple_sections entry for enum_values_mismatch.
  • test_check_openapi_drift.py: Synthetic finding, assertion, and schema version rejection test updated.

CLI (clickhousectl)

  • commands.rs: Delete KNOWN_PROVIDERS, KNOWN_REGIONS, KNOWN_RELEASE_CHANNELS, KNOWN_COMPLIANCE_TYPES, KNOWN_PROFILES; use Enum::VALUES in parse_serde_enum calls.
  • postgres.rs: Delete KNOWN_PG_PROVIDERS, KNOWN_PG_VERSIONS, KNOWN_PG_HA_TYPES; use Enum::VALUES in parse_serde_enum and PossibleValuesParser calls.

Documentation

  • AGENTS.md: Added VALUES const checking section under enum value coverage.

Verification

cargo test --workspace                    # 720+ tests, 0 failures
cargo clippy --workspace --all-targets -- -D warnings   # clean
cargo check --workspace --all-features    # clean
python3 -m unittest discover -s scripts/tests -p 'test_*.py'  # 3 tests pass
python3 scripts/check-openapi-drift.py --dry-run          # 0 actionable drift

@sdairs sdairs added the enhancement New feature or request label Jul 16, 2026
@sdairs
sdairs requested review from iskakaushik and rndD as code owners July 16, 2026 19:44
@sdairs sdairs added the enhancement New feature or request label Jul 16, 2026
@sdairs
sdairs temporarily deployed to cloud-integration July 16, 2026 19:44 — with GitHub Actions Inactive
Comment thread crates/clickhouse-openapi-analyzer/src/rust_inventory.rs Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 93f504b. Configure here.

Comment thread crates/clickhouse-cloud-api/src/models.rs
sdairs and others added 2 commits July 16, 2026 22:00
…291)

Replace eight hand-maintained KNOWN_* constant lists in the CLI with
pub const VALUES on the library enums they validate against. The
analyzer now verifies that any enum declaring a VALUES const has it
exactly equal (as a set) to its non-catch-all wire values, producing
FindingKind::EnumValuesMismatch on mismatch.

Library (models.rs):
- Add pub const VALUES to 9 enums: PgHaType, PgProvider, PgVersion,
  ServicePatchRequestReleasechannel, ServicePostRequestCompliancetype,
  ServicePostRequestProfile, ServicePostRequestProvider,
  ServicePostRequestRegion, ServicePostRequestReleasechannel.
- VALUES on ServicePostRequestRegion includes europe-west2 and
  ca-central-1, fixing existing drift where the CLI rejected valid
  regions.

Analyzer (clickhouse-openapi-analyzer):
- rust_inventory.rs: parse Item::Impl blocks in models.rs to extract
  VALUES const string literals into EnumInfo.values_const.
- report.rs: add FindingKind::EnumValuesMismatch, bump
  REPORT_SCHEMA_VERSION from 1 to 2.
- compare.rs: compare_enum_values_consts checks every enum with a
  VALUES const against its wire values (set equality); emits
  EnumValuesMismatch with details[missing] and details[extra].

Python issue rendering:
- check-openapi-drift.py: schema version check -> 2, summary table
  row and simple_sections entry for enum_values_mismatch.
- test_check_openapi_drift.py: synthetic finding, assertion, and
  schema version rejection test updated.

CLI (clickhousectl):
- commands.rs: delete KNOWN_PROVIDERS, KNOWN_REGIONS,
  KNOWN_RELEASE_CHANNELS, KNOWN_COMPLIANCE_TYPES, KNOWN_PROFILES;
  use Enum::VALUES in parse_serde_enum calls.
- postgres.rs: delete KNOWN_PG_PROVIDERS, KNOWN_PG_VERSIONS,
  KNOWN_PG_HA_TYPES; use Enum::VALUES in parse_serde_enum and
  PossibleValuesParser calls.

Closes #291.
An impl block that lexically precedes its enum declaration was silently
skipped, disabling the VALUES drift guard for that enum. Trait impls
with an associated VALUES const were also misattributed. Address both
review findings and replace the vacuous non-enum-impl test assertion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sdairs
sdairs force-pushed the issue-291-cli-known-values-drift-guard branch from 93f504b to 7e37405 Compare July 16, 2026 21:03
@sdairs
sdairs changed the base branch from main to fix/openapi-drift-298 July 16, 2026 21:03
@sdairs
sdairs temporarily deployed to cloud-integration July 16, 2026 21:04 — with GitHub Actions Inactive
@sdairs
sdairs merged commit 0c0643a into fix/openapi-drift-298 Jul 17, 2026
5 checks passed
@sdairs
sdairs deleted the issue-291-cli-known-values-drift-guard branch July 17, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI KNOWN_* value lists are hand-maintained copies of spec enums with no drift guard (--region europe-west2 rejected)

1 participant