Copilot commented on code in PR #6084: URL: https://github.com/apache/texera/pull/6084#discussion_r3522566838
########## common/config/src/test/scala/org/apache/texera/common/config/KubernetesConfigSpec.scala: ########## @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[KubernetesConfig]]. Reading each value forces resolution from kubernetes.conf, so a + * renamed or mistyped key surfaces here as a ConfigException. Every value except the port number + * carries a `${?ENV}` override, so exact-value assertions are guarded on the env var being unset. + */ +class KubernetesConfigSpec extends AnyFlatSpec with Matchers { + + private def ifUnset(env: String)(assertion: => Any): Unit = + if (sys.env.get(env).isEmpty) assertion Review Comment: `ifUnset` only checks `sys.env`, but `${?VAR}` substitutions in HOCON can also be satisfied via JVM system properties (and UserSystemConfig even references system properties in its warning). This can make the test assert defaults even when a `-D...` override is present. ########## common/config/src/test/scala/org/apache/texera/common/config/KubernetesConfigSpec.scala: ########## @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[KubernetesConfig]]. Reading each value forces resolution from kubernetes.conf, so a + * renamed or mistyped key surfaces here as a ConfigException. Every value except the port number + * carries a `${?ENV}` override, so exact-value assertions are guarded on the env var being unset. + */ +class KubernetesConfigSpec extends AnyFlatSpec with Matchers { + + private def ifUnset(env: String)(assertion: => Any): Unit = + if (sys.env.get(env).isEmpty) assertion + + "KubernetesConfig.computeUnitPortNumber" should "load the fixed port (no env override)" in { + KubernetesConfig.computeUnitPortNumber shouldBe 8085 + } + + "KubernetesConfig string settings" should "resolve to their kubernetes.conf defaults" in { + ifUnset("KUBERNETES_COMPUTE_UNIT_SERVICE_NAME")( + KubernetesConfig.computeUnitServiceName shouldBe "workflow-computing-unit-svc" + ) + ifUnset("KUBERNETES_COMPUTE_UNIT_POOL_NAME")( + KubernetesConfig.computeUnitPoolName shouldBe "texera-workflow-computing-unit" + ) + ifUnset("KUBERNETES_COMPUTE_UNIT_POOL_NAMESPACE")( + KubernetesConfig.computeUnitPoolNamespace shouldBe "texera-workflow-computing-unit-pool" + ) + ifUnset("KUBERNETES_IMAGE_NAME")( + KubernetesConfig.computeUnitImageName shouldBe "bobbai/texera-workflow-computing-unit:dev" + ) + ifUnset("KUBERNETES_IMAGE_PULL_POLICY")( + KubernetesConfig.computingUnitImagePullPolicy shouldBe "Always" + ) + ifUnset("KUBERNETES_COMPUTING_UNIT_GPU_RESOURCE_KEY")( + KubernetesConfig.gpuResourceKey shouldBe "nvidia.com/gpu" + ) + } + + "KubernetesConfig numeric and boolean settings" should "resolve to their kubernetes.conf defaults" in { + ifUnset("KUBERNETES_COMPUTING_UNIT_ENABLED")( + KubernetesConfig.kubernetesComputingUnitEnabled shouldBe false + ) + ifUnset("MAX_NUM_OF_RUNNING_COMPUTING_UNITS_PER_USER")( + KubernetesConfig.maxNumOfRunningComputingUnitsPerUser shouldBe 10 + ) + KubernetesConfig.maxNumOfRunningComputingUnitsPerUser should be > 0 + } Review Comment: This assertion is unconditional even though the value is env-overridable; an override of 0 (e.g., to disable Kubernetes CUs) would make the unit test fail. Consider relaxing this to a non-negative check (you already assert the default when the override is unset). ########## common/config/src/test/scala/org/apache/texera/common/config/AuthConfigSpec.scala: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[AuthConfig]]. Reading each value forces resolution from auth.conf, so a renamed or + * mistyped key surfaces here as a ConfigException. Exact-value assertions are guarded on the env + * override being unset; the random-secret path is exercised directly via getRandomHexString. + */ +class AuthConfigSpec extends AnyFlatSpec with Matchers { + + "AuthConfig.jwtExpirationMinutes" should "resolve from auth.conf" in { + if (sys.env.get("AUTH_JWT_EXPIRATION_IN_MINUTES").isEmpty) { + AuthConfig.jwtExpirationMinutes shouldBe 10080 + } else { + AuthConfig.jwtExpirationMinutes should be > 0 + } + } + + "AuthConfig.jwtSecretKey" should "return the configured secret (lowercased) and memoize it" in { + val first = AuthConfig.jwtSecretKey + if (sys.env.get("AUTH_JWT_SECRET").isEmpty) { Review Comment: `auth.conf` uses `${?AUTH_JWT_SECRET}`, which can be satisfied via a JVM system property as well as an environment variable. Guarding only on `sys.env` can cause the test to assert the default secret even when a `-DAUTH_JWT_SECRET=...` override is present. ########## common/config/src/test/scala/org/apache/texera/common/config/UserSystemConfigSpec.scala: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[UserSystemConfig]]. Reading each value forces resolution from user-system.conf, so a + * renamed or mistyped key surfaces here as a ConfigException. Every value carries a `${?ENV}` + * override, so exact-value assertions are guarded on the env var being unset. + */ +class UserSystemConfigSpec extends AnyFlatSpec with Matchers { + + private def ifUnset(env: String)(assertion: => Any): Unit = + if (sys.env.get(env).isEmpty) assertion Review Comment: `ifUnset` only checks `sys.env`, but `${?VAR}` substitutions in HOCON can also be satisfied via JVM system properties (and `UserSystemConfig` references system properties in its warning). This can make the test assert defaults even when a `-D...` override is present. ########## common/config/src/test/scala/org/apache/texera/common/config/KubernetesConfigSpec.scala: ########## @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[KubernetesConfig]]. Reading each value forces resolution from kubernetes.conf, so a + * renamed or mistyped key surfaces here as a ConfigException. Every value except the port number + * carries a `${?ENV}` override, so exact-value assertions are guarded on the env var being unset. + */ +class KubernetesConfigSpec extends AnyFlatSpec with Matchers { + + private def ifUnset(env: String)(assertion: => Any): Unit = + if (sys.env.get(env).isEmpty) assertion + + "KubernetesConfig.computeUnitPortNumber" should "load the fixed port (no env override)" in { + KubernetesConfig.computeUnitPortNumber shouldBe 8085 + } + + "KubernetesConfig string settings" should "resolve to their kubernetes.conf defaults" in { + ifUnset("KUBERNETES_COMPUTE_UNIT_SERVICE_NAME")( + KubernetesConfig.computeUnitServiceName shouldBe "workflow-computing-unit-svc" + ) + ifUnset("KUBERNETES_COMPUTE_UNIT_POOL_NAME")( + KubernetesConfig.computeUnitPoolName shouldBe "texera-workflow-computing-unit" + ) + ifUnset("KUBERNETES_COMPUTE_UNIT_POOL_NAMESPACE")( + KubernetesConfig.computeUnitPoolNamespace shouldBe "texera-workflow-computing-unit-pool" + ) + ifUnset("KUBERNETES_IMAGE_NAME")( + KubernetesConfig.computeUnitImageName shouldBe "bobbai/texera-workflow-computing-unit:dev" + ) + ifUnset("KUBERNETES_IMAGE_PULL_POLICY")( + KubernetesConfig.computingUnitImagePullPolicy shouldBe "Always" + ) + ifUnset("KUBERNETES_COMPUTING_UNIT_GPU_RESOURCE_KEY")( + KubernetesConfig.gpuResourceKey shouldBe "nvidia.com/gpu" + ) + } + + "KubernetesConfig numeric and boolean settings" should "resolve to their kubernetes.conf defaults" in { + ifUnset("KUBERNETES_COMPUTING_UNIT_ENABLED")( + KubernetesConfig.kubernetesComputingUnitEnabled shouldBe false + ) + ifUnset("MAX_NUM_OF_RUNNING_COMPUTING_UNITS_PER_USER")( + KubernetesConfig.maxNumOfRunningComputingUnitsPerUser shouldBe 10 + ) + KubernetesConfig.maxNumOfRunningComputingUnitsPerUser should be > 0 + } + + "KubernetesConfig limit options" should "parse into trimmed, non-empty lists" in { + ifUnset("KUBERNETES_COMPUTING_UNIT_CPU_LIMIT_OPTIONS")( + KubernetesConfig.cpuLimitOptions shouldBe List("1", "2", "4") + ) + ifUnset("KUBERNETES_COMPUTING_UNIT_MEMORY_LIMIT_OPTIONS")( + KubernetesConfig.memoryLimitOptions shouldBe List("1Gi", "2Gi", "4Gi") + ) + ifUnset("KUBERNETES_COMPUTING_UNIT_GPU_LIMIT_OPTIONS")( + KubernetesConfig.gpuLimitOptions shouldBe List("0", "1", "2") + ) + for ( + options <- Seq( + KubernetesConfig.cpuLimitOptions, + KubernetesConfig.memoryLimitOptions, + KubernetesConfig.gpuLimitOptions + ) + ) { + options should not be empty + options.forall(s => s == s.trim && s.nonEmpty) shouldBe true + } Review Comment: `options should not be empty` is unconditional even though the config is env-overridable; if an override is set to blank/whitespace, parsing will produce an empty list and this test will fail due to external environment. Since the default-value assertions above already pin non-empty defaults, consider removing the unconditional non-empty assertion here. ########## common/config/src/test/scala/org/apache/texera/common/config/UserSystemConfigSpec.scala: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[UserSystemConfig]]. Reading each value forces resolution from user-system.conf, so a + * renamed or mistyped key surfaces here as a ConfigException. Every value carries a `${?ENV}` + * override, so exact-value assertions are guarded on the env var being unset. + */ +class UserSystemConfigSpec extends AnyFlatSpec with Matchers { + + private def ifUnset(env: String)(assertion: => Any): Unit = + if (sys.env.get(env).isEmpty) assertion + + "UserSystemConfig" should "resolve every value from user-system.conf" in { + // reference each val to force resolution regardless of environment + UserSystemConfig.adminUsername should not be null + UserSystemConfig.adminPassword should not be null + UserSystemConfig.googleClientId should not be null + UserSystemConfig.gmail should not be null + UserSystemConfig.smtpPassword should not be null + UserSystemConfig.projectName should not be null + UserSystemConfig.workflowVersionCollapseIntervalInMinutes should be >= 0 + } + + it should "match the user-system.conf defaults when no env override is set" in { + ifUnset("USER_SYS_ADMIN_USERNAME")(UserSystemConfig.adminUsername shouldBe "texera") + ifUnset("USER_SYS_ADMIN_PASSWORD")(UserSystemConfig.adminPassword shouldBe "texera") + ifUnset("USER_SYS_GOOGLE_CLIENT_ID")(UserSystemConfig.googleClientId shouldBe "") + ifUnset("USER_SYS_GOOGLE_SMTP_GMAIL")(UserSystemConfig.gmail shouldBe "") + ifUnset("USER_SYS_GOOGLE_SMTP_PASSWORD")(UserSystemConfig.smtpPassword shouldBe "") + ifUnset("USER_SYS_PROJECT_NAME")(UserSystemConfig.projectName shouldBe "Texera") + ifUnset("USER_SYS_INVITE_ONLY")(UserSystemConfig.inviteOnly shouldBe false) + ifUnset("USER_SYS_VERSION_TIME_LIMIT_IN_MINUTES")( + UserSystemConfig.workflowVersionCollapseIntervalInMinutes shouldBe 60 + ) + } + + it should "return None for appDomain when the domain is blank/unset" in { + if (sys.env.get("USER_SYS_DOMAIN").forall(_.trim.isEmpty)) { Review Comment: This check only consults `sys.env`, but `user-system.conf`'s `${?USER_SYS_DOMAIN}` can also be satisfied via a JVM system property. If a `-DUSER_SYS_DOMAIN=...` override is present, the test could incorrectly expect `None`. ########## common/config/src/test/scala/org/apache/texera/common/config/AuthConfigSpec.scala: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.common.config + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +/** + * Spec for [[AuthConfig]]. Reading each value forces resolution from auth.conf, so a renamed or + * mistyped key surfaces here as a ConfigException. Exact-value assertions are guarded on the env + * override being unset; the random-secret path is exercised directly via getRandomHexString. + */ +class AuthConfigSpec extends AnyFlatSpec with Matchers { + + "AuthConfig.jwtExpirationMinutes" should "resolve from auth.conf" in { + if (sys.env.get("AUTH_JWT_EXPIRATION_IN_MINUTES").isEmpty) { Review Comment: `auth.conf` uses `${?AUTH_JWT_EXPIRATION_IN_MINUTES}`, which can be satisfied via a JVM system property as well as an environment variable. Guarding only on `sys.env` can cause this test to assert the default even when a `-DAUTH_JWT_EXPIRATION_IN_MINUTES=...` override is present. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
