Repository: 7mind/izumi
Pull request #1822 (2022-11-17 14:30:43)

unused axis choice specification

codecov-commenter: # [Codecov](https://codecov.io/gh/7mind/izumi/pull/1822?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=7mind) Report
> Merging [#1822](https://codecov.io/gh/7mind/izumi/pull/1822?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=7mind) (c67bfdd) into [develop](https://codecov.io/gh/7mind/izumi/commit/03332f9de113ad03cf01816dca2523ac0fa5d92a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=7mind) (03332f9) will **decrease** coverage by `0.15%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head c67bfdd differs from pull request most recent head d6d014e. Consider uploading reports for the commit d6d014e to get more accurate results

```diff
@@             Coverage Diff             @@
##           develop    #1822      +/-   ##
===========================================
- Coverage    63.58%   63.44%   -0.15%     
===========================================
  Files          506      454      -52     
  Lines        10382     9754     -628     
  Branches         0     1011    +1011     
===========================================
- Hits          6601     6188     -413     
+ Misses        3781     3566     -215     
```


Patch:
diff --git a/.gitignore b/.gitignore
index 9f0d1652b..b2119c841 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,7 @@ secrets.tar
 build/project
 .DS_Store
 .metals
-project/metals.sbt
+**/metals.sbt
 .bloop
 .bsp
 .java-version
diff --git a/.scalafmt.conf b/.scalafmt.conf
index efcd18433..0a8342c6f 100644
--- a/.scalafmt.conf
+++ b/.scalafmt.conf
@@ -1,5 +1,4 @@
 version = "3.6.0"
-runner.dialect = scala3Future
 project.git = true
 project.excludePaths = ["glob:**.sbt", "glob:**sbtgen.sc"]
 
@@ -59,3 +58,11 @@ rewrite.redundantBraces.includeUnitMethods = false
 rewrite.redundantBraces.stringInterpolation = true
 rewrite.redundantBraces.parensForOneLineApply = true
 rewrite.trailingCommas.style = multiple
+
+runner.dialect = scala3Future
+
+fileOverride {
+  "glob:**/scala-3/**" {
+    runner.dialect = scala3
+  }
+}
\ No newline at end of file
diff --git a/distage/distage-framework/src/main/scala/izumi/distage/framework/services/ActivationChoicesExtractor.scala b/distage/distage-framework/src/main/scala/izumi/distage/framework/services/ActivationChoicesExtractor.scala
index 7289e5dcb..3be5c2e98 100644
--- a/distage/distage-framework/src/main/scala/izumi/distage/framework/services/ActivationChoicesExtractor.scala
+++ b/distage/distage-framework/src/main/scala/izumi/distage/framework/services/ActivationChoicesExtractor.scala
@@ -11,7 +11,7 @@ trait ActivationChoicesExtractor {
 
 object ActivationChoicesExtractor {
 
-  class Impl extends ActivationChoicesExtractor {
+  class Impl(additionalAxisValues: Set[Axis.AxisChoice]) extends ActivationChoicesExtractor {
     def findAvailableChoices(module: ModuleBase): ActivationInfo = {
       findAvailableChoicesDetailed(module) match {
         case Left(badAxis) =>
@@ -27,7 +27,7 @@ object ActivationChoicesExtractor {
 
     /** @return Either conflicting axis names or a set of axis choices present in the bindings */
     def findAvailableChoicesDetailed(module: ModuleBase): Either[Map[String, Set[Axis]], ActivationInfo] = {
-      val allChoices = module.bindings.flatMap(_.tags).collect { case BindingTag.AxisTag(axisValue) => axisValue }
+      val allChoices = module.bindings.flatMap(_.tags).collect { case BindingTag.AxisTag(axisValue) => axisValue } ++ additionalAxisValues
       val allAxis = allChoices.map(_.axis).groupBy(_.name)
       val badAxis = allAxis.filter(_._2.size > 1)
       if (badAxis.isEmpty) Right(ActivationInfo(allChoices.groupBy(_.axis))) else Left(badAxis)
diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppBootModule.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppBootModule.scala
index 09a6411e9..60211f47e 100644
--- a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppBootModule.scala
+++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppBootModule.scala
@@ -52,6 +52,7 @@ class RoleAppBootModule[F[_]: TagK: DefaultModule](
   pluginConfig: PluginConfig,
   bootstrapPluginConfig: PluginConfig,
   appArtifact: IzArtifact,
+  unusedValidAxisChoices: Set[Axis.AxisChoice],
 ) extends ModuleDef {
   addImplicit[TagK[F]]
   addImplicit[DefaultModule[F]]
@@ -168,6 +169,7 @@ class RoleAppBootModule[F[_]: TagK: DefaultModule](
       rolesInfo.requiredComponents
   }
 
+  make[Set[Axis.AxisChoice]].fromValue(unusedValidAxisChoices)
   make[ActivationChoicesExtractor].from[ActivationChoicesExtractor.Impl]
   make[ActivationInfo].from {
     (activationExtractor: ActivationChoicesExtractor, appModule: ModuleBase @Id("main")) =>
diff --git a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppMain.scala b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppMain.scala
index 325beae19..f27cd2b95 100644
--- a/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppMain.scala
+++ b/distage/distage-framework/src/main/scala/izumi/distage/roles/RoleAppMain.scala
@@ -4,7 +4,7 @@ import cats.effect.kernel.Async
 import distage.Injector
 import izumi.distage.framework.services.ModuleProvider
 import izumi.distage.framework.{PlanCheckConfig, PlanCheckMaterializer, RoleCheckableApp}
-import izumi.distage.model.definition.{Module, ModuleDef}
+import izumi.distage.model.definition.{Axis, Module, ModuleDef}
 import izumi.distage.modules.{DefaultModule, DefaultModule2, DefaultModule3}
 import izumi.distage.plugins.PluginConfig
 import izumi.distage.roles.RoleAppMain.{ArgV, RequiredRoles}
@@ -15,6 +15,7 @@ import izumi.functional.bio.{Async2, Async3}
 import izumi.fundamentals.platform.cli.model.raw.RawRoleParams
 import izumi.fundamentals.platform.cli.model.schema.ParserDef
 import izumi.fundamentals.platform.functional.Identity
+
 import scala.annotation.unused
 import izumi.fundamentals.platform.resources.IzArtifactMaterializer
 import izumi.logstage.distage.{LogIO2Module, LogIO3Module}
@@ -50,6 +51,7 @@ abstract class RoleAppMain[F[_]](
 
   protected def pluginConfig: PluginConfig
   protected def bootstrapPluginConfig: PluginConfig = PluginConfig.empty
+  protected def unusedValidAxisChoices: Set[Axis.AxisChoice] = Set.empty
   protected def shutdownStrategy: AppShutdownStrategy[F]
 
   /**
@@ -129,6 +131,7 @@ abstract class RoleAppMain[F[_]](
       pluginConfig = pluginConfig,
       bootstrapPluginConfig = bootstrapPluginConfig,
       appArtifact = artifact.get,
+      unusedValidAxisChoices,
     )
   }
 


Test patch:
diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/TestConfig.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/TestConfig.scala
index bb5a380cd..430475c22 100644
--- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/TestConfig.scala
+++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/TestConfig.scala
@@ -107,6 +107,7 @@ final case class TestConfig(
   logLevel: Log.Level = Log.Level.Info,
   debugOutput: Boolean = false,
   activationStrategy: TestActivationStrategy = TestActivationStrategy.LoadConfig(ignoreUnknown = false, warnUnset = true),
+  unusedValidAxisChoices: Set[AxisChoice] = Set.empty,
 ) {
   def activate(changeActivation: Activation => Activation): TestConfig = {
     this.copy(activation = changeActivation(this.activation))
diff --git a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/services/dstest/DistageTestEnv.scala b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/services/dstest/DistageTestEnv.scala
index 8987ccd20..0152f3365 100644
--- a/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/services/dstest/DistageTestEnv.scala
+++ b/distage/distage-testkit-core/src/main/scala/izumi/distage/testkit/services/dstest/DistageTestEnv.scala
@@ -36,7 +36,7 @@ trait DistageTestEnv {
     val bsPlugins = pluginLoader.load(testConfig.bootstrapPluginConfig)
     val appModule = mergeStrategy.merge(appPlugins.result) overriddenBy testConfig.moduleOverrides
     val bootstrapModule = mergeStrategy.merge(bsPlugins.result) overriddenBy testConfig.bootstrapOverrides
-    val availableActivations = new ActivationChoicesExtractor.Impl().findAvailableChoices(appModule)
+    val availableActivations = new ActivationChoicesExtractor.Impl(testConfig.unusedValidAxisChoices).findAvailableChoices(appModule)
 
     val bsModule = bootstrapModule overriddenBy new BootstrapModuleDef {
       make[ActivationInfo].fromValue(availableActivations)