Adds the brain skill that proxies HTTP calls to the ingestion server, exposing brain_query (/query) and brain_write (/write) as MCP tools. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
// internal/skills/brain/handlers_test.go
|
|
package brain_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/mathiasbq/supervisor/internal/skills/brain"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHandle_BrainQuery_CallsIngestServer(t *testing.T) {
|
|
called := false
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "/query", r.URL.Path)
|
|
called = true
|
|
json.NewEncoder(w).Encode(map[string]any{
|
|
"results": []map[string]any{
|
|
{"path": "wiki/concepts/tdd.md", "title": "TDD", "excerpt": "Test-driven development.", "score": 3},
|
|
},
|
|
})
|
|
}))
|
|
defer srv.Close()
|
|
|
|
s := brain.New(brain.Config{IngestBaseURL: srv.URL})
|
|
args, _ := json.Marshal(map[string]string{"query": "test driven development"})
|
|
out, err := s.Handle(context.Background(), "brain_query", args)
|
|
require.NoError(t, err)
|
|
assert.True(t, called)
|
|
|
|
var result map[string]any
|
|
require.NoError(t, json.Unmarshal(out, &result))
|
|
results := result["results"].([]any)
|
|
assert.Len(t, results, 1)
|
|
}
|
|
|
|
func TestHandle_BrainWrite_CallsIngestServer(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "/write", r.URL.Path)
|
|
json.NewEncoder(w).Encode(map[string]string{"path": "raw/test.md"})
|
|
}))
|
|
defer srv.Close()
|
|
|
|
s := brain.New(brain.Config{IngestBaseURL: srv.URL})
|
|
args, _ := json.Marshal(map[string]string{"content": "# Test\n\nSome learning.", "type": "concept"})
|
|
out, err := s.Handle(context.Background(), "brain_write", args)
|
|
require.NoError(t, err)
|
|
var result map[string]string
|
|
require.NoError(t, json.Unmarshal(out, &result))
|
|
assert.Equal(t, "raw/test.md", result["path"])
|
|
}
|
|
|
|
func TestHandle_UnknownTool_ReturnsError(t *testing.T) {
|
|
s := brain.New(brain.Config{IngestBaseURL: "http://localhost:3300"})
|
|
_, err := s.Handle(context.Background(), "brain_unknown", nil)
|
|
assert.Error(t, err)
|
|
}
|