Skip to content

refactor(exporters): check styles against the models in the schema - #59

Merged
aaronlippold merged 3 commits into
nextfrom
refactor/fh9l3-style-checks-in-schema
Nov 19, 2026
Merged

aaronlippold merged 3 commits into
nextfrom
refactor/fh9l3-style-checks-in-schema

Conversation

@aaronlippold

Copy link
Copy Markdown
Member

Moves the style checks that need the XCCDF or Benchmark models from nine hand-written MappingEngine._refuse_* methods into the style schema (StyleConfig), so a style rule has one home and every refusal names the path of the key.

  • ConfigLoader gives the schema StyleModels as pydantic validation context, for each file of an extends chain: the XCCDF models of the style's version, the Recommendation and Benchmark models, and the engine's own transform lookup and template parser (one of each).
  • Field names: RecommendationField, RecommendationPath and BenchmarkField check source_field, sources, children and element sources; cci_lookup.source_field must hold CIS controls.
  • Transforms: TransformName checks the registry. Template checks its filters in the strings the engine fills; a filter-like text in a string nothing fills (severity, style_name) is plain text.
  • Elements: a field mapping's target, a Group element and a Benchmark element are checked against the XCCDF version.
  • Rule metadata: the prefix is declared and not XCCDF's, group_by names a field of the items, and the target must repeat and take elements of every namespace but XCCDF's. The holder's wildcard is read with the XCCDF namespace as parent namespace, and a Dublin Core prefix on dc_status is refused.
  • The engine reads the models through the same StyleModels; the nine methods, their constants and the engine's own XmlContext are deleted.

Every refusal of the nine methods was listed with the test that covers it before any deletion; the four with no test got one first, passing on the old code. Empty names keep their old behaviour.

Verification: 2821 tests passed, tests/scripts 53, mypy, ruff, format, mkdocs build --strict; 28 XCCDF exports (9 cached benchmarks and 5 synthetic fixtures, DISA and CIS) byte-identical to the exports before this change and valid.

Card: cis-bench-fh9l.3 (template variables and the nested child type follow in cis-bench-fh9l.12 and cis-bench-fh9l.13)

The checks that need the XCCDF and Benchmark models move from nine
hand-written MappingEngine._refuse_* methods into StyleConfig's
validation. ConfigLoader gives the schema StyleModels as pydantic
validation context: the XCCDF models of the style's version, the
Recommendation and Benchmark models, and the engine's own transform
lookup and template parser. Each refusal now carries the path of the key.

- Field names: RecommendationField, RecommendationPath and BenchmarkField
  types check source_field, sources, children and element sources.
- Transforms: TransformName checks the registry; Template checks its
  filters in the strings the engine fills (owner decision).
- Elements: a field mapping's target, a Group element and a Benchmark
  element are checked against the XCCDF version.
- Rule metadata: the prefix is declared and not XCCDF's, group_by names a
  field of the items, and the target repeats and takes elements of every
  namespace but XCCDF's, read with the XCCDF namespace as parent namespace
  (a Dublin Core prefix on dc_status is refused).

The engine reads the models through the same StyleModels. Exports are
unchanged: the 28-file comparison is byte-identical.

Refs: cis-bench-fh9l.3
Signed-off-by: Aaron Lippold <lippold@gmail.com>
An empty cci_lookup.source_field names no field; the engine skipped it
before the checks moved into the schema, and the schema does again.

Refs: cis-bench-fh9l.3
Signed-off-by: Aaron Lippold <lippold@gmail.com>
The compatibility case for an empty cci_lookup.source_field now goes
through MappingEngine and checks the written title, not only the load.

Refs: cis-bench-fh9l.3
Signed-off-by: Aaron Lippold <lippold@gmail.com>
@aaronlippold
aaronlippold merged commit 1bf71c6 into next Nov 19, 2026
7 checks passed
@aaronlippold
aaronlippold deleted the refactor/fh9l3-style-checks-in-schema branch November 19, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant