fix(core): reject binary files before reading
This commit is contained in:
parent
9a1199770b
commit
cc801089d7
3 changed files with 75 additions and 6 deletions
|
|
@ -43,7 +43,7 @@ const filesystem = Layer.succeed(
|
|||
type: "file" as const,
|
||||
target: new FileSystem.ReadTarget({
|
||||
real,
|
||||
resource: input.reference === undefined ? "README.md" : `${input.reference}:README.md`,
|
||||
resource: input.reference === undefined ? input.path : `${input.reference}:${input.path}`,
|
||||
size,
|
||||
dev: 1,
|
||||
}),
|
||||
|
|
@ -69,7 +69,7 @@ const filesystem = Layer.succeed(
|
|||
? Effect.succeed(
|
||||
new FileSystem.ReadTarget({
|
||||
real,
|
||||
resource: input.reference === undefined ? "README.md" : `${input.reference}:README.md`,
|
||||
resource: input.reference === undefined ? input.path : `${input.reference}:${input.path}`,
|
||||
size,
|
||||
dev: 1,
|
||||
}),
|
||||
|
|
@ -511,6 +511,34 @@ describe("ReadTool", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("rejects unsupported binary files before reading or paging them", () =>
|
||||
Effect.gen(function* () {
|
||||
reads.length = 0
|
||||
textPageInputs.length = 0
|
||||
samples.length = 0
|
||||
allow = true
|
||||
resolveFailure = undefined
|
||||
listResolveFailure = new Error("not a directory")
|
||||
size = 4
|
||||
real = "/project/archive.dat"
|
||||
afterApproval = () => {}
|
||||
readFailure = undefined
|
||||
sample = new Uint8Array([0, 1, 2, 3])
|
||||
configEntries = []
|
||||
const registry = yield* ToolRegistry.Service
|
||||
|
||||
expect(
|
||||
yield* registry.execute({
|
||||
sessionID,
|
||||
call: { type: "tool-call", id: "call-small-binary", name: "read", input: { path: "archive.dat" } },
|
||||
}),
|
||||
).toEqual({ type: "error", value: "Cannot read binary file: archive.dat" })
|
||||
expect(samples).toEqual([FileSystem.READ_SAMPLE_BYTES])
|
||||
expect(reads).toEqual([])
|
||||
expect(textPageInputs).toEqual([])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("does not read when the file changes after permission approval", () =>
|
||||
Effect.gen(function* () {
|
||||
assertions.length = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue