Skip to content

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

Merged
ogenstad merged 1 commit into
infrahub-developfrom
infp-506-check-definition-watch
Dec 4, 2026
Merged

ogenstad merged 1 commit into
infrahub-developfrom
infp-506-check-definition-watch

Conversation

@ogenstad

@ogenstad ogenstad commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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

View guided diff Turn on auto-fix

Check definitions now accept the same optional 'watch' block as Python
transforms and generator definitions, listing extra files and directories
the check depends on.

The JSON schema generated for .infrahub.yml marks 'watch' as required on
check definitions through the shared advisory allOf branch, so YAML language
servers warn when a check definition has no watch block. The models still
accept a check definition without watch, and 'watch: {}' or 'files: []'
does not trigger the warning.
@ogenstad
ogenstad requested a review from a team as a code owner December 3, 2026 18:46
@ogenstad ogenstad added the type/feature New feature or request label Dec 3, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: faf224b
Status: ✅  Deploy successful!
Preview URL: https://9bf486e1.infrahub-sdk-python.pages.dev
Branch Preview URL: https://infp-506-check-definition-wa.infrahub-sdk-python.pages.dev

View logs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

View guided diff | Turn on auto-fix | Re-trigger cubic

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop    #1585      +/-   ##
====================================================
- Coverage             88.65%   88.63%   -0.03%     
====================================================
  Files                   161      161              
  Lines                 17618    16571    -1047     
  Branches               2447     2224     -223     
====================================================
- Hits                  15620    14687     -933     
+ Misses                 1398     1319      -79     
+ Partials                600      565      -35     
Flag Coverage Δ
integration-tests 42.03% <0.00%> (-0.44%) ⬇️
python-3.10 65.10% <0.00%> (-0.21%) ⬇️
python-3.11 65.10% <0.00%> (-0.22%) ⬇️
python-3.12 65.10% <0.00%> (-0.22%) ⬇️
python-3.13 65.10% <0.00%> (-0.22%) ⬇️
python-3.14 65.09% <0.00%> (-0.22%) ⬇️
python-3.15 65.10% <0.00%> (-0.22%) ⬇️
python-filler-3.12 21.87% <100.00%> (-0.39%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/schema/repository.py 92.63% <100.00%> (+0.03%) ⬆️

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogenstad
ogenstad merged commit c18a764 into infrahub-develop Dec 4, 2026
32 checks passed
@ogenstad
ogenstad deleted the infp-506-check-definition-watch branch December 4, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants