Skip to content

feat(airc-bash): extract cmd_doctor — airc under 5000 lines (Phase 3) - #175

Merged
joelteply merged 1 commit into
canaryfrom
feat/airc-bash-extract-cmd-doctor
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/airc-bash-extract-cmd-doctor

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

435-line cmd_doctor section extracted. airc bash: 5386 → 4952 lines (under 5000 for the first time).

What

`lib/airc_bash/cmd_doctor.sh` holds cmd_doctor + 9 `doctor*` helpers + `_doctor_run_tests`. airc top sources it via the lib-dir resolver.

Live verify

`airc doctor` all probes [ok] on Mac (git/gh/openssl/ssh/ssh-keygen/python3/jq/sshd/tailscale).

Test posture

66 assertions / 6 scenarios green: tabs (19), identity (19), whois (5), part_persists (8), list (4), general_sidecar_default (12).

Remaining slices (next splits)

  • cmd_connect (~1500) — biggest
  • cmd_send (~300)
  • cmd_part + cmd_teardown (~250)

Goal: every file under ~500 lines.

…rc under 5000)

435 lines (cmd_doctor, _doctor_detect_pkgmgr, _doctor_install_cmd_for,
_doctor_probe, _doctor_probe_gh_auth, _doctor_probe_sshd,
_doctor_probe_tailscale, _doctor_connect_preflight, _doctor_run_tests)
extracted to lib/airc_bash/cmd_doctor.sh, sourced from airc top-level
via the lib-dir resolver.

## Impact

- airc bash: 5386 → 4952 lines. **Below 5000 for the first time today.**
- New file: 435 lines, self-contained.

## Why doctor was a clean candidate

- All `_doctor_*` helpers used by cmd_doctor only — no exterior consumers.
- The probes use `detect_platform` / `get_config_val` from airc top-level
  (resolver sources platform_adapters before this file, and config CRUD
  helpers are still in airc).
- Already organized as a marked logical section.

## Live verify

`airc doctor` on this Mac: all probes [ok]. git, gh, gh authenticated,
openssl, ssh, ssh-keygen, python3, jq, sshd, tailscale — all green via
the sourced file.

## Test posture (66 assertions / 6 scenarios)

- tabs 19, identity 19, whois 5, part_persists 8, list 4,
  general_sidecar_default 12

## Remaining biggest sections in airc

- cmd_connect (~1500 lines) — still in airc, biggest remaining slice
- cmd_send (~300 lines)
- cmd_part / cmd_teardown (~250 combined)
- gist envelope build (~200)

Continued split brings each below the ~500 threshold Joel called out.
Copilot AI review requested due to automatic review settings April 27, 2026 23:19
@joelteply
joelteply merged commit 27cbd01 into canary Apr 27, 2026
2 checks passed
@joelteply
joelteply deleted the feat/airc-bash-extract-cmd-doctor branch April 27, 2026 23:19

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

Extracts the airc doctor command implementation out of the monolithic airc bash script into a sourced module under lib/airc_bash/, continuing the Phase 3 split to keep airc under ~5000 lines.

Changes:

  • Added lib/airc_bash/cmd_doctor.sh containing cmd_doctor and related _doctor_* helper functions.
  • Removed the inlined cmd_doctor + helpers from airc and replaced them with a source call via _airc_lib_dir.

Reviewed changes

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

File Description
lib/airc_bash/cmd_doctor.sh New sourced module containing cmd_doctor, connect preflight probes, and test runner entrypoint.
airc Replaces the inlined doctor implementation with sourcing from $_airc_lib_dir/airc_bash/cmd_doctor.sh.

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

Comment thread airc
# shellcheck source=lib/airc_bash/cmd_doctor.sh
source "$_airc_lib_dir/airc_bash/cmd_doctor.sh"
else
echo "ERROR: airc_bash/cmd_doctor.sh not found via lib-dir resolver." >&2

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

The cmd_doctor.sh source-failure path exits with only a generic message. Earlier in this file, the analogous platform_adapters.sh sourcing block prints the resolved lib_dir and a remediation hint (re-run install.sh / check AIRC_DIR), which makes field debugging much easier. Consider matching that behavior here too (include resolved lib_dir and a next-step hint) before exiting.

Suggested change
echo "ERROR: airc_bash/cmd_doctor.sh not found via lib-dir resolver." >&2
echo "ERROR: airc_bash/cmd_doctor.sh not found via lib-dir resolver." >&2
echo " resolved lib_dir: ${_airc_lib_dir:-"(unset)"}" >&2
echo " Try re-running install.sh, or verify AIRC_DIR points at the expected airc checkout." >&2

Copilot uses AI. Check for mistakes.
Comment on lines +225 to +233
# Debian/Ubuntu uses 'ssh', RHEL/Fedora/Arch uses 'sshd'.
if systemctl is-active --quiet ssh 2>/dev/null || systemctl is-active --quiet sshd 2>/dev/null; then
printf " [ok] sshd (systemd active)\n"
return 0
fi
printf " [MISSING] sshd -- needed when you HOST a room\n"
printf " Fix (Debian/Ubuntu): sudo apt-get install openssh-server && sudo systemctl enable --now ssh\n"
printf " Fix (RHEL/Fedora): sudo dnf install openssh-server && sudo systemctl enable --now sshd\n"
return 1

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

In the linux|wsl sshd probe, the check assumes systemctl exists. On distros/environments without systemd (e.g., Alpine detected via apk, some WSL setups, containers), systemctl will be absent and this will always report [MISSING] sshd even though the service might be running under a different init system (or the probe is simply impossible). Consider guarding with command -v systemctl and either (a) using an alternate probe path when available (e.g., service sshd status, rc-service sshd status), or (b) returning an info/skip result without incrementing issues when you can’t reliably determine state.

Suggested change
# Debian/Ubuntu uses 'ssh', RHEL/Fedora/Arch uses 'sshd'.
if systemctl is-active --quiet ssh 2>/dev/null || systemctl is-active --quiet sshd 2>/dev/null; then
printf " [ok] sshd (systemd active)\n"
return 0
fi
printf " [MISSING] sshd -- needed when you HOST a room\n"
printf " Fix (Debian/Ubuntu): sudo apt-get install openssh-server && sudo systemctl enable --now ssh\n"
printf " Fix (RHEL/Fedora): sudo dnf install openssh-server && sudo systemctl enable --now sshd\n"
return 1
# Debian/Ubuntu uses 'ssh', RHEL/Fedora/Arch uses 'sshd'. Not all
# linux/wsl environments have systemd/systemctl (for example Alpine,
# some WSL setups, and containers), so only use probes that exist.
if command -v systemctl >/dev/null 2>&1; then
if systemctl is-active --quiet ssh 2>/dev/null || systemctl is-active --quiet sshd 2>/dev/null; then
printf " [ok] sshd (systemd active)\n"
return 0
fi
printf " [MISSING] sshd -- needed when you HOST a room\n"
printf " Fix (Debian/Ubuntu): sudo apt-get install openssh-server && sudo systemctl enable --now ssh\n"
printf " Fix (RHEL/Fedora): sudo dnf install openssh-server && sudo systemctl enable --now sshd\n"
return 1
fi
if command -v rc-service >/dev/null 2>&1; then
if rc-service sshd status >/dev/null 2>&1; then
printf " [ok] sshd (OpenRC active)\n"
return 0
fi
printf " [MISSING] sshd -- needed when you HOST a room\n"
printf " Fix (Alpine/OpenRC): sudo apk add openssh && sudo rc-service sshd start && sudo rc-update add sshd\n"
return 1
fi
if command -v service >/dev/null 2>&1; then
if service ssh status >/dev/null 2>&1 || service sshd status >/dev/null 2>&1; then
printf " [ok] sshd (service active)\n"
return 0
fi
printf " [MISSING] sshd -- needed when you HOST a room\n"
printf " Fix (Debian/Ubuntu): sudo apt-get install openssh-server && sudo service ssh start\n"
printf " Fix (RHEL/Fedora): sudo dnf install openssh-server && sudo service sshd start\n"
return 1
fi
printf " [info] sshd probe skipped (no supported service manager found)\n"
return 0

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +121
local mgr="$1" prereq="$2"
local pkg
case "$prereq" in
ssh|ssh-keygen)
case "$mgr" in
brew) pkg="openssh" ;;
apt) pkg="openssh-client" ;;
dnf) pkg="openssh-clients" ;;
pacman) pkg="openssh" ;;
apk) pkg="openssh-client" ;;
esac ;;
python3)
case "$mgr" in
pacman) pkg="python" ;;
*) pkg="python3" ;;
esac ;;
*) pkg="$prereq" ;;
esac
case "$mgr" in
brew) echo "brew install $pkg" ;;
apt) echo "sudo apt-get install -y $pkg" ;;
dnf) echo "sudo dnf install -y $pkg" ;;
pacman) echo "sudo pacman -S --needed $pkg" ;;
apk) echo "sudo apk add $pkg" ;;
brew-missing)
echo "Install Homebrew first: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\", then: brew install $pkg" ;;
*) echo "Install '$pkg' via your platform's package manager" ;;

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

_doctor_install_cmd_for can emit an empty package name when mgr is "unknown" (or any unhandled value) and prereq is ssh/ssh-keygen, because pkg is only set inside the mgr-specific case. This leads to hints like Install '' via your platform's package manager, which is incorrect/unhelpful. Initialize pkg to a sensible default (e.g., prereq) before the mgr-specific mapping, and only override it when a mapping exists.

Copilot uses AI. Check for mistakes.
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