Unverified Commit c9275fbf authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Prevent test dependencies from leaking into production (#2264)

* Prevent test dependencies from leaking into production

* refactor & fix tests

* fix tests take two

* fix more tests

* Fix missed called to mergeDependencyFeatures

* Add test

* fix glacier compilation

* fix more tests

* fix one more test
parent 7bf92516
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.client.Fluen
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.core.rustlang.Feature
import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg
import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics
@@ -228,7 +227,7 @@ private class AwsFluentClientDocs(private val codegenContext: CodegenContext) :
    private val serviceShape = codegenContext.serviceShape
    private val crateName = codegenContext.moduleUseName()
    private val codegenScope =
        arrayOf("aws_config" to AwsCargoDependency.awsConfig(codegenContext.runtimeConfig).copy(scope = DependencyScope.Dev).toType())
        arrayOf("aws_config" to AwsCargoDependency.awsConfig(codegenContext.runtimeConfig).toDevDependency().toType())

    // If no `aws-config` version is provided, assume that docs referencing `aws-config` cannot be given.
    // Also, STS and SSO must NOT reference `aws-config` since that would create a circular dependency.
+1 −2
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation
@@ -63,7 +62,7 @@ object AwsRuntimeType {
    fun awsCredentialTypes(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsCredentialTypes(runtimeConfig).toType()

    fun awsCredentialTypesTestUtil(runtimeConfig: RuntimeConfig) =
        AwsCargoDependency.awsCredentialTypes(runtimeConfig).copy(scope = DependencyScope.Dev).withFeature("test-util").toType()
        AwsCargoDependency.awsCredentialTypes(runtimeConfig).toDevDependency().withFeature("test-util").toType()

    fun awsEndpoint(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsEndpoint(runtimeConfig).toType()
    fun awsHttp(runtimeConfig: RuntimeConfig) = AwsCargoDependency.awsHttp(runtimeConfig).toType()
+6 −4
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.core.testutil.testDependenciesOnly
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.absolute
@@ -72,7 +73,7 @@ class IntegrationTestDependencies(
    private val hasBenches: Boolean,
) : LibRsCustomization() {
    override fun section(section: LibRsSection) = when (section) {
        is LibRsSection.Body -> writable {
        is LibRsSection.Body -> testDependenciesOnly {
            if (hasTests) {
                val smithyClient = CargoDependency.smithyClient(runtimeConfig)
                    .copy(features = setOf("test-util"), scope = DependencyScope.Dev)
@@ -81,7 +82,7 @@ class IntegrationTestDependencies(
                addDependency(SerdeJson)
                addDependency(Tokio)
                addDependency(FuturesUtil)
                addDependency(Tracing)
                addDependency(Tracing.toDevDependency())
                addDependency(TracingSubscriber)
            }
            if (hasBenches) {
@@ -91,6 +92,7 @@ class IntegrationTestDependencies(
                serviceSpecific.section(section)(this)
            }
        }

        else -> emptySection
    }

@@ -114,8 +116,8 @@ class S3TestDependencies : LibRsCustomization() {
    override fun section(section: LibRsSection): Writable =
        writable {
            addDependency(AsyncStd)
            addDependency(BytesUtils)
            addDependency(FastRand)
            addDependency(BytesUtils.toDevDependency())
            addDependency(FastRand.toDevDependency())
            addDependency(HdrHistogram)
            addDependency(Smol)
            addDependency(TempFile)
+8 −4
Original line number Diff line number Diff line
@@ -33,13 +33,16 @@ private val UploadMultipartPart: ShapeId = ShapeId.from("com.amazonaws.glacier#U
private val Applies = setOf(UploadArchive, UploadMultipartPart)

class TreeHashHeader(private val runtimeConfig: RuntimeConfig) : OperationCustomization() {
    private val glacierChecksums = RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("glacier_checksums"))
    private val glacierChecksums = RuntimeType.forInlineDependency(
        InlineAwsDependency.forRustFile(
            "glacier_checksums",
            additionalDependency = TreeHashDependencies.toTypedArray(),
        ),
    )

    override fun section(section: OperationSection): Writable {
        return when (section) {
            is OperationSection.MutateRequest -> writable {
                TreeHashDependencies.forEach { dep ->
                    addDependency(dep)
                }
                rustTemplate(
                    """
                    #{glacier_checksums}::add_checksum_treehash(
@@ -49,6 +52,7 @@ class TreeHashHeader(private val runtimeConfig: RuntimeConfig) : OperationCustom
                    "glacier_checksums" to glacierChecksums, "BuildError" to runtimeConfig.operationBuildError(),
                )
            }

            else -> emptySection
        }
    }
+2 −3
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointTypesG
import software.amazon.smithy.rust.codegen.client.smithy.generators.clientInstantiator
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.AttributeKind
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.escape
import software.amazon.smithy.rust.codegen.core.rustlang.join
import software.amazon.smithy.rust.codegen.core.rustlang.rust
@@ -25,6 +24,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.PublicImportSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
@@ -146,8 +146,7 @@ class OperationInputTestGenerator(_ctx: ClientCodegenContext, private val test:
                let _result = dbg!(#{invoke_operation});
                #{assertion}
                """,
                "capture_request" to CargoDependency.smithyClient(runtimeConfig)
                    .withFeature("test-util").toType().resolve("test_connection::capture_request"),
                "capture_request" to RuntimeType.captureRequest(runtimeConfig),
                "conf" to config(testOperationInput),
                "invoke_operation" to operationInvocation(testOperationInput),
                "assertion" to writable {
Loading