// internal/skills/sessionlog/handlers_test.go package sessionlog_test import ( "context" "encoding/json" "os" "path/filepath" "testing" "github.com/mathiasbq/supervisor/internal/skills/sessionlog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestHandle_SessionLog_AppendsEntry(t *testing.T) { dir := t.TempDir() s := sessionlog.New(sessionlog.Config{SessionsDir: dir}) args, _ := json.Marshal(map[string]any{ "session_id": "sess-abc", "skill": "tdd_green", "final_status": "pass", "model_used": "ollama/qwen3", "duration_ms": 3000, }) out, err := s.Handle(context.Background(), "session_log", args) require.NoError(t, err) var result map[string]string require.NoError(t, json.Unmarshal(out, &result)) assert.Equal(t, "ok", result["status"]) // Verify file written data, err := os.ReadFile(filepath.Join(dir, "sess-abc.jsonl")) require.NoError(t, err) assert.Contains(t, string(data), "tdd_green") } func TestHandle_SessionLog_RequiresSessionID(t *testing.T) { s := sessionlog.New(sessionlog.Config{SessionsDir: t.TempDir()}) args, _ := json.Marshal(map[string]any{"skill": "tdd_red"}) _, err := s.Handle(context.Background(), "session_log", args) assert.Error(t, err) }