fix(sensitive_data_scanner_rules): align description with linked standard pattern on write - #726
Conversation
michael-richey
left a comment
There was a problem hiding this comment.
Reviewed locally. The create/update-path alignment for both name and description looks correct and the added tests are solid.
I also ran ~/.pyenv/versions/fresh-sync-cli/bin/tox -e py39 -- tests/unit/test_sensitive_data_scanner_rules.py (28 passed).
Non-blocking suggestion: in pre_apply_hook, consider guarding on both mappings (name + description) instead of only destination_standard_pattern_mapping, so a partial-cache state cannot skip description initialization in future refactors or long-lived process scenarios.
No blocking issues from my side.
|
Re: review suggestion (pre_apply_hook partial-cache guard) Good suggestion — implemented in 7d88fb5. Added 4 regression tests (
All 32 SDS tests + full unit suite (1481 passed, 8 skipped) green; |
…dard pattern on write The destination API rejects a standard-pattern-linked rule whose attributes.description does not match the linked destination pattern's canonical description (HTTP 400 'description of the standard rule and the rule must match'). The existing _align_name_with_standard_pattern (PR #627) aligned attributes.name but not attributes.description, so rules whose source org's canonical pattern description differed from the destination org's failed to create/update. Rename to _align_with_standard_pattern and extend it to also overwrite attributes.description with the destination pattern's canonical description on create/update, emitting a standard_pattern_description_rewrite metric per rewrite (mirroring the name-rewrite metric) so operators can audit drift. pre_apply_hook now also populates destination_standard_pattern_description_mapping (pattern_id -> description) alongside the existing name->id mapping. Applied only on create/update (not diffs/import) so source state is not silently mutated. No-op when no standard pattern relationship or when the pattern id is absent from the destination mappings.
Address review suggestion: pre_apply_hook now repopulates when EITHER destination_standard_pattern_mapping or destination_standard_pattern_description_mapping is empty, so a partial-cache state (name mapping present, description mapping empty) cannot skip description initialization in long-lived process or future refactor scenarios. Adds 4 regression tests for the partial-cache guard.
0a2614c to
0cc8d5f
Compare
Problem
The destination API rejects a standard-pattern-linked sensitive data scanner rule whose
attributes.descriptiondoes not match the destination standard pattern's canonical description:PR #627 aligned
attributes.nameto the destination pattern's canonical name on create/update, but notattributes.description. The same-named standard pattern can have a different canonicaldescriptionbetween source and destination orgs, so rules carrying the source org's description were rejected.Fix
Extend
_align_name_with_standard_pattern→_align_with_standard_patternto also overwriteattributes.descriptionwith the destination pattern's canonical description on create/update, emitting astandard_pattern_description_rewritemetric (mirroring the existingstandard_pattern_name_rewritemetric).pre_apply_hooknow also populatesdestination_standard_pattern_description_mapping(pattern_id → canonical description).standard_patternrelationship, or when the pattern id is absent from the destination mappings.Testing
TestSensitiveDataScannerRulesCanonicalDescriptionRewriteplus 4 partial-cache regression tests inTestSensitiveDataScannerRulesPreApplyHookPartialCache.tox -e py39 -- tests/unit): 1481 passed, 8 skipped.ruffandblackclean (line-length 120).