Skip to content

Add rule engine (only the engine) - #407

Draft
bact wants to merge 9 commits into
spdx:mainfrom
bact:rule-engine-foundation
Draft

Add rule engine (only the engine)#407
bact wants to merge 9 commits into
spdx:mainfrom
bact:rule-engine-foundation

Conversation

@bact

@bact bact commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Note

  • This PR is a split out of Add RuleBasedChecker using conformance rules from YAML + Add SARIF output #393.
  • It adds infrastructure for rule-based checker.
  • It did not yet change any code in existing checkers (that will be done in future PRs).
  • This PR is relatively big (12 new files + dependency additions to pyproject.toml),
    but it does not change any existing file.
  • Half of the content are code comments, rule files, and tests.
  • We may start at ntia_conformance_checker/rules/README.md to get overview.
  • Then look at ntia_conformance_checker/rules/_example.yaml to see how rule will look like declaratively
  • Then look at ntia_conformance_checker/spec.py to see how rules will be represented in Python. spec.py is well documented. Most logic are explained there.
  • The actual checking is not yet in this PR. Probes to actually look at minimum elements will be added in future PRs.

Add declarative rule engine foundation (spec model, YAML loader, probes),
preparing for the implementation of rule-based checker in the future.

  • spec.py: dataclasses, including Spec, represent a compliance standard.
  • spec_loader.py: YAML -> Spec loader with load-time validation
  • registry.py: discovers and loads every packaged rules/*.yaml at import time
  • probes/: registered probe functions (name -> callable) that answer presence questions about a parsed SBOM.
  • rules/ntia.yaml, rules/fsct3.yaml: the NTIA and FSCT3 rule catalogues as data, propose to replace per-standard Python logic in the future

Adding a new compliance standard in the future can be done by adding a rule to rules/<id>.yaml with no Python subclass required (but additional Python probes may still required if existing probes cannot answer questions for the new compliance standard).

bact added 2 commits July 4, 2026 10:40
Split out of PR spdx#393 (rule-engine + SARIF branch) as a standalone,
additive PR per the PR-splitting plan. Nothing in the existing
checkers imports these modules yet, so this changes no external
behavior -- it only adds the schema these modules define.

Introduces:
- spec.py: frozen dataclasses (Spec, SpecCategory, SpecMaturity,
  SpecRule, ProbeRef) that model a compliance standard's full rule
  catalogue, independent of any output format.
- spec_loader.py: YAML -> Spec loader with load-time validation
  (unknown keys, bad enum values, duplicate rule ids, unknown
  spec_category references, unregistered probe names).
- registry.py: discovers and loads every packaged rules/*.yaml at
  import time, indexed by spec id.
- probes/: registered probe functions (name -> callable) that answer
  presence questions about a parsed SBOM.
- rules/ntia.yaml, rules/fsct3.yaml: the NTIA and FSCT3 rule
  catalogues as data, replacing hardcoded per-standard Python logic.
- RULES.md: rule id and schema documentation.

Adding a new compliance standard is now "drop a rules/<id>.yaml file"
with no Python subclass required.

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
RULES.md documents the rule id scheme as a public contract. Will publish later.

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact bact added this to the 6.0 milestone Jul 4, 2026
@bact bact added the enhancement New feature or request label Jul 4, 2026
@bact

bact commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

@InduwaraGunasena since you're thinking about this concept as well in the past week, please help review. Particularly the shape and the keywords in the rule (can see ntia_conformance_checker/rules/ntia.yaml as example).

Feel free to propose any changes, asking for clarifications, etc.

bact added 2 commits July 4, 2026 13:31
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
@bact
bact marked this pull request as draft July 4, 2026 12:46
bact added 5 commits July 4, 2026 13:47
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Never called anywhere and not re-exported from probes/__init__.py;
base_checker.py calls probes.lookup() directly instead.

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Optional, empty-by-default IRI field to later link each rule's element
to a shared semantic concept in an external SBOM ontology (SKOS /
SSSOM). No shipped rule populates it yet; the slot is plumbed through
the loader and documented in _example.yaml so linking becomes a pure
data change.

Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant