Consistency Constraints

On top of the semantic diff, cfgdrift overlays a constraint-checking layer: after drift is detected, the changed configuration tree is validated against five constraint types, and only violations associated with the current drift are reported — deterministic, explainable, compound alerts.

The five constraint types

TypeMeaningExample
rangenumeric value must stay in [min, max]server.port ∈ [1, 65535]
enumvalue must be in a whitelistlog.level ∈ {debug, info, warn, error}
conditional_requiredwhen the condition holds, the key is requiredif tls.enabled then tls.cert required
correlationnumeric/string relation when the condition holdsreplicas ≤ max_replicas
mutual_exclusiontwo keys must not both be presenthttp.auth ≠ oauth

Complete schema: examples/constraints.yaml.example.

CLI usage

# diff / scan enable the built-in library by default (20 constraints, four domains: web/db/log/auth)
cfgdrift diff ./config --baseline prod
cfgdrift diff ./config --baseline prod --no-builtin           # disable built-ins
cfgdrift diff ./config --baseline prod --constraints extra.yaml   # add more (repeatable)

# manage <home>/constraints.yaml
cfgdrift constraint add --rule '{"id":"my_port","type":"range","keys":["server.port"],"min":1,"max":65535,"message":"server.port must be ≤ 65535"}'
cfgdrift constraint list                  # effective view (builtin + user merged, same id → user wins)
cfgdrift constraint list --source builtin # built-in library only
cfgdrift constraint remove my_port
cfgdrift constraint disable my_port       # / enable my_port

How violations escalate

Baseline violations report (v0.7.0)

cfgdrift scan PATH --baseline B --report-violations   # off by default

Reports pre-existing violations on the baseline itself, deduplicated against drift-associated ones by (constraint_id, file, frozenset(involved_keys)); severity comes straight from the constraint.

Constraint auto-mining (v0.7.0)

cfgdrift constraint mine --min-support 5 --source scans
cfgdrift constraint mine --source corpus --corpus instances.jsonl
cfgdrift constraint mine --json

Discovers candidates (enum/range domains, co-occurrence → conditional_required, mutual exclusion) and writes them to <home>/mined_candidates.yaml with enabled: false / status: pending. The candidate zone never auto-activates; promote with constraint add --rule '<JSON>' after review.

Deep-dive semantics: README.en.md — Consistency Constraints.