feat: add system-wide config file support#963
feat: add system-wide config file support#963goodtune wants to merge 15 commits intomax-sixty:mainfrom
Conversation
Load organization-wide defaults from a system config file before user config, allowing companies to distribute shared preferences via configuration management. Config loading order (later overrides earlier): 1. System config (organization defaults) 2. User config (personal preferences) 3. Environment variables System config search locations: - $WORKTRUNK_SYSTEM_CONFIG_PATH (explicit override) - $XDG_CONFIG_DIRS directories (colon-separated) - Linux: /etc/xdg/worktrunk/config.toml - macOS: /Library/Application Support/worktrunk/config.toml - Windows: %PROGRAMDATA%\worktrunk\config.toml Uses the same format as user config. Visible in `wt config show`. https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC
Apply rustfmt formatting to fix CI lint failures: - Split long `pub use` statement across multiple lines in `mod.rs` - Condense multi-line path building to single line in `path.rs` - Format long string assignment in `tests.rs` - Improve method chaining formatting in integration tests
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to test environment setup to prevent platform-specific system config paths from appearing in snapshots. Changes: - Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_wt_cmd()` (TestRepo) - Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_cli_command()` (standalone tests) - Add filter for non-canonicalized macOS temp paths (`/var/folders/...`) This ensures tests show consistent "Not found (optional)" for system config across Linux, macOS, and Windows, preventing snapshot mismatches.
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to `test_env_vars()` to ensure PTY-based tests (like switch picker) have consistent system config behavior across platforms. Without this, PTY tests would fall back to platform-specific system config paths, causing test output to vary between Linux, macOS, and Windows.
|
thanks for the reformed PR is this actually something that people want, though? I agree re the Could folks share some use cases where this would be helpful? |
|
Here are some examples where it would be useful in our company. We already deploy standardised configuration to all our developer machines to configure a proxy We have begun installing
Unless we have something like this, we need to ask users to copy our preferred configuration into their home directory. They don't always follow instructions to the letter, so when they try to follow along with internal guides they get confused because they missed a step. The philosophy I think is very sound, and is echoed through specifications such as the XDG base directory standard, and tools such as pip ( The ability to set sensible defaults system-wide while still allowing users to override them in their personal config is well-established and makes tools manageable in enterprise/team settings. Users who don't need this feature wouldn't be affected, but for organizations deploying tools at scale, it's the difference between a smooth rollout and constant support tickets. |
|
ok, that makes a lot of sense, thanks for the thoughtful response @goodtune let me make some small adjustments to the code, if that's OK |
|
Absolutely, please tweak as needed! |
Eliminate all test/non-test cfg annotations from path.rs. Both user config and system config now use the same pattern: env var check first, then platform default. Test isolation relies on env vars set by TestRepo (WORKTRUNK_CONFIG_PATH, WORKTRUNK_SYSTEM_CONFIG_PATH), which already covered integration tests. Delete system_config_search_dirs() (fragile double-.parent() hack), replace with default_system_config_path() that returns the env var or first platform default. Co-authored-by: Claude <noreply@anthropic.com>
…paths Cover the system config resolution paths that were previously behind #[cfg(not(test))] and never tested: XDG_CONFIG_DIRS lookup (found and not-found cases), and platform default display path fallback. Co-authored-by: Claude <noreply@anthropic.com>
Add tests for empty system config (hint message), invalid system config (TOML parse error display), and unknown keys warning during config loading. These exercise the render_system_config() and config loading paths. Co-Authored-By: Claude <noreply@anthropic.com>
|
Looks good, thanks for taking the time to improve it. |
System config is a niche feature for organizations. Replace the dedicated section, TOML example, and table row with a single sentence pointing to `wt config show`. Env vars remain in the table for discoverability. Co-Authored-By: Claude <noreply@anthropic.com>
Test from main needed its snapshot updated to include the new SYSTEM CONFIG section in config show output. Co-Authored-By: Claude <noreply@anthropic.com>
|
hi @goodtune — wdyt about those changes? lmk if you think we can make any final improvements. ty! |
Load organization-wide defaults from a system config file before user config, allowing companies to distribute shared preferences via configuration management.
Config loading order (later overrides earlier):
System config search locations:
$WORKTRUNK_SYSTEM_CONFIG_PATH(explicit override)$XDG_CONFIG_DIRSdirectories (colon-separated)/etc/xdg/worktrunk/config.toml/Library/Application Support/worktrunk/config.toml%PROGRAMDATA%\worktrunk\config.tomlUses the same format as user config. Visible in
wt config show.Prior art in other highly correlated tools:
Cleaned up version of #960.