Files
arcrun-collector/extract_test.go
T
Leo 6c9d74d588 fix(t91+t92): 萃取狀態可見+Finder 啟動 PATH 修正——背景執行不可見的兩題同根一起解
leo 07-28 實測根因:Finder 起的 GUI app 只有最小 PATH(無 /opt/homebrew/bin)
→ claude 靜默找不到→整輪萃取失敗,托盤卻顯示「看守中」。leo:「我怎麼知道它有萃?」
- FindClaudeBin:LookPath 失敗後掃 4 個常見絕對路徑,找到回寫 config claude_bin
- CheckExtractor 預檢+每輪寫 ~/.arcrun-rag/status.json(ok/fail 計數+失敗清單)
- 托盤:引擎未就緒→「⚠ 萃取引擎未就緒:<白話原因>」;失敗>0→可點開明細;正常→「已萃 N 檔」
測試:collector+supervisor+tray 三模組 go test 全綠(總管親跑)。
(實作=子 CC;驗證+commit=總管)
2026-07-28 12:41:41 +08:00

67 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// extract_test.go — task 3 claude 萃取路(用 stub 執行檔驗呼叫契約,不需真 claude)。
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"testing"
)
// writeStubClaude 產生一支假 claude:驗證收到的參數與 cwd,並寫一張卡進 cards/。
func writeStubClaude(t *testing.T, dir string, script string) string {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("stub 腳本測試僅跑 unix")
}
p := filepath.Join(dir, "claude")
if err := os.WriteFile(p, []byte("#!/bin/sh\n"+script), 0o755); err != nil {
t.Fatal(err)
}
return p
}
// 正常路:stub 收到 -p "/rag-extract-file <檔>"、cwd=監看根,寫卡後被 diff 偵測到。
func TestExtractWithClaudeHappyPath(t *testing.T) {
root := t.TempDir()
if err := os.MkdirAll(filepath.Join(root, "system-dev", "wiki", "cards"), 0o755); err != nil {
t.Fatal(err)
}
stub := writeStubClaude(t, t.TempDir(), fmt.Sprintf(`
[ "$1" = "-p" ] || { echo "第一參數應為 -pgot $1" >&2; exit 9; }
case "$2" in "/rag-extract-file 我的筆記.md") ;; *) echo "prompt 錯:$2" >&2; exit 9;; esac
[ "$(pwd)" = "%s" ] || { echo "cwd 錯:$(pwd)" >&2; exit 9; }
mkdir -p system-dev/wiki/cards
printf '# 我的筆記\n\n## 摘要\nstub 卡\n' > "system-dev/wiki/cards/我的筆記.md"
`, root))
cards, err := ExtractWithClaude(stub, root, "我的筆記.md")
if err != nil {
t.Fatal(err)
}
if len(cards) != 1 || cards[0] != "system-dev/wiki/cards/我的筆記.md" {
t.Fatalf("cards=%v", cards)
}
}
// claude 跑完但沒寫卡=誠實報錯(不假綠)。
func TestExtractWithClaudeNoCard(t *testing.T) {
root := t.TempDir()
stub := writeStubClaude(t, t.TempDir(), "exit 0\n")
if _, err := ExtractWithClaude(stub, root, "x.md"); err == nil {
t.Fatal("沒寫卡應報錯")
}
}
// 找不到執行檔=引導改用 gemma 路的錯誤訊息。
// t92:覆蓋 fallback 清單為空,確保即使本機有 claude 安裝,測試仍能驗到「找不到」路徑。
func TestExtractWithClaudeMissingBin(t *testing.T) {
orig := claudeFallbackPaths
claudeFallbackPaths = nil // 停用 fallback,讓找不到 /no/such/claude-bin 就直接報錯
defer func() { claudeFallbackPaths = orig }()
if _, err := ExtractWithClaude("/no/such/claude-bin", t.TempDir(), "x.md"); err == nil {
t.Fatal("缺執行檔應報錯")
}
}