Repository navigation
refactor(config): read system config from one fixed path per platform - #4169
Conversation
`system_config_dirs()` split `XDG_CONFIG_DIRS` on `:` and dropped only the empty entries, so a relative one survived. `system_config_path()` then joined `worktrunk/config.toml` onto it and resolved the result against the process cwd — inside whatever repository `wt` was run in. That file loads as system config, which `load_with_warnings` merges into the same `UserConfig` table the user's own file merges into. Its `[aliases]` and `post-*` hooks are therefore user hooks, and the approval gate deliberately does not cover those, so the commands would run unprompted. The XDG spec already says to ignore a relative entry, and `etcetera` applies that rule to the `XDG_*_HOME` variables it resolves for wt. It exposes no accessor for `XDG_CONFIG_DIRS`, so filter on `is_absolute()` here. An all-relative value now falls back to the platform defaults, as an empty one already did. `resolve_input_path`'s docstring cites the spec's absoluteness requirement as its reason for leaving `XDG_CONFIG_DIRS` alone; this makes that true.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Self-review; not approving, since GitHub rejects a self-approval. Two findings, both pushed as a follow-up commit on this branch.
The regression test held over output that said nothing about system config. render_user_config returns right after the "Not found" hint when the user config file is absent — before it reaches render_system_config_hint — and set_xdg_config_path points WORKTRUNK_CONFIG_PATH at a file the test never creates. So wt config show printed USER CONFIG / PROJECT CONFIG / SHELL INTEGRATION / OTHER and no system-config line at all, which satisfies !contains("SYSTEM CONFIG") and !contains("/planted/") without ever observing the fallback the change introduces. The test still discriminated on the bug, but any future break in that render path would turn it green rather than red. The fix plants a user config the way test_config_show_absent_system_config_is_a_user_config_hint does, then asserts Optional system config not found — the hint naming the platform default the all-relative value fell back to. Checked both directions: it fails with the old !d.is_empty() filter restored and passes with the change.
Two comments still state the contract the change replaces. system_config_dirs's docstring ("When set, it defines the search path exclusively (per XDG spec) — no fallback to platform defaults") and the matching comment in system_config_path are now false for exactly the case this PR introduces: an all-relative value drops every entry, leaves dirs empty, and falls through to platform_default_dirs(). Reworded to "names at least one absolute directory", with the fallback spelled out — the PR description states it but the code didn't.
Nothing else came out of the pass. The filter swap keeps the empty-entry drop it replaced (PathBuf::from("").is_absolute() is false), both callers of system_config_dirs only improve, and the all-relative fallback to /etc/xdg is what the spec asks for on an effectively-empty value. The hand-rolled rule is the documented escape hatch in CLAUDE.md → Use Existing Dependencies rather than a re-derivation: etcetera has no XDG_CONFIG_DIRS accessor, and its env_var_or_none applies the same is_absolute() filter to the variables it does own.
…back The assertions were all negative, and `config show` never reached the system-config hint: `render_user_config` returns after the "Not found" hint when the user config file is absent, which `set_xdg_config_path` guarantees. Plant a user config so the hint renders, then assert it — the hint names the platform default an all-relative value falls back to. Also correct the docstring and comment that still said XDG_CONFIG_DIRS being set means no fallback to platform defaults.
`resolve_input_path` is already imported in this module, so the bare label resolves. The explicit target tripped `rustdoc::redundant_explicit_links`, which `-D warnings` makes fatal, and failed the pre-merge `doc` step in fast-checks.
|
this is an incredibly minor issue and we're spending a lot of text on it here (and so many PRs) can we just delegate it all to etcetera? even if not perfect; we shouldn't be spending our time on building lots of corner cases to slightly incorrectly created env bars. see if we can wash all this config code away and just delegate it |
Per review: the fix is one predicate, so the explanation should be a sentence. The docstring loses the spec quote and the approval-gate argument (both live in the PR body and #4106), the call-site comment is now shorter than the one it replaced, and the test's commentary is trimmed to what a reader needs.
|
Can't delegate this one to The other delegate would be the So what's left is the one-line predicate this PR already is, and it's the same rule // etcetera-0.11.0/src/base_strategy/xdg.rs
fn env_var_or_none(env_var: &str) -> Option<PathBuf> {
std::env::var_os(env_var).and_then(|path| {
let path = PathBuf::from(path);
// Return None if the path obtained from the environment variable isn't absolute.
if path.is_absolute() { Some(path) } else { None }
})
}Your other point stands on its own though, so I've cut the text: the docstring goes from 14 lines to 3 (the spec quote and the approval-gate argument were already in the PR body and #4106), the call-site comment is now shorter than the one it replaces, the test's commentary is trimmed, and the PR description is a third of its old length. That's 30 lines off the branch. The whole PR is now On the PR count: #4106 is a survey of nine items and I've been opening one PR per item. Happy to stop there and leave the rest as issue text unless you want a specific one picked up. |
what's this |
|
etcetera's user config dir — It's a different variable from the one this PR touches, though — What carries over is the rule. etcetera's |
System config no longer consults XDG_CONFIG_DIRS. The location is WORKTRUNK_SYSTEM_CONFIG_PATH when set, otherwise one path per platform: /Library/Application Support/worktrunk/config.toml on macOS, %PROGRAMDATA%\worktrunk\config.toml on Windows, and /etc/xdg/worktrunk/config.toml elsewhere. That removes the search path, and with it the relative-entry case this branch first patched, rather than filtering it. Behavior changes: XDG_CONFIG_DIRS directories are no longer searched, and macOS no longer falls back to /etc/xdg. system_config_path() now returns the location whether or not the file exists, so default_system_config_path() goes; callers that need an existing file check for it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…fig-dirs-absolute # Conflicts: # src/commands/config/show.rs
Adds **Other Tools Own Their Conventions** under Code Quality in
`AGENTS.md`, and folds "Use Existing Dependencies"' closing sentence
("Let dependencies own their own rules") into it:
> Where another tool owns a convention, such as its config location,
file format, URL syntax, or error reporting, ask that tool or a library
that implements its rules instead of encoding them in Worktrunk: `nu`
reports its own directories, and `gh auth token --hostname` reports
whether a host is authenticated. Worktrunk's role is the standard uses
of those conventions. Where neither the tool nor a library answers,
support the standard case and remove rather than refine: an input that
only misbehaves outside standard use is a reason to stop reading it, and
a tool that isn't installed has nothing to integrate with, so needs no
fallback table.
#4169 is the case it comes from: filtering relative `XDG_CONFIG_DIRS`
entries became, on review, no longer reading `XDG_CONFIG_DIRS` at all.
Code the rule implies removing, to be done in a follow-up rather than
found piecemeal: `nushell_data_dir_fallback` in `src/shell/paths.rs`,
which re-encodes Nushell's data-dir rule for when `nu` can't be queried,
and the PowerShell `~/.config/powershell` fallback for when `pwsh` can't
answer.
> _This was written by Claude Code on behalf of max-sixty_
---------
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
System config is now read from one fixed path per platform, and
XDG_CONFIG_DIRSis no longer consulted. The location isWORKTRUNK_SYSTEM_CONFIG_PATHwhen set, otherwise:/Library/Application Support/worktrunk/config.toml%PROGRAMDATA%\worktrunk\config.toml/etc/xdg/worktrunk/config.tomlThis PR started as a filter for relative
XDG_CONFIG_DIRSentries (#4106, item 4). Removing the search path removes that case without a filter, and git's--systemfile is a fixed path for the same reason.system_config_path()now returns the location whether or not the file exists, sodefault_system_config_path(), which repeated the lookup order for thewt config showhint, is deleted, along withsystem_config_dirs(),platform_default_dirs(), the threeXDG_CONFIG_DIRStests and the env-var docs row.Behavior changes: directories listed in
XDG_CONFIG_DIRSare no longer searched (common values such as NixOS's, Ubuntu's and Flatpak's already include/etc/xdg), and macOS no longer falls back to/etc/xdgafter/Library/Application Support.