Skip to content

Commit 2f85b26

Browse files
committed
test(mcp): cover fair-share truncation in pc_process_logs_search
Verifies that when N processes * log_limit exceeds searchMaxCorpusLines, each process's budget is reduced to the fair share and the result is flagged truncated.
1 parent 8921eee commit 2f85b26

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/mcp/control_tools_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"fmt"
78
"strings"
89
"testing"
910

@@ -540,6 +541,42 @@ func TestProcessLogsSearch(t *testing.T) {
540541
t.Errorf("expected log_limit clamped to %d, got %d", searchMaxLogLimit, runner.logLimit)
541542
}
542543
})
544+
545+
t.Run("truncates when fair share is below log_limit", func(t *testing.T) {
546+
// 20 procs * log_limit=5000 = 100k requested, well over the 50k cap.
547+
// Fair share collapses to 50000/20 = 2500 per proc, which is below
548+
// the requested log_limit, so the result must be flagged truncated.
549+
const n = 20
550+
states := make([]types.ProcessState, 0, n)
551+
logsByName := map[string][]string{}
552+
for i := range n {
553+
name := fmt.Sprintf("p%d", i)
554+
states = append(states, types.ProcessState{Name: name})
555+
logsByName[name] = []string{"hello world"}
556+
}
557+
runner := &fakeRunner{
558+
listResult: &types.ProcessesState{States: states},
559+
logResultsByName: logsByName,
560+
}
561+
s := newTestServer(runner)
562+
res, _ := s.handleProcessLogsSearch(context.Background(), callRequest(map[string]any{
563+
"query": "hello",
564+
"log_limit": float64(searchMaxLogLimit),
565+
}))
566+
if resultIsError(res) {
567+
t.Fatalf("unexpected tool error: %s", resultText(res))
568+
}
569+
var got logSearchResult
570+
if err := json.Unmarshal([]byte(resultText(res)), &got); err != nil {
571+
t.Fatalf("result not valid JSON: %v", err)
572+
}
573+
if !got.Truncated {
574+
t.Errorf("expected truncated=true with %d procs and log_limit=%d", n, searchMaxLogLimit)
575+
}
576+
if want := searchMaxCorpusLines / n; runner.logLimit != want {
577+
t.Errorf("expected per-proc limit %d, got %d", want, runner.logLimit)
578+
}
579+
})
543580
}
544581

545582
func TestProjectDependencyGraph(t *testing.T) {

0 commit comments

Comments
 (0)