Skip to content

Add Config, the single owner of environment reads - #191

Open
ecalifornica wants to merge 2 commits into
mainfrom
robert/config-composition-root
Open

Add Config, the single owner of environment reads#191
ecalifornica wants to merge 2 commits into
mainfrom
robert/config-composition-root

Conversation

@ecalifornica

@ecalifornica ecalifornica commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Part of #184 (PR 1 of the plan there). path-cli only. No library changes. No user-visible changes.

What

  • Config holds 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::defaults under an env layer restricted to those 8 variables.
  • The env layer is VerbatimEnv. It wraps Env and emits values as verbatim strings. Env::data type-infers values and has no option to disable this (the 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.
  • 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: HOME on Linux and macOS, USERPROFILE on Windows. Same order as the resolvers' internal lookup. config_dir() resolves from HOME alone; a USERPROFILE fallback there is a behavior change, out of scope for this series.
  • The free config_dir() is transitional. It loads a Config per call and keeps the ~30 call sites unchanged until the command-module PRs pass &Config down from run().
  • PATHBASE_URL_ENV moves to config.rs. cmd_pathbase is compiled out of the wasm/emscripten build, and CONFIG_ENV_VARS needs the constant on every target. cmd_pathbase re-exports it.

Tests

  • figment::Jail tests pin the env-to-Config mapping. They hold the existing TEST_ENV_LOCK: Jail serializes only against other Jail tests, and other test modules mutate HOME / TOOLPATH_CONFIG_DIR under that lock.
  • One Jail test pins verbatim extraction: TOOLPATH_QUERY_EXPLAIN=01 extracts as "01". Type inference turns 01 into the integer 1.
  • config_dir precedence and home_dir fallback tests use plain values and do not touch the environment.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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.
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

🔍 Preview deployed: https://c9bd0426.toolpath.pages.dev

@ecalifornica
ecalifornica force-pushed the robert/config-composition-root branch from d25d9d4 to 9243904 Compare August 13, 2026 12:46
Config::home_dir() resolves the home the provider resolvers use:
HOME, falling back to USERPROFILE (Windows). The fallback matches
the resolvers' internal home lookup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant