From d64aea29ad48d7bddb5a7511f3f1175c478e2c1e Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Wed, 28 Aug 2024 15:54:14 -0500 Subject: [PATCH] Fix deterministic codegen check for `SmokeTestsDecorator` (#3809) ## 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._ --- .../software/amazon/smithy/rustsdk/SmokeTestsDecorator.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SmokeTestsDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SmokeTestsDecorator.kt index 3e880bd6fd..deb5a3068c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SmokeTestsDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SmokeTestsDecorator.kt @@ -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().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