#!/usr/bin/env bash # 迴歸測試:scripts/isep-doctor(inkstone/ISEP#150) set -u HERE="$(cd "$(dirname "$0")" && pwd)" T=$(mktemp -d); trap 'rm -rf "$T"' EXIT pass=0; fail=0 check() { # name expected_exit grep_pattern local out code; out=$(ISEP_DOCTOR_CLAUDE_HOME="$T/home" ISEP_DOCTOR_PLUGIN_LIST_JSON="$T/list.json" python3 "$HERE/isep-doctor" 2>&1); code=$? if [ "$code" = "$2" ] && printf '%s' "$out" | grep -q -- "$3"; then pass=$((pass+1)); echo "ok $1" else fail=$((fail+1)); echo "FAIL $1 (exit=$code)"; printf '%s\n' "$out" | sed 's/^/ /'; fi } mkdir -p "$T/home/plugins" echo '{"inkstone":{"source":{"source":"git","url":"https://git.uncle6.me/inkstone/ISEP.git"}}}' > "$T/home/plugins/known_marketplaces.json" # 1. 09-13 實況:settings 多了 path、plugin list 報 Marketplace not found → 1,點名 path echo '{"extraKnownMarketplaces":{"inkstone":{"source":{"source":"git","url":"https://git.uncle6.me/inkstone/ISEP.git","path":"/Users/x/ISEP"}}}}' > "$T/home/settings.json" echo '[{"id":"isep@inkstone","version":"0.30.1","enabled":true,"errors":["Marketplace inkstone not found"]}]' > "$T/list.json" check "path 造成載入失敗" 1 "多了 path" # 2. 修好後:沒有 path、沒有 errors → 0 echo '{"extraKnownMarketplaces":{"inkstone":{"source":{"source":"git","url":"https://git.uncle6.me/inkstone/ISEP.git"}}}}' > "$T/home/settings.json" echo '[{"id":"isep@inkstone","version":"0.30.1","enabled":true}]' > "$T/list.json" check "正常載入" 0 "已載入" # 3. 別的原因失敗(沒有多餘欄位)→ 1,照實轉述 Claude Code 的錯 echo '[{"id":"isep@inkstone","version":"0.30.1","enabled":true,"errors":["Plugin directory missing"]}]' > "$T/list.json" check "其他錯誤照實轉述" 1 "Plugin directory missing" # 4. 根本沒裝 → 1 echo '[]' > "$T/list.json" check "沒安裝" 1 "沒有安裝" # 5. 修法那一行真的修得好(在假 HOME 上執行印出來的指令) echo '{"extraKnownMarketplaces":{"inkstone":{"source":{"source":"git","url":"https://git.uncle6.me/inkstone/ISEP.git","path":"/Users/x/ISEP"}}},"model":"keep"}' > "$T/home/settings.json" echo '[{"id":"isep@inkstone","version":"0.30.1","enabled":true,"errors":["Marketplace inkstone not found"]}]' > "$T/list.json" fixline=$(ISEP_DOCTOR_CLAUDE_HOME="$T/home" ISEP_DOCTOR_PLUGIN_LIST_JSON="$T/list.json" python3 "$HERE/isep-doctor" | grep '^ python3 ' | sed 's/^ //') mkdir -p "$T/fake/.claude" && cp "$T/home/settings.json" "$T/fake/.claude/settings.json" HOME="$T/fake" bash -c "$fixline" # 原封不動執行印給 leo 的那一行 if python3 -c "import json,sys;d=json.load(open('$T/fake/.claude/settings.json'));s=d['extraKnownMarketplaces']['inkstone']['source'];sys.exit(0 if 'path' not in s and d['model']=='keep' and s['url'].endswith('ISEP.git') else 1)"; then pass=$((pass+1)); echo "ok 修法一行拿掉 path、其他設定不動" else fail=$((fail+1)); echo "FAIL 修法一行"; cat "$T/home/settings.json"; fi echo "pass=$pass fail=$fail"; [ "$fail" = 0 ]