Add user-controlled local file access in chat
This commit is contained in:
@@ -1073,6 +1073,24 @@ final class ConnectedChatTests: XCTestCase {
|
||||
}
|
||||
|
||||
final class ChatFilePreviewTests: XCTestCase {
|
||||
func testExplicitChatFileAccessUsesSelectedScope() throws {
|
||||
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let allowed = root.appending(path: "Project")
|
||||
try FileManager.default.createDirectory(at: allowed, withIntermediateDirectories: true)
|
||||
let outside = root.appending(path: "outside.txt")
|
||||
try "Outside".write(to: outside, atomically: true, encoding: .utf8)
|
||||
let file = allowed.appending(path: "hello world.txt")
|
||||
try "Inside".write(to: file, atomically: true, encoding: .utf8)
|
||||
let alias = allowed.appending(path: "escape.txt")
|
||||
try FileManager.default.createSymbolicLink(at: alias, withDestinationURL: outside)
|
||||
XCTAssertEqual(ChatFileRequest.path(in: #"/read "hello world.txt""#), "hello world.txt")
|
||||
XCTAssertEqual(try ChatFileRequest.read("hello world.txt", inside: allowed.path).text, "Inside")
|
||||
XCTAssertThrowsError(try ChatFileRequest.read("escape.txt", inside: allowed.path))
|
||||
XCTAssertThrowsError(try ChatFileRequest.read(file.path, inside: ""))
|
||||
XCTAssertEqual(try ChatFileRequest.read(outside.path, inside: "/").text, "Outside")
|
||||
}
|
||||
|
||||
func testPreviewsSelectedTextAndListsFolderWithoutReadingChildren() throws {
|
||||
let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
|
||||
Reference in New Issue
Block a user