fix(tunnel): token-based daemon-present probe (fixes silent hsh login skip)#30
Merged
Merged
Conversation
Follow-up to the previous fix. The 'is the daemon present?' check that decides whether hsh login's optional daemon leg may skip silently used existsSync() on the unix SOCKET path. On at least one user's host that returned false for a LIVE daemon (hsh tunnel status worked fine), so the daemon leg of hsh login skipped silently again — leaving the daemon on its old token with zero output. Root cause: TunnelClient.connect() never stats the socket; it keys on a readable control token. The existsSync(socket) discriminator was thus inconsistent with how connect()/status actually reach the daemon. Fix: daemonLooksInstalled() now mirrors connect() — a readable control token (or a present/ env-pointed token file, or an env-pointed socket) means 'daemon is here; surface any failure'. Only the bare-default, nothing-present case counts as genuinely absent and skips silently. Tests updated to the token-based contract: present-but-unusable (readable token, dead socket) → false; env-pointed socket → false; non-optional → false; genuinely-absent default path → silent skip (guarded so it never false-fails on a box that has a real daemon installed). 🤖 Generated with Mister Maluco Co-Authored-By: MisterMal <teskeslab@lucasteske.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in the field on 0.3.1:
hsh loginprinted only 'Successfully authenticated with Hoop!' and silently did nothing for the daemon, leaving it on a stale/expired token (hsh tunnel refreshthen 401'd). One browser, zero daemon output — even though the daemon was running andhsh tunnel statusreached it fine.Root cause
The previous fix used
existsSync()on the unix socket path to decide whether the daemon is 'present' (and thus whether the optional daemon leg may skip silently). On the affected host thatexistsSyncreturned false for a live daemon, sologinDaemontook the 'genuinely absent → silent skip' branch.But
TunnelClient.connect()(used byhsh tunnel status, which worked) never stats the socket — it keys on a readable control token. So the socket-existsSync discriminator was inconsistent with how the client actually reaches the daemon.Fix
daemonLooksInstalled()now mirrorsconnect()'s reachability basis:So a live daemon is now always detected as present, and any failure to update it surfaces a warning + non-zero exit instead of a silent skip.
Note on the 401 itself
The token rejection you saw is the known no-refresh-token expiry (already tracked) — OIDC access tokens from sandbox expire well under 12h and the daemon can't renew. This PR doesn't change that; it ensures
hsh loginactually re-authenticates the daemon (instead of silently skipping) so the user can recover, andhsh tunnel statusalready hints the re-login.Testing
tests/login-daemon.test.tsrewritten to the token-based contract: present-but-unusable → false; env-pointed socket → false; non-optional → false; genuinely-absent default → silent skip (guarded against boxes with a real daemon).Automated by MisterMal