返回 DeepSeek-Reasonix
capdiag_app_test.go
根目录 / desktop / capdiag_app_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/control"
9 "reasonix/internal/plugin"
10 )
11
12 func TestCapabilityDiagnosticsStaticUsesWorkspaceRoot(t *testing.T) {
13 isolateDesktopUserDirs(t)
14 root := t.TempDir()
15 if err := os.WriteFile(filepath.Join(root, "AGENTS.md"), []byte("# workspace agents\n"), 0o644); err != nil {
16 t.Fatal(err)
17 }
18
19 app := NewApp()
20 app.mu.Lock()
21 tab := &WorkspaceTab{
22 ID: "diag",
23 Scope: "project",
24 WorkspaceRoot: root,
25 Ready: true,
26 disabledMCP: map[string]ServerView{},
27 }
28 app.tabs = map[string]*WorkspaceTab{"diag": tab}
29 app.tabOrder = []string{"diag"}
30 app.activeTabID = "diag"
31 app.mu.Unlock()
32
33 report := app.CapabilityDiagnostics(false)
34 if report.Live {
35 t.Fatal("static diagnostics must not set live")
36 }
37 if report.SchemaVersion != 1 {
38 t.Fatalf("schema = %d", report.SchemaVersion)
39 }
40 }
41
42 func TestCapabilityDiagnosticsRuntimeUsesActiveHost(t *testing.T) {
43 isolateDesktopUserDirs(t)
44 app := NewApp()
45 host := plugin.NewHost()
46 ctrl := control.New(control.Options{Host: host})
47 app.setTestCtrl(ctrl, "test-model")
48
49 report := app.CapabilityDiagnostics(true)
50 if report.SchemaVersion != 1 {
51 t.Fatalf("schema = %d", report.SchemaVersion)
52 }
53 _ = app.CapabilityDiagnostics(true)
54 if ctrl.Host() != host {
55 t.Fatal("diagnostics must reuse the same Host pointer")
56 }
57 }
58
59 func TestCapabilityDiagnosticsAtomicSnapshot(t *testing.T) {
60 isolateDesktopUserDirs(t)
61 app := NewApp()
62 host := plugin.NewHost()
63 ctrl := control.New(control.Options{Host: host})
64 root := t.TempDir()
65 app.mu.Lock()
66 app.tabs = map[string]*WorkspaceTab{
67 "t1": {
68 ID: "t1", Scope: "project", WorkspaceRoot: root, Ready: true,
69 Ctrl: ctrl, disabledMCP: map[string]ServerView{},
70 },
71 }
72 app.tabOrder = []string{"t1"}
73 app.activeTabID = "t1"
74 app.mu.Unlock()
75
76 gotRoot, gotHost := app.activeDiagSnapshot(true)
77 if gotRoot != root {
78 t.Fatalf("root = %q, want %q", gotRoot, root)
79 }
80 if gotHost != host {
81 t.Fatal("host mismatch from atomic snapshot")
82 }
83 }
84
85 func TestCapabilityDiagnosticsRuntimeUnavailableWithoutTab(t *testing.T) {
86 isolateDesktopUserDirs(t)
87 app := NewApp()
88 // Explicitly empty tabs.
89 app.mu.Lock()
90 app.tabs = map[string]*WorkspaceTab{}
91 app.tabOrder = nil
92 app.activeTabID = ""
93 app.mu.Unlock()
94
95 report := app.CapabilityDiagnostics(true)
96 found := false
97 for _, is := range report.Issues {
98 if is.Code == "mcp.runtime_unavailable" {
99 found = true
100 break
101 }
102 }
103 if !found {
104 t.Fatalf("expected mcp.runtime_unavailable, issues=%+v", report.Issues)
105 }
106 }
107
107 lines GO