Skip to content

Conversation

@AkashS0510
Copy link
Collaborator

Pull Request Template

This pull request improves the handling of metadata and addresses in evaluation results and provider outputs. The changes ensure better compatibility, clarity, and backward support by explicitly managing the address field and enhancing how metadata is processed.

Enhancements to metadata and address handling:

  • generate_evaluator_result in src/tirith/core/core.py: Updated to include the meta field only if it exists and is not None. Additionally, the address field is now explicitly handled, either directly from the input or as a fallback from the meta dictionary for backward compatibility. The message field is updated to include the address when available.

  • get_value in src/tirith/providers/json/handler.py: Modified to add the address field as a separate property in the result dictionary instead of embedding it in meta. This change improves clarity and aligns with the new handling approach.

Description

Add Resource Address to Evaluation Results
Summary
This PR adds support for including resource addresses in evaluation results, making it easier to identify which specific resources are passing or failing evaluations.

Changes
Modified core to include resource addresses in evaluation results and messages
Updated the JSON provider to include key paths as address fields
Enhanced the pretty printer to display resource addresses in CLI output
Made address a top-level field in evaluation results for easier programmatic access

  • What changes are being made?

  • Why are these changes necessary?

  • Which issues or tickets does this PR close or relate to?

    • Related issue: #

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Other (please specify):

Checklist

  • Code has been linted.
  • Documentation has been updated (if needed).
  • Tests have been added or updated (if needed).
  • Any breaking changes have been communicated to the team.

Screenshots or Recordings (if applicable)

image image

Additional Information

@codecov
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tirith/providers/terraform_plan/handler.py 80.95% 5 Missing and 3 partials ⚠️
src/tirith/prettyprinter.py 0.00% 5 Missing ⚠️
src/tirith/core/core.py 75.00% 1 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/tirith/providers/json/handler.py 81.39% <100.00%> (+1.90%) ⬆️
src/tirith/core/core.py 75.00% <75.00%> (-8.15%) ⬇️
src/tirith/prettyprinter.py 0.00% <0.00%> (-51.49%) ⬇️
src/tirith/providers/terraform_plan/handler.py 63.70% <80.95%> (+1.64%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AkashS0510 AkashS0510 requested a review from Copilot June 4, 2025 12:09

This comment was marked as outdated.

Copy link
Member

@refeed refeed left a comment

Choose a reason for hiding this comment

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

Thanks. I think you forgot to include terraform_plan provider related changes here :)

@AkashS0510
Copy link
Collaborator Author

Thanks. I think you forgot to include terraform_plan provider related changes here :)

You mean in the PR description?

@refeed refeed requested a review from Copilot June 11, 2025 07:50
Copy link

Copilot AI left a 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 enhances the handling of evaluation results and provider outputs by explicitly including a top-level "address" field. Key changes include:

  • Updating the core evaluator result handling to copy and display the "address" in messages.
  • Modifying the Terraform plan handler to conditionally add the "address" field in multiple output cases.
  • Adjusting the JSON provider to separate the "address" from the metadata.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/tirith/providers/terraform_plan/handler.py Updates to conditionally add an "address" field to result dictionaries in various operation paths.
src/tirith/providers/json/handler.py Refactors result creation to include a separate "address" property for JSON outputs.
src/tirith/core/core.py Enhances evaluator result generation to include and display the "address" in the output message.

Copy link
Member

@refeed refeed left a comment

Choose a reason for hiding this comment

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

Hi Akash, thanks, could you also make sure that every result["addresses"] is always a list of strings. Example in the suggestions

continue
for reference in expressions_val.get("references", []):
# Only get the resource type
resource_references.add(reference.split(".")[0])
Copy link
Member

Choose a reason for hiding this comment

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

Please use the address from the reference

addresses.append(reference)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@refeed I am unable to understand why do we need to do this?

Copy link
Member

Choose a reason for hiding this comment

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

Because that's the real addresses the optype is processing. The resource var that's placed in the meta key was actually not placed correctly, it only contains one resource even though this optype is processing more than one resources

Copy link
Member

@refeed refeed left a comment

Choose a reason for hiding this comment

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

Thanks, put some comments


if "addresses" in evaluator_input:
# Add addresses directly
# TODO: We need to make a model class for the `evaluator_input` and move this validation there
Copy link
Member

Choose a reason for hiding this comment

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

Please add the type assertion mentioned in #262 (comment) here

                if not isinstance(addresses, list):
                    raise Exception("`addresses` should be a list")

Copy link
Member

Choose a reason for hiding this comment

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

Move the comment to the top of line 94

Copy link
Member

Choose a reason for hiding this comment

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

                # TODO: We need to make a model class for the `evaluator_input` and move this validation there
                if not isinstance(addresses, list):
                    raise Exception("`addresses` should be a 
 

Comment on lines 93 to 94
address = resource_change.get("address")
addresses = [address] if address is not None else []
Copy link
Member

Choose a reason for hiding this comment

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

Please create a helper method that creates addresses from resource_change dict as I'm seeing this pattern often

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are just repeating it twice or thrice atmost. I dont think we need a helper class for this

Copy link
Member

Choose a reason for hiding this comment

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

Repeating it twice is already a good candidate for making a helper method. It doesn't hurt much and improves readability :)

@sonarqubecloud
Copy link


if "addresses" in evaluator_input:
# Add addresses directly
# TODO: We need to make a model class for the `evaluator_input` and move this validation there
Copy link
Member

Choose a reason for hiding this comment

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

Move the comment to the top of line 94


if "addresses" in evaluator_input:
# Add addresses directly
# TODO: We need to make a model class for the `evaluator_input` and move this validation there
Copy link
Member

Choose a reason for hiding this comment

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

                # TODO: We need to make a model class for the `evaluator_input` and move this validation there
                if not isinstance(addresses, list):
                    raise Exception("`addresses` should be a 
 

Comment on lines 93 to 94
address = resource_change.get("address")
addresses = [address] if address is not None else []
Copy link
Member

Choose a reason for hiding this comment

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

Repeating it twice is already a good candidate for making a helper method. It doesn't hurt much and improves readability :)

@refeed
Copy link
Member

refeed commented Sep 26, 2025

I'll continue to work on this

@sonarqubecloud
Copy link

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.

3 participants