ios: support safe assistant inline images
This commit is contained in:
@@ -65,6 +65,59 @@ final class AgentUITests: XCTestCase {
|
||||
return try XCTUnwrap(json["attachment"] as? [String: Any])
|
||||
}
|
||||
|
||||
func testAssistantImageOnlyLiveRetryAndHistoryWithoutInputCapability() async throws {
|
||||
app.terminate()
|
||||
try await control(["action": "reset", "count": 0])
|
||||
try await control(["action": "capability", "enabled": false, "assistantImages": true])
|
||||
try await control(["action": "push-available", "enabled": false])
|
||||
app.launch(); openAgent()
|
||||
XCTAssertFalse(app.buttons["agent-attach"].exists)
|
||||
let image = UIGraphicsImageRenderer(size: CGSize(width: 320, height: 180)).image { context in
|
||||
UIColor.systemTeal.setFill(); context.fill(CGRect(x: 0, y: 0, width: 320, height: 180))
|
||||
UIColor.systemYellow.setFill(); context.cgContext.fillEllipse(in: CGRect(x: 225, y: 25, width: 50, height: 50))
|
||||
UIColor.systemIndigo.setFill()
|
||||
context.cgContext.move(to: CGPoint(x: 0, y: 180)); context.cgContext.addLine(to: CGPoint(x: 120, y: 55))
|
||||
context.cgContext.addLine(to: CGPoint(x: 250, y: 180)); context.cgContext.fillPath()
|
||||
}
|
||||
try await control(["action": "reply", "content": "\n\n<img src='http://127.0.0.1:8799/blocked-html.png' alt='HTML landscape'>"])
|
||||
try await control(["action": "assistant-image", "content": "", "png": try XCTUnwrap(image.pngData()).base64EncodedString(), "failFirstDownload": true])
|
||||
XCTAssertTrue(app.staticTexts["fixture-landscape.png"].waitForExistence(timeout: 8))
|
||||
XCTAssertTrue(app.buttons["Retry download"].waitForExistence(timeout: 8))
|
||||
let imageFrame = app.otherElements["agent-image-frame"]
|
||||
XCTAssertTrue(imageFrame.exists)
|
||||
let placeholder = imageFrame.frame
|
||||
XCTAssertGreaterThan(placeholder.width, 0)
|
||||
XCTAssertEqual(placeholder.height, 180, accuracy: 1)
|
||||
app.buttons["Retry download"].tap()
|
||||
let preview = app.images["agent-image-preview"]
|
||||
XCTAssertTrue(preview.waitForExistence(timeout: 8))
|
||||
XCTAssertEqual(preview.label, "Image: fixture-landscape.png")
|
||||
XCTAssertLessThanOrEqual(preview.frame.height, 180)
|
||||
XCTAssertEqual(imageFrame.frame.width, placeholder.width, accuracy: 1)
|
||||
XCTAssertEqual(imageFrame.frame.height, placeholder.height, accuracy: 1)
|
||||
let loadedSize = imageFrame.frame.size
|
||||
XCTAssertTrue(app.staticTexts["Markdown landscape"].exists)
|
||||
XCTAssertTrue(app.staticTexts["HTML landscape"].exists)
|
||||
XCTAssertFalse(app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Copy workspace path:")).firstMatch.exists)
|
||||
capture("agent-assistant-image-live")
|
||||
|
||||
// Previously saved output remains visible when both capabilities disappear.
|
||||
try await control(["action": "capability", "enabled": false, "assistantImages": false])
|
||||
app.terminate(); app.launch(); openAgent()
|
||||
XCTAssertTrue(preview.waitForExistence(timeout: 8))
|
||||
XCTAssertEqual(imageFrame.frame.width, placeholder.width, accuracy: 1)
|
||||
XCTAssertEqual(imageFrame.frame.height, placeholder.height, accuracy: 1)
|
||||
print("Assistant image frame sizes: placeholder=\(placeholder.size), live=\(loadedSize), history=\(imageFrame.frame.size)")
|
||||
XCTAssertEqual(app.staticTexts.matching(NSPredicate(format: "label == %@", "fixture-landscape.png")).count, 1)
|
||||
XCTAssertFalse(app.buttons["agent-attach"].exists)
|
||||
capture("agent-assistant-image-history")
|
||||
let state = try await control(["action": "state"])
|
||||
let log = try XCTUnwrap(state["log"] as? [[String: Any]])
|
||||
XCTAssertFalse(log.contains { ($0["path"] as? String)?.hasPrefix("/blocked-") == true })
|
||||
XCTAssertGreaterThanOrEqual(log.filter { ($0["path"] as? String) == "/api/v1/agent/attachments/fixture-output-image/content" }.count, 3)
|
||||
XCTAssertTrue((state["requests"] as? [String: Any])?.isEmpty == true)
|
||||
}
|
||||
|
||||
func testAttachmentHistoryDownloadAndReload() async throws {
|
||||
let original = Data("Synthetic original text. <script>plain text only</script>".utf8)
|
||||
let file = try await uploadOriginal(name: "fixture-original.txt", mime: "text/plain", bytes: original)
|
||||
|
||||
Reference in New Issue
Block a user