返回 DeepSeek-Reasonix
tools_test.go
根目录 / internal / config / tools_test.go
1 package config
2
3 import (
4 "testing"
5
6 "github.com/BurntSushi/toml"
7 )
8
9 func TestBashTimeoutSecondsDefaultsToSafetyCap(t *testing.T) {
10 cfg := Default()
11 if cfg.Tools.BashTimeoutSeconds != nil {
12 t.Fatalf("default raw bash timeout = %v, want nil", *cfg.Tools.BashTimeoutSeconds)
13 }
14 if got := cfg.BashTimeoutSeconds(); got != 120 {
15 t.Fatalf("BashTimeoutSeconds() = %d, want 120", got)
16 }
17 }
18
19 func TestBashTimeoutSecondsAllowsExplicitZero(t *testing.T) {
20 cfg := Default()
21 cfg.Tools.BashTimeoutSeconds = intPtr(0)
22 if got := cfg.BashTimeoutSeconds(); got != 0 {
23 t.Fatalf("BashTimeoutSeconds() = %d, want 0", got)
24 }
25 }
26
27 func TestBashTimeoutSecondsParsesExplicitZero(t *testing.T) {
28 cfg := Default()
29 if _, err := toml.Decode("[tools]\nbash_timeout_seconds = 0\n", cfg); err != nil {
30 t.Fatalf("decode explicit zero: %v", err)
31 }
32 if cfg.Tools.BashTimeoutSeconds == nil {
33 t.Fatal("explicit zero decoded as nil")
34 }
35 if got := cfg.BashTimeoutSeconds(); got != 0 {
36 t.Fatalf("BashTimeoutSeconds() = %d, want 0", got)
37 }
38 }
39
40 func TestBashTimeoutSecondsFallsBackForNegative(t *testing.T) {
41 cfg := Default()
42 cfg.Tools.BashTimeoutSeconds = intPtr(-1)
43 if got := cfg.BashTimeoutSeconds(); got != 120 {
44 t.Fatalf("BashTimeoutSeconds() = %d, want 120", got)
45 }
46 }
47
48 func TestMCPCallTimeoutSecondsDefaultsToSafetyCap(t *testing.T) {
49 cfg := Default()
50 if cfg.Tools.MCPCallTimeoutSeconds != nil {
51 t.Fatalf("default raw MCP call timeout = %v, want nil", *cfg.Tools.MCPCallTimeoutSeconds)
52 }
53 if got := cfg.MCPCallTimeoutSeconds(); got != 300 {
54 t.Fatalf("MCPCallTimeoutSeconds() = %d, want 300", got)
55 }
56 }
57
58 func TestMCPCallTimeoutSecondsExplicitPositive(t *testing.T) {
59 cfg := Default()
60 if _, err := toml.Decode("[tools]\nmcp_call_timeout_seconds = 600\n", cfg); err != nil {
61 t.Fatalf("decode MCP timeout: %v", err)
62 }
63 if cfg.Tools.MCPCallTimeoutSeconds == nil {
64 t.Fatal("explicit MCP timeout decoded as nil")
65 }
66 if got := cfg.MCPCallTimeoutSeconds(); got != 600 {
67 t.Fatalf("MCPCallTimeoutSeconds() = %d, want 600", got)
68 }
69 }
70
71 func TestMCPCallTimeoutSecondsFallsBackForZeroOrNegative(t *testing.T) {
72 cfg := Default()
73 cfg.Tools.MCPCallTimeoutSeconds = intPtr(0)
74 if got := cfg.MCPCallTimeoutSeconds(); got != 300 {
75 t.Fatalf("zero MCPCallTimeoutSeconds() = %d, want 300", got)
76 }
77 cfg.Tools.MCPCallTimeoutSeconds = intPtr(-1)
78 if got := cfg.MCPCallTimeoutSeconds(); got != 300 {
79 t.Fatalf("negative MCPCallTimeoutSeconds() = %d, want 300", got)
80 }
81 }
82
83 func TestMCPStartupTimeoutSecondsDefaultsToBackgroundSafetyCap(t *testing.T) {
84 cfg := Default()
85 if cfg.Tools.MCPStartupTimeoutSeconds != nil {
86 t.Fatalf("default raw MCP startup timeout = %v, want nil", *cfg.Tools.MCPStartupTimeoutSeconds)
87 }
88 if got := cfg.MCPStartupTimeoutSeconds(); got != 30 {
89 t.Fatalf("MCPStartupTimeoutSeconds() = %d, want 30", got)
90 }
91 }
92
93 func TestMCPStartupTimeoutSecondsExplicitPositive(t *testing.T) {
94 cfg := Default()
95 if _, err := toml.Decode("[tools]\nmcp_startup_timeout_seconds = 45\n", cfg); err != nil {
96 t.Fatalf("decode MCP startup timeout: %v", err)
97 }
98 if got := cfg.MCPStartupTimeoutSeconds(); got != 45 {
99 t.Fatalf("MCPStartupTimeoutSeconds() = %d, want 45", got)
100 }
101 }
102
103 func TestMCPStartupTimeoutSecondsFallsBackForZeroOrNegative(t *testing.T) {
104 cfg := Default()
105 cfg.Tools.MCPStartupTimeoutSeconds = intPtr(0)
106 if got := cfg.MCPStartupTimeoutSeconds(); got != 30 {
107 t.Fatalf("zero MCPStartupTimeoutSeconds() = %d, want 30", got)
108 }
109 cfg.Tools.MCPStartupTimeoutSeconds = intPtr(-1)
110 if got := cfg.MCPStartupTimeoutSeconds(); got != 30 {
111 t.Fatalf("negative MCPStartupTimeoutSeconds() = %d, want 30", got)
112 }
113 }
114
115 func TestBackgroundJobStalledWarningSecondsDefault(t *testing.T) {
116 cfg := Default()
117 if cfg.Tools.BackgroundJobs.StalledWarningSeconds != nil {
118 t.Fatalf("default raw stalled warning = %v, want nil", *cfg.Tools.BackgroundJobs.StalledWarningSeconds)
119 }
120 if got := cfg.BackgroundJobStalledWarningSeconds(); got != 900 {
121 t.Fatalf("BackgroundJobStalledWarningSeconds() = %d, want 900", got)
122 }
123 }
124
125 func TestBackgroundJobStalledWarningSecondsAllowsExplicitZero(t *testing.T) {
126 cfg := Default()
127 cfg.Tools.BackgroundJobs.StalledWarningSeconds = intPtr(0)
128 if got := cfg.BackgroundJobStalledWarningSeconds(); got != 0 {
129 t.Fatalf("BackgroundJobStalledWarningSeconds() = %d, want 0", got)
130 }
131 }
132
133 func TestBackgroundJobStalledWarningSecondsParsesExplicitZero(t *testing.T) {
134 cfg := Default()
135 if _, err := toml.Decode("[tools.background_jobs]\nstalled_warning_seconds = 0\n", cfg); err != nil {
136 t.Fatalf("decode explicit zero: %v", err)
137 }
138 if cfg.Tools.BackgroundJobs.StalledWarningSeconds == nil {
139 t.Fatal("explicit zero decoded as nil")
140 }
141 if got := cfg.BackgroundJobStalledWarningSeconds(); got != 0 {
142 t.Fatalf("BackgroundJobStalledWarningSeconds() = %d, want 0", got)
143 }
144 }
145
146 func TestBackgroundJobStalledWarningSecondsBounds(t *testing.T) {
147 cfg := Default()
148 cfg.Tools.BackgroundJobs.StalledWarningSeconds = intPtr(-1)
149 if got := cfg.BackgroundJobStalledWarningSeconds(); got != 900 {
150 t.Fatalf("negative BackgroundJobStalledWarningSeconds() = %d, want 900", got)
151 }
152 cfg.Tools.BackgroundJobs.StalledWarningSeconds = intPtr(90000)
153 if got := cfg.BackgroundJobStalledWarningSeconds(); got != 86400 {
154 t.Fatalf("oversized BackgroundJobStalledWarningSeconds() = %d, want 86400", got)
155 }
156 }
157
157 lines GO