From 6f416546cec5135fc2611d1e779df5e6f77e1702 Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Mon, 10 Jan 2022 22:12:25 -0500 Subject: [PATCH 1/5] Add reproducing integration test --- test/tla/cli-integration-tests.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/tla/cli-integration-tests.md b/test/tla/cli-integration-tests.md index da7808fab3..b338548f7e 100644 --- a/test/tla/cli-integration-tests.md +++ b/test/tla/cli-integration-tests.md @@ -2436,6 +2436,20 @@ $ test -d ./configured-run-dir $ rm -rf ./configured-run-dir ./cli-config.cfg ``` +### configuration management: tilde is expanded in configured paths + +We set `user.home` to the current working directly, so we can test tilde +expansion in the path without writing outside of the test directory. + +```sh +$ echo "run-dir: ~/run-dir" > .apalache.cfg +$ JVM_ARGS="-Duser.home=$PWD" apalache-mc check --length=0 Counter.tla | sed 's/[IEW]@.*//' +... +EXITCODE: OK +$ test -d ./run-dir +$ rm -rf ./run-dir ./.apalache.cfg +``` + ## server mode ### server mode: subcommand is not yet implemented From 5d4c44bee45ab0b93b18ce314429c4f634c28b01 Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Tue, 11 Jan 2022 22:13:56 -0500 Subject: [PATCH 2/5] Fix path expansion of ~ --- .../forsyte/apalache/io/ConfigManager.scala | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala b/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala index a7c9ec481a..8f0d036133 100644 --- a/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala +++ b/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala @@ -4,39 +4,24 @@ import pureconfig._ import pureconfig.generic.auto._ import java.io.{File} import java.nio.file.{Path, Files, Paths} +import com.typesafe.config.ConfigValueFactory +import com.typesafe.config.ConfigObject + +// Provides implicit conversions used when deserializing into configurable values. +private object Converters { + import pureconfig.ConvertHelpers._ -object Converters { private def expandedFilePath(s: String): Path = { Paths.get(if (s.startsWith("~")) s.replaceFirst("~", System.getProperty("user.home")) else s) } - // Value class to allow adding a new implicit for the File - case class ExpandedFile(val file: File) extends AnyVal - - object ExpandedFile { - def apply(f: File): ExpandedFile = { - new ExpandedFile(expandedFilePath(f.toString()).toFile()) - } - } - - // Value class to allow adding a new implicit for Path - case class ExpandedPath(val path: Path) extends AnyVal - - object ExpandedPath { - def apply(f: Path): ExpandedPath = { - new ExpandedPath(expandedFilePath(f.toString())) - } - } - - // Briniging these implicits in scope lets us override the existing - // file deserialization behavior, so we get path expansion in all configured - // paths - implicit def expandedFileConfigReader: ConfigReader[ExpandedFile] = - ConfigReader[File].map(ExpandedFile.apply) - - implicit def expandedPathConfigReader: ConfigReader[ExpandedPath] = - ConfigReader[Path].map(ExpandedPath.apply) + // Briniging these implicits in scope lets us override the existing File and + // Path deserialization behavior, so we get path expansion in all configured + // paths. + // See https://pureconfig.github.io/docs/overriding-behavior-for-types.html + implicit val overridePathReader = ConfigReader.fromString[Path](catchReadError(expandedFilePath)) + implicit val overrideFileReader = ConfigReader.fromString[File](catchReadError(expandedFilePath(_).toFile())) } /** The configuration values that can be overriden based on CLI arguments */ From dc71fbd5a6723a1ab525c06adcf4bf45ee0861f2 Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Tue, 11 Jan 2022 22:19:13 -0500 Subject: [PATCH 3/5] Fix formatting --- tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala b/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala index 8f0d036133..f50b66bc96 100644 --- a/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala +++ b/tla-io/src/main/scala/at/forsyte/apalache/io/ConfigManager.scala @@ -11,7 +11,6 @@ import com.typesafe.config.ConfigObject private object Converters { import pureconfig.ConvertHelpers._ - private def expandedFilePath(s: String): Path = { Paths.get(if (s.startsWith("~")) s.replaceFirst("~", System.getProperty("user.home")) else s) } From d2bc5668dab84bc24c45ac7e6e4f762bb8c0c84e Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Tue, 11 Jan 2022 22:20:20 -0500 Subject: [PATCH 4/5] Update changelog --- UNRELEASED.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UNRELEASED.md b/UNRELEASED.md index 84488f67af..6cd230c3f9 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -10,3 +10,6 @@ * Some bug fix, see #124 DO NOT LEAVE A BLANK LINE BELOW THIS PREAMBLE --> +### Bug fixes + +* Fix expansion of `~` in configured paths, see #1208 From 1a14c4422dfaf8187502191f728f7675c9c6ba0d Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Wed, 12 Jan 2022 20:36:31 -0500 Subject: [PATCH 5/5] Fix integration test on docker --- test/tla/cli-integration-tests.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/tla/cli-integration-tests.md b/test/tla/cli-integration-tests.md index b338548f7e..d38ff4866c 100644 --- a/test/tla/cli-integration-tests.md +++ b/test/tla/cli-integration-tests.md @@ -2441,9 +2441,12 @@ $ rm -rf ./configured-run-dir ./cli-config.cfg We set `user.home` to the current working directly, so we can test tilde expansion in the path without writing outside of the test directory. +NOTE: We need to set the home to a relative path to the cwd in order to +ensure the tests also works in the docker container. + ```sh $ echo "run-dir: ~/run-dir" > .apalache.cfg -$ JVM_ARGS="-Duser.home=$PWD" apalache-mc check --length=0 Counter.tla | sed 's/[IEW]@.*//' +$ JVM_ARGS="-Duser.home=." apalache-mc check --length=0 Counter.tla | sed 's/[IEW]@.*//' ... EXITCODE: OK $ test -d ./run-dir