diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e51f28d..f4808ca 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -56,15 +56,53 @@ jobs: src/apps/mobile/android/app/build/test-results/ if-no-files-found: ignore ios: - runs-on: macos-latest + runs-on: macos-26 + env: + DEVELOPER_DIR: /Applications/Xcode_26.5.app/Contents/Developer steps: - uses: actions/checkout@v5 + - name: Create iPhone simulator + run: | + xcodebuild -version + xcrun simctl list runtimes + simulator_id=$(xcrun simctl create 'OpenBitFun CI' \ + com.apple.CoreSimulator.SimDeviceType.iPhone-17-Pro-Max \ + com.apple.CoreSimulator.SimRuntime.iOS-26-5) + echo "IOS_SIMULATOR_DESTINATION=platform=iOS Simulator,id=$simulator_id" >> "$GITHUB_ENV" + - uses: actions/setup-node@v4 + with: + node-version: '22' - uses: actions/setup-java@v5 with: distribution: temurin java-version: '21' - uses: gradle/actions/setup-gradle@v4 - - run: ./gradlew compileKotlinIosSimulatorArm64 --no-daemon + - name: Build shared iOS XCFramework + run: ./gradlew compileKotlinIosSimulatorArm64 :core-feature:assembleOpenBitFunMobileCoreDebugXCFramework --no-daemon working-directory: src/apps/mobile/shared - run: ./Testing/run-pure-swift-tests.sh working-directory: src/apps/mobile/ios + - name: Build iOS app and UI tests + working-directory: src/apps/mobile/ios + run: | + xcodebuild -project OpenBitFun.xcodeproj -scheme OpenBitFun -configuration Debug \ + -destination "$IOS_SIMULATOR_DESTINATION" \ + -derivedDataPath "$RUNNER_TEMP/OpenBitFunDerivedData" \ + build-for-testing + - name: Run StreamingPresentationUITests + working-directory: src/apps/mobile/ios + run: | + xcodebuild -project OpenBitFun.xcodeproj -scheme OpenBitFun -configuration Debug \ + -destination "$IOS_SIMULATOR_DESTINATION" \ + -derivedDataPath "$RUNNER_TEMP/OpenBitFunDerivedData" \ + -resultBundlePath "$RUNNER_TEMP/StreamingPresentationUITests.xcresult" \ + -parallel-testing-enabled NO -testLanguage zh-Hans -testRegion CN \ + -only-testing:OpenBitFunUITests/StreamingPresentationUITests \ + test-without-building + - name: Upload iOS UI test results on failure + if: failure() + uses: actions/upload-artifact@v6 + with: + name: ios-streaming-ui-test-results + path: ${{ runner.temp }}/StreamingPresentationUITests.xcresult + if-no-files-found: ignore diff --git a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift index 8fffd0a..20f0e8c 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/Chat/ChatTimelineView.swift @@ -618,6 +618,7 @@ private struct ThinkingBlock: View { .foregroundStyle(OpenBitFunTheme.muted) .lineSpacing(MobileDesignTypography.bodyLarge.lineSpacing) .textSelection(.enabled) + .accessibilityIdentifier("thinking.content.\(partID)") } } // Match Harmony: preserve manual toggles during one thinking phase, diff --git a/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/MobileDesignGallery.swift b/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/MobileDesignGallery.swift index 8ba87a3..e7c38c7 100644 --- a/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/MobileDesignGallery.swift +++ b/src/apps/mobile/ios/OpenBitFun/Features/DesignSystem/MobileDesignGallery.swift @@ -86,12 +86,22 @@ struct MobileDesignGallery: View { #if DEBUG /// Deterministic native rendering fixture. It never opens a remote transport. struct StreamingRegressionView: View { + private enum ThinkingPhase { + case waiting, readyForAnswer, answering + } + @StateObject private var model = MobileAppModel(sessions: [], selectedSessionID: "fixture", messages: [], connectCore: false) @State private var generation = 0 @State private var finished = false @State private var olderCount = 0 @State private var historyCount = 40 @State private var historyRequests = 0 + @State private var thinkingPhase = ThinkingPhase.waiting + private let showsThinkingControls = ProcessInfo.processInfo.arguments.contains("--thinking-regression") + private let showsDelayedOpenControls = ProcessInfo.processInfo.arguments.contains("--open-loading-regression") + private let thinkingSegments = (1...12).map { index in + "Thinking segment \(index): checking chronology and viewport stability.\nCheck input.\nCheck output.\nCheck viewport.\nCheck ordering.\n\n" + } var body: some View { VStack(spacing: 0) { @@ -101,6 +111,7 @@ struct StreamingRegressionView: View { model.composerSendGeneration &+= 1 model.isSending = true finished = false + thinkingPhase = .waiting generation += 1 }.accessibilityIdentifier("fixture.send") Button("Reset session") { @@ -108,6 +119,7 @@ struct StreamingRegressionView: View { model.selectedSessionID = UUID().uuidString model.timelineRows = history model.isSending = false + thinkingPhase = .waiting }.accessibilityIdentifier("fixture.reset") } Button("Short history") { @@ -116,8 +128,27 @@ struct StreamingRegressionView: View { olderCount = 0 model.timelineRows = history model.remoteHasMoreMessages = true + thinkingPhase = .waiting }.accessibilityIdentifier("fixture.shortHistory") - if ProcessInfo.processInfo.arguments.contains("--open-loading-regression") { + if showsThinkingControls { + HStack { + Button("Show answer") { + showThinkingRegression(thought: thinkingSegments.joined(), answerVisible: true, live: true) + thinkingPhase = .answering + } + .disabled(thinkingPhase != .readyForAnswer) + .accessibilityIdentifier("fixture.showThinkingAnswer") + Button("Finish stream") { + showThinkingRegression(thought: thinkingSegments.joined(), answerVisible: true, live: false) + model.isSending = false + finished = true + thinkingPhase = .waiting + } + .disabled(thinkingPhase != .answering) + .accessibilityIdentifier("fixture.finishThinkingAnswer") + } + } + if showsDelayedOpenControls { HStack { Button("Open delayed session") { model.remoteExpectedDeviceKey = "account:fixture-device" @@ -135,6 +166,8 @@ struct StreamingRegressionView: View { model.finishRemoteConversationOpenIfReady(timelineSessionID: "delayed") }.accessibilityIdentifier("fixture.finishLoading") } + .buttonStyle(.bordered) + .font(.footnote) } if ProcessInfo.processInfo.arguments.contains("--history-pagination-regression") { Text("History requests: \(historyRequests)").accessibilityIdentifier("fixture.historyRequests") @@ -219,19 +252,14 @@ struct StreamingRegressionView: View { finished = true return } - if ProcessInfo.processInfo.arguments.contains("--thinking-regression") { + if showsThinkingControls { var thought = "" - for index in 1...12 { - thought += "Thinking segment \(index): checking chronology and viewport stability.\nCheck input.\nCheck output.\nCheck viewport.\nCheck ordering.\n\n" - model.timelineRows = history + [thinkingRow(thought: thought, answer: "", live: true)] + for segment in thinkingSegments { do { try await Task.sleep(nanoseconds: 350_000_000) } catch { return } + thought += segment + showThinkingRegression(thought: thought, answerVisible: false, live: true) } - do { try await Task.sleep(nanoseconds: 3_000_000_000) } catch { return } - model.timelineRows = history + [thinkingRow(thought: thought, answer: "ANSWER-AFTER-THINKING", live: true)] - do { try await Task.sleep(nanoseconds: 2_000_000_000) } catch { return } - model.timelineRows = history + [thinkingRow(thought: thought, answer: "ANSWER-AFTER-THINKING", live: false)] - model.isSending = false - finished = true + thinkingPhase = .readyForAnswer return } var body = "" @@ -284,12 +312,14 @@ struct StreamingRegressionView: View { ], streaming: false, typing: false, showRetry: false, error: nil) } - private func thinkingRow(thought: String, answer: String, live: Bool) -> MobileConversationRow { + private func showThinkingRegression(thought: String, answerVisible: Bool, live: Bool) { + let answer = answerVisible ? "ANSWER-AFTER-THINKING" : "" var blocks: [MobileTimelineBlock] = [.thinking(id: "thought", text: thought, streaming: answer.isEmpty && live)] if !answer.isEmpty { blocks.append(.text(id: "answer", text: answer, streaming: live)) } - return MobileConversationRow(id: live ? "thinking-live" : "thinking-final", kind: "ASSISTANT", text: answer, + let row = MobileConversationRow(id: live ? "thinking-live" : "thinking-final", kind: "ASSISTANT", text: answer, thinking: thought, images: [], tools: [], blocks: blocks, streaming: live, typing: false, showRetry: false, error: nil, live: live) + model.timelineRows = history + [row] } private var history: [MobileConversationRow] { diff --git a/src/apps/mobile/ios/OpenBitFunUITests/RemoteCodeSessionSendUITests.swift b/src/apps/mobile/ios/OpenBitFunUITests/RemoteCodeSessionSendUITests.swift index 21ccd62..f059e40 100644 --- a/src/apps/mobile/ios/OpenBitFunUITests/RemoteCodeSessionSendUITests.swift +++ b/src/apps/mobile/ios/OpenBitFunUITests/RemoteCodeSessionSendUITests.swift @@ -956,11 +956,13 @@ final class StreamingPresentationUITests: XCTestCase { XCTAssertTrue(timestamps.firstMatch.waitForExistence(timeout: 15)) XCTAssertEqual(timestamps.count, 2) let summary = app.buttons["tool.summary.read"] + let failure = app.buttons["tool.toggle.fetch"] XCTAssertTrue(summary.exists) - XCTAssertFalse(app.buttons["tool.toggle.fetch"].exists) - summary.tap() - app.buttons["tool.toggle.fetch"].tap() - XCTAssertTrue(app.staticTexts["HTTP 404"].waitForExistence(timeout: 3)) + XCTAssertFalse(failure.exists) + tapDisclosure(summary, expanded: false) + XCTAssertTrue(failure.wait(for: \.isHittable, toEqual: true, timeout: 10)) + tapToolRow(failure) + XCTAssertTrue(app.staticTexts["HTTP 404"].waitForExistence(timeout: 10)) let capture = XCTAttachment(screenshot: app.screenshot()) capture.name = "Message times and expandable tool failure" capture.lifetime = .keepAlways @@ -1009,21 +1011,20 @@ final class StreamingPresentationUITests: XCTestCase { app.launchArguments = ["--streaming-regression", "--fixture-shell", "--open-loading-regression", "--status-regression"] app.launch() let open = app.buttons["fixture.openDelayed"] - XCTAssertTrue(open.waitForExistence(timeout: 15)) - let status = app.descendants(matching: .any)["conversation.connectionStatus"].firstMatch - XCTAssertTrue(status.exists) - XCTAssertEqual(status.frame.height, 48, accuracy: 1) + XCTAssertTrue(open.wait(for: \.isHittable, toEqual: true, timeout: 15)) + let initial = app.otherElements["conversation.session.fixture"] + XCTAssertTrue(initial.waitForExistence(timeout: 10)) open.tap() - let detail = app.descendants(matching: .any)["conversation.session.delayed"].firstMatch - XCTAssertTrue(detail.waitForExistence(timeout: 2)) - let loading = app.descendants(matching: .any)["conversation.loading"].firstMatch - XCTAssertTrue(loading.waitForExistence(timeout: 2)) - XCTAssertFalse(status.exists, "The connection strip must not compete with the loading skeleton") + let detail = app.otherElements["conversation.session.delayed"] + XCTAssertTrue(detail.waitForExistence(timeout: 10), "Navigation must occur before the device binds") + XCTAssertFalse(initial.exists) + let loading = detail.otherElements["conversation.loading"] + XCTAssertTrue(loading.waitForExistence(timeout: 5)) app.buttons["fixture.bindTarget"].tap() XCTAssertTrue(detail.exists, "Binding the selected device must preserve pending navigation") - XCTAssertTrue(loading.waitForExistence(timeout: 2)) + XCTAssertTrue(loading.exists) app.buttons["fixture.finishLoading"].tap() - XCTAssertTrue(app.staticTexts["LOADED-SESSION"].waitForExistence(timeout: 3)) + XCTAssertTrue(detail.staticTexts["LOADED-SESSION"].waitForExistence(timeout: 5)) XCTAssertFalse(loading.exists) } @@ -1035,8 +1036,8 @@ final class StreamingPresentationUITests: XCTestCase { XCTAssertTrue(task.waitForExistence(timeout: 15)) XCTAssertFalse(app.staticTexts["LIVE-CHILD-THOUGHT"].exists) XCTAssertFalse(app.buttons["subagent.toggle.empty"].isEnabled, "Empty tasks must not offer disclosure") - task.tap() - XCTAssertTrue(app.staticTexts["LIVE-CHILD-THOUGHT"].waitForExistence(timeout: 3)) + tapDisclosure(task, expanded: false) + XCTAssertTrue(app.staticTexts["LIVE-CHILD-THOUGHT"].waitForExistence(timeout: 10)) XCTAssertFalse(app.staticTexts["OLD-CHILD-THOUGHT"].exists) XCTAssertFalse(app.staticTexts["PARENT-SUMMARY-MUST-NOT-REPEAT"].exists) let preview = app.staticTexts["subagent.output.child-output"] @@ -1048,15 +1049,18 @@ final class StreamingPresentationUITests: XCTestCase { XCTAssertTrue(app.buttons["tool.toggle.child-two"].exists) XCTAssertFalse(app.buttons["tool.summary.child-one"].exists) XCTAssertFalse(app.staticTexts["NESTED-OUTPUT"].exists) - app.buttons["subagent.toggle.nested"].tap() - XCTAssertTrue(app.staticTexts["NESTED-OUTPUT"].exists) - app.buttons["subagent.toggle.nested"].tap() + let nested = app.buttons["subagent.toggle.nested"] + let nestedOutput = app.staticTexts["NESTED-OUTPUT"] + tapDisclosure(nested, expanded: false) + XCTAssertTrue(nestedOutput.waitForExistence(timeout: 10)) + tapDisclosure(nested, expanded: true) + XCTAssertTrue(nestedOutput.waitForNonExistence(timeout: 10)) app.buttons["fixture.send"].tap() XCTAssertTrue(task.label.contains("失败"), "Host failures must remain visible in the subtask header") XCTAssertTrue(preview.exists, "Completing keeps the manually opened subtask open") XCTAssertFalse(app.staticTexts["LIVE-CHILD-THOUGHT"].exists) - app.buttons["thinking.toggle.child-old"].tap() - XCTAssertTrue(app.staticTexts["OLD-CHILD-THOUGHT"].exists) + tapDisclosure(app.buttons["thinking.toggle.child-old"], expanded: false) + XCTAssertTrue(app.staticTexts["OLD-CHILD-THOUGHT"].waitForExistence(timeout: 10)) } func testCardsMatchHarmonyExpansionAndOrdering() { @@ -1065,13 +1069,14 @@ final class StreamingPresentationUITests: XCTestCase { app.launch() let task = app.buttons["subagent.toggle.task"] XCTAssertTrue(task.waitForExistence(timeout: 15)) - XCTAssertFalse(app.staticTexts["TASK-BODY"].exists, "Running tasks start collapsed") - task.tap() - XCTAssertTrue(app.staticTexts["TASK-BODY"].waitForExistence(timeout: 3)) + let taskBody = app.staticTexts["TASK-BODY"] + XCTAssertFalse(taskBody.exists, "Running tasks start collapsed") + tapDisclosure(task, expanded: false) + XCTAssertTrue(taskBody.waitForExistence(timeout: 10)) app.buttons["fixture.send"].tap() - XCTAssertTrue(app.staticTexts["TASK-BODY"].exists, "Status updates preserve the user's expansion") - task.tap() - XCTAssertFalse(app.staticTexts["TASK-BODY"].exists) + XCTAssertTrue(taskBody.exists, "Status updates preserve the user's expansion") + tapDisclosure(task, expanded: true) + XCTAssertTrue(taskBody.waitForNonExistence(timeout: 10)) let summary = app.buttons["tool.summary.one"] XCTAssertTrue(summary.exists) XCTAssertFalse(app.buttons["tool.toggle.one"].exists) @@ -1079,29 +1084,29 @@ final class StreamingPresentationUITests: XCTestCase { XCTAssertFalse(app.buttons["thinking.toggle.before"].exists) XCTAssertTrue(app.buttons["tool.toggle.running"].exists) XCTAssertTrue(app.buttons["tool.toggle.failed"].exists) - summary.tap() + tapDisclosure(summary, expanded: false) let one = app.buttons["tool.toggle.one"] let two = app.buttons["tool.toggle.two"] - XCTAssertTrue(one.waitForExistence(timeout: 3)) + XCTAssertTrue(one.waitForExistence(timeout: 10)) let before = app.buttons["thinking.toggle.before"] let between = app.buttons["thinking.toggle.between"] XCTAssertTrue(before.exists && between.exists) XCTAssertLessThan(before.frame.minY, one.frame.minY) XCTAssertLessThan(one.frame.minY, between.frame.minY) XCTAssertLessThan(between.frame.minY, two.frame.minY) - one.tap() - XCTAssertTrue(app.staticTexts["OUTPUT-one"].waitForExistence(timeout: 3)) - two.tap() - XCTAssertTrue(app.staticTexts["OUTPUT-two"].waitForExistence(timeout: 3)) + tapToolRow(one) + XCTAssertTrue(app.staticTexts["OUTPUT-one"].waitForExistence(timeout: 10)) + tapToolRow(two) + XCTAssertTrue(app.staticTexts["OUTPUT-two"].waitForExistence(timeout: 10)) XCTAssertFalse(app.staticTexts["OUTPUT-one"].exists, "Only one tool detail is expanded") XCTAssertLessThan(one.frame.minY, two.frame.minY) app.buttons["fixture.send"].tap() - XCTAssertTrue(app.buttons["tool.toggle.three"].waitForExistence(timeout: 3), + XCTAssertTrue(app.buttons["tool.toggle.three"].waitForExistence(timeout: 10), "Appending a completed tool must preserve the open summary") XCTAssertTrue(app.staticTexts["OUTPUT-two"].exists, "Appending tools must preserve the selected detail") - summary.tap() - XCTAssertFalse(one.exists) + tapDisclosure(summary, expanded: true) + XCTAssertTrue(one.waitForNonExistence(timeout: 10)) XCTAssertFalse(app.staticTexts["OUTPUT-two"].exists) XCTAssertTrue(app.staticTexts["ANSWER-AFTER-ACTIVITY"].isHittable) let capture = XCTAttachment(screenshot: app.screenshot()) @@ -1109,6 +1114,17 @@ final class StreamingPresentationUITests: XCTestCase { add(capture) } + private func tapDisclosure(_ button: XCUIElement, expanded: Bool) { + let chevron = button.images[expanded ? "chevron.up" : "chevron.down"] + XCTAssertTrue(chevron.waitForExistence(timeout: 10)) + chevron.tap() + } + + private func tapToolRow(_ button: XCUIElement) { + XCTAssertTrue(button.wait(for: \.isHittable, toEqual: true, timeout: 10)) + button.coordinate(withNormalizedOffset: CGVector(dx: 0.05, dy: 0.5)).tap() + } + func testSentUserBubbleStaysVisibleBeforeReply() { let app = XCUIApplication() app.launchArguments = ["--streaming-regression", "--user-bubble-regression"] @@ -1142,17 +1158,23 @@ final class StreamingPresentationUITests: XCTestCase { let start = app.buttons["fixture.send"] XCTAssertTrue(start.waitForExistence(timeout: 15)) start.tap() - let thought = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "Thinking segment 12")).firstMatch + let showAnswer = app.buttons["fixture.showThinkingAnswer"] + XCTAssertTrue(showAnswer.wait(for: \.isEnabled, toEqual: true, timeout: 20)) + let thought = app.staticTexts["thinking.content.thought"] XCTAssertTrue(thought.waitForExistence(timeout: 10)) + XCTAssertTrue(thought.label.contains("Thinking segment 12")) XCTAssertGreaterThan(thought.frame.height, app.scrollViews.firstMatch.frame.height) - let answer = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "ANSWER-AFTER-THINKING")).firstMatch + showAnswer.tap() + let answer = app.staticTexts["ANSWER-AFTER-THINKING"] XCTAssertTrue(answer.waitForExistence(timeout: 10)) let folded = NSPredicate { _, _ in !thought.exists } expectation(for: folded, evaluatedWith: nil) waitForExpectations(timeout: 5) - XCTAssertTrue(answer.isHittable) + XCTAssertTrue(answer.wait(for: \.isHittable, toEqual: true, timeout: 5), + "The answer should scroll into view after the thinking block folds") + app.buttons["fixture.finishThinkingAnswer"].tap() XCTAssertTrue(app.staticTexts["Stream finished"].waitForExistence(timeout: 10)) - XCTAssertTrue(answer.isHittable) + XCTAssertTrue(answer.wait(for: \.isHittable, toEqual: true, timeout: 5)) let capture = XCTAttachment(screenshot: app.screenshot()) capture.lifetime = .keepAlways add(capture)