Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public class ReadFileTool<Path>(private val fs: FileSystemProvider.ReadOnly<Path
validate(metadata.type == FileMetadata.FileType.File) { "Not a file: ${args.path}" }

val type = fs.getFileContentType(path)
validate(type == FileMetadata.FileContentType.Text) { "File is not a text file: ${args.path}" }
val isEmpty = fs.size(path) == 0L
val isText = isEmpty || (type == FileMetadata.FileContentType.Text)
validate(isText) { "File is not a text file: ${args.path}" }

return runCatching {
var warningMessage: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,17 @@ class ReadFileToolJvmTest {
}

@Test
fun `throws ValidationFailure when reading empty markdown file`() {
fun `reading empty markdown file renders empty fenced block`() = runBlocking {
val f = createTestFile("empty.md", "")
assertThrows<ToolException.ValidationFailure> {
runBlocking { readFile(f) }
}
val result = readFile(f)
val expected = """
${"${f.toAbsolutePath().toString().norm()} (0 bytes, 1 line)"}
Content:
```markdown
```
""".trimIndent()

assertEquals(expected, tool.encodeResultToString(result))
}

@Test
Expand Down Expand Up @@ -249,11 +255,17 @@ class ReadFileToolJvmTest {
}

@Test
fun `throws ValidationFailure when reading empty kotlin file`() {
fun `reading empty kotlin file renders empty fenced block`() = runBlocking {
val f = createTestFile("Empty.kt", "")
assertThrows<ToolException.ValidationFailure> {
runBlocking { readFile(f) }
}
val result = readFile(f)
val expected = """
${"${f.toAbsolutePath().toString().norm()} (0 bytes, 1 line)"}
Content:
```kotlin
```
""".trimIndent()

assertEquals(expected, tool.encodeResultToString(result))
}

@Test
Expand Down