fix(ios): restore Quick Question composer behavior
TestFlight / Build and upload (push) Successful in 1m53s
TestFlight / Build and upload (push) Successful in 1m53s
This commit is contained in:
@@ -15,7 +15,6 @@ from aiohttp import web
|
||||
sockets = set()
|
||||
messages = []
|
||||
requests = {}
|
||||
quick_questions = []
|
||||
read_cursor = 0
|
||||
cursor = 0
|
||||
busy = False
|
||||
@@ -109,7 +108,7 @@ async def route(request):
|
||||
for task in reply_tasks:
|
||||
task.cancel()
|
||||
reply_tasks.clear()
|
||||
messages.clear(); requests.clear(); quick_questions.clear(); attempts.clear(); cursor = 0; read_cursor = 0; busy = False
|
||||
messages.clear(); requests.clear(); attempts.clear(); cursor = 0; read_cursor = 0; busy = False
|
||||
attachment_capability = True; next_upload_error = None; blocked_proxy = False; transcript_comparison = False
|
||||
assistant_image_capability = False; fail_image_download = False
|
||||
push_installations.clear(); push_retired.clear(); push_requests.clear(); log.clear()
|
||||
@@ -178,7 +177,7 @@ async def route(request):
|
||||
await socket.close(code=1012)
|
||||
elif action == 'malformed':
|
||||
await broadcast(dict(type='messages', conversationId='fixture-root', messages=[{'id': 'broken'}], cursor='999999', beforeCursor=None, hasMore=False))
|
||||
return web.json_response(dict(cursor=cursor, readCursor=read_cursor, messages=messages, requests=requests, quickQuestions=quick_questions, log=log,
|
||||
return web.json_response(dict(cursor=cursor, readCursor=read_cursor, messages=messages, requests=requests, log=log,
|
||||
pushRequests=push_requests, pushActive=len(push_installations), pushRetired=len(push_retired)))
|
||||
if path == '/api/v1/auth/session':
|
||||
if auth_required and request.headers.get('Authorization') != 'Bearer fixture-token':
|
||||
@@ -296,12 +295,6 @@ async def route(request):
|
||||
if request.method == 'PUT':
|
||||
read_cursor = max(read_cursor, int((await request.json())['cursor']))
|
||||
return web.json_response(dict(cursor=str(read_cursor), updatedAt=stamp(), sourceId=PUSH_SOURCE))
|
||||
if path == '/api/v1/quick-questions/stream' and request.method == 'POST':
|
||||
quick_questions.append(await request.json())
|
||||
return web.Response(
|
||||
text='event: done\ndata: {"text":"Fixture answer"}\n\n',
|
||||
content_type='text/event-stream',
|
||||
)
|
||||
if path == '/api/v1/agent/messages':
|
||||
if request.method == 'POST':
|
||||
body = await request.json()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
/// Uses the repository's 127.0.0.1 contract fixture and the real iOS home-screen shortcut.
|
||||
/// Exercises Quick Question through its real home-screen action and shared SwiftUI field.
|
||||
@MainActor
|
||||
final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
private let app = XCUIApplication()
|
||||
@@ -18,194 +17,49 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
|
||||
override func tearDown() async throws {
|
||||
app.terminate()
|
||||
UIPasteboard.general.string = nil
|
||||
}
|
||||
|
||||
func testQuickActionReselectsRetainedDraft() async throws {
|
||||
func testQuickQuestionKeepsKeyboardVisibleAcrossSeparateKeypressesAndStaysCompact() {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
let prompt = quickQuestionPrompt()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
XCTAssertLessThan(prompt.frame.height, 80, "Quick Question should retain its original compact single-line field.")
|
||||
|
||||
prompt.typeText("a")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the first keypress.")
|
||||
prompt.typeText("b")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the second keypress.")
|
||||
prompt.typeText("c")
|
||||
XCTAssertTrue(app.keyboards.firstMatch.exists, "Keyboard should remain visible after the third keypress.")
|
||||
XCTAssertEqual(prompt.value as? String, "abc")
|
||||
}
|
||||
|
||||
func testQuickQuestionReappearanceSelectsRetainedDraftForReplacement() {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPrompt()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
XCTAssertLessThan(prompt.frame.height, 80, "An empty Quick Question composer should stay one line tall.")
|
||||
prompt.typeText("retained draft")
|
||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||
|
||||
// The real home-screen action requests a new focusRequest even while
|
||||
// this sheet remains presented. That task refocuses and reselects text.
|
||||
// A second real home-screen Quick Question action advances the existing
|
||||
// focus request. The original TextSelection binding selects the draft.
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
XCTAssertEqual(prompt.value as? String, "retained draft")
|
||||
XCTAssertLessThan(prompt.frame.height, 80, "A one-line draft should keep the normal chat composer height.")
|
||||
|
||||
// The field is already focused with its initial draft selected. Do not tap
|
||||
// it here: typing immediately is the behavior under test.
|
||||
prompt.typeText("replacement")
|
||||
XCTAssertEqual(prompt.value as? String, "replacement")
|
||||
}
|
||||
|
||||
func testQuickQuestionComposerStartsCompactAndGrowsForMultilineText() {
|
||||
app.launch()
|
||||
let agentButton = app.buttons["agent-sidebar"]
|
||||
if !agentButton.waitForExistence(timeout: 2) || !agentButton.isHittable {
|
||||
let showSidebar = app.buttons["Show sidebar"]
|
||||
XCTAssertTrue(showSidebar.waitForExistence(timeout: 15))
|
||||
showSidebar.tap()
|
||||
}
|
||||
XCTAssertTrue(agentButton.waitForExistence(timeout: 5))
|
||||
agentButton.tap()
|
||||
|
||||
let normalField = app.textFields["agent-composer"]
|
||||
let normalView = app.textViews["agent-composer"]
|
||||
XCTAssertTrue(normalField.waitForExistence(timeout: 5) || normalView.waitForExistence(timeout: 5))
|
||||
let normalComposer = normalField.exists ? normalField : normalView
|
||||
let normalHeight = normalComposer.frame.height
|
||||
XCTAssertLessThan(normalHeight, 80, "The normal composer should start at one line.")
|
||||
|
||||
XCUIDevice.shared.press(.home)
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
let oneLineHeight = prompt.frame.height
|
||||
XCTAssertLessThan(oneLineHeight, 80, "The Quick Question field must not fill the sheet when empty.")
|
||||
XCTAssertEqual(oneLineHeight, normalHeight, accuracy: 4, "The six-line Return field must keep the normal composer’s compact first line.")
|
||||
captureFrame("quick-question-empty-keyboard-visible", element: prompt)
|
||||
capture("quick-question-empty-keyboard-visible")
|
||||
|
||||
let growingDraft = (1...4).map { "Question line \($0)" }.joined(separator: "\n")
|
||||
UIPasteboard.general.string = growingDraft
|
||||
prompt.press(forDuration: 1.2)
|
||||
let paste = app.descendants(matching: .any)
|
||||
.matching(NSPredicate(format: "label == %@", "Paste"))
|
||||
.firstMatch
|
||||
XCTAssertTrue(paste.waitForExistence(timeout: 5), "The multiline fixture should be available to paste into the real text field.")
|
||||
paste.tap()
|
||||
|
||||
XCTAssertEqual(prompt.value as? String, growingDraft)
|
||||
let multilineHeight = prompt.frame.height
|
||||
captureFrame("quick-question-multiline-growing-keyboard-visible", element: prompt)
|
||||
capture("quick-question-multiline-growing-keyboard-visible")
|
||||
XCTAssertGreaterThan(multilineHeight, oneLineHeight * 2, "The shared vertical field should grow as lines are added.")
|
||||
XCTAssertLessThan(multilineHeight, oneLineHeight * 6 + 16, "The growing field should remain below its six-line cap.")
|
||||
|
||||
let appendedLines = (5...9).map { "\nQuestion line \($0)" }.joined()
|
||||
prompt.typeText(appendedLines)
|
||||
let cappedDraft = growingDraft + appendedLines
|
||||
XCTAssertEqual(prompt.value as? String, cappedDraft)
|
||||
let cappedHeight = prompt.frame.height
|
||||
captureFrame("quick-question-six-line-cap-keyboard-visible", element: prompt)
|
||||
capture("quick-question-six-line-cap-keyboard-visible")
|
||||
XCTAssertGreaterThan(cappedHeight, oneLineHeight * 5, "Nine lines should reach the existing six-line height cap.")
|
||||
XCTAssertLessThan(cappedHeight, oneLineHeight * 6 + 16, "Nine lines should remain inside the existing six-line visual cap.")
|
||||
XCTAssertEqual(
|
||||
prompt.value as? String,
|
||||
cappedDraft,
|
||||
"The capped field must retain all nine lines while its visible editor stays at the six-line cap."
|
||||
)
|
||||
}
|
||||
|
||||
func testQuickQuestionOneLineHeightMatchesNormalChatComposer() {
|
||||
app.launch()
|
||||
let agentButton = app.buttons["agent-sidebar"]
|
||||
if !agentButton.waitForExistence(timeout: 2) || !agentButton.isHittable {
|
||||
let showSidebar = app.buttons["Show sidebar"]
|
||||
XCTAssertTrue(showSidebar.waitForExistence(timeout: 15))
|
||||
showSidebar.tap()
|
||||
}
|
||||
XCTAssertTrue(agentButton.waitForExistence(timeout: 5))
|
||||
agentButton.tap()
|
||||
|
||||
let textField = app.textFields["agent-composer"]
|
||||
let textView = app.textViews["agent-composer"]
|
||||
XCTAssertTrue(textField.waitForExistence(timeout: 5) || textView.waitForExistence(timeout: 5))
|
||||
let normalComposer = textField.exists ? textField : textView
|
||||
let normalHeight = normalComposer.frame.height
|
||||
XCTAssertLessThan(normalHeight, 80, "The normal-chat composer should start at one line.")
|
||||
captureFrame("normal-chat-composer", element: normalComposer)
|
||||
capture("normal-chat-one-line-keyboard-hidden")
|
||||
|
||||
XCUIDevice.shared.press(.home)
|
||||
openQuickQuestionFromHomeScreen()
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
let quickQuestionHeight = prompt.frame.height
|
||||
captureFrame("quick-question-composer-keyboard-visible", element: prompt)
|
||||
capture("quick-question-one-line-keyboard-visible")
|
||||
XCTAssertLessThan(quickQuestionHeight, 80, "Quick Question should start at one line.")
|
||||
XCTAssertEqual(
|
||||
quickQuestionHeight,
|
||||
normalHeight,
|
||||
accuracy: 4,
|
||||
"Quick Question should use the same one-line field sizing as normal chat."
|
||||
)
|
||||
}
|
||||
|
||||
func testQuickQuestionReturnSubmitsPromptExactlyOnceWithoutNewline() async throws {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
prompt.typeText("Return submits once\n")
|
||||
|
||||
XCTAssertTrue(app.staticTexts["Fixture answer"].waitForExistence(timeout: 10))
|
||||
XCTAssertEqual(prompt.value as? String, "Return submits once", "Return must submit without adding a newline.")
|
||||
let state = try await control(["action": "state"])
|
||||
let submitted = try XCTUnwrap(state["quickQuestions"] as? [[String: Any]])
|
||||
XCTAssertEqual(submitted.count, 1, "One Return press must submit exactly one quick question.")
|
||||
XCTAssertEqual(submitted.first?["question"] as? String, "Return submits once")
|
||||
}
|
||||
|
||||
func testQuickQuestionMultilinePasteDoesNotSubmit() async throws {
|
||||
app.launch()
|
||||
openQuickQuestionFromHomeScreen()
|
||||
|
||||
let prompt = quickQuestionPromptElement()
|
||||
XCTAssertTrue(prompt.waitForExistence(timeout: 10))
|
||||
XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10))
|
||||
let pasted = "First line\nSecond line"
|
||||
UIPasteboard.general.string = pasted
|
||||
prompt.press(forDuration: 1.2)
|
||||
let paste = app.descendants(matching: .any)
|
||||
.matching(NSPredicate(format: "label == %@", "Paste"))
|
||||
.firstMatch
|
||||
XCTAssertTrue(paste.waitForExistence(timeout: 5))
|
||||
paste.tap()
|
||||
|
||||
XCTAssertEqual(prompt.value as? String, pasted)
|
||||
let state = try await control(["action": "state"])
|
||||
let submitted = try XCTUnwrap(state["quickQuestions"] as? [[String: Any]])
|
||||
XCTAssertTrue(submitted.isEmpty, "Pasting multiline text must not submit the question.")
|
||||
}
|
||||
|
||||
func testSharedNormalComposerReturnInsertsNewline() async throws {
|
||||
app.launch()
|
||||
let textField = app.textFields["Enter Prompt"]
|
||||
let textView = app.textViews["Enter Prompt"]
|
||||
XCTAssertTrue(textField.waitForExistence(timeout: 5) || textView.waitForExistence(timeout: 5))
|
||||
let composer = textField.exists ? textField : textView
|
||||
composer.tap()
|
||||
composer.typeText("Normal chat keeps newline\n")
|
||||
|
||||
XCTAssertTrue((composer.value as? String)?.contains("\n") == true)
|
||||
let state = try await control(["action": "state"])
|
||||
let log = try XCTUnwrap(state["log"] as? [[String: Any]])
|
||||
XCTAssertFalse(
|
||||
log.contains { $0["method"] as? String == "POST" && ($0["path"] as? String)?.hasSuffix("/chat-completions/stream") == true },
|
||||
"Plain Return in normal chat must insert a newline without submitting."
|
||||
)
|
||||
}
|
||||
|
||||
private func quickQuestionPromptElement() -> XCUIElement {
|
||||
let textField = app.textFields["quick-question-prompt"]
|
||||
return textField.exists ? textField : app.textViews["quick-question-prompt"]
|
||||
private func quickQuestionPrompt() -> XCUIElement {
|
||||
app.textFields["Ask anything..."]
|
||||
}
|
||||
|
||||
private func openQuickQuestionFromHomeScreen() {
|
||||
@@ -213,12 +67,10 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
let sybilIcon = springboard.icons.matching(identifier: "Sybil").firstMatch
|
||||
XCTAssertTrue(sybilIcon.waitForExistence(timeout: 10))
|
||||
let homeScreen = springboard.otherElements["Home screen icons"]
|
||||
XCTAssertTrue(homeScreen.waitForExistence(timeout: 5))
|
||||
for _ in 0..<2 {
|
||||
guard !sybilIcon.isHittable else {
|
||||
break
|
||||
if !sybilIcon.isHittable, homeScreen.waitForExistence(timeout: 5) {
|
||||
for _ in 0..<2 where !sybilIcon.isHittable {
|
||||
homeScreen.swipeLeft()
|
||||
}
|
||||
homeScreen.swipeLeft()
|
||||
}
|
||||
XCTAssertTrue(sybilIcon.isHittable, "Navigate to the home-screen page containing Sybil before opening its quick action.")
|
||||
sybilIcon.press(forDuration: 1.2)
|
||||
@@ -228,29 +80,12 @@ final class QuickQuestionSelectionUITests: XCTestCase {
|
||||
quickQuestion.tap()
|
||||
}
|
||||
|
||||
private func capture(_ name: String) {
|
||||
let attachment = XCTAttachment(screenshot: app.screenshot())
|
||||
attachment.name = name
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
private func captureFrame(_ name: String, element: XCUIElement) {
|
||||
let frame = element.frame
|
||||
let attachment = XCTAttachment(string: "x=\(frame.origin.x), y=\(frame.origin.y), width=\(frame.width), height=\(frame.height)")
|
||||
attachment.name = "frame-\(name)"
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func control(_ body: [String: Any]) async throws -> [String: Any] {
|
||||
private func control(_ body: [String: Any]) async throws {
|
||||
var request = URLRequest(url: URL(string: "http://127.0.0.1:8799/control")!)
|
||||
request.httpMethod = "POST"
|
||||
request.httpBody = try JSONSerialization.data(withJSONObject: body)
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
let (_, response) = try await URLSession.shared.data(for: request)
|
||||
XCTAssertEqual((response as? HTTPURLResponse)?.statusCode, 200)
|
||||
return try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user