Skip to content

refactor(exporters): dispatch map_rule on the typed field mapping - #63

Merged
aaronlippold merged 1 commit into
nextfrom
refactor/fh9l14-map-rule-dispatch
Nov 19, 2026
Merged

aaronlippold merged 1 commit into
nextfrom
refactor/fh9l14-map-rule-dispatch

Conversation

@aaronlippold

Copy link
Copy Markdown
Member

map_rule now dispatches on the field mapping's model, and the remaining field-mapping builders read typed models instead of dicts.

  • Dispatch: map_rule loops over the style model's field mappings and uses match on each one's type. The last case is assert_never, so a structure with no case is a mypy error (checked by dropping one).
  • Builders: _build_field_value, _composite_text, create_embedded_xml_tags and dublin_core_elements take typed models. The old in-loop branches are now _nested_element, _references and _element_from_value, with the same logic.
  • Loader: the per-file pass that resolves cci_lookup.mapping_file matches the shape of the raw YAML. No .get() on field-mapping data is left in mapping_engine.py.
  • Defaults: stated once in the models, with the same values. A composite's separator is a blank line; a tag source's separator and an embedded tag's content are ""; a nested mapping's system and a Dublin Core href are ""; multiple is false. Rule attribute maps take RuleTemplateText.
  • Engine checks removed: checks the schema already makes at load are gone from the engine (missing components or sources, an unknown Dublin Core source_logic). apply_field_mapping, which nothing called, is deleted, and the developer guide's code reference shows the real loop.
  • Tests: tests that changed engine.config dicts now load a style file that extends the DISA style. A source-text assertion on the loop is replaced by a test that builds a Rule from one mapping of each of the seven structures.

Checks:

  • Full suite, tests/scripts, mypy, ruff and mkdocs build --strict pass.
  • All 28 exports (9 cached real benchmarks and 5 synthetic fixtures, DISA and CIS) are byte-identical to next and pass cis-bench validate.

Card: cis-bench-fh9l.14.

map_rule loops over the style model's field mappings and matches on each
mapping's model; an unhandled structure is a mypy error (assert_never).
The simple, composite, embedded_xml_tags, nested and dublin_core builders
take their typed variants (_build_field_value, _composite_text,
create_embedded_xml_tags, dublin_core_elements, and the new
_nested_element, _references and _element_from_value). The loader's
per-file pass for cci_lookup.mapping_file matches the raw YAML's shape.
No .get() on field-mapping data is left in mapping_engine.py.

The defaults those reads carried are stated once in the models: a
composite's separator is a blank line, a tag source's separator and an
embedded tag's content are "", a nested mapping's system and a dublin_core
href are "", and multiple is false. Rule attribute maps take
RuleTemplateText (always text). Checks the schema already makes at load
are gone from the engine (missing components or sources, an unknown
dublin_core source_logic), and apply_field_mapping, which nothing called,
is deleted.

Tests that changed engine.config dicts now load a style file that
extends the DISA style. The 28 exports are byte-identical.

Refs: cis-bench-fh9l.14
Signed-off-by: Aaron Lippold <lippold@gmail.com>
@aaronlippold
aaronlippold merged commit ff6268c into next Nov 19, 2026
7 checks passed
@aaronlippold
aaronlippold deleted the refactor/fh9l14-map-rule-dispatch branch November 19, 2026 22:06
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