-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocs_command_test.go
More file actions
98 lines (87 loc) · 2.46 KB
/
Copy pathdocs_command_test.go
File metadata and controls
98 lines (87 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func TestDocsCommandListsHumanAndAgentEntryPoints(t *testing.T) {
var output bytes.Buffer
command := newDocsCommand()
command.SetOut(&output)
if err := command.Execute(); err != nil {
t.Fatalf("docs command failed: %v", err)
}
for _, expected := range []string{
"https://help.doit.com/docs/cli",
"https://help.doit.com/docs/cli.md",
"https://help.doit.com/docs/cli/generated/command-groups/",
"https://developer.doit.com/",
"https://help.doit.com/llms.txt",
"https://help.doit.com/llms-full.txt",
"dci skill",
"dci commands --json",
} {
if !strings.Contains(output.String(), expected) {
t.Errorf("docs output missing %q", expected)
}
}
}
func TestDocsCommandRejectsArguments(t *testing.T) {
command := newDocsCommand()
command.SetArgs([]string{"unexpected"})
if err := command.Execute(); err == nil {
t.Fatal("docs command accepted an argument")
}
}
func TestAgentOnboardingHintShowsOnce(t *testing.T) {
oldAgentMode := agentMode
oldEnvDetected := agentEnvDetected
agentMode = true
agentEnvDetected = "TEST_AGENT"
t.Cleanup(func() {
agentMode = oldAgentMode
agentEnvDetected = oldEnvDetected
})
configDir := t.TempDir()
captureStderr := func(fn func()) string {
old := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w
fn()
if err := w.Close(); err != nil {
t.Fatalf("close stderr writer: %v", err)
}
os.Stderr = old
buf := make([]byte, 4096)
n, _ := r.Read(buf)
return string(buf[:n])
}
first := captureStderr(func() { maybeAgentOnboardingHint(configDir) })
if !strings.Contains(first, "dci skill") || !strings.Contains(first, "llms.txt") {
t.Fatalf("first hint = %q, want skill and llms.txt pointers", first)
}
if _, err := os.Stat(filepath.Join(configDir, "agent_onboarding_shown")); err != nil {
t.Fatalf("marker file not written: %v", err)
}
second := captureStderr(func() { maybeAgentOnboardingHint(configDir) })
if second != "" {
t.Fatalf("second run printed %q, want silence", second)
}
}
func TestAgentOnboardingHintSkippedInHumanMode(t *testing.T) {
oldAgentMode := agentMode
oldEnvDetected := agentEnvDetected
agentMode = false
agentEnvDetected = ""
t.Cleanup(func() {
agentMode = oldAgentMode
agentEnvDetected = oldEnvDetected
})
configDir := t.TempDir()
maybeAgentOnboardingHint(configDir)
if _, err := os.Stat(filepath.Join(configDir, "agent_onboarding_shown")); err == nil {
t.Fatal("marker written in human mode")
}
}