From 2e09fd0f26d0c936bba22e426267839e3af19e28 Mon Sep 17 00:00:00 2001 From: Brian Holt <bholt@dwolla.com> Date: Thu, 10 Oct 2024 14:25:11 -0500 Subject: [PATCH 1/2] Update Scala 2 ShadedGeneratedSmithySpec to avoid using MUnit's macros The MUnit `compileErrors` macro seems to follow a different compilation cadence than other code, meaning the tests are more likely to erroneously fail. This seems to work better. --- build.sbt | 8 +++++ .../bincompat/ShadedGeneratedSmithySpec.scala | 29 ++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index fd9ca04..01e6367 100644 --- a/build.sbt +++ b/build.sbt @@ -77,6 +77,14 @@ lazy val `secure-config` = (project in file(".")) "org.http4s" %% "http4s-ember-client" % "0.23.28" % Test, ) }, + libraryDependencies ++= { + (scalaBinaryVersion.value) match { + case "2.13" => + Seq("org.scala-lang" % "scala-compiler" % scalaVersion.value % Test) + case _ => + Nil + } + }, smithy4sAwsSpecs ++= Seq(AWS.kms), scalacOptions += "-Wconf:src=src_managed/.*:s", Compile / smithy4sModelTransformers += "com.dwolla.config.smithy.ShadeNamespace", diff --git a/src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala b/src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala index 59940d8..3d0e5d1 100644 --- a/src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala +++ b/src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala @@ -1,21 +1,30 @@ package bincompat +import cats.syntax.all.* import munit.* +import scala.reflect.runtime.currentMirror +import scala.reflect.runtime.universe.* +import scala.tools.reflect.ToolBox + class ShadedGeneratedSmithySpec extends FunSuite { + private val toolbox = currentMirror.mkToolBox() + + private def typecheck(input: String): Either[Throwable, Tree] = + for { + parsed <- Either.catchNonFatal(toolbox.parse(input)) + typechecked <- Either.catchNonFatal(toolbox.typecheck(parsed)) + } yield typechecked + test("we don't have access to the generated KMS objects in their original package") { - assertNoDiff(compileErrors("""com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")"""), - """error: object amazonaws is not a member of package com - |com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService") - | ^ - |""".stripMargin) + val typedchecked = typecheck("""com.amazonaws.kms.KMS.id""") + + assertEquals(typedchecked.leftMap(_.getMessage), Left("reflective typecheck has failed: object id is not a member of package com.amazonaws.kms.KMS")) } test("we don't have access to the generated KMS objects in the shaded package") { - assertNoDiff(compileErrors("""assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))"""), - """error: value KMS in package kms cannot be accessed as a member of object com.dwolla.config.smithy_shaded.com.amazonaws.kms.package from class ShadedGeneratedSmithySpec in package bincompat - |assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService")) - | ^ - |""".stripMargin) + val typedchecked = typecheck("""com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id""") + + assertEquals(typedchecked.leftMap(_.getMessage), Left("reflective typecheck has failed: value KMS in package kms cannot be accessed as a member of object com.dwolla.config.smithy_shaded.com.amazonaws.kms.package from package <root>")) } } From 2514730ddf2ac4851e36df3ecc01eec5edefd59d Mon Sep 17 00:00:00 2001 From: Brian Holt <bholt@dwolla.com> Date: Mon, 14 Oct 2024 11:50:13 -0500 Subject: [PATCH 2/2] exclude some FinalMethodProblems in the shaded package from MiMa checks --- build.sbt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build.sbt b/build.sbt index 01e6367..f764336 100644 --- a/build.sbt +++ b/build.sbt @@ -92,6 +92,17 @@ lazy val `secure-config` = (project in file(".")) Compile / smithy4sSmithyLibrary := false, Compile / scalafix / unmanagedSources := (Compile / sources).value, scalafixOnCompile := true, + mimaBinaryIssueFilters ++= { + import com.typesafe.tools.mima.core.* + + // exclusions in this package should be safe since everything in there should be package private + val shadedPackage = "com.dwolla.config.smithy_shaded.com.amazonaws.kms" + + Seq( + ProblemFilters.exclude[FinalMethodProblem](s"$shadedPackage.KMSOperation#Transformed.transform"), + ProblemFilters.exclude[FinalMethodProblem](s"$shadedPackage.KMSOperation#reified.transform"), + ) + } ) .enablePlugins( Smithy4sCodegenPlugin,