fix(config): stop dropping sieve gating metadata on the effective config path#317
Conversation
…l loader Fixes an issue where sieve controls with `when`, `depends_on`, `inferred_from`, and `on_pass` metadata attributes were stripped during config merging. This correctly honors skipping applicability for OSPS-QA-02.01. Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
|
Thanks @Jaydeep869 I verified on main that the effective-config path (used by both the MCP audit tool and Two changes needed before merge:
Minors:
|
… regression tests Remove the hasattr/getattr guards in merge_control — ControlConfig is a Pydantic model that always declares when, depends_on, inferred_from, and on_pass as fields, so the guards were dead code. Plain attribute access is cleaner and more idiomatic. Add TestSieveGatingMetadataPreservation regression test class that: - Builds a FrameworkControl with all four gating metadata fields set - Runs it through the full effective-config pipeline: merge_control → control_from_effective → ControlSpec - Asserts all four fields (when, depends_on, inferred_from, on_pass) survive into both EffectiveControl and ControlSpec.metadata - Also verifies controls without optional gating fields are unaffected This test would have caught the metadata-stripping regression when it was originally introduced. Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
|
Hey @Marc-cn I have pushed the changes you asked can you reveiw the pr again. |
|
Thanks @Jaydeep869 , all addressed: the regression tests cover both layers with exact-value asserts including the negative case, the dead guards are gone, and the description now matches the diff. Re-verified against current main |
Summary
Fixes a framework-level bug where the effective-config path (
merge_control→control_from_effective) was silently droppingwhen,depends_on,inferred_from, andon_passfrom all controls. This meant everywhengate andinferred_fromauto-pass was dead in production audits — 0 of 62 baseline controls carried gating metadata despite 53 uses in the TOML.The parallel
control_from_frameworkpath already carried these fields correctly, which is why unit tests stayed green.Root Cause
merge_controlinconfig/merger.pyconstructedEffectiveControlwithout copying the four sieve gating fields fromFrameworkControl. SinceControlConfigis a Pydantic model that always defines these fields, thehasattr/getattrguards added later were also dead code.Changes
packages/darnit/src/darnit/config/merger.py: Passwhen,depends_on,inferred_from, andon_passfromFrameworkControlintoEffectiveControlinmerge_control. Remove deadhasattr/getattrguards — plain attribute access is correct sinceControlConfigalways defines these fields.tests/darnit/config/test_merger.py: AddTestSieveGatingMetadataPreservationregression test class that:FrameworkControlwith all four gating fields setmerge_control→control_from_effective→ControlSpecEffectiveControlandControlSpec.metadataType of Change
Testing
uv run pytest tests/ -v)uv run ruff check .)