Skip to content

Auto-init guard: consult merged global+local .hx config#271

Draft
half-ogre wants to merge 2 commits into
mainfrom
half-ogre/270
Draft

Auto-init guard: consult merged global+local .hx config#271
half-ogre wants to merge 2 commits into
mainfrom
half-ogre/270

Conversation

@half-ogre

Copy link
Copy Markdown
Contributor

Closes #270.

Summary

The auto-init guard added in #267 reads only ./.hx via
RestoreLocalConfig, so a complete global ~/.hx is treated as
missing. That triggers runInitApp, which then fails when the runtime
user doesn't own CWD — the shipped cmd/entrypoint/hyphen-entrypoint.sh
hits this on every cold start in any non-root container.

This PR extracts the merge that RestoreConfigFromFile already does
into RestoreMergedConfig(file) (Config, bool, error) and has the
guard call it. The guard now passes whenever the resolved (merged)
config is complete, matching what the guarded commands themselves see.

HasCompleteLocalAppConfig is renamed to HasCompleteAppConfig and
NeedsLocalAppConfig to NeedsAppConfig to reflect that the check is
no longer local-only. The "local" qualifier is also dropped from the
guidance message; hx init still creates a local .hx, so the
suggested remediation is unchanged.

Test isolation

cmd/autoinit/autoinit_test.go previously isolated only CWD, which
worked while the guard was local-only. Now that the guard reads global,
withTempDir also redirects $HOME (and USERPROFILE) to a separate
temp dir so tests can't pick up the developer's real ~/.hx. The
missing-coverage gap that let #270 ship is closed by three new
subtests: global-only complete, global+local merging to complete, and
Ensure passing through when global is complete.

Validation

  • go test ./cmd/autoinit/ — pass
  • go test ./... — pass except tests/acceptance/TestCLIExitCodes,
    which fails identically on main (it expects an unauthenticated
    environment; a logged-in hx session makes the call succeed)

half-ogre added 2 commits May 25, 2026 19:24
Adds failing tests for the cases described in #270: a complete global
~/.hx alone, and global+local merging to a complete config, should both
satisfy the auto-init guard. Today both fall through to runInitApp.
Closes #270.

The guard added in #267 read only ./.hx via RestoreLocalConfig, so a
complete global ~/.hx was treated as missing. That triggered runInitApp,
which then failed when the runtime user didn't own CWD (the shipped
hyphen-entrypoint.sh's exact scenario in non-root containers).

Extract the merge that RestoreConfigFromFile already does into
RestoreMergedConfig(file) (Config, bool, error) and have the guard call
it. Rename HasCompleteLocalAppConfig -> HasCompleteAppConfig and
NeedsLocalAppConfig -> NeedsAppConfig to reflect that the check is no
longer local-only. Drop "local" from the guidance message for the same
reason; hx init still creates a local .hx, so the suggested remediation
is unchanged.

Also tighten test isolation: withTempDir now also redirects $HOME to a
separate temp dir, so the guard's global-config check doesn't pick up
the developer's real ~/.hx during local test runs.
@half-ogre half-ogre requested a review from osbornm May 26, 2026 02:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the configuration validation logic to support merged global and local configurations. It introduces RestoreMergedConfig to read and merge global (~/.hx) and local (./.hx) configs, and updates the auto-initialization guards to check this merged configuration instead of only the local one. Corresponding tests have been updated and expanded to cover these changes. There are no review comments to address, so I have no additional feedback to provide.

@half-ogre

Copy link
Copy Markdown
Contributor Author

Converting to draft while we discuss whether this is the right approach or we do #269 (which I had missed when opening #270 )

@half-ogre half-ogre marked this pull request as draft May 26, 2026 15:41
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.

Auto-init guard ignores global ~/.hx, breaking the shipped hx entrypoint

2 participants