Skip to content

refactor(cli): remove the last environment reads below the composition root - #205

Draft
ecalifornica wants to merge 1 commit into
robert/config-cachefrom
robert/config-cleanup
Draft

refactor(cli): remove the last environment reads below the composition root#205
ecalifornica wants to merge 1 commit into
robert/config-cachefrom
robert/config-cleanup

Conversation

@ecalifornica

@ecalifornica ecalifornica commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Last PR of the #184 series. path-cli only.

Closes #184.

What

  • The free home_dir() in config.rs is deleted. Its two callers take a
    &Config already:
    • cmd_share::bail_no_sessions gains a &Config parameter and calls
      Config::home_dir.
    • share_config::resolve_remote calls Config::home_dir for the ~/
      expansion argument.
  • cmd_derive::run takes a &Config and passes it to cmd_import::run. The
    p derive arm in cmd_p::run passes the &Config it already holds. This
    was the last transitional Config::load().
  • Outside tests, Config::load() has one caller: run() in lib.rs.

Audit

$PATH is the only environment variable read below the composition root:
fuzzy.rs (external fzf lookup), cmd_resume.rs (harness binary lookup),
and cmd_export.rs (cursor-on-PATH check). A binary lookup is execution
environment, not configuration, so $PATH is not a Config field.
CONFIG_ENV_VARS and the Config fields are a 1:1 match, 8 for 8: APPDATA,
COPILOT_HOME, HOME, PATHBASE_URL, TOOLPATH_CONFIG_DIR,
TOOLPATH_QUERY_EXPLAIN, USERPROFILE, XDG_DATA_HOME. Every field has a
consumer: appdata, copilot_home, and xdg_data_home in providers.rs;
pathbase_url in cmd_pathbase.rs; toolpath_query_explain in cmd_query.rs;
toolpath_config_dir, home, and userprofile through Config::config_dir
and Config::home_dir.

Behavior change

  • None. The same environment reaches the same code. It is read once, in
    run().

Tests

  • sync::engine::tests::with_cfg builds a Config and nothing else. It drops
    the $TOOLPATH_CONFIG_DIR write and the TEST_ENV_LOCK hold, so the whole
    sync-engine suite runs without serializing against the rest of the tests.
  • cmd_resume's resolve_input_url_uses_cache_on_hit_without_refetching drops
    its $TOOLPATH_CONFIG_DIR save/set/restore block and its TEST_ENV_LOCK
    hold. The injected Config pins the config directory.
  • cmd_resume's resolve_input_unresolvable_errors_clearly drops its
    TEST_ENV_LOCK hold. It reads no environment.
  • TEST_ENV_LOCK has two users left: the figment::Jail tests in config.rs,
    and the $PATH guard in cmd_resume. Its doc comment states this.
  • tests/support/mod.rs ScopedHome keeps its $HOME and
    $TOOLPATH_CONFIG_DIR writes. The integration tests drive the CLI at its
    composition root, which reads the environment by design. Tracking: single owner for configuration #183 Phase 1 owns
    removing that machinery and adding a lint.

Follow-on


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

…n root (#184)

Delete the free `home_dir()` from config.rs. Its two callers take a
`&Config` already: `cmd_share::bail_no_sessions` and
`share_config::resolve_remote` now use `Config::home_dir()`.

Thread `&Config` into `p derive` and delete its transitional
`Config::load()`. `Config::load()` runs once, in `run()`.

Test cleanup:
- `sync::engine::tests::with_cfg` builds a `Config` only. It drops the
  `$TOOLPATH_CONFIG_DIR` write and the `TEST_ENV_LOCK` hold.
- Two `cmd_resume` tests drop their `$TOOLPATH_CONFIG_DIR` write and
  their `TEST_ENV_LOCK` hold.

`$PATH` is the only variable read below the root. It is the execution
environment, not configuration.
@github-actions

Copy link
Copy Markdown

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

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.

Add Config at the composition root

1 participant