Skip to content

Normalizing the AquaSec fetched input for parent issues#70

Merged
tmikula-dev merged 1 commit into
masterfrom
feature/risk-management-section-fix
Jun 5, 2026
Merged

Normalizing the AquaSec fetched input for parent issues#70
tmikula-dev merged 1 commit into
masterfrom
feature/risk-management-section-fix

Conversation

@tmikula-dev

@tmikula-dev tmikula-dev commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Overview

This pull request enhances the data normalization logic in the RuleDetails model and adds comprehensive tests to ensure correct handling of whitespace and missing values. The changes improve the robustness and consistency of how display fields are processed and validated.

Release Notes

  • Data normalization logic in the RuleDetails model

Related

Closes #69

Summary by CodeRabbit

  • Refactor

    • Updated alert rule detail field normalization logic for consistency.
  • Tests

    • Added test coverage for alert rule detail field handling and fallback values.

@tmikula-dev tmikula-dev self-assigned this Jun 5, 2026
@tmikula-dev tmikula-dev added the bug Something isn't working label Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

RuleDetails.post_init normalization logic is refactored to group target display fields (impact, likelihood, confidence) into a _display_fields tuple and apply consistent string-strip-or-NOT_AVAILABLE normalization via a single loop. Test coverage is added to validate the behavior with parameterized inputs including None fallback cases.

Changes

RuleDetails Display Field Normalization

Layer / File(s) Summary
Display field normalization refactor
src/security/alerts/models.py
RuleDetails.post_init extracts the list of display fields into a _display_fields tuple and applies strip-or-NOT_AVAILABLE normalization to impact, likelihood, and confidence in a single consolidated loop.
Normalization test coverage
tests/security/alerts/test_models.py
Test module imports RuleDetails and NOT_AVAILABLE constant, and adds a parameterized test that verifies impact, likelihood, and confidence fields are normalized consistently, using NOT_AVAILABLE when the raw input is None.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A field so bare, stripped of whitespace care,
Now grouped in a tuple, with NOT_AVAILABLE spare,
Tests hop through the cases, none and empty too,
Display normalization dances, clean and true! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: normalizing AquaSec input for parent issues, which aligns with the refactoring of display field normalization in RuleDetails.
Description check ✅ Passed The PR description follows the required template with Overview and Release Notes sections, though the template placeholder 'TBD' items are replaced with actual content; however, the Related section is incomplete.
Linked Issues check ✅ Passed The PR successfully addresses issue #69 by normalizing display fields (impact, likelihood, confidence) with whitespace stripping and NOT_AVAILABLE fallback for missing values, matching the requirement to strip AquaSec values for Risk Assessment section.
Out of Scope Changes check ✅ Passed All changes are focused on the RuleDetails model normalization and related tests; no unrelated modifications are present outside the scope of issue #69.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/risk-management-section-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/security/alerts/test_models.py (1)

65-69: ⚡ Quick win

Consider adding edge case test parameters.

The current test cases cover the main scenarios, but two important edge cases are missing:

  • Empty string "" → should normalize to NOT_AVAILABLE
  • Whitespace-only string " " → should strip to empty and become NOT_AVAILABLE

These edge cases would strengthen confidence in the normalization contract without violating the "minimal tests" guideline.

🧪 Suggested additional test cases
 `@pytest.mark.parametrize`("raw, expected", [
     ("HIGH\n", "HIGH"),
     ("  MEDIUM  ", "MEDIUM"),
+    ("", NOT_AVAILABLE),
+    ("   ", NOT_AVAILABLE),
     (None, NOT_AVAILABLE),
 ])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/security/alerts/test_models.py` around lines 65 - 69, Add two edge-case
parameters to the existing pytest.mark.parametrize tuple in
tests/security/alerts/test_models.py so the normalization covers empty and
whitespace-only inputs: include ("", NOT_AVAILABLE) and ("   ", NOT_AVAILABLE)
alongside the existing ("HIGH\n", "HIGH"), ("  MEDIUM  ", "MEDIUM"), (None,
NOT_AVAILABLE) entries; keep the param names raw and expected and use the
NOT_AVAILABLE sentinel so the test asserts the normalization function treats
empty/blank strings as NOT_AVAILABLE.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/security/alerts/test_models.py`:
- Line 61: The comment line containing "RuleDetails – whitespace stripping and
NOT_AVAILABLE fallback" uses an EN DASH; replace that character with a standard
hyphen-minus so it reads "RuleDetails - whitespace stripping and NOT_AVAILABLE
fallback" to satisfy the RUF003 ambiguous-unicode-characters check and remove
the warning.

---

Nitpick comments:
In `@tests/security/alerts/test_models.py`:
- Around line 65-69: Add two edge-case parameters to the existing
pytest.mark.parametrize tuple in tests/security/alerts/test_models.py so the
normalization covers empty and whitespace-only inputs: include ("",
NOT_AVAILABLE) and ("   ", NOT_AVAILABLE) alongside the existing ("HIGH\n",
"HIGH"), ("  MEDIUM  ", "MEDIUM"), (None, NOT_AVAILABLE) entries; keep the param
names raw and expected and use the NOT_AVAILABLE sentinel so the test asserts
the normalization function treats empty/blank strings as NOT_AVAILABLE.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e8b9fce-ed46-4cfc-9339-6c7910292402

📥 Commits

Reviewing files that changed from the base of the PR and between fb3f4c2 and a531ba1.

📒 Files selected for processing (2)
  • src/security/alerts/models.py
  • tests/security/alerts/test_models.py

Comment thread tests/security/alerts/test_models.py
@tmikula-dev tmikula-dev merged commit d57cd45 into master Jun 5, 2026
9 of 10 checks passed
@tmikula-dev tmikula-dev deleted the feature/risk-management-section-fix branch June 5, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strip the AquaSec values for Risk Assessment section

2 participants