Add Config, the single owner of environment reads - #191
Open
ecalifornica wants to merge 2 commits into
Open
Conversation
Add Config to path-cli. Config::load() extracts one immutable value with figment: Serialized::defaults under an env layer restricted to TOOLPATH_CONFIG_DIR, HOME, XDG_DATA_HOME, COPILOT_HOME, APPDATA, PATHBASE_URL, and TOOLPATH_QUERY_EXPLAIN. Config::config_dir() resolves the config root from plain values. The env layer is VerbatimEnv, a provider that wraps Env and emits values as verbatim strings. Env's own Provider::data type-infers values and has no option to disable this (its env cargo feature requires parse-value), so TOOLPATH_QUERY_EXPLAIN=1 would arrive as an integer. The Config field types are the single type authority. The free config_dir() loads a Config per call. It keeps the ~30 call sites working until the command-module PRs pass &Config down from run(). Move PATHBASE_URL_ENV to config.rs: cmd_pathbase is cfg-gated off emscripten, and Config builds on every target. cmd_pathbase re-exports it. Test the env-to-Config mapping with figment::Jail, holding TEST_ENV_LOCK: Jail serializes only against other Jail tests, and other test modules mutate HOME/TOOLPATH_CONFIG_DIR under that lock. config_dir precedence tests use plain values, no environment.
|
🔍 Preview deployed: https://c9bd0426.toolpath.pages.dev |
ecalifornica
force-pushed
the
robert/config-composition-root
branch
from
August 13, 2026 12:46
d25d9d4 to
9243904
Compare
Config::home_dir() resolves the home the provider resolvers use: HOME, falling back to USERPROFILE (Windows). The fallback matches the resolvers' internal home lookup.
ecalifornica
force-pushed
the
robert/config-composition-root
branch
from
August 13, 2026 13:04
9243904 to
9cd4eee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #184 (PR 1 of the plan there). path-cli only. No library changes. No user-visible changes.
What
Configholds every value the CLI reads from the process environment:TOOLPATH_CONFIG_DIR,HOME,USERPROFILE,XDG_DATA_HOME,COPILOT_HOME,APPDATA,PATHBASE_URL,TOOLPATH_QUERY_EXPLAIN.Config::load()extracts one immutable value with figment:Serialized::defaultsunder an env layer restricted to those 8 variables.VerbatimEnv. It wrapsEnvand emits values as verbatim strings.Env::datatype-infers values and has no option to disable this (theenvcargo feature requiresparse-value), soTOOLPATH_QUERY_EXPLAIN=1would arrive as an integer. TheConfigfield types are the single type authority.Config::config_dir()resolves the config root from plain values: override, then$HOME/.toolpath, then error.Config::home_dir()resolves the home the provider resolvers use:HOMEon Linux and macOS,USERPROFILEon Windows. Same order as the resolvers' internal lookup.config_dir()resolves fromHOMEalone; aUSERPROFILEfallback there is a behavior change, out of scope for this series.config_dir()is transitional. It loads aConfigper call and keeps the ~30 call sites unchanged until the command-module PRs pass&Configdown fromrun().PATHBASE_URL_ENVmoves toconfig.rs.cmd_pathbaseis compiled out of the wasm/emscripten build, andCONFIG_ENV_VARSneeds the constant on every target.cmd_pathbasere-exports it.Tests
figment::Jailtests pin the env-to-Configmapping. They hold the existingTEST_ENV_LOCK: Jail serializes only against other Jail tests, and other test modules mutateHOME/TOOLPATH_CONFIG_DIRunder that lock.TOOLPATH_QUERY_EXPLAIN=01extracts as"01". Type inference turns01into the integer1.config_dirprecedence andhome_dirfallback tests use plain values and do not touch the environment.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.