aws / aws/aws-cdk

integ-tests: broken assertion caused by `getAttX` calls

Open
#30,477 1 comment 1 reaction 0 assignees View on GitHub
@aws-cdk/integ-tests bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Running `getAtt` or `getAttString` on a SDK integration will cause the `flattenResults` property to be set, allowing users to retrieve JSONPath-ish property values. However, this also causes assertions for that integration to fail

### Expected Behavior

Given that `flattenResults` is not exposed to the user, they would expect their object/path assertions to work regardless of `getAttX` calls.

### Current Behavior

`actual` is `undefined`:

https://github.com/aws/aws-cdk/blob/8f4d4d75df7adf994f97de633de3da2fc32c7eee/packages/%40aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/assertion.ts#L9

### Reproduction Steps

```ts
import * as cdk from 'aws-cdk-lib';
import { ExpectedResult, IntegTest } from '../../../lib';

const app = new cdk.App();

const stack = new cdk.Stack(app, 'foo');

const integ = new IntegTest(app, 'Integ', {
testCases: [stack],
});

const models = integ.assertions.awsApiCall('Bedrock', 'GetFoundationModel', {
modelIdentifier: 'amazon.titan-embed-text-v1',
});

models.expect(ExpectedResult.objectLike({
modelDetails: { modelId: 'amazon.titan-embed-text-v1' },
}));

// Enabling this line will cause the assertion to fail
// eslint-disable-next-line no-console
// console.log(models.getAttString('modelDetails.modelName'));
```

Output:
```
Expected type object but received undefined
```

### Possible Solution

I'm assuming the flattened object is not being sent/parsed properly. Reversion the flattening process in `AssertionHandler` would be satisfactory

### Additional Information/Context

_No response_

### CDK CLI Version

2.144.0

### Framework Version

_No response_

### Node.js Version

v20.11.1

### OS

macOS 14.4.1

### Language

TypeScript

### Language Version

_No response_

### Other information

I discovered this issue while attempting to write an integration test for #30361, which implements `flattenResults` for HTTP assertions

Contributor guide

Open the contributing guide

Research direction

Start at packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/assertion.ts#L9 and trace how AssertionHandler handles getAttX calls and flattened results. Run the supplied TypeScript reproduction with getAttString enabled, then verify that the objectLike assertion receives the expected object rather than undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.