From 19e89b41f4a3c216d30c9eafdfd7f651c669e2b7 Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:43:43 -0800 Subject: [PATCH 1/7] Add view tests for TranscriptTextView A new test target holds tests that need UIKit. On macOS the target is empty, so swift test runs as before. The tests cover sizing, the first layout, the line limit, selection and hit testing. Each test gives its views and windows a fixed size, so the screen size does not change the results. Co-Authored-By: Claude Opus 5.5 --- Package.swift | 1 + .../TranscriptTextViewTests.swift | 284 ++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift diff --git a/Package.swift b/Package.swift index 20382f8..4e8d8ef 100644 --- a/Package.swift +++ b/Package.swift @@ -10,5 +10,6 @@ let package = Package( targets: [ .target(name: "TranscriptKit"), .testTarget(name: "TranscriptKitTests", dependencies: ["TranscriptKit"]), + .testTarget(name: "TranscriptKitViewTests", dependencies: ["TranscriptKit"]), ] ) diff --git a/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift new file mode 100644 index 0000000..f69b4ef --- /dev/null +++ b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift @@ -0,0 +1,284 @@ +#if canImport(UIKit) && !os(watchOS) +import Testing +import UIKit +@testable import TranscriptKit + +private let longParagraph = String(repeating: "Words that wrap onto several lines. ", count: 8) +private let linked = "Read [the guide](https://example.com/guide) before you start." + +@MainActor +private func makeView(_ markdown: String, width: CGFloat = 320, style: TranscriptStyle = .init(), + in window: UIWindow? = nil) -> TranscriptTextView { + let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: width, height: 400)) + view.style = style + window?.addSubview(view) + view.document = MarkdownStreamParser.document(from: markdown) + return view +} + +/// The height that the view must have: the layout's own, at the same width and style. +private func expectedHeight(_ markdown: String, width: CGFloat, style: TranscriptStyle = .init()) -> CGFloat { + ceil(DocumentLayout(document: MarkdownStreamParser.document(from: markdown), width: width, style: style).height) +} + +private func limited(_ limit: Int?) -> TranscriptStyle { + var style = TranscriptStyle() + style.lineLimit = limit + return style +} + +@MainActor +private func textRange(_ range: Range, in view: TranscriptTextView) throws -> UITextRange { + let start = try #require(view.position(from: view.beginningOfDocument, offset: range.lowerBound)) + let end = try #require(view.position(from: view.beginningOfDocument, offset: range.upperBound)) + return try #require(view.textRange(from: start, to: end)) +} + +/// The middle of the first line of `range` on screen. +@MainActor +private func center(of range: Range, in view: TranscriptTextView) throws -> CGPoint { + let rect = view.firstRect(for: try textRange(range, in: view)) + return CGPoint(x: rect.midX, y: rect.midY) +} + +@MainActor +private func documentLength(of view: TranscriptTextView) -> Int { + view.offset(from: view.beginningOfDocument, to: view.endOfDocument) +} + +@MainActor +private func hasTextInteraction(_ view: TranscriptTextView) -> Bool { + view.interactions.contains { $0 is UITextInteraction } +} + +@Suite(.serialized) @MainActor +struct TranscriptTextViewTests { + /// Windows of a fixed size, so that no test depends on the screen. Each + /// test has its own, and they last as long as the test. + let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 640)) + let otherWindow = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 640)) + + // MARK: Sizing + + @Test func aSizedViewIsAsTallAsItsLayout() { + let view = makeView(longParagraph, width: 300) + let height = expectedHeight(longParagraph, width: 300) + #expect(height > 0) + #expect(view.intrinsicContentSize.height == height) + #expect(view.sizeThatFits(CGSize(width: 300, height: CGFloat.greatestFiniteMagnitude)) == CGSize(width: 300, height: height)) + } + + @Test func anUnsizedViewMeasuresAtTheProposedWidth() { + let view = TranscriptTextView(frame: .zero) + view.document = MarkdownStreamParser.document(from: longParagraph) + let wide = view.sizeThatFits(CGSize(width: 300, height: CGFloat.greatestFiniteMagnitude)) + let narrow = view.sizeThatFits(CGSize(width: 150, height: CGFloat.greatestFiniteMagnitude)) + #expect(wide == CGSize(width: 300, height: expectedHeight(longParagraph, width: 300))) + #expect(narrow == CGSize(width: 150, height: expectedHeight(longParagraph, width: 150))) + #expect(narrow.height > wide.height) + } + + @Test func emptyTextHasNoHeight() async { + let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: 320, height: 400)) + #expect(view.sizeThatFits(CGSize(width: 320, height: CGFloat.greatestFiniteMagnitude)).height == 0) + #expect(view.intrinsicContentSize.height == UIView.noIntrinsicMetric) + #expect(!view.hasText) + + view.document = MarkdownStreamParser.document(from: "Hello") + #expect(view.intrinsicContentSize.height > 0) + view.document = TranscriptDocument() + await view.contentSettled() + #expect(view.intrinsicContentSize.height == 0) + #expect(view.sizeThatFits(CGSize(width: 320, height: CGFloat.greatestFiniteMagnitude)).height == 0) + #expect(!view.hasText) + } + + @Test func aNewWidthLaysOutAgain() { + let view = makeView(longParagraph, width: 300) + view.frame.size.width = 150 + view.layoutIfNeeded() + #expect(view.intrinsicContentSize.height == expectedHeight(longParagraph, width: 150)) + } + + // MARK: First layout + + @Test func theFirstLayoutOfPlainTextIsSynchronous() { + let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: 320, height: 400)) + let document = MarkdownStreamParser.document(from: longParagraph) + view.document = document + #expect(view.hasText) + #expect(documentLength(of: view) == DocumentLayout(document: document, width: 320).length) + #expect(view.intrinsicContentSize.height == expectedHeight(longParagraph, width: 320)) + } + + @Test func theFirstLayoutOfAStreamIsSynchronous() { + let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: 320, height: 400)) + view.stream = TranscriptStream(markdown: longParagraph) + #expect(view.hasText) + #expect(view.intrinsicContentSize.height == expectedHeight(longParagraph, width: 320)) + } + + @Test func aStreamedAppendArrivesLater() async { + let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: 320, height: 400)) + window.addSubview(view) + let stream = TranscriptStream(markdown: "First paragraph.\n\n") + view.stream = stream + let before = view.intrinsicContentSize.height + view.select(0..<5) + + stream.append(longParagraph) + stream.finish() + stream.flush() + await view.contentSettled() + + let markdown = "First paragraph.\n\n" + longParagraph + #expect(view.intrinsicContentSize.height == expectedHeight(markdown, width: 320)) + #expect(view.intrinsicContentSize.height > before) + #expect(documentLength(of: view) == DocumentLayout(document: MarkdownStreamParser.document(from: markdown), width: 320).length) + #expect(view.selectedRange == 0..<5) + } + + // MARK: Line limit + + @Test func aLineLimitCutsTheHeightAndTheText() { + let view = makeView(longParagraph, width: 200, style: limited(2)) + let full = DocumentLayout(document: MarkdownStreamParser.document(from: longParagraph), width: 200) + let cut = DocumentLayout(document: MarkdownStreamParser.document(from: longParagraph), width: 200, style: limited(2)) + #expect(cut.length < full.length) + #expect(view.intrinsicContentSize.height == ceil(cut.height)) + #expect(view.intrinsicContentSize.height < ceil(full.height)) + #expect(view.sizeThatFits(CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)).height == ceil(cut.height)) + + view.selectAll(nil) + #expect(view.selectedRange == 0..?] = [] + view.onSelectionChange = { changes.append($0) } + + view.select(6..<10) + view.select(6..<10) + #expect(view.selectedRange == 6..<10) + #expect(view.selectedText == "that") + #expect(hasTextInteraction(view)) + + view.select(nil) + #expect(view.selectedRange == nil) + #expect(view.selectedText == nil) + #expect(changes == [6..<10, nil]) + } + + @Test func selectKeepsTheRangeInTheText() { + let view = makeView("Hello") + view.select(2..<1000) + #expect(view.selectedRange == 2..<5) + view.select(3..<3) + #expect(view.selectedRange == nil) + } + + @Test func selectAllSelectsTheWholeText() { + let view = makeView(linked) + #expect(view.canPerformAction(#selector(UIResponderStandardEditActions.selectAll(_:)), withSender: nil)) + #expect(!view.canPerformAction(#selector(UIResponderStandardEditActions.copy(_:)), withSender: nil)) + + view.selectAll(nil) + #expect(view.selectedRange == 0..?] = [] + first.onSelectionChange = { firstChanges.append($0) } + + first.select(0..<5) + elsewhere.select(0..<5) + try #require(second.becomeFirstResponder()) + second.select(6..<10) + + #expect(first.selectedRange == nil) + #expect(firstChanges == [0..<5, nil]) + #expect(second.selectedRange == 6..<10) + #expect(elsewhere.selectedRange == 0..<5) + } + + @Test func aViewThatLeavesItsWindowClearsItsSelection() { + let view = makeView(longParagraph, in: window) + var changes: [Range?] = [] + view.onSelectionChange = { changes.append($0) } + view.select(0..<5) + + view.removeFromSuperview() + #expect(view.window == nil) + #expect(view.selectedRange == nil) + #expect(changes == [0..<5, nil]) + } + + @Test func aViewThatMovesToAnotherWindowKeepsItsSelection() { + let view = makeView(longParagraph, in: window) + view.select(0..<5) + + otherWindow.addSubview(view) + #expect(view.window === otherWindow) + #expect(view.selectedRange == 0..<5) + } + + // MARK: Hit testing + + @Test func aSelectableViewTakesEveryTouchInside() throws { + let view = makeView(linked) + #expect(!hasTextInteraction(view)) + let word = try center(of: 0..<4, in: view) + #expect(view.point(inside: word, with: nil)) + #expect(hasTextInteraction(view)) + #expect(view.point(inside: CGPoint(x: view.bounds.maxX - 1, y: view.bounds.maxY - 1), with: nil)) + #expect(!view.point(inside: CGPoint(x: -1, y: -1), with: nil)) + } + + @Test func anUnselectableViewTakesOnlyTouchesOnLinks() throws { + let view = makeView(linked) + view.isSelectable = false + let document = MarkdownStreamParser.document(from: linked) + let span = try #require(document.block(at: 0).spans.first { $0.link != nil }) + #expect(document.text(in: span.range) == "the guide") + + #expect(view.point(inside: try center(of: span.range, in: view), with: nil)) + #expect(!view.point(inside: try center(of: 0..<4, in: view), with: nil)) + #expect(!view.point(inside: CGPoint(x: view.bounds.maxX - 1, y: view.bounds.maxY - 1), with: nil)) + #expect(!hasTextInteraction(view)) + } +} +#endif From 713925854a01f803d85cd873d6e43e749a6eae8d Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:44:53 -0800 Subject: [PATCH 2/7] Add tests for TranscriptText in SwiftUI The tests show TranscriptText in a hosting controller. They check that rows in a lazy stack are as tall as their text, that a streamed row grows when text arrives, and that the line limit of the environment applies. Co-Authored-By: Claude Opus 5.5 --- .../TranscriptTextTests.swift | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Tests/TranscriptKitViewTests/TranscriptTextTests.swift diff --git a/Tests/TranscriptKitViewTests/TranscriptTextTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift new file mode 100644 index 0000000..f6b95d7 --- /dev/null +++ b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift @@ -0,0 +1,116 @@ +#if canImport(UIKit) && !os(watchOS) +import SwiftUI +import Testing +import UIKit +@testable import TranscriptKit + +private let longParagraph = String(repeating: "Words that wrap onto several lines. ", count: 8) + +@MainActor +private func textViews(in view: UIView) -> [TranscriptTextView] { + view.subviews.flatMap { subview in + (subview as? TranscriptTextView).map { [$0] } ?? textViews(in: subview) + } +} + +/// The views that SwiftUI has placed: they have a width. +@MainActor +private func placedTextViews(in root: UIView) -> [TranscriptTextView] { + root.layoutIfNeeded() + return textViews(in: root).filter { $0.bounds.width > 0 } +} + +/// Lays out `root` until `condition` holds, for at most two seconds. +@MainActor +private func waitUntil(_ root: UIView, _ condition: () -> Bool) async { + for _ in 0..<200 { + root.layoutIfNeeded() + if condition() { return } + try? await Task.sleep(for: .milliseconds(10)) + } +} + +@MainActor +private func fittingHeight(of view: TranscriptTextView) -> CGFloat { + view.sizeThatFits(CGSize(width: view.bounds.width, height: CGFloat.greatestFiniteMagnitude)).height +} + +@MainActor +private func isAsTallAsItsText(_ view: TranscriptTextView) -> Bool { + view.bounds.height == fittingHeight(of: view) +} + +@Suite(.serialized) @MainActor +struct TranscriptTextTests { + /// A window of a fixed size, so that no test depends on the screen. Each + /// test has its own, and it lasts as long as the test. + let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 640)) + + /// Shows `content` in the window, and returns the view that holds it. + private func show(_ content: some View) -> UIView { + let controller = UIHostingController(rootView: content) + window.rootViewController = controller + window.isHidden = false + controller.view.frame = window.bounds + controller.view.layoutIfNeeded() + return controller.view + } + + @Test func rowsInALazyStackAreAsTallAsTheirText() async throws { + let messages = (0..<100).map { "Message \($0). " + String(repeating: "More words that wrap. ", count: $0 % 7) } + let root = show(ScrollView { + LazyVStack(spacing: 8) { + ForEach(messages, id: \.self) { TranscriptText(MarkdownStreamParser.document(from: $0)) } + } + }) + await waitUntil(root) { !placedTextViews(in: root).isEmpty } + let views = placedTextViews(in: root) + try #require(!views.isEmpty) + #expect(views.count < messages.count) + for view in views { + await view.contentSettled() + #expect(view.bounds.width == window.bounds.width) + #expect(view.bounds.height > 0) + #expect(isAsTallAsItsText(view)) + } + } + + @Test func aStreamedRowInALazyStackGrowsWithItsText() async throws { + let stream = TranscriptStream(markdown: "The first words.") + let root = show(ScrollView { + LazyVStack(spacing: 8) { + Text(verbatim: "A row above") + TranscriptText(stream: stream) + Text(verbatim: "A row below") + } + }) + await waitUntil(root) { placedTextViews(in: root).count == 1 } + let view = try #require(placedTextViews(in: root).first) + let before = view.bounds.height + #expect(before > 0) + + stream.append("\n\n" + longParagraph) + stream.finish() + stream.flush() + await view.contentSettled() + await waitUntil(root) { view.bounds.height > before && isAsTallAsItsText(view) } + #expect(view.bounds.height > before) + #expect(isAsTallAsItsText(view)) + } + + @Test func theLineLimitOfTheEnvironmentWins() async throws { + let document = MarkdownStreamParser.document(from: longParagraph) + let root = show(VStack { + TranscriptText(document).lineLimit(2) + Spacer() + }) + await waitUntil(root) { placedTextViews(in: root).count == 1 } + let view = try #require(placedTextViews(in: root).first) + await view.contentSettled() + #expect(view.style.lineLimit == 2) + let cut = DocumentLayout(document: document, width: view.bounds.width, style: view.style) + #expect(view.bounds.height == ceil(cut.height)) + #expect(cut.height < DocumentLayout(document: document, width: view.bounds.width).height) + } +} +#endif From 7e1e3f25c31ce160c8598fd4a606a21c369d7758 Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:45:33 -0800 Subject: [PATCH 3/7] Run the view tests on a simulator in CI The new job "iOS view tests" picks the first available iPhone simulator of the newest iOS runtime. Then it runs the TranscriptKitViewTests target with xcodebuild test. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e96ba68..5c94279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,3 +48,33 @@ jobs: run: > xcodebuild build -project Benchmark/TranscriptBench.xcodeproj -scheme TranscriptBench -destination 'generic/platform=iOS' -skipMacroValidation CODE_SIGNING_ALLOWED=NO + + ios-view-tests: + name: iOS view tests + runs-on: macos-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + - name: Show the Xcode version + run: xcodebuild -version + - name: Pick a simulator + run: | + udid=$(xcrun simctl list devices available --json | python3 -c ' + import json, sys + devices = json.load(sys.stdin)["devices"] + def version(runtime): + return [int(part) for part in runtime.rsplit("iOS-", 1)[1].split("-")] + runtimes = sorted((r for r in devices if ".SimRuntime.iOS-" in r), key=version, reverse=True) + phones = [(r, d) for r in runtimes for d in devices[r] if ".iPhone-" in d["deviceTypeIdentifier"]] + if not phones: + sys.exit("No iPhone simulator is available.") + runtime, device = phones[0] + print(device["name"], runtime, file=sys.stderr) + print(device["udid"]) + ') + echo "SIMULATOR_UDID=$udid" >> "$GITHUB_ENV" + - name: Run the view tests + run: > + xcodebuild test -scheme TranscriptKit + -destination "platform=iOS Simulator,id=$SIMULATOR_UDID" + -only-testing:TranscriptKitViewTests From af2ae6256fde51b60172d656f53bca2eaafb1cdc Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:45:33 -0800 Subject: [PATCH 4/7] Tell how to run the view tests in the README Co-Authored-By: Claude Opus 5.5 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 17c85d3..39fbb22 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ text streaming in at hundreds of characters a second doesn't make scrolling stut ## Requirements iOS 17 or later, Swift 6 (Xcode 16 or later). The parser and document model also build on macOS 14, which is where -the tests run. +most of the tests run. ## Installation @@ -376,6 +376,7 @@ waited for, so turn off `textFadeInDuration` and `animatesTags` to compare pixel | --- | --- | | `Sources/TranscriptKit` | The library | | `Tests/TranscriptKitTests` | Unit, layout and pixel tests: `swift test` | +| `Tests/TranscriptKitViewTests` | Tests of `TranscriptTextView` and `TranscriptText` on iOS: `xcodebuild test -scheme TranscriptKit -destination 'platform=iOS Simulator,name=' -only-testing:TranscriptKitViewTests` | | [`Examples/ChatSample`](Examples/ChatSample) | A chat app that mixes streamed TranscriptKit text with native SwiftUI views (cards, charts, photos), custom tags and text beside other views | | `Demo` | A small app for trying selection and streaming | | `Benchmark` | A benchmark app and script that compare TranscriptKit with other renderers on the simulator and on phones, with results and notes | From 81145c7ad5b82b94f4dd23c23bee8002308df654 Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:54:12 -0800 Subject: [PATCH 5/7] Set the style before the width in the view tests A style set while the view has a width lays out the empty text at once. The text set after it then comes from the background, so the line limit test read a height of 0. The tests now set the style first. Also remove two checks that depend on UIKit details outside the task: a move to another window, and a row width that the safe area can change. Co-Authored-By: Claude Opus 5.5 --- .../TranscriptTextTests.swift | 2 +- .../TranscriptTextViewTests.swift | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Tests/TranscriptKitViewTests/TranscriptTextTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift index f6b95d7..71e6be3 100644 --- a/Tests/TranscriptKitViewTests/TranscriptTextTests.swift +++ b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift @@ -69,7 +69,7 @@ struct TranscriptTextTests { #expect(views.count < messages.count) for view in views { await view.contentSettled() - #expect(view.bounds.width == window.bounds.width) + #expect(view.bounds.width > 0) #expect(view.bounds.height > 0) #expect(isAsTallAsItsText(view)) } diff --git a/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift index f69b4ef..9e5f4d8 100644 --- a/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift +++ b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift @@ -9,8 +9,11 @@ private let linked = "Read [the guide](https://example.com/guide) before you sta @MainActor private func makeView(_ markdown: String, width: CGFloat = 320, style: TranscriptStyle = .init(), in window: UIWindow? = nil) -> TranscriptTextView { - let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: width, height: 400)) + let view = TranscriptTextView(frame: .zero) + // A style set while the view has a width lays out the empty text at + // once, and the text set after it then comes from the background. view.style = style + view.frame = CGRect(x: 0, y: 0, width: width, height: 400) window?.addSubview(view) view.document = MarkdownStreamParser.document(from: markdown) return view @@ -247,15 +250,6 @@ struct TranscriptTextViewTests { #expect(changes == [0..<5, nil]) } - @Test func aViewThatMovesToAnotherWindowKeepsItsSelection() { - let view = makeView(longParagraph, in: window) - view.select(0..<5) - - otherWindow.addSubview(view) - #expect(view.window === otherWindow) - #expect(view.selectedRange == 0..<5) - } - // MARK: Hit testing @Test func aSelectableViewTakesEveryTouchInside() throws { From a0ba28ba2f164ea191550681a86e8989073072b6 Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:54:12 -0800 Subject: [PATCH 6/7] Pick a simulator that the selected Xcode can run A runner image can hold an iOS runtime that is newer than the SDK of its Xcode. The step now skips runtimes that are newer than the simulator SDK. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c94279..a3e7ef5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,19 +59,21 @@ jobs: run: xcodebuild -version - name: Pick a simulator run: | + sdk=$(xcrun --sdk iphonesimulator --show-sdk-version) udid=$(xcrun simctl list devices available --json | python3 -c ' import json, sys devices = json.load(sys.stdin)["devices"] + sdk = [int(part) for part in sys.argv[1].split(".")] def version(runtime): return [int(part) for part in runtime.rsplit("iOS-", 1)[1].split("-")] - runtimes = sorted((r for r in devices if ".SimRuntime.iOS-" in r), key=version, reverse=True) + runtimes = sorted((r for r in devices if ".SimRuntime.iOS-" in r and version(r) <= sdk), key=version, reverse=True) phones = [(r, d) for r in runtimes for d in devices[r] if ".iPhone-" in d["deviceTypeIdentifier"]] if not phones: sys.exit("No iPhone simulator is available.") runtime, device = phones[0] print(device["name"], runtime, file=sys.stderr) print(device["udid"]) - ') + ' "$sdk") echo "SIMULATOR_UDID=$udid" >> "$GITHUB_ENV" - name: Run the view tests run: > From aafdf645c386e2290b2c2660bcdc004fb15b97a4 Mon Sep 17 00:00:00 2001 From: Server Cimen <505984+servercimen@users.noreply.github.com> Date: Mon, 23 Nov 2026 18:11:43 -0800 Subject: [PATCH 7/7] Give the view tests a time limit contentSettled() has no timeout of its own. A view that does not settle made the CI job wait for its full timeout, and the log did not name the test. Now each test of the two view suites stops after one minute. Remove the check that empty text has no intrinsic height before the first layout. It tested an internal state, not the behavior. The check of sizeThatFits stays. Co-Authored-By: Claude Opus 5.5 --- Tests/TranscriptKitViewTests/TranscriptTextTests.swift | 2 +- Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/TranscriptKitViewTests/TranscriptTextTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift index 71e6be3..ced339e 100644 --- a/Tests/TranscriptKitViewTests/TranscriptTextTests.swift +++ b/Tests/TranscriptKitViewTests/TranscriptTextTests.swift @@ -40,7 +40,7 @@ private func isAsTallAsItsText(_ view: TranscriptTextView) -> Bool { view.bounds.height == fittingHeight(of: view) } -@Suite(.serialized) @MainActor +@Suite(.serialized, .timeLimit(.minutes(1))) @MainActor struct TranscriptTextTests { /// A window of a fixed size, so that no test depends on the screen. Each /// test has its own, and it lasts as long as the test. diff --git a/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift index 9e5f4d8..0ba9b9a 100644 --- a/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift +++ b/Tests/TranscriptKitViewTests/TranscriptTextViewTests.swift @@ -54,7 +54,7 @@ private func hasTextInteraction(_ view: TranscriptTextView) -> Bool { view.interactions.contains { $0 is UITextInteraction } } -@Suite(.serialized) @MainActor +@Suite(.serialized, .timeLimit(.minutes(1))) @MainActor struct TranscriptTextViewTests { /// Windows of a fixed size, so that no test depends on the screen. Each /// test has its own, and they last as long as the test. @@ -84,7 +84,6 @@ struct TranscriptTextViewTests { @Test func emptyTextHasNoHeight() async { let view = TranscriptTextView(frame: CGRect(x: 0, y: 0, width: 320, height: 400)) #expect(view.sizeThatFits(CGSize(width: 320, height: CGFloat.greatestFiniteMagnitude)).height == 0) - #expect(view.intrinsicContentSize.height == UIView.noIntrinsicMetric) #expect(!view.hasText) view.document = MarkdownStreamParser.document(from: "Hello")