Unverified Commit 682dc7fb authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Upgrade Smithy to 1.35 (#2892)



_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: default avatardavid-perez <d@vidp.dev>
parent d2690e7a
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -614,6 +614,20 @@ class DefaultProtocolTestGenerator(

        // These tests are not even attempted to be generated, either because they will not compile
        // or because they are flaky
        private val DisableTests = setOf<String>()
        private val DisableTests = setOf<String>(
            // TODO(https://github.com/awslabs/smithy-rs/issues/2891): Implement support for `@requestCompression`
            "SDKAppendedGzipAfterProvidedEncoding_restJson1",
            "SDKAppendedGzipAfterProvidedEncoding_restXml",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query",
            "SDKAppliedContentEncoding_awsJson1_0",
            "SDKAppliedContentEncoding_awsJson1_1",
            "SDKAppliedContentEncoding_awsQuery",
            "SDKAppliedContentEncoding_ec2Query",
            "SDKAppliedContentEncoding_restJson1",
            "SDKAppliedContentEncoding_restXml",
        )
    }
}
+3 −16
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ import software.amazon.smithy.rulesengine.language.syntax.Identifier
import software.amazon.smithy.rulesengine.language.syntax.expr.Expression
import software.amazon.smithy.rulesengine.language.syntax.expr.Literal
import software.amazon.smithy.rulesengine.language.syntax.expr.Template
import software.amazon.smithy.rulesengine.language.syntax.fn.LibraryFunction
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.Context
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.FunctionRegistry
import software.amazon.smithy.rust.codegen.core.rustlang.rust
@@ -26,25 +25,13 @@ import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest
import software.amazon.smithy.rust.codegen.core.testutil.unitTest

internal class ExprGeneratorTest {
    /**
     * This works around a bug in smithy-endpoint-rules where the constructors on functions like `BooleanEquals`
     * hit the wrong branch in the visitor (but when they get parsed, they hit the right branch).
     */
    fun Expression.shoop() = Expression.fromNode(this.toNode())
    private val testContext = Context(FunctionRegistry(listOf()), TestRuntimeConfig)

    @Test
    fun `fail when smithy is fixed`() {
        check(BooleanEquals.ofExpressions(Expression.of(true), Expression.of(true)) is LibraryFunction) {
            "smithy has been fixed, shoop can be removed"
        }
    }

