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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
// Integration tests for hexaimcp orchestrator.
package hexaimcp
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
"testing"
"codeberg.org/snonux/hexai/internal/appconfig"
"codeberg.org/snonux/hexai/internal/mcp"
"codeberg.org/snonux/hexai/internal/promptstore"
)
// mockServerRunner implements ServerRunner for testing
type mockServerRunner struct {
runFunc func() error
}
func (m *mockServerRunner) Run() error {
if m.runFunc != nil {
return m.runFunc()
}
return nil
}
// TestFullProtocolFlow tests the complete MCP protocol interaction
func TestFullProtocolFlow(t *testing.T) {
tmpDir := t.TempDir()
// Create test server factory
serverFactory := func(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer mcp.SlashCommandSyncer) ServerRunner {
return mcp.NewServer(r, w, logger, store, syncer)
}
// Setup I/O pipes
inBuf := &bytes.Buffer{}
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
// Send initialize request
initReq := map[string]any{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": map[string]any{
"protocolVersion": "2024-11-05",
"capabilities": map[string]any{},
"clientInfo": map[string]any{
"name": "test-client",
"version": "1.0",
},
},
}
writeJSONRPC(t, inBuf, initReq)
// Run server in background (it will read from inBuf and write to outBuf)
go func() {
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: tmpDir}
// Note: This will hang waiting for more input, which is expected
_ = RunWithFactory("", "", overrides, inBuf, outBuf, errBuf, serverFactory)
}()
// Give server time to process
// Note: In a real test, you'd use proper synchronization
// For now, just verify the server starts and creates the prompts directory
// A full integration test would require more sophisticated I/O handling
}
func writeJSONRPC(t *testing.T, w io.Writer, req map[string]any) {
t.Helper()
data, err := json.Marshal(req)
if err != nil {
t.Fatalf("marshal request: %v", err)
}
header := fmt.Sprintf("Content-Length: %d\r\n\r\n", len(data))
if _, err := io.WriteString(w, header); err != nil {
t.Fatalf("write header: %v", err)
}
if _, err := w.Write(data); err != nil {
t.Fatalf("write body: %v", err)
}
}
func TestGetPromptsDir(t *testing.T) {
tests := []struct {
name string
cfgValue string
wantMatch string
}{
{
name: "config value used",
cfgValue: "/config/prompts",
wantMatch: "/config/prompts",
},
{
name: "uses default XDG location",
cfgValue: "",
wantMatch: ".local/hexai/data/prompts",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{MCPPromptsDir: tt.cfgValue},
}
result, err := getPromptsDir(cfg)
if err != nil {
t.Fatalf("getPromptsDir() error = %v", err)
}
if !strings.Contains(result, tt.wantMatch) {
t.Errorf("getPromptsDir() = %v, want to contain %v", result, tt.wantMatch)
}
})
}
}
func TestExpandPath(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
}{
{
name: "expand tilde",
input: "~/prompts",
wantErr: false,
},
{
name: "absolute path",
input: "/absolute/path",
wantErr: false,
},
{
name: "relative path",
input: "relative/path",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := expandPath(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("expandPath() error = %v, wantErr %v", err, tt.wantErr)
}
if err == nil {
if tt.input == "~/prompts" && strings.Contains(result, "~") {
t.Error("expandPath() should expand tilde")
}
if !strings.Contains(result, "/") {
t.Error("expandPath() should return absolute path")
}
}
})
}
}
func TestSetupLogger(t *testing.T) {
t.Run("empty path uses stderr", func(t *testing.T) {
logger, err := setupLogger("")
if err != nil {
t.Fatalf("setupLogger() error = %v", err)
}
if logger == nil {
t.Fatal("setupLogger() returned nil logger")
}
})
t.Run("creates log file", func(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
logger, err := setupLogger(logPath)
if err != nil {
t.Fatalf("setupLogger() error = %v", err)
}
if logger == nil {
t.Fatal("setupLogger() returned nil logger")
}
// Write a test message
logger.Print("test message")
// Verify file exists
if _, err := os.Stat(logPath); os.IsNotExist(err) {
t.Error("Log file was not created")
}
// Close the file
if f, ok := logger.Writer().(*os.File); ok && f != os.Stderr {
f.Close()
}
})
t.Run("creates log directory if needed", func(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "subdir", "test.log")
logger, err := setupLogger(logPath)
if err != nil {
t.Fatalf("setupLogger() error = %v", err)
}
// Verify directory was created
dirPath := filepath.Dir(logPath)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
t.Error("Log directory was not created")
}
// Close the file
if f, ok := logger.Writer().(*os.File); ok && f != os.Stderr {
f.Close()
}
})
}
func TestLoadConfig(t *testing.T) {
logger := log.New(io.Discard, "", 0)
t.Run("loads default config when path empty", func(t *testing.T) {
cfg := loadConfig(logger, "")
// Should return a valid config (may be defaults)
// Just verify it returns without panic
_ = cfg
})
t.Run("loads config with nonexistent path", func(t *testing.T) {
cfg := loadConfig(logger, "/nonexistent/config.yaml")
// Should return default config without error
// Just verify it returns without panic
_ = cfg
})
}
func TestDefaultServerFactory(t *testing.T) {
inBuf := &bytes.Buffer{}
outBuf := &bytes.Buffer{}
logger := log.New(io.Discard, "", 0)
tmpDir := t.TempDir()
store, err := promptstore.NewJSONLStore(tmpDir)
if err != nil {
t.Fatalf("NewJSONLStore() error = %v", err)
}
server := defaultServerFactory(inBuf, outBuf, logger, store, nil)
if server == nil {
t.Fatal("defaultServerFactory() returned nil")
}
}
func TestRun(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
// Create a mock server factory that returns immediately
mockFactory := func(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer mcp.SlashCommandSyncer) ServerRunner {
return &mockServerRunner{
runFunc: func() error {
return nil // Exit immediately
},
}
}
inBuf := &bytes.Buffer{}
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: tmpDir}
err := RunWithFactory(logPath, "", overrides, inBuf, outBuf, errBuf, mockFactory)
if err != nil {
t.Fatalf("RunWithFactory() error = %v", err)
}
// Verify log file was created
if _, err := os.Stat(logPath); os.IsNotExist(err) {
t.Error("Log file was not created")
}
}
func TestRunWithFactory_ServerError(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
// Create a mock server factory that returns an error
mockFactory := func(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer mcp.SlashCommandSyncer) ServerRunner {
return &mockServerRunner{
runFunc: func() error {
return fmt.Errorf("mock server error")
},
}
}
inBuf := &bytes.Buffer{}
outBuf := &bytes.Buffer{}
errBuf := &bytes.Buffer{}
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: tmpDir}
err := RunWithFactory(logPath, "", overrides, inBuf, outBuf, errBuf, mockFactory)
if err == nil {
t.Fatal("RunWithFactory() expected error, got nil")
}
if !strings.Contains(err.Error(), "server error") {
t.Errorf("RunWithFactory() error = %v, want to contain 'server error'", err)
}
}
// TestRunWithFactory_LoggerError verifies that a bad log path propagates as an error.
func TestRunWithFactory_LoggerError(t *testing.T) {
// Use /dev/null/impossible as log path — directory creation will fail
// because /dev/null is a file, not a directory.
badLogPath := "/dev/null/impossible/test.log"
mockFactory := func(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer mcp.SlashCommandSyncer) ServerRunner {
return &mockServerRunner{}
}
err := RunWithFactory(badLogPath, "", MCPOverrides{}, &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}, mockFactory)
if err == nil {
t.Fatal("expected error for invalid log path, got nil")
}
if !strings.Contains(err.Error(), "cannot setup logger") {
t.Errorf("error = %v, want to contain 'cannot setup logger'", err)
}
}
// TestRunWithFactory_StderrLogger verifies RunWithFactory works when logPath
// is empty (logger writes to stderr, defer close branch is a no-op).
func TestRunWithFactory_StderrLogger(t *testing.T) {
tmpDir := t.TempDir()
mockFactory := func(r io.Reader, w io.Writer, logger *log.Logger, store promptstore.PromptStore, syncer mcp.SlashCommandSyncer) ServerRunner {
return &mockServerRunner{}
}
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: tmpDir}
// Empty logPath causes logger to write to stderr (no file to close)
err := RunWithFactory("", "", overrides, &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}, mockFactory)
if err != nil {
t.Fatalf("RunWithFactory() error = %v", err)
}
}
// TestRun_CallsDefaultFactory verifies the Run() entry point invokes
// RunWithFactory with the defaultServerFactory. The real server reads
// from stdin until EOF; with an empty buffer it returns immediately.
func TestRun_CallsDefaultFactory(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: tmpDir}
// Run with empty stdin — the real server hits EOF and exits cleanly.
// This exercises the full Run -> RunWithFactory -> defaultServerFactory path.
err := Run(logPath, "", overrides, &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{})
// The server may return nil or an error depending on how it handles EOF;
// the important thing is that Run() itself does not panic.
_ = err
}
// TestSetupLogger_InvalidPath verifies setupLogger returns an error when
// the log directory cannot be created.
func TestSetupLogger_InvalidPath(t *testing.T) {
// /dev/null is a file, so creating a subdirectory under it fails
_, err := setupLogger("/dev/null/subdir/test.log")
if err == nil {
t.Fatal("expected error for invalid log path, got nil")
}
if !strings.Contains(err.Error(), "cannot create log directory") {
t.Errorf("error = %v, want to contain 'cannot create log directory'", err)
}
}
// TestSetupLogger_WhitespacePath verifies that a whitespace-only path
// falls back to stderr logging.
func TestSetupLogger_WhitespacePath(t *testing.T) {
logger, err := setupLogger(" ")
if err != nil {
t.Fatalf("setupLogger() error = %v", err)
}
if logger == nil {
t.Fatal("setupLogger() returned nil logger")
}
}
// TestGetPromptsDir_XDGDataHome verifies getPromptsDir uses XDG_DATA_HOME
// when set (covers the branch where XDG_DATA_HOME is non-empty).
func TestGetPromptsDir_XDGDataHome(t *testing.T) {
oldXDG := os.Getenv("XDG_DATA_HOME")
defer os.Setenv("XDG_DATA_HOME", oldXDG)
os.Setenv("XDG_DATA_HOME", "/custom/xdg/data")
cfg := appconfig.App{}
result, err := getPromptsDir(cfg)
if err != nil {
t.Fatalf("getPromptsDir() error = %v", err)
}
want := "/custom/xdg/data/prompts"
if result != want {
t.Errorf("getPromptsDir() = %v, want %v", result, want)
}
}
// TestGetPromptsDir_TildeInConfig verifies tilde expansion for config path.
func TestGetPromptsDir_TildeInConfig(t *testing.T) {
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{MCPPromptsDir: "~/my-prompts"},
}
result, err := getPromptsDir(cfg)
if err != nil {
t.Fatalf("getPromptsDir() error = %v", err)
}
// Should not contain tilde and should be absolute
if strings.Contains(result, "~") {
t.Errorf("getPromptsDir() = %v, tilde not expanded", result)
}
if !filepath.IsAbs(result) {
t.Errorf("getPromptsDir() = %v, want absolute path", result)
}
if !strings.HasSuffix(result, "my-prompts") {
t.Errorf("getPromptsDir() = %v, want suffix 'my-prompts'", result)
}
}
// TestCreateSyncer_Disabled verifies createSyncer returns a non-nil syncer
// when sync is disabled.
func TestCreateSyncer_Disabled(t *testing.T) {
logger := log.New(io.Discard, "", 0)
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{MCPSlashCommandSync: false},
}
syncer, err := createSyncer(cfg, logger)
if err != nil {
t.Fatalf("createSyncer() error = %v", err)
}
if syncer == nil {
t.Fatal("createSyncer() returned nil syncer")
}
}
// TestCreateSyncer_Enabled verifies createSyncer when sync is enabled
// with a valid temporary directory.
func TestCreateSyncer_Enabled(t *testing.T) {
tmpDir := t.TempDir()
logger := log.New(io.Discard, "", 0)
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{
MCPSlashCommandSync: true,
MCPSlashCommandDir: tmpDir,
},
}
syncer, err := createSyncer(cfg, logger)
if err != nil {
t.Fatalf("createSyncer() error = %v", err)
}
if syncer == nil {
t.Fatal("createSyncer() returned nil syncer")
}
}
// TestCreateSyncer_Error verifies createSyncer returns an error when sync
// is enabled but the directory config is empty.
func TestCreateSyncer_Error(t *testing.T) {
logger := log.New(io.Discard, "", 0)
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{
MCPSlashCommandSync: true,
MCPSlashCommandDir: "",
},
}
_, err := createSyncer(cfg, logger)
if err == nil {
t.Fatal("createSyncer() expected error for empty dir, got nil")
}
}
// TestRunBackfill_FullHappyPath verifies the happy path of RunBackfill by
// providing a config file with a valid slash command directory and prompts dir.
func TestRunBackfill_FullHappyPath(t *testing.T) {
tmpDir := t.TempDir()
promptsDir := filepath.Join(tmpDir, "prompts")
cmdDir := filepath.Join(tmpDir, "commands")
logPath := filepath.Join(tmpDir, "test.log")
// Create prompts directory so the store can be initialized
if err := os.MkdirAll(promptsDir, 0o755); err != nil {
t.Fatalf("cannot create prompts dir: %v", err)
}
// Write a config file with [mcp] section that sets the slash command dir
cfgContent := fmt.Sprintf("[mcp]\nslashcommand_dir = %q\nslashcommand_sync = true\n", cmdDir)
cfgPath := filepath.Join(tmpDir, "config.toml")
if err := os.WriteFile(cfgPath, []byte(cfgContent), 0o644); err != nil {
t.Fatalf("cannot write config: %v", err)
}
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: promptsDir}
// RunBackfill should succeed: config sets MCPSlashCommandDir, prompts
// dir exists, and SyncAll on an empty store is a no-op.
err := RunBackfill(logPath, cfgPath, overrides)
if err != nil {
t.Fatalf("RunBackfill() error = %v", err)
}
// Verify log file was created
if _, statErr := os.Stat(logPath); os.IsNotExist(statErr) {
t.Error("log file was not created")
}
}
// TestRunBackfill_CreateSyncerError verifies RunBackfill propagates
// syncer creation errors (e.g. when MCPSlashCommandDir is set but
// the syncer cannot be created due to an invalid path).
func TestRunBackfill_CreateSyncerError(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
// Use /dev/null as the slash command dir — creating subdirs under
// /dev/null will fail, which triggers a syncer creation error.
cfgContent := "[mcp]\nslashcommand_dir = \"/dev/null/impossible\"\n"
cfgPath := filepath.Join(tmpDir, "config.toml")
if err := os.WriteFile(cfgPath, []byte(cfgContent), 0o644); err != nil {
t.Fatalf("cannot write config: %v", err)
}
err := RunBackfill(logPath, cfgPath, MCPOverrides{})
if err == nil {
t.Fatal("expected error for invalid slash command dir, got nil")
}
if !strings.Contains(err.Error(), "cannot create syncer") {
t.Errorf("error = %v, want to contain 'cannot create syncer'", err)
}
}
// TestRunBackfill_StderrLogger verifies RunBackfill works when logPath
// is empty (logger writes to stderr).
func TestRunBackfill_StderrLogger(t *testing.T) {
tmpDir := t.TempDir()
promptsDir := filepath.Join(tmpDir, "prompts")
cmdDir := filepath.Join(tmpDir, "commands")
if err := os.MkdirAll(promptsDir, 0o755); err != nil {
t.Fatalf("cannot create prompts dir: %v", err)
}
cfgContent := fmt.Sprintf("[mcp]\nslashcommand_dir = %q\n", cmdDir)
cfgPath := filepath.Join(tmpDir, "config.toml")
if err := os.WriteFile(cfgPath, []byte(cfgContent), 0o644); err != nil {
t.Fatalf("cannot write config: %v", err)
}
// Pass prompts dir via overrides instead of environment variable
overrides := MCPOverrides{PromptsDir: promptsDir}
// Empty logPath — logger writes to stderr, defer close is a no-op
err := RunBackfill("", cfgPath, overrides)
if err != nil {
t.Fatalf("RunBackfill() error = %v", err)
}
}
// TestRunBackfill_LoggerError verifies RunBackfill returns an error when
// the log path is invalid.
func TestRunBackfill_LoggerError(t *testing.T) {
err := RunBackfill("/dev/null/impossible/test.log", "", MCPOverrides{})
if err == nil {
t.Fatal("expected error for invalid log path, got nil")
}
if !strings.Contains(err.Error(), "cannot setup logger") {
t.Errorf("error = %v, want to contain 'cannot setup logger'", err)
}
}
// TestRunBackfill_NoCmdDir verifies RunBackfill returns an error when
// slash command directory is not configured. Uses a nonexistent config
// path and unsets relevant env vars to avoid picking up real config.
func TestRunBackfill_NoCmdDir(t *testing.T) {
tmpDir := t.TempDir()
logPath := filepath.Join(tmpDir, "test.log")
// Write an empty config file so loadConfig doesn't fall back to
// the user's real global config or project config.
emptyCfgPath := filepath.Join(tmpDir, "empty.toml")
if err := os.WriteFile(emptyCfgPath, []byte(""), 0o644); err != nil {
t.Fatalf("cannot write empty config: %v", err)
}
// Unset env var that could set the slash command dir
oldEnv := os.Getenv("HEXAI_MCP_SLASHCOMMAND_DIR")
defer os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", oldEnv)
os.Setenv("HEXAI_MCP_SLASHCOMMAND_DIR", "")
err := RunBackfill(logPath, emptyCfgPath, MCPOverrides{})
if err == nil {
t.Fatal("expected error for empty slash command dir, got nil")
}
if !strings.Contains(err.Error(), "commands directory not configured") {
t.Errorf("error = %v, want to contain 'commands directory not configured'", err)
}
}
// TestApplyOverrides verifies that MCPOverrides are correctly applied to config.
func TestApplyOverrides(t *testing.T) {
t.Run("applies all overrides", func(t *testing.T) {
cfg := appconfig.App{}
overrides := MCPOverrides{
PromptsDir: "/custom/prompts",
SlashCommandSync: true,
SlashCommandDir: "/custom/cmds",
}
applyOverrides(&cfg, overrides)
if cfg.MCPPromptsDir != "/custom/prompts" {
t.Errorf("MCPPromptsDir = %q, want /custom/prompts", cfg.MCPPromptsDir)
}
if !cfg.MCPSlashCommandSync {
t.Error("MCPSlashCommandSync = false, want true")
}
if cfg.MCPSlashCommandDir != "/custom/cmds" {
t.Errorf("MCPSlashCommandDir = %q, want /custom/cmds", cfg.MCPSlashCommandDir)
}
})
t.Run("does not overwrite with zero values", func(t *testing.T) {
cfg := appconfig.App{
FeatureConfig: appconfig.FeatureConfig{
MCPPromptsDir: "/existing/prompts",
MCPSlashCommandSync: true,
MCPSlashCommandDir: "/existing/cmds",
},
}
overrides := MCPOverrides{} // all zero values
applyOverrides(&cfg, overrides)
if cfg.MCPPromptsDir != "/existing/prompts" {
t.Errorf("MCPPromptsDir = %q, want /existing/prompts", cfg.MCPPromptsDir)
}
// SlashCommandSync false doesn't overwrite existing true
if !cfg.MCPSlashCommandSync {
t.Error("MCPSlashCommandSync should remain true")
}
if cfg.MCPSlashCommandDir != "/existing/cmds" {
t.Errorf("MCPSlashCommandDir = %q, want /existing/cmds", cfg.MCPSlashCommandDir)
}
})
}
|