Skip to main content

Test Rules

Use the public harness to exercise discovery, compilation, and Rules evaluation:
RuleCase.files adds supporting project files. RuleCase.config supplies option values. Include passing cases, failing cases, near misses, and exact source-position assertions. Repository pytest files remain outside the SQLBuild project’s SQL tests/ directory.

Helpers

Custom Rules can import repository-owned helpers under rules/ and supported pure Python modules. Changing an imported helper invalidates the Rules that depend on it. Only decorated functions register. Ordinary functions, constants, dataclasses, and classes remain helpers.

Deterministic inputs

Direct filesystem, environment, clock, randomness, network, and subprocess access is rejected. Those inputs cannot be reproduced safely by the Rules cache. Read supported project text and structure through ctx.project.tree:
Both positive and negative observations are tracked. If glob returns no paths, adding a matching path invalidates the cached result.

Cache granularity

Cache identity incorporates the Rule implementation, imported helper closure, configured options, subject, accessed compiler facts, tracked project observations, dialect, and compatibility versions. Prefer model subjects for independent per-model checks and project subjects for genuine cross-project invariants.