Skip to content

Handle multiple requirement mapping sets in libraries #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

monsieurswag
Copy link
Contributor

@monsieurswag monsieurswag commented May 7, 2025

We want to be able to put any number of any type of objects in a library. Currently this is not the case for mapping_set and framework. It is the case for matrix, but the word is incorrect (should be matrices).
The change done is the following:

  • The words matrix/matrices, framework/frameworks, mapping_set/mapping_sets become synonymous.
  • The normal expected content is a list of objects, but if a single object as a dict is given, this is accepted.

This approach make migration easy.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages to accurately report invalid item indices.
    • Corrected a typographical error in the documentation's entity-relationship diagram.
  • New Features

    • Enhanced support for importing multiple requirement mapping sets and risk matrices, with backward compatibility for previous formats.
    • Improved error handling by accumulating and reporting multiple validation errors during library import.
  • Refactor

    • Modernized code with type annotations and removal of unused imports.
    • Updated filtering and API endpoints to use non-deprecated object type names with backward compatibility for legacy names.
  • Documentation

    • Corrected typographical error in the data model diagram.

Copy link
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

The changes refactor and enhance the validation, error reporting, and initialization logic for requirement mappings and related sets in the library import process. They improve error accumulation, unify handling of singular and plural fields for mappings and risk matrices with backward compatibility, correct off-by-one errors in error messages, update code style with type hints, and remove unused imports. Additionally, a typographical error in documentation is fixed, and multiple YAML library files are updated to rename singular keys to plural forms and increment version numbers. The filtering logic in library views is adjusted for backward compatibility with deprecated object type names.

Changes

File(s) Change Summary
backend/library/utils.py Refactored validation and initialization for requirement mappings and sets; improved error accumulation; updated singular/plural field handling for mappings and risk matrices with backward compatibility; fixed off-by-one errors in error messages; removed unused imports; added type hints; updated method signatures; added is_empty method.
backend/core/models.py Modified store_library_content to adjust objects_meta computation; updated LibraryUpdater constructor to prefer "risk_matrices" over "risk_matrix" when initializing risk matrices.
backend/library/views.py Replaced references to LibraryImporter.OBJECT_FIELDS with NON_DEPRECATED_OBJECT_FIELDS; added backward compatibility in filter methods for deprecated plural object type names; updated API endpoint to return non-deprecated object types.
documentation/architecture/data-model.md Fixed a typographical error in the entity name "REQUIREMMENT_MAPPING_SET" to "REQUIREMENT_MAPPING_SET" in the entity-relationship diagram.
backend/library/libraries/*.yaml Updated multiple YAML library files to rename singular keys (requirement_mapping_set, risk_matrix) to plural forms (requirement_mapping_sets, risk_matrices); incremented version numbers accordingly; applied UTF-8 escape sequences for accented characters in some risk matrix files; adjusted YAML structure formatting without changing semantic content.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LibraryImporter
    participant RequirementMappingSetImporter
    participant RequirementMappingImporter

    User->>LibraryImporter: import_objects(library_object)
    LibraryImporter->>LibraryImporter: init()
    LibraryImporter->>RequirementMappingSetImporter: init_requirement_mapping_set(requirement_mapping_sets)
    loop For each mapping set
        RequirementMappingSetImporter->>RequirementMappingSetImporter: init()
        RequirementMappingSetImporter->>RequirementMappingSetImporter: is_empty()
        RequirementMappingSetImporter->>RequirementMappingSetImporter: init_requirement_mappings(requirement_mappings)
        loop For each mapping
            RequirementMappingSetImporter->>RequirementMappingImporter: is_valid()
        end
    end
    LibraryImporter-->>User: Return accumulated errors or success
Loading

Poem

In the warren where mappings abound,
Errors once hid, but now they’re all found.
Singular, plural—no mix-up, hooray!
Off-by-one bugs have all hopped away.
With cleaner code and diagrams set,
This bunny’s the happiest coder yet! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9b0928 and c31ff53.

📒 Files selected for processing (1)
  • backend/app_tests/api/test_api_libraries.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: build (3.12)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: Analyze (python)
  • GitHub Check: test (3.12)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
backend/app_tests/api/test_api_libraries.py (1)

140-140: Good update to align with the new plural data structure.

This change correctly updates the test to access the risk matrix data through the new plural "risk_matrices" array instead of the deprecated singular "risk_matrix" key. This aligns with the broader refactoring of the library data structure to use plural forms for collections of entities.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@monsieurswag monsieurswag marked this pull request as draft May 7, 2025 14:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 328f29a and 642ef3e.

📒 Files selected for processing (2)
  • backend/library/utils.py (14 hunks)
  • documentation/architecture/data-model.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: test (3.12)
  • GitHub Check: build (3.12)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
documentation/architecture/data-model.md (1)

95-95: Typo fixed – looks good

The ER diagram now uses the correct entity name REQUIREMENT_MAPPING_SET. ✅

Comment on lines +608 to +613
if (
"requirement_mapping_set" in library_objects
and "requirement_mapping_ses" in library_objects
):
return "A library can't have both 'requirement_mapping_set' and 'requirement_mapping_ses' objects fields."

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo breaks mutual-exclusion check for requirement-mapping sets

The guard tests "requirement_mapping_ses" instead of "requirement_mapping_sets", so the conflict is never detected and the associated error message is misleading.

-        if (
-            "requirement_mapping_set" in library_objects
-            and "requirement_mapping_ses" in library_objects
-        ):
-            return "A library can't have both 'requirement_mapping_set' and 'requirement_mapping_ses' objects fields."
+        if (
+            "requirement_mapping_set" in library_objects
+            and "requirement_mapping_sets" in library_objects
+        ):
+            return "A library can't have both 'requirement_mapping_set' and 'requirement_mapping_sets' object fields."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
"requirement_mapping_set" in library_objects
and "requirement_mapping_ses" in library_objects
):
return "A library can't have both 'requirement_mapping_set' and 'requirement_mapping_ses' objects fields."
if (
"requirement_mapping_set" in library_objects
and "requirement_mapping_sets" in library_objects
):
return "A library can't have both 'requirement_mapping_set' and 'requirement_mapping_sets' object fields."

Comment on lines +643 to 646
key for key in ["risk_matrix", "risk_matrices"] if key in library_objects
]:
risk_matrix_data = library_objects[keys_found[0]]
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Singular risk_matrix objects are not converted to a list

For backward compatibility you correctly turn a singular requirement mapping set into a list, but the same pattern is missing for risk matrices.
If a legacy YAML uses the (deprecated) risk_matrix key with a single object, init_risk_matrices will iterate over a dict and raise.

-            risk_matrix_data = library_objects[keys_found[0]]
+            risk_matrix_data = library_objects[keys_found[0]]
+            if not isinstance(risk_matrix_data, list):
+                # Back-compat with the deprecated singular field
+                risk_matrix_data = [risk_matrix_data]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
key for key in ["risk_matrix", "risk_matrices"] if key in library_objects
]:
risk_matrix_data = library_objects[keys_found[0]]
if (
for keys_found in [
key for key in ["risk_matrix", "risk_matrices"] if key in library_objects
]:
risk_matrix_data = library_objects[keys_found[0]]
+ if not isinstance(risk_matrix_data, list):
+ # Back-compat with the deprecated singular field
+ risk_matrix_data = [risk_matrix_data]
if (
# ...
):
# existing logic…

@monsieurswag monsieurswag marked this pull request as ready for review May 7, 2025 15:22
@monsieurswag monsieurswag requested a review from eric-intuitem May 7, 2025 15:22
@monsieurswag monsieurswag marked this pull request as draft May 7, 2025 17:00
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