-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
823 lines (689 loc) · 20.4 KB
/
integration_test.go
File metadata and controls
823 lines (689 loc) · 20.4 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
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
package main
import (
"bytes"
"encoding/json"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
// Integration tests for the claude_peepee CLI
func TestCLIVersion(t *testing.T) {
cmd := exec.Command("./claude_peepee", "version")
output, err := cmd.Output()
if err != nil {
t.Fatalf("version command failed: %v", err)
}
if !strings.Contains(string(output), "claude_peepee version") {
t.Error("version output should contain 'claude_peepee version'")
}
if !strings.Contains(string(output), "0.1.0") {
t.Error("version output should contain version number")
}
}
func TestCLIHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("help command failed: %v", err)
}
expectedCommands := []string{
"remember",
"recall",
"instances",
"messages",
"send",
"serve",
"setup",
"status",
"version",
}
for _, expected := range expectedCommands {
if !strings.Contains(string(output), expected) {
t.Errorf("help output should contain '%s'", expected)
}
}
}
func TestCLIRememberHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "remember", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("remember --help failed: %v", err)
}
if !strings.Contains(string(output), "-t, --tags") {
t.Error("remember help should mention tags flag")
}
}
func TestCLIRecallHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "recall", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("recall --help failed: %v", err)
}
expectedFlags := []string{"-t, --tags", "-n, --limit", "-l, --local"}
for _, flag := range expectedFlags {
if !strings.Contains(string(output), flag) {
t.Errorf("recall help should mention %s flag", flag)
}
}
}
func TestCLISetupHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "setup", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("setup --help failed: %v", err)
}
expectedFlags := []string{"--global", "--project", "--opencode", "--codex", "--gemini", "--allow-all"}
for _, flag := range expectedFlags {
if !strings.Contains(string(output), flag) {
t.Errorf("setup help should mention %s flag", flag)
}
}
}
func TestCLIRememberAndRecall(t *testing.T) {
// Use a temporary data directory
tmpDir, err := os.MkdirTemp("", "claude_peepee_integration_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Remember a fact
rememberCmd := exec.Command("./claude_peepee", "remember", "Integration test fact", "-t", "test", "-t", "integration")
rememberCmd.Env = env
rememberOutput, err := rememberCmd.CombinedOutput()
if err != nil {
t.Fatalf("remember failed: %v, output: %s", err, rememberOutput)
}
if !strings.Contains(string(rememberOutput), "Stored fact") {
t.Error("remember should output 'Stored fact'")
}
// Recall the fact
recallCmd := exec.Command("./claude_peepee", "recall", "Integration")
recallCmd.Env = env
recallOutput, err := recallCmd.CombinedOutput()
if err != nil {
t.Fatalf("recall failed: %v, output: %s", err, recallOutput)
}
if !strings.Contains(string(recallOutput), "Integration test fact") {
t.Error("recall should return the stored fact")
}
if !strings.Contains(string(recallOutput), "test, integration") {
t.Error("recall should show the tags")
}
}
func TestCLIStatus(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_status_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Add a fact first
rememberCmd := exec.Command("./claude_peepee", "remember", "Status test fact")
rememberCmd.Env = env
rememberCmd.Run()
// Check status
cmd := exec.Command("./claude_peepee", "status")
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("status failed: %v, output: %s", err, output)
}
expectedStrings := []string{
"Claude PeePee Status",
"Data directory:",
"Working directory:",
"Facts:",
"Total:",
"Running instances:",
}
for _, s := range expectedStrings {
if !strings.Contains(string(output), s) {
t.Errorf("status output should contain '%s'", s)
}
}
}
func TestCLIInstances(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_instances_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Create the data directory
os.MkdirAll(filepath.Join(tmpDir, ".claude_peepee"), 0755)
cmd := exec.Command("./claude_peepee", "instances")
cmd.Env = append(os.Environ(), "HOME="+tmpDir)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("instances failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "No running instances found") {
t.Error("instances should report no running instances")
}
}
func TestMCPServerProtocol(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_mcp_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Test initialize
initRequest := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}`
cmd := exec.Command("./claude_peepee", "serve")
cmd.Env = env
cmd.Stdin = strings.NewReader(initRequest + "\n")
var stdout bytes.Buffer
cmd.Stdout = &stdout
err = cmd.Start()
if err != nil {
t.Fatalf("failed to start serve: %v", err)
}
// Give it a moment to process
cmd.Process.Kill()
output := stdout.String()
if output == "" {
t.Skip("MCP server didn't produce output (might need more time)")
}
var response map[string]interface{}
if err := json.Unmarshal([]byte(strings.Split(output, "\n")[0]), &response); err != nil {
t.Fatalf("failed to parse response: %v, output: %s", err, output)
}
result, ok := response["result"].(map[string]interface{})
if !ok {
t.Fatal("response should have result field")
}
if result["protocolVersion"] != "2024-11-05" {
t.Errorf("protocolVersion = %v, want 2024-11-05", result["protocolVersion"])
}
}
func TestCLIRecallFilters(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_filter_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Add multiple facts with different tags
cmd1 := exec.Command("./claude_peepee", "remember", "Database PostgreSQL", "-t", "database")
cmd1.Env = env
cmd1.Run()
cmd2 := exec.Command("./claude_peepee", "remember", "API REST endpoints", "-t", "api")
cmd2.Env = env
cmd2.Run()
cmd3 := exec.Command("./claude_peepee", "remember", "Frontend React", "-t", "frontend")
cmd3.Env = env
cmd3.Run()
// Test tag filter
cmd := exec.Command("./claude_peepee", "recall", "-t", "database")
cmd.Env = env
output, _ := cmd.CombinedOutput()
if !strings.Contains(string(output), "PostgreSQL") {
t.Error("tag filter should return database fact")
}
if strings.Contains(string(output), "React") {
t.Error("tag filter should not return frontend fact")
}
// Test limit
cmd = exec.Command("./claude_peepee", "recall", "-n", "1")
cmd.Env = env
output, _ = cmd.CombinedOutput()
lines := strings.Split(strings.TrimSpace(string(output)), "\n\n")
if len(lines) > 1 {
t.Error("limit should restrict results")
}
}
func TestDataPersistence(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_persist_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Store a fact
rememberCmd := exec.Command("./claude_peepee", "remember", "Persistent data test")
rememberCmd.Env = env
rememberCmd.Run()
// Verify database file exists
dbPath := filepath.Join(tmpDir, ".claude_peepee", "claude_peepee.db")
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
t.Error("database file should be created")
}
// Recall should still work (data persisted)
cmd := exec.Command("./claude_peepee", "recall", "Persistent")
cmd.Env = env
output, _ := cmd.CombinedOutput()
if !strings.Contains(string(output), "Persistent data test") {
t.Error("data should persist across commands")
}
}
func TestErrorHandling(t *testing.T) {
tests := []struct {
name string
args []string
wantErr bool
}{
{
name: "remember without fact",
args: []string{"remember"},
wantErr: true,
},
{
name: "send without enough args",
args: []string{"send", "only-one-arg"},
wantErr: true,
},
{
name: "messages without instance id",
args: []string{"messages"},
wantErr: true,
},
{
name: "invalid command",
args: []string{"nonexistent"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := exec.Command("./claude_peepee", tt.args...)
err := cmd.Run()
if (err != nil) != tt.wantErr {
t.Errorf("Command error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
// ==================== ADDITIONAL INTEGRATION TESTS ====================
func TestCLIUIHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "ui", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("ui --help failed: %v", err)
}
if !strings.Contains(string(output), "-p, --port") {
t.Error("ui help should mention port flag")
}
if !strings.Contains(string(output), "8420") {
t.Error("ui help should mention default port 8420")
}
}
func TestCLIServeHelp(t *testing.T) {
cmd := exec.Command("./claude_peepee", "serve", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("serve --help failed: %v", err)
}
if !strings.Contains(string(output), "MCP server") {
t.Error("serve help should mention MCP server")
}
}
func TestCLISpecialCharacters(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_special_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
specialFacts := []struct {
name string
fact string
}{
{"unicode", "日本語テスト with English"},
{"quotes", `Testing "quotes" in facts`},
{"special", "Special chars: @#$%^&*()"},
}
for _, tc := range specialFacts {
t.Run(tc.name, func(t *testing.T) {
// Remember the fact
rememberCmd := exec.Command("./claude_peepee", "remember", tc.fact)
rememberCmd.Env = env
output, err := rememberCmd.CombinedOutput()
if err != nil {
t.Fatalf("remember failed: %v, output: %s", err, output)
}
// Recall and verify
recallCmd := exec.Command("./claude_peepee", "recall")
recallCmd.Env = env
recallOutput, err := recallCmd.CombinedOutput()
if err != nil {
t.Fatalf("recall failed: %v, output: %s", err, recallOutput)
}
if !strings.Contains(string(recallOutput), tc.fact) {
t.Errorf("Recall should contain %q, got: %s", tc.fact, recallOutput)
}
})
}
}
func TestCLIMultipleTags(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_tags_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Remember with multiple tags
cmd := exec.Command("./claude_peepee", "remember", "Multi-tag fact", "-t", "tag1", "-t", "tag2", "-t", "tag3")
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("remember failed: %v, output: %s", err, output)
}
// Recall with one of the tags
recallCmd := exec.Command("./claude_peepee", "recall", "-t", "tag2")
recallCmd.Env = env
recallOutput, err := recallCmd.CombinedOutput()
if err != nil {
t.Fatalf("recall failed: %v, output: %s", err, recallOutput)
}
if !strings.Contains(string(recallOutput), "Multi-tag fact") {
t.Error("Should find fact by one of its tags")
}
}
func TestCLIRecallEmpty(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_empty_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
// Create the data directory
os.MkdirAll(filepath.Join(tmpDir, ".claude_peepee"), 0755)
env := append(os.Environ(), "HOME="+tmpDir)
// Recall with no facts stored (database will be created)
cmd := exec.Command("./claude_peepee", "recall")
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("recall failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "No matching facts") {
t.Error("Should report no matching facts")
}
}
func TestCLILocalOnlyFilter(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_local_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Remember a fact
cmd := exec.Command("./claude_peepee", "remember", "Local test fact")
cmd.Env = env
cmd.Run()
// Recall with -l flag
recallCmd := exec.Command("./claude_peepee", "recall", "-l")
recallCmd.Env = env
output, err := recallCmd.CombinedOutput()
if err != nil {
t.Fatalf("recall -l failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "Local test fact") {
t.Error("Local recall should return local facts")
}
}
func TestCLIStatusWithFacts(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_status_facts")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Add multiple facts
for i := 0; i < 5; i++ {
cmd := exec.Command("./claude_peepee", "remember", "Fact "+string(rune('A'+i)))
cmd.Env = env
cmd.Run()
}
// Check status
statusCmd := exec.Command("./claude_peepee", "status")
statusCmd.Env = env
output, err := statusCmd.CombinedOutput()
if err != nil {
t.Fatalf("status failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "Total: 5") {
t.Errorf("Status should show 5 total facts, got: %s", output)
}
}
func TestCLIVersionFormat(t *testing.T) {
cmd := exec.Command("./claude_peepee", "version")
output, err := cmd.Output()
if err != nil {
t.Fatalf("version failed: %v", err)
}
requiredInfo := []string{
"claude_peepee version",
"0.1.0",
"Go version:",
"OS/Arch:",
}
for _, info := range requiredInfo {
if !strings.Contains(string(output), info) {
t.Errorf("version output should contain %q", info)
}
}
}
func TestCLIRecallWithQuery(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_query_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Add facts
facts := []string{
"PostgreSQL database setup",
"MySQL database configuration",
"Redis caching layer",
}
for _, fact := range facts {
cmd := exec.Command("./claude_peepee", "remember", fact)
cmd.Env = env
cmd.Run()
}
// Search for "database"
recallCmd := exec.Command("./claude_peepee", "recall", "database")
recallCmd.Env = env
output, err := recallCmd.CombinedOutput()
if err != nil {
t.Fatalf("recall failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "PostgreSQL") {
t.Error("Should find PostgreSQL fact")
}
if !strings.Contains(string(output), "MySQL") {
t.Error("Should find MySQL fact")
}
if strings.Contains(string(output), "Redis") {
t.Error("Should NOT find Redis fact when searching for 'database'")
}
}
func TestCLICompletionCommands(t *testing.T) {
shells := []string{"bash", "zsh", "fish", "powershell"}
for _, shell := range shells {
t.Run(shell, func(t *testing.T) {
cmd := exec.Command("./claude_peepee", "completion", shell)
output, err := cmd.Output()
if err != nil {
t.Fatalf("completion %s failed: %v", shell, err)
}
if len(output) == 0 {
t.Errorf("completion %s should produce output", shell)
}
})
}
}
func TestCLISetupFlags(t *testing.T) {
cmd := exec.Command("./claude_peepee", "setup", "--help")
output, err := cmd.Output()
if err != nil {
t.Fatalf("setup --help failed: %v", err)
}
expectedFlags := []string{
"--global",
"--project",
"--opencode",
"--codex",
"--gemini",
"--allow-all",
}
for _, flag := range expectedFlags {
if !strings.Contains(string(output), flag) {
t.Errorf("setup help should contain %s", flag)
}
}
}
func TestCLIHelpAllCommands(t *testing.T) {
commands := []string{
"remember",
"recall",
"status",
"instances",
"send",
"messages",
"serve",
"setup",
"ui",
"version",
}
for _, command := range commands {
t.Run(command, func(t *testing.T) {
cmd := exec.Command("./claude_peepee", command, "--help")
_, err := cmd.Output()
if err != nil {
t.Errorf("%s --help failed: %v", command, err)
}
})
}
}
func TestWebUIAPIStatus(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_webui_test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Start the web UI
cmd := exec.Command("./claude_peepee", "ui", "-p", "18421")
cmd.Env = env
err = cmd.Start()
if err != nil {
t.Fatalf("failed to start ui: %v", err)
}
defer cmd.Process.Kill()
// Wait for server to start
var lastErr error
for i := 0; i < 10; i++ {
time.Sleep(100 * time.Millisecond)
resp, err := http.Get("http://localhost:18421/api/status")
if err == nil {
defer resp.Body.Close()
if resp.StatusCode == 200 {
var status map[string]interface{}
json.NewDecoder(resp.Body).Decode(&status)
if _, ok := status["version"]; !ok {
t.Error("Status response should contain version")
}
if _, ok := status["total_facts"]; !ok {
t.Error("Status response should contain total_facts")
}
return
}
}
lastErr = err
}
t.Skipf("Web UI server might not be ready: %v", lastErr)
}
func TestWebUIAPIFacts(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_webui_facts")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Add a fact first
rememberCmd := exec.Command("./claude_peepee", "remember", "Web UI test fact", "-t", "webui")
rememberCmd.Env = env
rememberCmd.Run()
// Start the web UI
cmd := exec.Command("./claude_peepee", "ui", "-p", "18422")
cmd.Env = env
err = cmd.Start()
if err != nil {
t.Fatalf("failed to start ui: %v", err)
}
defer cmd.Process.Kill()
// Wait and test
var lastErr error
for i := 0; i < 10; i++ {
time.Sleep(100 * time.Millisecond)
resp, err := http.Get("http://localhost:18422/api/facts")
if err == nil {
defer resp.Body.Close()
if resp.StatusCode == 200 {
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
count, ok := result["count"].(float64)
if !ok || count < 1 {
t.Error("Should have at least 1 fact")
}
return
}
}
lastErr = err
}
t.Skipf("Web UI server might not be ready: %v", lastErr)
}
func TestConcurrentRememberOperations(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_concurrent")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Run multiple remember commands sequentially but quickly
// SQLite with WAL mode handles concurrent writes well, but
// running 10 simultaneous processes can still cause some contention
successCount := 0
for i := 0; i < 10; i++ {
cmd := exec.Command("./claude_peepee", "remember", "Sequential fact "+string(rune('A'+i)))
cmd.Env = env
if err := cmd.Run(); err == nil {
successCount++
}
}
if successCount != 10 {
t.Errorf("Expected all 10 operations to succeed, got %d", successCount)
}
// Verify all facts were stored
statusCmd := exec.Command("./claude_peepee", "status")
statusCmd.Env = env
output, _ := statusCmd.CombinedOutput()
if !strings.Contains(string(output), "Total: 10") {
t.Errorf("Expected 10 facts, got: %s", output)
}
}
func TestCLILongFact(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "claude_peepee_long_fact")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
env := append(os.Environ(), "HOME="+tmpDir)
// Create a fact with 10000 characters
longFact := strings.Repeat("This is a long fact. ", 500)
cmd := exec.Command("./claude_peepee", "remember", longFact)
cmd.Env = env
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("remember long fact failed: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "Stored fact") {
t.Error("Should successfully store long fact")
}
}