-
Notifications
You must be signed in to change notification settings - Fork 41
bug_fix (terraform_plan): enhance evaluation logic and add new test fi… #240
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- tests/providers/terraform_plan/fixtures/input_multiple_rescource_tag_check.json: Language not supported
- tests/providers/terraform_plan/fixtures/policy_multiple_rescource_tag_check.json: Language not supported
Comments suppressed due to low confidence (1)
src/tirith/core/core.py:93
- The logic for handling skipped evaluations appears ambiguous. If no valid evaluations are processed, ensure that setting 'has_evaluation_passed' to None accurately reflects the desired overall evaluation result.
if not has_valid_evaluation and has_evaluation_passed is None:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, btw how much time do you need to cover the missing tests?
I think we can do it in a separate PR. The tests for the current changes have been added. We need to add coverage tests only for our existing core implentation |
I think we can do it in this PR unless it takes a lot of time. Only for what commented by @codecov, the code that we touch in this PR, not all of the existing core implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the Terraform plan provider and updates the core evaluation logic so that policies correctly fail when any resource fails the tag check. It also adds new tests to verify both failing and passing scenarios for multiple resource evaluations.
- Updated the provider to return a None value when a resource is missing the requested tag.
- Enhanced the evaluator to require all resources to pass for overall success.
- Added tests for multiple resource evaluations and for provider error scenarios.
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/providers/terraform_plan/test_dot_star_attr.py | Added tests to validate tag-check behavior across multiple resources; note one test function is not descriptively named. |
tests/core/test_core.py | Introduced new tests for generating evaluator results, including handling provider errors and multiple resource results. |
src/tirith/providers/terraform_plan/handler.py | Updated logic to include resources missing the attribute by appending a None value for evaluation. |
src/tirith/core/core.py | Refactored generate_evaluator_result to fail evaluation when no inputs are found and to track valid evaluations. |
Files not reviewed (2)
- tests/providers/terraform_plan/fixtures/input_multiple_resource_tag_check.json: Language not supported
- tests/providers/terraform_plan/fixtures/policy_multiple_resource_tag_check.json: Language not supported
Comments suppressed due to low confidence (1)
tests/providers/terraform_plan/test_dot_star_attr.py:59
- The test function name 'test_' is not descriptive of its purpose; consider renaming it to reflect what is being validated.
def test_(split_expressions, input_data, expected_result):
|
…xtures
Pull Request Template
Description
With these changes, when your policy checks for tag 'a':
The bucket with the tag returns a value, which passes the evaluation
The bucket without the tag returns None, which fails the evaluation
Since one resource fails, the overall policy correctly fails
This ensures that all resources must meet the policy requirements for the policy to pass, which is the expected behavior for policy enforcement.
What changes are being made?
Evaluation Logic Issue: The core evaluation logic was considering a policy as passed if any of the resources passed, instead of requiring all resources to pass
Why are these changes necessary?
Fixed the Evaluation Logic: Enhanced the core evaluation logic to properly handle multiple resources. Now, the policy will only pass if all resources pass the evaluation, and will fail if any resource fails.
Which issues or tickets does this PR close or relate to?
Type of Change
Checklist
Screenshots or Recordings (if applicable)
Additional Information