|
4 | 4 | "context" |
5 | 5 | "encoding/json" |
6 | 6 | "errors" |
| 7 | + "fmt" |
7 | 8 | "strings" |
8 | 9 | "testing" |
9 | 10 |
|
@@ -540,6 +541,42 @@ func TestProcessLogsSearch(t *testing.T) { |
540 | 541 | t.Errorf("expected log_limit clamped to %d, got %d", searchMaxLogLimit, runner.logLimit) |
541 | 542 | } |
542 | 543 | }) |
| 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 | + }) |
543 | 580 | } |
544 | 581 |
|
545 | 582 | func TestProjectDependencyGraph(t *testing.T) { |
|
0 commit comments