Skip to content

Commit

Permalink
Fix deterministic codegen check for SmokeTestsDecorator (#3809)
Browse files Browse the repository at this point in the history
## Motivation and Context
Attempts to fix [a release
blocker](https://github.com/smithy-lang/smithy-rs/actions/runs/10601508703/job/29381493978)

## Description
This PR ensures that `SmokeTestsDecorator` renders test functions into
`smoketests` in a consistent order, e.g. sorted first by operation name
and then within that operation, sorted by test case ID.

## Testing
- [x] Existing tests in CI (specifically `check-deterministic-codegen`)

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
ysaito1001 authored Aug 28, 2024
1 parent 069ec70 commit d64aea2
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ class SmokeTestsDecorator : ClientCodegenDecorator {
codegenContext.model.getOperationShapesWithTrait(SmokeTestsTrait::class.java).toList()
val supportedTests =
smokeTestedOperations.map { operationShape ->
// filter out unsupported smoke tests, logging a warning for each one.
// filter out unsupported smoke tests, logging a warning for each one, and sort the remaining tests by
// case ID. This ensures deterministic rendering, meaning the test methods are always rendered in a
// consistent order.
val testCases =
operationShape.expectTrait<SmokeTestsTrait>().testCases.filter { smokeTestCase ->
isSmokeTestSupported(smokeTestCase)
}
}.sortedBy { smokeTestCase -> smokeTestCase.id }

operationShape to testCases
}
// filter out operations with no supported smoke tests
.filter { (_, testCases) -> testCases.isNotEmpty() }
// Similar to sorting test cases above, sort operations by name to ensure consistent ordering.
.sortedBy { (operationShape, _) -> operationShape.id.name }
// Return if there are no supported smoke tests across all operations
if (supportedTests.isEmpty()) return

Expand Down

0 comments on commit d64aea2

Please sign in to comment.