Skip to content

fix(sensitive_data_scanner_rules): align description with linked standard pattern on write - #726

Merged
michael-richey merged 3 commits into
mainfrom
michael.richey/sds-rules-align-description
Sep 28, 2026
Merged

michael-richey merged 3 commits into
mainfrom
michael.richey/sds-rules-align-description

Conversation

@michael-richey

@michael-richey michael-richey commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The destination API rejects a standard-pattern-linked sensitive data scanner rule whose attributes.description does not match the destination standard pattern's canonical description:

400 Bad Request - {"errors":[{"title":"Generic Error","detail":"description of the standard rule and the rule must match"}]}

PR #627 aligned attributes.name to the destination pattern's canonical name on create/update, but not attributes.description. The same-named standard pattern can have a different canonical description between source and destination orgs, so rules carrying the source org's description were rejected.

Fix

Extend _align_name_with_standard_pattern → _align_with_standard_pattern to also overwrite attributes.description with the destination pattern's canonical description on create/update, emitting a standard_pattern_description_rewrite metric (mirroring the existing standard_pattern_name_rewrite metric). pre_apply_hook now also populates destination_standard_pattern_description_mapping (pattern_id → canonical description).

  • Applied only on create/update (not diffs/import) — source state is not mutated.
  • No-op when there is no standard_pattern relationship, or when the pattern id is absent from the destination mappings.
  • Name and description are aligned independently; each emits its own metric.

Testing

  • 9 new unit tests in TestSensitiveDataScannerRulesCanonicalDescriptionRewrite plus 4 partial-cache regression tests in TestSensitiveDataScannerRulesPreApplyHookPartialCache.
  • Full unit suite green (tox -e py39 -- tests/unit): 1481 passed, 8 skipped.
  • ruff and black clean (line-length 120).

@michael-richey michael-richey left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@michael-richey
michael-richey marked this pull request as ready for review September 28, 2026 15:32
@michael-richey
michael-richey requested a review from a team as a code owner September 28, 2026 15:32
@michael-richey

Copy link
Copy Markdown
Collaborator Author

Re: review suggestion (pre_apply_hook partial-cache guard)

Good suggestion — implemented in 7d88fb5. pre_apply_hook now guards on both destination_standard_pattern_mapping and destination_standard_pattern_description_mapping, repopulating when either 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.

Added 4 regression tests (TestSensitiveDataScannerRulesPreApplyHookPartialCache):

  • both mappings empty → repopulates both
  • name-only present → repopulates (fetches description)
  • description-only present → repopulates (fetches name)
  • both populated → skips re-fetch

All 32 SDS tests + full unit suite (1481 passed, 8 skipped) green; ruff/black clean.

…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.
@michael-richey
michael-richey force-pushed the michael.richey/sds-rules-align-description branch from 0a2614c to 0cc8d5f Compare September 28, 2026 19:43
@michael-richey
michael-richey merged commit 446af58 into main Sep 28, 2026
10 checks passed
@michael-richey
michael-richey deleted the michael.richey/sds-rules-align-description branch September 28, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants