#!/bin/sh # Tests for bin/doctor. # # Every case here is a real state this fleet was found in on 2026-08-23, and # every one of them was SILENT — nothing errored, git status was clean, the # harness simply ran with the wrong skills or none at all. The point of doctor # is that none of these can be silent again, so each fixture asserts both a # non-zero exit AND that the report names the fault. # # Fixtures drive doctor through $HOME and $DOCTOR_CHECKOUT, so no test touches # the real host. set -u ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) DOCTOR="$ROOT/bin/doctor" pass=0 fail=0 WORK=${TMPDIR:-/tmp}/doctor_test.$$ if [ ! -f "$DOCTOR" ]; then printf 'FAIL: %s does not exist\n' "$DOCTOR" exit 1 fi # The toolchain check (golangci-lint build-Go vs GOROOT) reads the real host # unless we say otherwise, which made every unrelated fixture fail on a machine # whose golangci-lint is genuinely stale. Give the whole suite a matching fake # pair so only the cases that OPT IN exercise that check. STUB_BIN="$WORK/_stub_bin" mkdir -p "$STUB_BIN" printf '#!/bin/sh\nprintf "golangci-lint has version 2.0.0 built with go1.27.0 from abc\\n"\n' > "$STUB_BIN/golangci-lint" printf '#!/bin/sh\ncase "$1" in version) printf "go version go1.27.0 linux/amd64\\n";; *) printf "\\n";; esac\n' > "$STUB_BIN/go" chmod +x "$STUB_BIN/golangci-lint" "$STUB_BIN/go" PATH="$STUB_BIN:$PATH" export PATH cleanup() { rm -rf "$WORK"; } trap cleanup EXIT INT TERM # new_fixture — builds $WORK//{ck,home} with a 2-skill checkout # and an empty fake HOME. Echoes the fixture root. new_fixture() { _f="$WORK/$1" mkdir -p "$_f/ck/skills/alpha" "$_f/ck/skills/beta" "$_f/home" printf -- '---\nname: alpha\ndescription: a\n---\n' > "$_f/ck/skills/alpha/SKILL.md" printf -- '---\nname: beta\ndescription: b\n---\n' > "$_f/ck/skills/beta/SKILL.md" printf '%s' "$_f" } # wire_clean [extra-source-dir] — the correct wiring since #27: the # canonical location is a REAL directory of per-skill links, fed by one or more # sources, with each harness keeping its single directory link to it. wire_clean() { mkdir -p "$1/home/.agents/skills" "$1/home/.config/crush" "$1/home/.config/opencode" for _d in "$1"/ck/skills/*/; do ln -sfn "${_d%/}" "$1/home/.agents/skills/$(basename "$_d")" done printf '%s\n' "$1/ck/skills" > "$1/home/.agents/skills-sources" if [ -n "${2:-}" ]; then for _d in "$2"/*/; do ln -sfn "${_d%/}" "$1/home/.agents/skills/$(basename "$_d")" done printf '%s\n' "$2" >> "$1/home/.agents/skills-sources" fi ln -sfn "$1/home/.agents/skills" "$1/home/.config/crush/skills" ln -sfn "$1/home/.agents/skills" "$1/home/.config/opencode/skills" } # assert_fails