KAOS/code/internal/server/test_helpers_test.go
djuka 098ed13705 T22: Reorganizacija testova + logs handler + konzola fix
- Razbijen monolitni server_test.go na fokusirane test fajlove:
  api_test.go, dashboard_test.go, docs_test.go, search_test.go,
  submit_test.go, task_detail_test.go, console_test.go, sse_test.go,
  timestamp_test.go, ui_test.go, test_helpers_test.go
- Dodat logs.go handler (handleLogsTail) koji je nedostajao
- Dodat LogFile u config
- Fix konzola: prompt se šalje preko fajla umesto direktno u PTY
- 192 testova prolazi

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 04:45:50 +00:00

83 lines
1.9 KiB
Go

package server
import (
"os"
"path/filepath"
"testing"
"github.com/dal/kaos/internal/config"
)
const testTask1 = `# T01: Prvi task
**Agent:** coder
**Model:** Sonnet
**Zavisi od:** —
---
## Opis
Opis prvog taska.
---
`
const testTask2 = `# T08: HTTP server
**Agent:** coder
**Model:** Sonnet
**Zavisi od:** T07
---
## Opis
Implementacija HTTP servera.
---
`
func setupTestServer(t *testing.T) *Server {
t.Helper()
dir := t.TempDir()
tasksDir := filepath.Join(dir, "TASKS")
for _, folder := range []string{"backlog", "ready", "active", "review", "done", "reports"} {
os.MkdirAll(filepath.Join(tasksDir, folder), 0755)
}
os.WriteFile(filepath.Join(tasksDir, "done", "T01.md"), []byte(testTask1), 0644)
os.WriteFile(filepath.Join(tasksDir, "backlog", "T08.md"), []byte(testTask2), 0644)
// Docs: create markdown files in project root
os.WriteFile(filepath.Join(dir, "CLAUDE.md"), []byte("# CLAUDE.md\n\nGlavni fajl.\n\n| Kolona | Opis |\n|--------|------|\n| A | B |\n"), 0644)
os.WriteFile(filepath.Join(dir, "README.md"), []byte("# README\n\nOpis projekta.\n"), 0644)
os.MkdirAll(filepath.Join(dir, "agents", "coder"), 0755)
os.WriteFile(filepath.Join(dir, "agents", "coder", "CLAUDE.md"), []byte("# Coder Agent\n\nPravila kodiranja.\n"), 0644)
os.MkdirAll(filepath.Join(dir, "agents", "checker"), 0755)
os.WriteFile(filepath.Join(dir, "agents", "checker", "CLAUDE.md"), []byte("# Checker Agent\n\nBuild + Test verifikacija.\n"), 0644)
os.WriteFile(filepath.Join(tasksDir, "reports", "T01-report.md"), []byte("# T01 Report\n\n10 testova, svi prolaze.\n"), 0644)
cfg := &config.Config{
TasksDir: tasksDir,
ProjectPath: dir,
Port: "0",
}
return New(cfg)
}
func containsStr(s, substr string) bool {
return len(s) >= len(substr) && findStr(s, substr)
}
func findStr(s, substr string) bool {
for i := 0; i <= len(s)-len(substr); i++ {
if s[i:i+len(substr)] == substr {
return true
}
}
return false
}