diff --git a/.gitignore b/.gitignore index fdc7fb3..6f29f9b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ tools/dev/gifs/out/ *.test *.out /internal/ui/testdata/golden-actual/ +/cmd/sshtermy/sshtermy diff --git a/cmd/sshtermy/doctorcmd.go b/cmd/sshtermy/doctorcmd.go new file mode 100644 index 0000000..f7d2ce1 --- /dev/null +++ b/cmd/sshtermy/doctorcmd.go @@ -0,0 +1,45 @@ +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/charmbracelet/x/term" + + "github.com/db9979/sshtermy/internal/doctor" + "github.com/db9979/sshtermy/internal/i18n" +) + +// runDoctor: „sshtermy doctor“ prüft die Umgebung ohne Oberfläche und ohne +// Master-Passwort. 0 = in Ordnung (auch mit Hinweisen), 1 = Probleme. +func runDoctor(dir string) int { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + fmt.Println(i18n.T("sshTermy-Selbstprüfung …")) + rs := doctor.Run(ctx, doctor.Env{Dir: dir, Extra: []doctor.Check{checkTerminal}}) + fmt.Print("\n" + doctor.Format(rs)) + if doctor.Worst(rs) == doctor.Fail { + return 1 + } + return 0 +} + +// checkTerminal: Farben und Größe des Terminals, in dem sshtermy läuft. +func checkTerminal(context.Context) doctor.Result { + name := i18n.T("Terminal") + t, ct := os.Getenv("TERM"), os.Getenv("COLORTERM") + if !term.IsTerminal(os.Stdout.Fd()) { + return doctor.Result{Name: name, Status: doctor.Info, Detail: i18n.T("Ausgabe ist kein Terminal (umgeleitet)")} + } + w, h, _ := term.GetSize(os.Stdout.Fd()) + d := fmt.Sprintf("%dx%d, TERM=%s", w, h, t) + if ct != "" { + d += ", COLORTERM=" + ct + } + if w > 0 && (w < 80 || h < 20) { + return doctor.Result{Name: name, Status: doctor.Warn, Detail: d + i18n.T(" (kleiner als 80×20: manches wird gekürzt)")} + } + return doctor.Result{Name: name, Status: doctor.OK, Detail: d} +} diff --git a/cmd/sshtermy/main.go b/cmd/sshtermy/main.go index 01255ec..e9db921 100644 --- a/cmd/sshtermy/main.go +++ b/cmd/sshtermy/main.go @@ -56,6 +56,9 @@ func main() { os.Exit(runBackup(os.Args[2:])) case "restore", "einspielen": os.Exit(runRestore(os.Args[2:])) + case "doctor", "pruefen", "prüfen": + // Selbstprüfung für Fehlerberichte (internal/doctor) + os.Exit(runDoctor(dir)) case "mcp": // MCP-Server für KI-Clients über stdin/stdout (internal/mcp) if err := mcp.Serve(os.Stdin, os.Stdout, &mcp.Remote{DataDir: dir}); err != nil { diff --git a/cmd/sshtermy/sshtermy b/cmd/sshtermy/sshtermy deleted file mode 100755 index ba36f63..0000000 Binary files a/cmd/sshtermy/sshtermy and /dev/null differ diff --git a/internal/doctor/doctor.go b/internal/doctor/doctor.go new file mode 100644 index 0000000..d96bcc8 --- /dev/null +++ b/internal/doctor/doctor.go @@ -0,0 +1,253 @@ +// Package doctor ist die Selbstprüfung (sshtermy doctor, Palette › Hilfe › +// Fehlersuche › Selbstprüfung): Datenordner und Rechte, Tresor, +// Schlüsselbund, SSH-Agent, Update-Signatur, Internet und Uhrzeit, +// Absturzberichte. Das Ergebnis ist reiner Text ohne Geheimnisse und Hosts, +// damit man es in einen Fehlerbericht kopieren kann. +package doctor + +import ( + "context" + "fmt" + "net/http" + "os" + "path/filepath" + "runtime" + "strings" + "time" + + "github.com/db9979/sshtermy/internal/crash" + "github.com/db9979/sshtermy/internal/i18n" + "github.com/db9979/sshtermy/internal/keychain" + "github.com/db9979/sshtermy/internal/sshx" + "github.com/db9979/sshtermy/internal/update" + "github.com/db9979/sshtermy/internal/vault" + "github.com/db9979/sshtermy/internal/version" +) + +// Status einer Prüfung. +type Status int + +const ( + OK Status = iota + Info // nur zur Kenntnis (z. B. Version) + Warn // geht, aber etwas fehlt + Fail // so funktioniert etwas nicht +) + +// Mark: Zeichen vor der Zeile (nur ASCII/Cascadia-sicher). +func (s Status) Mark() string { + switch s { + case OK: + return "✓" + case Warn: + return "!" + case Fail: + return "✗" + } + return "·" +} + +// Result ist eine Zeile der Selbstprüfung. +type Result struct { + Name string + Status Status + Detail string +} + +// Check ist eine einzelne Prüfung. +type Check func(ctx context.Context) Result + +// Env: Umgebung der Prüfungen. Leere Felder = Standard. +type Env struct { + Dir string // Datenordner + HTTP *http.Client // für Internet/Uhrzeit (Tests setzen einen eigenen) + Probe string // Adresse für Internet/Uhrzeit (Standard: GitHub-API) + Now func() time.Time + Extra []Check // z. B. KI-Endpunkt (Oberfläche) oder Terminal (Kommandozeile) +} + +// Run führt alle Prüfungen aus (Reihenfolge fest, jede mit eigener Frist). +func Run(ctx context.Context, env Env) []Result { + if env.HTTP == nil { + env.HTTP = &http.Client{Timeout: 8 * time.Second} + } + if env.Probe == "" { + env.Probe = "https://api.github.com" + } + if env.Now == nil { + env.Now = time.Now + } + checks := []Check{ + func(context.Context) Result { return checkVersion() }, + func(context.Context) Result { return checkDir(env.Dir) }, + func(context.Context) Result { return checkVault(env.Dir) }, + func(context.Context) Result { return checkKeychain() }, + func(context.Context) Result { return checkAgent() }, + func(context.Context) Result { return checkSigned() }, + func(ctx context.Context) Result { return checkNet(ctx, env) }, + func(context.Context) Result { return checkCrashes(env.Dir) }, + } + checks = append(checks, env.Extra...) + out := make([]Result, 0, len(checks)) + for _, c := range checks { + cctx, cancel := context.WithTimeout(ctx, 15*time.Second) + out = append(out, c(cctx)) + cancel() + } + return out +} + +// Worst: schlechtester Status (für den Rückgabewert der Kommandozeile). +func Worst(rs []Result) Status { + w := OK + for _, r := range rs { + if r.Status != Info && r.Status > w { + w = r.Status + } + } + return w +} + +// Format: Text zum Anzeigen und Kopieren. +func Format(rs []Result) string { + n := 0 + for _, r := range rs { + n = max(n, len([]rune(r.Name))) + } + var b strings.Builder + for _, r := range rs { + pad := strings.Repeat(" ", n-len([]rune(r.Name))) + fmt.Fprintf(&b, "%s %s%s %s\n", r.Status.Mark(), r.Name, pad, r.Detail) + } + switch Worst(rs) { + case OK: + b.WriteString("\n" + i18n.T("Alles in Ordnung.") + "\n") + case Warn: + b.WriteString("\n" + i18n.T("Läuft, aber nicht alles ist eingerichtet (Zeilen mit !).") + "\n") + default: + b.WriteString("\n" + i18n.T("Es gibt Probleme (Zeilen mit ✗). Text kopieren und dem Fehlerbericht beilegen.") + "\n") + } + return b.String() +} + +func checkVersion() Result { + return Result{i18n.T("Version"), Info, fmt.Sprintf("%s · %s/%s · %s", version.Short(), runtime.GOOS, runtime.GOARCH, runtime.Version())} +} + +func checkDir(dir string) Result { + name := i18n.T("Datenordner") + if dir == "" { + return Result{name, Fail, i18n.T("unbekannt (kein Benutzerordner?)")} + } + fi, err := os.Stat(dir) + if os.IsNotExist(err) { + return Result{name, Info, i18n.T("noch nicht angelegt (erster Start)")} + } + if err != nil { + return Result{name, Fail, err.Error()} + } + if !fi.IsDir() { + return Result{name, Fail, i18n.T("ist eine Datei, kein Ordner")} + } + probe := filepath.Join(dir, ".doctor-probe") + if err := os.WriteFile(probe, []byte("ok"), 0o600); err != nil { + return Result{name, Fail, i18n.T("nicht beschreibbar: ") + err.Error()} + } + _ = os.Remove(probe) + if runtime.GOOS != "windows" && fi.Mode().Perm()&0o077 != 0 { + return Result{name, Warn, fmt.Sprintf(i18n.T("für andere lesbar (%o), besser: chmod 700"), fi.Mode().Perm())} + } + return Result{name, OK, i18n.T("beschreibbar")} +} + +func checkVault(dir string) Result { + name := i18n.T("Tresor") + p := filepath.Join(dir, "store.vault") + if _, err := os.Stat(p); os.IsNotExist(err) { + return Result{name, Info, i18n.T("noch nicht angelegt (erster Start)")} + } + v, err := vault.Open(p) + if err != nil { + return Result{name, Fail, err.Error()} + } + d := i18n.T("lesbar, Master-Passwort") + if v.HasDPAPI() { + d += i18n.T(" + Windows-Konto") + } + return Result{name, OK, d} +} + +func checkKeychain() Result { + name := i18n.T("Schlüsselbund") + if keychain.Available() { + return Result{name, OK, i18n.T("verfügbar (Passwörter können dort liegen)")} + } + return Result{name, Warn, i18n.T("nicht verfügbar: Passwörter liegen nur im Tresor")} +} + +func checkAgent() Result { + name := i18n.T("SSH-Agent") + if err := sshx.AgentReachable(); err != nil { + return Result{name, Info, i18n.T("nicht erreichbar (nur nötig für Schlüssel im Agenten): ") + err.Error()} + } + return Result{name, OK, i18n.T("erreichbar")} +} + +func checkSigned() Result { + name := i18n.T("Update-Signatur") + if update.Signed() { + return Result{name, OK, i18n.T("Updates werden vor dem Einspielen geprüft")} + } + return Result{name, Warn, i18n.T("eigener Build ohne Schlüssel: Updates werden nicht geprüft")} +} + +// checkNet: Internet (für Updates) und Uhrzeit (falsche Uhr ⇒ Zertifikate, +// Einmal-Codes und SSH-Zertifikate scheitern scheinbar grundlos). +func checkNet(ctx context.Context, env Env) Result { + name := i18n.T("Internet und Uhr") + req, err := http.NewRequestWithContext(ctx, http.MethodHead, env.Probe, nil) + if err != nil { + return Result{name, Warn, err.Error()} + } + req.Header.Set("User-Agent", version.Short()) + resp, err := env.HTTP.Do(req) + if err != nil { + return Result{name, Warn, i18n.T("GitHub nicht erreichbar, Updates gehen nicht: ") + err.Error()} + } + resp.Body.Close() + srv, err := http.ParseTime(resp.Header.Get("Date")) + if err != nil { + return Result{name, OK, i18n.T("GitHub erreichbar")} + } + diff := env.Now().Sub(srv) + if diff < 0 { + diff = -diff + } + if diff > 2*time.Minute { + return Result{name, Warn, fmt.Sprintf(i18n.T("Uhr geht %s falsch: Anmeldung mit Einmal-Codes oder Zertifikaten kann scheitern"), diff.Round(time.Second))} + } + return Result{name, OK, i18n.T("GitHub erreichbar, Uhr stimmt")} +} + +func checkCrashes(dir string) Result { + name := i18n.T("Absturzberichte") + es, _ := os.ReadDir(crash.Dir(dir)) + n := 0 + for _, e := range es { + if strings.HasPrefix(e.Name(), "sshtermy-crash-") { + n++ + } + } + if n == 0 { + return Result{name, OK, i18n.T("keine")} + } + return Result{name, Info, fmt.Sprintf(i18n.T("%d im Ordner %s"), n, tilde(crash.Dir(dir)))} +} + +// tilde: Home-Ordner als ~ (der Text landet ggf. in einem Fehlerbericht). +func tilde(p string) string { + if h, err := os.UserHomeDir(); err == nil && h != "" && strings.HasPrefix(p, h) { + return "~" + p[len(h):] + } + return p +} diff --git a/internal/doctor/doctor_test.go b/internal/doctor/doctor_test.go new file mode 100644 index 0000000..2bf0b71 --- /dev/null +++ b/internal/doctor/doctor_test.go @@ -0,0 +1,111 @@ +package doctor + +import ( + "context" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "runtime" + "strings" + "testing" + "time" +) + +func server(t *testing.T, date time.Time) string { + t.Helper() + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Date", date.UTC().Format(http.TimeFormat)) + })) + t.Cleanup(ts.Close) + return ts.URL +} + +func find(t *testing.T, rs []Result, prefix string) Result { + t.Helper() + for _, r := range rs { + if strings.HasPrefix(r.Name, prefix) { + return r + } + } + t.Fatalf("keine Zeile %q", prefix) + return Result{} +} + +func TestRunFreshDir(t *testing.T) { + dir := t.TempDir() + now := time.Now() + rs := Run(context.Background(), Env{Dir: dir, Probe: server(t, now), Now: func() time.Time { return now }}) + if r := find(t, rs, "Datenordner"); r.Status != OK && !(runtime.GOOS != "windows" && r.Status == Warn) { + t.Fatalf("Datenordner: %+v", r) + } + if r := find(t, rs, "Tresor"); r.Status != Info { + t.Fatalf("Tresor bei erstem Start: %+v", r) + } + if r := find(t, rs, "Internet"); r.Status != OK { + t.Fatalf("Internet: %+v", r) + } + if r := find(t, rs, "Absturz"); r.Status != OK { + t.Fatalf("Absturzberichte: %+v", r) + } + if _, err := os.Stat(filepath.Join(dir, ".doctor-probe")); !os.IsNotExist(err) { + t.Fatal("Probedatei liegen geblieben") + } + txt := Format(rs) + if !strings.Contains(txt, "Version") || !strings.Contains(txt, "✓") { + t.Fatalf("Format: %s", txt) + } +} + +func TestClockSkew(t *testing.T) { + now := time.Now() + rs := Run(context.Background(), Env{Dir: t.TempDir(), Probe: server(t, now.Add(-10*time.Minute)), Now: func() time.Time { return now }}) + r := find(t, rs, "Internet") + if r.Status != Warn || !strings.Contains(r.Detail, "10m") { + t.Fatalf("falsche Uhr nicht erkannt: %+v", r) + } +} + +func TestOfflineAndBrokenDir(t *testing.T) { + dir := filepath.Join(t.TempDir(), "datei") + _ = os.WriteFile(dir, []byte("x"), 0o600) + if r := checkDir(filepath.Join(t.TempDir(), "fehlt")); r.Status != Info { + t.Fatalf("erster Start: %+v", r) + } + rs := Run(context.Background(), Env{Dir: dir, Probe: "http://127.0.0.1:1"}) + if r := find(t, rs, "Datenordner"); r.Status != Fail { + t.Fatalf("Datei statt Ordner: %+v", r) + } + if r := find(t, rs, "Internet"); r.Status != Warn { + t.Fatalf("offline: %+v", r) + } + if Worst(rs) != Fail { + t.Fatal("Worst") + } + if !strings.Contains(Format(rs), "✗") { + t.Fatal("Fehlerzeile fehlt") + } +} + +func TestCrashesAndExtra(t *testing.T) { + dir := t.TempDir() + _ = os.MkdirAll(filepath.Join(dir, "crash"), 0o700) + _ = os.WriteFile(filepath.Join(dir, "crash", "sshtermy-crash-1.txt"), []byte("x"), 0o600) + extra := func(context.Context) Result { return Result{"KI", Fail, "antwortet nicht"} } + rs := Run(context.Background(), Env{Dir: dir, Probe: server(t, time.Now()), Extra: []Check{extra}}) + if r := find(t, rs, "Absturz"); r.Status != Info || !strings.HasPrefix(r.Detail, "1 ") { + t.Fatalf("Absturzberichte: %+v", r) + } + if rs[len(rs)-1].Name != "KI" { + t.Fatal("Zusatzprüfung fehlt am Ende") + } +} + +func TestVaultGarbage(t *testing.T) { + dir := t.TempDir() + _ = os.WriteFile(filepath.Join(dir, "store.vault"), []byte("{kaputt"), 0o600) + r := checkVault(dir) + if r.Status != Fail { + t.Fatalf("kaputter Tresor: %+v", r) + } +} diff --git a/internal/i18n/en_stability.go b/internal/i18n/en_stability.go index 8e52b70..b2de0db 100644 --- a/internal/i18n/en_stability.go +++ b/internal/i18n/en_stability.go @@ -12,4 +12,38 @@ var enStability = map[string]string{ "Fehler abgefangen, sshTermy lief weiter": "Error caught, sshTermy kept running", "Interner Fehler abgefangen, sshTermy läuft weiter.": "Internal error caught, sshTermy keeps running.", "update: Download kam %s lang nicht voran": "update: download made no progress for %s", + " (kleiner als 80×20: manches wird gekürzt)": " (smaller than 80×20: some things get cut off)", + " + Windows-Konto": " + Windows account", + " antwortet": " answers", + " antwortet nicht: ": " does not answer: ", + "%d im Ordner %s": "%d in folder %s", + "Absturzberichte": "Crash reports", + "Alles in Ordnung.": "Everything is fine.", + "Ausgabe ist kein Terminal (umgeleitet)": "Output is not a terminal (redirected)", + "Es gibt Probleme (Zeilen mit ✗). Text kopieren und dem Fehlerbericht beilegen.": "There are problems (lines with ✗). Copy this text and attach it to your bug report.", + "GitHub erreichbar": "GitHub reachable", + "GitHub erreichbar, Uhr stimmt": "GitHub reachable, clock is correct", + "GitHub nicht erreichbar, Updates gehen nicht: ": "GitHub not reachable, updates won't work: ", + "Internet und Uhr": "Internet and clock", + "Läuft, aber nicht alles ist eingerichtet (Zeilen mit !).": "Works, but not everything is set up (lines with !).", + "Selbstprüfung": "Self-check", + "Selbstprüfung (Ordner, Tresor, KI, Internet, Uhr)": "Self-check (folder, vault, AI, internet, clock)", + "Selbstprüfung läuft …": "Self-check running …", + "Tresor": "Vault", + "Uhr geht %s falsch: Anmeldung mit Einmal-Codes oder Zertifikaten kann scheitern": "Clock is off by %s: sign-in with one-time codes or certificates may fail", + "Update-Signatur": "Update signature", + "Updates werden vor dem Einspielen geprüft": "Updates are verified before installing", + "beschreibbar": "writable", + "eigener Build ohne Schlüssel: Updates werden nicht geprüft": "own build without key: updates are not verified", + "für andere lesbar (%o), besser: chmod 700": "readable by others (%o), better: chmod 700", + "ist eine Datei, kein Ordner": "is a file, not a folder", + "lesbar, Master-Passwort": "readable, master password", + "nicht beschreibbar: ": "not writable: ", + "nicht eingerichtet": "not set up", + "nicht erreichbar (nur nötig für Schlüssel im Agenten): ": "not reachable (only needed for keys in the agent): ", + "nicht verfügbar: Passwörter liegen nur im Tresor": "not available: passwords are kept in the vault only", + "noch nicht angelegt (erster Start)": "not created yet (first start)", + "sshTermy-Selbstprüfung …": "sshTermy self-check …", + "unbekannt (kein Benutzerordner?)": "unknown (no user folder?)", + "verfügbar (Passwörter können dort liegen)": "available (passwords can be stored there)", } diff --git a/internal/sshx/agent_unix.go b/internal/sshx/agent_unix.go index 623f14e..2e4fbff 100644 --- a/internal/sshx/agent_unix.go +++ b/internal/sshx/agent_unix.go @@ -19,3 +19,12 @@ func dialAgent() (net.Conn, error) { } return net.Dial("unix", sock) } + +// AgentReachable: läuft ein SSH-Agent, den sshTermy erreicht (Selbstprüfung)? +func AgentReachable() error { + c, err := dialAgent() + if err != nil { + return err + } + return c.Close() +} diff --git a/internal/sshx/agent_windows.go b/internal/sshx/agent_windows.go index bc15392..82af65c 100644 --- a/internal/sshx/agent_windows.go +++ b/internal/sshx/agent_windows.go @@ -21,3 +21,13 @@ func dialAgent() (net.Conn, error) { t := 3 * time.Second return winio.DialPipe(pipe, &t) } + +// AgentReachable: läuft ein SSH-Agent (Pageant oder OpenSSH-Dienst), den +// sshTermy erreicht (Selbstprüfung)? +func AgentReachable() error { + c, err := dialAgent() + if err != nil { + return err + } + return c.Close() +} diff --git a/internal/ui/app.go b/internal/ui/app.go index bcff75f..94d8279 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -623,6 +623,10 @@ func (a *App) coreMsg(msg tea.Msg) (tea.Cmd, bool) { // featureMsg reicht die Nachricht an die Bereiche weiter (Broadcast, Sync, // KI, Dateien …); jeder nimmt nur seine eigenen. func (a *App) featureMsg(msg tea.Msg) (tea.Cmd, bool) { + if m, ok := msg.(doctorMsg); ok { // Selbstprüfung (doctor.go) + a.doctorDone(m) + return nil, true + } if m, ok := msg.(palFindMsg); ok { // „Wo finde ich …?“ (palask.go) return a.palFindDone(m), true } diff --git a/internal/ui/doctor.go b/internal/ui/doctor.go new file mode 100644 index 0000000..41f4210 --- /dev/null +++ b/internal/ui/doctor.go @@ -0,0 +1,58 @@ +package ui + +import ( + "context" + "strings" + "time" + + tea "charm.land/bubbletea/v2" + + "github.com/db9979/sshtermy/internal/doctor" + "github.com/db9979/sshtermy/internal/domain" + "github.com/db9979/sshtermy/internal/i18n" + "github.com/db9979/sshtermy/internal/llm" +) + +// Selbstprüfung (internal/doctor) aus der Palette: wie „sshtermy doctor“, +// dazu der KI-Endpunkt (dafür muss der Tresor offen sein). Das Ergebnis +// steht in einem Textfenster, c kopiert es für den Fehlerbericht. + +type doctorMsg struct{ text string } + +func (a *App) runDoctor() tea.Cmd { + a.flash(i18n.T("Selbstprüfung läuft …")) + dir := a.st.Dir + chain := a.st.LLM().Chain() + return func() tea.Msg { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + rs := doctor.Run(ctx, doctor.Env{Dir: dir, Extra: []doctor.Check{aiCheck(chain[0])}}) + return doctorMsg{doctor.Format(rs)} + } +} + +// aiCheck: antwortet der eingestellte KI-Endpunkt? (ohne Schlüssel im Text) +func aiCheck(cfg domain.LLMConfig) doctor.Check { + return func(ctx context.Context) doctor.Result { + name := i18n.T("KI") + if cfg.Model == "" && cfg.BaseURL == "" { + return doctor.Result{Name: name, Status: doctor.Info, Detail: i18n.T("nicht eingerichtet")} + } + what := cfg.Model + if what == "" { + what = string(cfg.Provider) + } + cctx, cancel := context.WithTimeout(ctx, testTimeout(cfg)) + defer cancel() + if err := llm.Probe(cctx, cfg); err != nil { + return doctor.Result{Name: name, Status: doctor.Warn, Detail: what + i18n.T(" antwortet nicht: ") + err.Error()} + } + return doctor.Result{Name: name, Status: doctor.OK, Detail: what + i18n.T(" antwortet")} + } +} + +func (a *App) doctorDone(m doctorMsg) { + md := textModal(i18n.T("Selbstprüfung"), strings.Split(strings.TrimRight(m.text, "\n"), "\n")) + md.copy = m.text + a.modal = md +} diff --git a/internal/ui/doctor_test.go b/internal/ui/doctor_test.go new file mode 100644 index 0000000..d3675ec --- /dev/null +++ b/internal/ui/doctor_test.go @@ -0,0 +1,46 @@ +package ui + +import ( + "context" + "strings" + "testing" + + "github.com/db9979/sshtermy/internal/doctor" + "github.com/db9979/sshtermy/internal/domain" +) + +func TestDoctorModal(t *testing.T) { + a := newPaletteTestApp(t) + a.modal = nil + a.Update(doctorMsg{"✓ Datenordner beschreibbar\n\nAlles in Ordnung.\n"}) + if a.modal == nil || a.modal.kind != mText || a.modal.title != "Selbstprüfung" { + t.Fatalf("kein Ergebnisfenster: %+v", a.modal) + } + if !strings.Contains(a.modal.copy, "Alles in Ordnung.") { + t.Fatal("c kopiert nicht das Ergebnis") + } +} + +func TestDoctorAICheck(t *testing.T) { + r := aiCheck(domain.LLMConfig{})(context.Background()) + if r.Status != doctor.Info { + t.Fatalf("ohne KI: %+v", r) + } + r = aiCheck(domain.LLMConfig{Provider: domain.ProviderOllama, BaseURL: "http://127.0.0.1:1", Model: "test", TimeoutSec: 2})(context.Background()) + if r.Status != doctor.Warn || !strings.HasPrefix(r.Detail, "test") { + t.Fatalf("KI nicht erreichbar: %+v", r) + } +} + +func TestDoctorInPalette(t *testing.T) { + a := newPaletteTestApp(t) + found := false + for _, it := range a.palMenuItems() { + if it.menu == "help/debug" && strings.HasPrefix(it.label, "Selbstprüfung") { + found = true + } + } + if !found { + t.Fatal("Selbstprüfung fehlt unter Hilfe › Fehlersuche") + } +} diff --git a/internal/ui/palette.go b/internal/ui/palette.go index 472d69c..4f1380a 100644 --- a/internal/ui/palette.go +++ b/internal/ui/palette.go @@ -1115,6 +1115,8 @@ func (a *App) palMenuItems() []palItem { a.palNewFolder(), // Hilfe & Info › Fehlersuche + palItem{group: pgHelp, menu: "help/debug", icon: ic("llmcheck"), label: i18n.T("Selbstprüfung (Ordner, Tresor, KI, Internet, Uhr)"), hint: "doctor", + keys: "selbstprüfung doctor check prüfen diagnose fehler problem geht nicht", run: func() tea.Cmd { return a.runDoctor() }}, proItem(help("help/debug", palToggle(ic("sesslog"), i18n.T("Debug-Protokoll für Fehlerberichte"), a.debugOn(), "debug log protokoll fehler bug support", func() tea.Cmd { return a.toggleDebug() }))), palItem{group: pgHelp, menu: "help/debug", icon: ic("export"), label: i18n.T("Debug-Protokoll bereinigt speichern (für Fehlerbericht)"), hint: ".txt", keys: "debug log protokoll fehler bug support issue", run: func() tea.Cmd { return a.exportDebug() }},