    @Test
    fun generateExprs() {
        val boolEq = Expression.of(true).equal(true).shoop()
        val strEq = Expression.of("helloworld").equal("goodbyeworld").not().shoop()
        val combined = BooleanEquals.ofExpressions(boolEq, strEq).shoop()
        val boolEq = Expression.of(true).equal(true)
        val strEq = Expression.of("helloworld").equal("goodbyeworld").not()
        val combined = BooleanEquals.ofExpressions(boolEq, strEq)
        TestWorkspace.testProject().unitTest {
            val generator = ExpressionGenerator(Ownership.Borrowed, testContext)
            rust("assert_eq!(true, #W);", generator.generate(boolEq))
+25 −52
Original line number Diff line number Diff line
@@ -230,26 +230,6 @@ class ServerProtocolTestGenerator(
    // not been written with a server-side perspective in mind.
    private fun List<TestCase>.fixBroken(): List<TestCase> = this.map {
        when (it) {
            is TestCase.RequestTest -> {
                val howToFixIt = BrokenRequestTests[Pair(codegenContext.serviceShape.id.toString(), it.id)]
                if (howToFixIt == null) {
                    it
                } else {
                    val fixed = howToFixIt(it.testCase, it.operationShape)
                    TestCase.RequestTest(fixed, it.operationShape)
                }
            }

            is TestCase.ResponseTest -> {
                val howToFixIt = BrokenResponseTests[Pair(codegenContext.serviceShape.id.toString(), it.id)]
                if (howToFixIt == null) {
                    it
                } else {
                    val fixed = howToFixIt(it.testCase)
                    TestCase.ResponseTest(fixed, it.targetShape)
                }
            }

            is TestCase.MalformedRequestTest -> {
                val howToFixIt = BrokenMalformedRequestTests[Pair(codegenContext.serviceShape.id.toString(), it.id)]
                if (howToFixIt == null) {
@@ -259,6 +239,7 @@ class ServerProtocolTestGenerator(
                    TestCase.MalformedRequestTest(fixed)
                }
            }
            else -> it
        }
    }

@@ -847,7 +828,25 @@ class ServerProtocolTestGenerator(

        // These tests are not even attempted to be generated, either because they will not compile
        // or because they are flaky
        private val DisableTests = setOf<String>()
        private val DisableTests = setOf<String>(
            // TODO(https://github.com/awslabs/smithy-rs/issues/2891): Implement support for `@requestCompression`
            "SDKAppendedGzipAfterProvidedEncoding_restJson1",
            "SDKAppendedGzipAfterProvidedEncoding_restXml",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery",
            "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query",
            "SDKAppliedContentEncoding_awsJson1_0",
            "SDKAppliedContentEncoding_awsJson1_1",
            "SDKAppliedContentEncoding_awsQuery",
            "SDKAppliedContentEncoding_ec2Query",
            "SDKAppliedContentEncoding_restJson1",
            "SDKAppliedContentEncoding_restXml",

            // RestXml S3 tests that fail to compile
            "S3EscapeObjectKeyInUriLabel",
            "S3EscapePathObjectKeyInUriLabel",
        )

        private fun fixRestJsonAllQueryStringTypes(
            testCase: HttpRequestTestCase,
@@ -903,24 +902,6 @@ class ServerProtocolTestGenerator(
                ).asObjectNode().get(),
            ).build()

        private fun fixRestJsonQueryStringEscaping(
            testCase: HttpRequestTestCase,
            @Suppress("UNUSED_PARAMETER")
            operationShape: OperationShape,
        ): HttpRequestTestCase =
            testCase.toBuilder().params(
                Node.parse(
                    """
                    {
                        "queryString": "%:/?#[]@!${'$'}&'()*+,;=😹",
                        "queryParamsMapOfStringList": {
                            "String": ["%:/?#[]@!${'$'}&'()*+,;=😹"]
                        }
                    }
                    """.trimMargin(),
                ).asObjectNode().get(),
            ).build()

        // TODO(https://github.com/awslabs/smithy/issues/1506)
        private fun fixRestJsonMalformedPatternReDOSString(testCase: HttpMalformedRequestTestCase): HttpMalformedRequestTestCase {
            val brokenResponse = testCase.response
@@ -942,19 +923,11 @@ class ServerProtocolTestGenerator(
                .build()
        }

        // These are tests whose definitions in the `awslabs/smithy` repository are wrong.
        // This is because they have not been written from a server perspective, and as such the expected `params` field is incomplete.
        // TODO(https://github.com/awslabs/smithy-rs/issues/1288): Contribute a PR to fix them upstream.
        private val BrokenRequestTests = mapOf(
            // TODO(https://github.com/awslabs/smithy/pull/1564)
            // Pair(RestJson, "RestJsonAllQueryStringTypes") to ::fixRestJsonAllQueryStringTypes,
            // TODO(https://github.com/awslabs/smithy/pull/1562)
            Pair(RestJson, "RestJsonQueryStringEscaping") to ::fixRestJsonQueryStringEscaping,
        )

        private val BrokenResponseTests: Map<Pair<String, String>, KFunction1<HttpResponseTestCase, HttpResponseTestCase>> =
            mapOf()

        // TODO(https://github.com/awslabs/smithy-rs/issues/1288): Move the fixed versions into
        // `rest-json-extras.smithy` and put the unfixed ones in `ExpectFail`: this has the
        // advantage that once our upstream PRs get merged and we upgrade to the next Smithy release, our build will
        // fail and we will take notice to remove the fixes from `rest-json-extras.smithy`. This is exactly what the
        // client does.
        private val BrokenMalformedRequestTests: Map<Pair<String, String>, KFunction1<HttpMalformedRequestTestCase, HttpMalformedRequestTestCase>> =
            // TODO(https://github.com/awslabs/smithy/issues/1506)
            mapOf(
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ smithy.rs.runtime.crate.version=0.0.0-smithy-rs-head
kotlin.code.style=official

# codegen
smithyGradlePluginVersion=0.6.0
smithyVersion=1.29.0
smithyGradlePluginVersion=0.7.0
smithyVersion=1.35.0

# kotlin
kotlinVersion=1.7.21