test(schema): pin offline-validation errors and AttributeKind values

Merged
SA
7d ago
+63-22

Why

PR #1135 added the offline schema validator tests. Its review left two threads open (AttributeKind test, error-message assertions):

  • Five tests in tests/unit/test_schema_offline_validation.py asserted any("<field>" in message for message in result.messages). These pass as long as some message mentions the field, so a changed message text or an extra error does not fail them. The reviewer asked for "only 1 error and it should be possible to assert more, or all, of its text".
  • test_attribute_kind_enum_present_without_deprecated_string_member repeated the parametrized enum test because AttributeKind was missing from its table.

Tracked as INBOX-129 in the Engineering Inbox.

What changed

Test code only. The validator and the generated models are unchanged.

  • test_schema_offline_validation.py:
    • The Jinja2, TransformPython, choice-color and relationship-cardinality tests assert the full list of messages.
    • test_out_of_enum_value_is_rejected_naming_field_and_value asserts exactly one error, its field, the received value, the reason and the rendered message. For the two literal enums (relationship kind and cardinality) the expected reason is the whole reason. For the attribute and computed-attribute kind discriminators, it is the part that names the rejected tag. Pydantic then lists every accepted tag in the order of the generated union. That list is not pinned, so regenerating the union in a different order does not break the test.
  • test_schema_generated_models.py: AttributeKind is an entry of _EXPECTED_ENUM_VALUES with its full member list, which does not include String. The separate test is removed.

How to test

uv run pytest tests/unit/test_schema_generated_models.py tests/unit/test_schema_offline_validation.py

112 passed. Full unit suite: 3,148 passed, 2 skipped, 1 xfailed, the same as on stable. invoke format, ruff, ty, mypy, yamllint, rumdl and invoke docs-validate pass. Vale is not installed on the machine that ran the checks, so the docs style check did not run. The diff changes no documentation.

To check that the tests now detect message changes, (received: was changed to (got: in infrahub_sdk/schema/validate.py. The two modules then fail 10 tests on this branch and 2 on stable.

šŸ¤– Generated with Claude Code