Skip to content

fix(installer): resolve the gateway config dir like the CLI does - #4063

Merged
TaylorMutch merged 2 commits into
NVIDIA:mainfrom
fede-kamel:fix/4042-installer-xdg-config-home
Oct 22, 2026
Merged

TaylorMutch merged 2 commits into
NVIDIA:mainfrom
fede-kamel:fix/4042-installer-xdg-config-home

Conversation

@fede-kamel

Copy link
Copy Markdown
Contributor

Summary

install.sh hardcoded $TARGET_HOME/.config/openshell in two places while the
CLI keeps gateway entries and client certificates under
$XDG_CONFIG_HOME/openshell whenever that variable is set:

  • wait_for_local_gateway_listener, which reads the mTLS client bundle that the
    gateway registration writes.
  • remove_local_gateway_registration, which clears a stale openshell entry
    before re-adding it.

With XDG_CONFIG_HOME pointing anywhere other than ~/.config, the installer
and the CLI looked in different directories: the readiness check waited out its
timeout on certificates that were never going to appear there, and the cleanup
left the real stale entry untouched.

Related Issue

Fixes #4042

Changes

  • Add target_openshell_config_dir, which resolves the directory through
    as_target_user so the answer comes from the same environment the CLI is
    invoked in. This covers both branches without restating their logic: the
    same-user branch inherits the caller's XDG_CONFIG_HOME, while the sudo and
    runuser branches reset the environment and fall back to the target user's
    home.
  • Use it for the readiness check and the registration cleanup.

remove_snap_gateway_registration is deliberately untouched: the snap confines
its own config root under ~/snap/openshell/common/.config, which is not
XDG_CONFIG_HOME.

Testing

Added three assertions to tasks/scripts/test-install-sh.sh, which sources
install.sh and exercises the function directly. Full suite passes:

$ bash tasks/scripts/test-install-sh.sh
install.sh focused tests passed

They are a real guard, not a vacuous pass — reverting only the helper to the old
hardcoded path fails the suite:

FAIL: XDG_CONFIG_HOME is honored: expected /tmp/tmp.XXXX/xdg-config/openshell,
      got /tmp/tmp.XXXX/target-home/.config/openshell

Resolution probed against the CLI's own rule
(openshell_core::paths::xdg_config_dir joined with openshell), running the
real as_target_user:

XDG_CONFIG_HOME CLI resolves before after
unset $HOME/.config/openshell match match
/home/u/cfg /home/u/cfg/openshell mismatch match
set but empty openshell (relative) mismatch $HOME/.config/openshell

A divergence worth a separate look

The empty case is the one place this does not match the CLI byte for byte. The
installer follows the XDG base directory specification, which says an empty
value is treated as unset. xdg_config_dir instead takes env::var's Ok("")
as set and joins onto it, so it yields the relative path openshell,
resolved against the process working directory. No installer path can usefully
match that, and it looks like a bug on the CLI side rather than something to
mirror here. Happy to file it separately if you agree.

install.sh hardcoded $TARGET_HOME/.config/openshell in two places: the
readiness check, which reads the client certificates it expects the
gateway registration to have written, and the cleanup that removes a
stale openshell entry before re-adding it. The CLI instead keeps both
under $XDG_CONFIG_HOME/openshell whenever that variable is set, so with
the variable pointing anywhere other than ~/.config the installer and
the CLI looked in different directories: the readiness check waited for
certificates that were never going to appear there, and the cleanup left
the real stale entry in place.

Resolve the directory through as_target_user instead, which answers from
the same environment the CLI is invoked in. That covers both branches
without duplicating their logic: the same-user branch inherits the
caller's XDG_CONFIG_HOME, while the sudo and runuser branches reset the
environment and fall back to the target user's home.

An empty XDG_CONFIG_HOME falls back to $HOME/.config, following the XDG
base directory specification. The CLI diverges here: xdg_config_dir
treats a set-but-empty value as set and joins onto it, yielding the
relative path "openshell", which no installer path can usefully match.
Worth fixing separately in the CLI.

Signed-off-by: fede-kamel <fkamelhar@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@TaylorMutch TaylorMutch self-assigned this Oct 20, 2026

@TaylorMutch TaylorMutch left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-empty XDG_CONFIG_HOME fix is sound, but the empty-value case still leaves the installer and CLI using different directories.

target_openshell_config_dir deliberately treats XDG_CONFIG_HOME="" as unset and returns $HOME/.config/openshell. The current openshell_core::paths::xdg_config_dir() treats an empty value as set, so the CLI resolves its root to the relative path openshell. Because registration invokes the CLI with that same empty environment value, it can write the gateway entry under ./openshell while the readiness and cleanup paths introduced here look under $HOME/.config/openshell. That preserves the mismatch for an acceptance case in #4042.

Please make the two paths agree for an empty value. Updating xdg_config_dir() to treat empty as unset would match the XDG specification and the behavior chosen here. Please also add the requested set-with-spaces test; the current focused tests cover unset, non-empty, and empty values only. A focused assertion through registration cleanup or another consumer of the helper would ensure this does more than validate the helper in isolation.

I ran tasks/scripts/test-install-sh.sh from commit 96a589822af55cb85e7be0651aea1d0a6e0db2fc; it passes. No related agent-skill updates appear necessary for this installer-path correction.

Maintainer note: the linked issue currently has state:validated, not state:accepted, and the author has read-only repository access. The issue acceptance gate must also be satisfied before merge. Outdated

xdg_config_dir() joined onto an empty XDG_CONFIG_HOME and resolved the
config root to the relative path "openshell", while the installer falls
back to $HOME/.config/openshell for the same value. Registration runs the
CLI with the caller's environment, so the two could disagree on where the
gateway entry lives.

Treat an empty value as unset, as the XDG base directory spec requires,
so the CLI and installer resolve the same directory. Add tests for a value
with spaces and drive registration cleanup through the helper for the
spaces and empty cases.

Signed-off-by: fede-kamel <fkamelhar@gmail.com>
@TaylorMutch

Copy link
Copy Markdown
Collaborator

/ok to test 9ef492f

@fede-kamel

Copy link
Copy Markdown
Contributor Author

@TaylorMutch Thanks for the review. Addressed in 9ef492f:

  • openshell_core::paths::xdg_config_dir() now treats an empty XDG_CONFIG_HOME as unset and falls back to $HOME/.config, as the XDG spec says. For an empty value the installer and the CLI now both resolve $HOME/.config/openshell, and registration no longer writes under a relative ./openshell.
  • New unit tests cover the empty and set-with-spaces cases for the helper.
  • tasks/scripts/test-install-sh.sh adds the set-with-spaces case for target_openshell_config_dir. It also runs remove_local_gateway_registration through the real as_target_user path twice. With XDG_CONFIG_HOME set to a path with spaces, the entry there is cleared and $HOME/.config/openshell is left alone. With an empty value, cleanup clears $HOME/.config/openshell and creates nothing relative to the working directory.

tasks/scripts/test-install-sh.sh and cargo test -p openshell-core --lib paths:: pass locally. cargo clippy -p openshell-core --lib --tests -- -D warnings is clean.

@TaylorMutch

Copy link
Copy Markdown
Collaborator

/ok to test 9ef492f

@TaylorMutch
TaylorMutch added this pull request to the merge queue Oct 22, 2026
Merged via the queue into NVIDIA:main with commit 78376bd Oct 22, 2026
95 checks passed
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.

bug: install.sh ignores XDG_CONFIG_HOME for the local gateway config

2 participants