(t *testing.T)
| 115 | } |
| 116 | |
| 117 | func TestReadDirMaxEntries(t *testing.T) { |
| 118 | // Create a temporary test directory with many files |
| 119 | tmpDir, err := os.MkdirTemp("", "readdir_test_max") |
| 120 | if err != nil { |
| 121 | t.Fatalf("Failed to create temp dir: %v", err) |
| 122 | } |
| 123 | defer os.RemoveAll(tmpDir) |
| 124 | |
| 125 | // Create 10 test files |
| 126 | for i := 0; i < 10; i++ { |
| 127 | testFile := filepath.Join(tmpDir, filepath.Base(tmpDir)+string(rune('a'+i))+".txt") |
| 128 | if err := os.WriteFile(testFile, []byte("test"), 0644); err != nil { |
| 129 | t.Fatalf("Failed to create test file: %v", err) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Test reading with max_entries=5 |
| 134 | maxEntries := 5 |
| 135 | input := map[string]any{ |
| 136 | "path": tmpDir, |
| 137 | "max_entries": maxEntries, |
| 138 | } |
| 139 | |
| 140 | result, err := readDirCallback(input, &uctypes.UIMessageDataToolUse{}) |
| 141 | if err != nil { |
| 142 | t.Fatalf("readDirCallback failed: %v", err) |
| 143 | } |
| 144 | |
| 145 | resultMap := result.(map[string]any) |
| 146 | entryCount := resultMap["entry_count"].(int) |
| 147 | totalEntries := resultMap["total_entries"].(int) |
| 148 | |
| 149 | if entryCount != maxEntries { |
| 150 | t.Errorf("Expected %d entries, got %d", maxEntries, entryCount) |
| 151 | } |
| 152 | |
| 153 | // Verify total_entries reports the original count, not the truncated count |
| 154 | if totalEntries != 10 { |
| 155 | t.Errorf("Expected total_entries to be 10, got %d", totalEntries) |
| 156 | } |
| 157 | |
| 158 | if _, ok := resultMap["truncated"]; !ok { |
| 159 | t.Error("Expected truncated field to be present") |
| 160 | } |
| 161 | |
| 162 | // Verify the truncation message includes the correct total |
| 163 | truncMsg, ok := resultMap["truncated_message"].(string) |
| 164 | if !ok { |
| 165 | t.Error("Expected truncated_message to be present") |
| 166 | } |
| 167 | expectedMsg := fmt.Sprintf("Directory listing truncated to %d entries (out of %d total)", maxEntries, 10) |
| 168 | if !strings.Contains(truncMsg, expectedMsg[:len(expectedMsg)-1]) { |
| 169 | t.Errorf("Expected truncated_message to contain %q, got %q", expectedMsg, truncMsg) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func TestReadDirSortBeforeTruncate(t *testing.T) { |
| 174 | // Create a temporary test directory |
nothing calls this directly
no test coverage detected