feat: add watch to check definitions in .infrahub.yml (INFP-506)

Merged
OG
10h ago
+64-6

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 InfrahubCheck or infrahub_sdk/checks.py.
  • No change to the shared InfrahubWatchConfig docstring or to the MISSING_WATCH_MESSAGE and MALFORMED_WATCH_MESSAGE texts, which also mention transforms and regeneration. Rewording them would change the warnings for generators and transforms too.
  • No change to the .infrahub.yml reference documentation, which is generated in the Infrahub repository.

What changed

  • InfrahubCheckDefinitionConfig has an optional watch field, defined the same way as on InfrahubGeneratorDefinitionConfig. A check definition without watch still parses, with watch set to None. A list such as watch: [a, b] is rejected, as it is for generators.
  • The JSON schema generated for .infrahub.yml marks watch as required on check definitions, through the same REQUIRE_WATCH_JSON_SCHEMA branch that generators and Python transforms use. YAML language servers then show a warning in the editor when a check definition has no watch block. The warning is advisory: the models still accept a check definition without watch, and watch: {} or files: [] does not trigger it.
  • The genuine required fields of a check definition in the generated schema stay name and file_path.

How to test

uv run pytest tests/unit/sdk/test_schema_repository.py

The tests cover:

  • The watch field on check definitions: omitted, object form, list form.
  • The schema warning: a check definition without watch is flagged, one with watch: {}, files: [] or files: ["lib/"] is not.
  • The guidance messages and the genuine required fields in the generated schema.

Impact & rollout

  • Backward compatibility: existing .infrahub.yml files still parse. Editors that use the published JSON schema will show a new warning on check definitions without a watch block.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated: not in this repository, the .infrahub.yml reference is generated in the Infrahub repository
  • Internal .md docs updated: not needed