Skip to content

feat(cli): CcApi context provider can be configured to fail if listing does not find a specific count of resources #251

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

Merged
merged 13 commits into from
Apr 1, 2025

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Mar 19, 2025

Fixes #257

As described in the issue, CcApiContextProviderPlugin should have the way to ensure the result has exact one resource.

This PR adds the expectedMatchCount option to restrict the length of results in listResources().

Unit tests are added and modified ensure the changes.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

auto-merge was automatically disabled March 19, 2025 12:11

Head branch was pushed to by a user without write access

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

@rix0rrr this looks okay to me, but you were more involved with the original version of this

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

I agree with you that persisting a 0-length array may make it harder to recover from problems in the future.

But I don't agree that a >=1 length array is automatically a failure. It is up the lookup method to reject >=1 element if it is expecting exactly one. It is not up to the provider to say "I will never support looking up more than one resource". For example, securitygroups associated with another resource are a perfectly legit resource to look up.

For your issue:

  • It is the job of PrefixList.fromLookup() to handle the >=1 case.
  • As for the 0 results case: we can fail the provider, that's an easy way of making sure that the 0-length array is not persisted. To achieve that, we should add an additional field into the query that indicates that a 0-element list should be considered an error.

@Tietew
Copy link
Contributor Author

Tietew commented Mar 21, 2025

@rix0rrr Thank you for clarification.

I've pushed following updates:

  • reverted the test I changed
  • added allowEmptyResult and exactResult options to CcApiContextQuery (requires to bump schema version)
  • updated tests to ensure above options

Current PRs using CC API Context Provider, except for my PrefixList, use exactIdentifier and is not affected by this change.
For my PrefixList.fromLookup(), specifying exactResult: true could ensure to expect 1 resources.

@Tietew Tietew changed the title fix(cli): ensure exact one result in CcApiContextProviderPlugin fix(cli): no way to ensure exact one result in CcApiContextProviderPlugin Mar 21, 2025
@github-actions github-actions bot added the bug label Mar 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.40%. Comparing base (cd35a1c) to head (76bc207).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #251      +/-   ##
==========================================
+ Coverage   85.24%   85.40%   +0.15%     
==========================================
  Files         222      222              
  Lines       36898    36926      +28     
  Branches     4438     4454      +16     
==========================================
+ Hits        31455    31535      +80     
+ Misses       5348     5296      -52     
  Partials       95       95              
Flag Coverage Δ
suite.unit 85.40% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Tietew Tietew requested a review from rix0rrr March 24, 2025 08:41
@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 24, 2025

I'm going to wait for #211 to be in, then refactor this PR a bit on top of that other one.

They're too uncomfortably close for me so I'm taking the reins to make them play nicely together.

@Tietew
Copy link
Contributor Author

Tietew commented Mar 25, 2025

Ok, thanks for adjustment!

@rix0rrr rix0rrr temporarily deployed to integ-approval April 1, 2025 12:10 — with GitHub Actions Inactive
@rix0rrr rix0rrr added this pull request to the merge queue Apr 1, 2025
Merged via the queue into aws:main with commit a1d5af9 Apr 1, 2025
20 checks passed
iankhou pushed a commit that referenced this pull request Apr 1, 2025
…g does not find a specific count of resources (#251)

Fixes #257

As described in the issue, `CcApiContextProviderPlugin` should have the
way to ensure the result has exact one resource.

This PR adds the `expectedMatchCount` option to restrict the length of
results in `listResources()`.

Unit tests are added and modified ensure the changes.

---
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license

---------

Co-authored-by: Rico Huijbers <[email protected]>
@Tietew Tietew deleted the cc-api-single-result branch April 2, 2025 02:01
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request May 26, 2025
…m CcApi context provider has exactly one resource (#34199)

### Issue # (if applicable)

Follow-up to #33619.

### Reason for this change

CcApi context provider now can expect the matched count of resources: aws/aws-cdk-cli#251.
`PrefixList.fromLookup()` is needed to be updated using this feature not to persist invalid results in `cdk.context.json`.
See also aws/aws-cdk-cli#257.

### Description of changes

- Bumped `@aws-cdk/cloud-assembly-schema` to latest ^43.6.0.
- Specify `expectedMatchCount: 'exactly-one'` to expect exactly one prefix list id is returned.
- Updated validation to check unexpected result. Actual error will be returned from the context provider.

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Updated integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request May 30, 2025
…m CcApi context provider has exactly one resource (#34565)

Re-creation of #34199
A jsii related issue #34199 (comment) should be fixed before merging this PR.

### Issue # (if applicable)

Follow-up to #33619.

### Reason for this change

CcApi context provider now can expect the matched count of resources: aws/aws-cdk-cli#251.
`PrefixList.fromLookup()` is needed to be updated using this feature not to persist invalid results in `cdk.context.json`.
See also aws/aws-cdk-cli#257.

### Description of changes

- Bumped `@aws-cdk/cloud-assembly-schema` to latest ^44.1.0.
- Specify `expectedMatchCount: 'exactly-one'` to expect exactly one prefix list id is returned.
- Updated validation to check unexpected result. Actual error will be returned from the context provider.

### Describe any new or updated permissions being added

N/A

### Description of how you validated changes

Updated integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contextprovider: CC API context provider should have the way to ensure the result has exact one value
4 participants