fix(mcp): align brain list notifications and cleanup test runtime

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 12:41:37 +00:00
parent 91e41615d1
commit c7b317402b
5 changed files with 58 additions and 13 deletions

View file

@ -289,10 +289,10 @@ func (s *DirectSubsystem) list(ctx context.Context, _ *mcp.CallToolRequest, inpu
if s.onChannel != nil {
s.onChannel(ctx, coremcp.ChannelBrainListDone, map[string]any{
"project": input.Project,
"type": input.Type,
"agent": input.AgentID,
"limit": limit,
"project": input.Project,
"type": input.Type,
"agent_id": input.AgentID,
"limit": limit,
})
}

View file

@ -361,6 +361,50 @@ func TestDirectList_Good(t *testing.T) {
}
}
func TestDirectList_Good_EmitsAgentIDChannelPayload(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]any{"memories": []any{}})
}))
defer srv.Close()
var gotChannel string
var gotPayload map[string]any
s := newTestDirect(srv.URL)
s.onChannel = func(_ context.Context, channel string, data any) {
gotChannel = channel
if payload, ok := data.(map[string]any); ok {
gotPayload = payload
}
}
_, out, err := s.list(context.Background(), nil, ListInput{
Project: "eaas",
Type: "decision",
AgentID: "virgil",
Limit: 20,
})
if err != nil {
t.Fatalf("list failed: %v", err)
}
if !out.Success {
t.Fatal("expected list success")
}
if gotChannel != "brain.list.complete" {
t.Fatalf("expected brain.list.complete, got %q", gotChannel)
}
if gotPayload == nil {
t.Fatal("expected channel payload")
}
if gotPayload["agent_id"] != "virgil" {
t.Fatalf("expected agent_id=virgil, got %v", gotPayload["agent_id"])
}
if gotPayload["project"] != "eaas" {
t.Fatalf("expected project=eaas, got %v", gotPayload["project"])
}
}
func TestDirectList_Good_DefaultLimit(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("limit"); got != "50" {

View file

@ -318,10 +318,10 @@ func (p *BrainProvider) list(c *gin.Context) {
}
p.emitEvent(coremcp.ChannelBrainListDone, map[string]any{
"project": project,
"type": typ,
"agent": agentID,
"limit": limit,
"project": project,
"type": typ,
"agent_id": agentID,
"limit": limit,
})
c.JSON(http.StatusOK, api.OK(ListOutput{

View file

@ -235,10 +235,10 @@ func (s *Subsystem) brainList(ctx context.Context, _ *mcp.CallToolRequest, input
}
s.emitChannel(ctx, coremcp.ChannelBrainListDone, map[string]any{
"project": input.Project,
"type": input.Type,
"agent": input.AgentID,
"limit": limit,
"project": input.Project,
"type": input.Type,
"agent_id": input.AgentID,
"limit": limit,
})
return nil, ListOutput{

View file

@ -75,6 +75,8 @@ func isTestProcess(command string, args []string) bool {
}
func (s *Service) emitTestResult(ctx context.Context, processID string, exitCode int, duration time.Duration, signal string, errText string) {
defer s.forgetProcessRuntime(processID)
meta, ok := s.processRuntimeFor(processID)
if !ok || !isTestProcess(meta.Command, meta.Args) {
return
@ -115,5 +117,4 @@ func (s *Service) emitTestResult(ctx context.Context, processID string, exitCode
}
s.ChannelSend(ctx, ChannelTestResult, payload)
s.forgetProcessRuntime(processID)
}