feat: add watch to check definitions in .infrahub.yml (INFP-506)
Merged
OG
10h ago+64+64+01234567890123456789-6-6-0123456789
Why
This prepares the watch field on check definitions for selective user check runs (INFP-506) in Infrahub 1.13. Repository authors can list the extra files and directories a check depends on in .infrahub.yml, in the same form they already use for Python transforms and generator definitions.
Infrahub does not read this field yet. The backend part that would use it to decide which checks to run has not been built, so declaring watch on a check definition has no effect on check runs today.
Non-goals:
- No change to
InfrahubCheckorinfrahub_sdk/checks.py. - No change to the shared
InfrahubWatchConfigdocstring or to theMISSING_WATCH_MESSAGEandMALFORMED_WATCH_MESSAGEtexts, which also mention transforms and regeneration. Rewording them would change the warnings for generators and transforms too. - No change to the
.infrahub.ymlreference documentation, which is generated in the Infrahub repository.
What changed
InfrahubCheckDefinitionConfighas an optionalwatchfield, defined the same way as onInfrahubGeneratorDefinitionConfig. A check definition withoutwatchstill parses, withwatchset toNone. A list such aswatch: [a, b]is rejected, as it is for generators.- The JSON schema generated for
.infrahub.ymlmarkswatchas required on check definitions, through the sameREQUIRE_WATCH_JSON_SCHEMAbranch that generators and Python transforms use. YAML language servers then show a warning in the editor when a check definition has nowatchblock. The warning is advisory: the models still accept a check definition withoutwatch, andwatch: {}orfiles: []does not trigger it. - The genuine required fields of a check definition in the generated schema stay
nameandfile_path.
How to test
uv run pytest tests/unit/sdk/test_schema_repository.py
The tests cover:
- The
watchfield on check definitions: omitted, object form, list form. - The schema warning: a check definition without
watchis flagged, one withwatch: {},files: []orfiles: ["lib/"]is not. - The guidance messages and the genuine required fields in the generated schema.
Impact & rollout
- Backward compatibility: existing
.infrahub.ymlfiles still parse. Editors that use the published JSON schema will show a new warning on check definitions without awatchblock.
Checklist
- Tests added/updated
- Changelog entry added
- External docs updated: not in this repository, the
.infrahub.ymlreference is generated in the Infrahub repository - Internal .md docs updated: not needed