Skip to content

feat(doctor): airc doctor --connect pre-flight check (closes #80) - #87

Merged
joelteply merged 2 commits into
canaryfrom
feat/doctor-connect-preflight
Apr 25, 2026
Merged

joelteply merged 2 commits into
canaryfrom
feat/doctor-connect-preflight

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Closes #80. Adds airc doctor --connect pre-flight mode. Use case:

airc doctor --connect && airc connect

Surfaces the silent-fail classes that produced #78 / #85 / #79 cascades for first-time users BEFORE the pair attempt instead of during. Each probe is [ok] / [BLOCKED] / [info] with a fix command; exit non-zero if any BLOCKED.

What's checked

Default health probes plus connect-specific:

  • github gists API reachable (catches network outages + token issues that silently break gist substrate)
  • tailscale UP (not just installed) when cached host_target is tailnet CGNAT — Memento's exact failure mode (bug+feat: airc connect should detect Tailscale logged-out state before silently failing #78) caught earlier in the workflow
  • AIRC_PORT free (info-only since airc handles port-shift gracefully)
  • Cached host_target reachable + ssh-auth works (resume scenario — catches stale-pairing + dead-host before silent queue / dead-monitor cascade)

Bash + PS1 lockstep

Per Joel's no-neglect-Windows rule. Both languages have the same probe set in their own idiom.

Test plan

  • 133/133 integration tests pass
  • Bash syntax check
  • Verified locally on Mac: airc doctor --connect returns READY in healthy env, prints fix commands otherwise
  • Live verify on Windows native (Toby / future test machine)

Related issues

Closes #80. Complements landed #84 (resume + fresh-pair tailscale gate) + #86 (gh-bin winget fallback). Together these three eliminate the silent-fail classes at install/connect time.

🤖 Generated with Claude Code

Adds a third doctor mode beyond the existing health-check default and
--tests integration-suite mode. Use case:

    airc doctor --connect && airc connect

Eliminates the silent-fail classes that produced #78 / #85 / #79
cascades for first-time users by surfacing them before pair attempt
rather than during.

Default health probes (git/gh/openssl/ssh/python3 + gh-auth) PLUS
connect-specific checks:

- github gists API reachable (catches network outages + token issues
  that would silently break gist substrate)
- tailscale UP (not just installed) when the cached host_target is in
  tailnet CGNAT range — handles Memento's exact failure mode (#78)
  but at a different point in the workflow
- AIRC_PORT free or auto-shift available (info-only, since airc
  handles port collision gracefully)
- Cached host_target reachable + ssh-auth works (resume scenario;
  catches stale-pairing + dead-host cases before the user notices
  silent queue / dead-monitor cascade)

Each probe outputs [ok] / [BLOCKED] / [info] with a fix command;
exits non-zero on any BLOCKED so the call site can chain with &&.

Bash + ps1 in lockstep per the no-neglect-Windows rule. The ps1 mode
mirrors structure exactly; both share the same probe set.

Verified locally on this Mac: doctor --connect returns READY when env
is healthy, prints fix commands when not.

133/133 integration tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 25, 2026 17:30

Copilot AI 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.

Pull request overview

Adds a new airc doctor --connect mode (bash + PowerShell) that runs connect-specific preflight checks so first-time (and resume-path) failures surface before attempting airc connect.

Changes:

  • Extend doctor to support a new --connect mode alongside --tests and default environment health checks.
  • Implement connect preflight probes: GitHub API reachability via gh, Tailscale UP gating when cached host_target is CGNAT, port availability, and cached host SSH reachability.
  • Update PowerShell dispatch to pass through doctor sub-args.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airc Adds cmd_doctor --connect routing and implements _doctor_connect_preflight probes.
airc.ps1 Adds Invoke-DoctorConnectPreflight and routes airc doctor --connect via Invoke-Doctor -Argv.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread airc Outdated
Comment on lines +4097 to +4104
# ── Connect-specific: gist API reachable ──
if command -v gh >/dev/null 2>&1; then
if gh api user >/dev/null 2>&1; then
printf " [ok] github gists API reachable\n"
else
printf " [BLOCKED] github gists API not reachable -- network or token issue\n"
printf " Fix: check internet, then re-run 'gh auth login -s gist'\n"
issues=$((issues+1))

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

The “github gists API reachable” probe uses gh api user, which can succeed even when gist write access is missing (and also overlaps with the prior gh auth status probe). This means doctor --connect may still report READY while gist creation/deletion later fails, and it may double-count the same root cause as multiple issues. Consider checking for the gist scope explicitly (e.g., parse gh auth status scopes output) and/or probe an endpoint/operation that requires gist scope, and skip/avoid counting this probe when gh is missing or already unauthenticated.

Suggested change
# ── Connect-specific: gist API reachable ──
if command -v gh >/dev/null 2>&1; then
if gh api user >/dev/null 2>&1; then
printf " [ok] github gists API reachable\n"
else
printf " [BLOCKED] github gists API not reachable -- network or token issue\n"
printf " Fix: check internet, then re-run 'gh auth login -s gist'\n"
issues=$((issues+1))
# ── Connect-specific: gist access available ──
if command -v gh >/dev/null 2>&1; then
local gh_auth_status=""
if gh_auth_status=$(gh auth status 2>&1); then
case "$gh_auth_status" in
*"Token scopes:"*"gist"*|*"scopes:"*"gist"*)
printf " [ok] github gist scope available\n"
;;
*)
printf " [BLOCKED] github gist scope missing\n"
printf " Fix: re-run 'gh auth login -s gist'\n"
issues=$((issues+1))
;;
esac
else
printf " [info] github gist scope check skipped -- gh auth already failing\n"

Copilot uses AI. Check for mistakes.
Comment thread airc.ps1 Outdated
Comment on lines +1277 to +1300
Probe 'gh (GitHub CLI)' {
Get-Command gh -ErrorAction SilentlyContinue
} 'winget install --id GitHub.cli (then: gh auth login -s gist)'
Probe 'gh authenticated (gist scope)' {
if (-not (Get-Command gh -ErrorAction SilentlyContinue)) { return $false }
& gh auth status 2>$null | Out-Null
$LASTEXITCODE -eq 0
} 'gh auth login -s gist'
Probe 'ssh (OpenSSH client)' {
Get-Command ssh -ErrorAction SilentlyContinue
} 'Settings -> Apps -> Optional Features -> Add -> OpenSSH Client'
Probe 'ssh-keygen' {
Get-Command ssh-keygen -ErrorAction SilentlyContinue
} 'Comes with OpenSSH Client (see above)'
Probe 'openssl' {
$null -ne $script:OpenSSLBin
} 'winget install --id Git.Git (Git for Windows bundles openssl)'

# Connect-specific: github gists API reachable
Probe 'github gists API reachable' {
if (-not (Get-Command gh -ErrorAction SilentlyContinue)) { return $false }
& gh api user 2>$null | Out-Null
$LASTEXITCODE -eq 0
} 'check internet, then re-run gh auth login -s gist'

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

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

In doctor --connect, the gh-related probes will over-count and may give a false sense of coverage: gh auth status doesn’t verify gist scope, and gh api user doesn’t actually exercise the gists API (it can succeed without gist permission). Also, because these are implemented as independent Probe calls, a missing/unauthenticated gh can be counted 2–3 times. Consider (1) short-circuiting downstream gh probes when gh is missing/unauthenticated, and (2) validating gist scope explicitly (e.g., parse gh auth status for scopes) or probing an endpoint/operation that requires gist scope.

Copilot uses AI. Check for mistakes.
#87)

Two issues Copilot caught on PR #87:

1. **Over-counting**: when gh is missing/unauthed, the cascade of
   probes (gh installed, gh auth, gh gist API) each counted as a
   separate issue, producing inflated 'BLOCKED on 3 issues' messages
   that all share one root cause.

2. **Gist scope wasn't actually verified**: `gh auth status` passes
   for a gist-scope-less token, and `gh api user` doesn't exercise
   the gists endpoint. Result: doctor --connect could report READY
   while gist creation/deletion later silently fails.

Fix: single chain (installed -> authed -> gist scope present -> gists
API reachable), early-return on first failure with the most specific
fix command. Each step's failure counts as exactly one issue with
exactly the right diagnosis. Both bash and PS1 use the same chain
shape for parity.

Gist-scope check parses `gh auth status` output for "Token scopes:
... gist ..." (works on both 2.x output styles). Gists-API reach
uses `gh api 'gists?per_page=1'` -- minimal endpoint that actually
exercises the gist permission, no side effects.

133/133 integration tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit ea98bfe into canary Apr 25, 2026
1 check passed
@joelteply
joelteply deleted the feat/doctor-connect-preflight branch April 25, 2026 17:43
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.

2 participants