Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

feat(meeting): live captions as solidifying chat bubbles

Shreeraman A Ke43cadb111bb
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift
index c0923381..cfb337ab 100644
--- a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveModels.swift
@@ -24,13 +24,26 @@ nonisolated struct MeetingLiveUtterance: Identifiable, Sendable, Equatable {
var end: TimeInterval
}
+/// `id` is minted at the turn's first partial and reused as the `MeetingLiveUtterance.id` at EOU,
+/// so SwiftUI keeps one continuous row identity as the bubble "solidifies".
+nonisolated struct MeetingLivePartial: Sendable, Equatable, Identifiable {
+ var id: UUID
+ var text: String
+ var start: TimeInterval
+}
+
/// In-memory only. Never written into `MeetingSession.transcriptSegments`, so it can never reach
/// the manifest, Copy Transcript, or Export — those all read a `MeetingSession` value, a type this
/// struct cannot become.
nonisolated struct MeetingLiveTranscriptSnapshot: Sendable, Equatable {
+ private static let finalizedTurnIDCap = 64
+
var utterances: [MeetingLiveUtterance] = []
- var partials: [MeetingLiveSpeaker: String] = [:]
+ var partials: [MeetingLiveSpeaker: MeetingLivePartial] = [:]
var availability: MeetingLiveAvailability = .unavailable(reason: "Live captions have not started.")
+ /// Turn IDs whose EOU already fired — a partial for one of these is a stale, out-of-order
+ /// arrival that must not resurrect a bubble. Oldest-first so eviction trims from the front.
+ private(set) var finalizedTurnIDs: [UUID] = []
static let empty = MeetingLiveTranscriptSnapshot()
@@ -40,20 +53,38 @@ nonisolated struct MeetingLiveTranscriptSnapshot: Sendable, Equatable {
var copy = self
let index = copy.utterances.firstIndex { $0.start > utterance.start } ?? copy.utterances.count
copy.utterances.insert(utterance, at: index)
+ copy.markFinalized(utterance.id)
return copy
}
- /// Each engine returns the whole growing partial, not a delta — this replaces, never appends.
- func settingPartial(_ text: String?, for speaker: MeetingLiveSpeaker) -> MeetingLiveTranscriptSnapshot {
+ /// Replaces, never appends — and drops a partial whose turn already finalized.
+ func settingPartial(_ partial: MeetingLivePartial?, for speaker: MeetingLiveSpeaker) -> MeetingLiveTranscriptSnapshot {
var copy = self
- if let text, !text.isEmpty {
- copy.partials[speaker] = text
+ if let partial, !partial.text.isEmpty {
+ guard !copy.finalizedTurnIDs.contains(partial.id) else { return copy }
+ copy.partials[speaker] = partial
} else {
copy.partials.removeValue(forKey: speaker)
}
return copy
}
+ /// Finalizes a turn without an utterance — the echo-suppression path, where the bubble is
+ /// discarded rather than solidified.
+ func markingFinalized(_ id: UUID) -> MeetingLiveTranscriptSnapshot {
+ var copy = self
+ copy.markFinalized(id)
+ return copy
+ }
+
+ private mutating func markFinalized(_ id: UUID) {
+ guard !self.finalizedTurnIDs.contains(id) else { return }
+ self.finalizedTurnIDs.append(id)
+ if self.finalizedTurnIDs.count > Self.finalizedTurnIDCap {
+ self.finalizedTurnIDs.removeFirst(self.finalizedTurnIDs.count - Self.finalizedTurnIDCap)
+ }
+ }
+
func settingAvailability(_ availability: MeetingLiveAvailability) -> MeetingLiveTranscriptSnapshot {
var copy = self
copy.availability = availability
@@ -61,6 +92,37 @@ nonisolated struct MeetingLiveTranscriptSnapshot: Sendable, Equatable {
}
}
+/// Pure row composition for the live captions card: finalized turns in transcript order, then
+/// active partials bottom-pinned by turn start, so a solidifying bubble keeps its row identity.
+nonisolated enum MeetingLiveBubbleComposer {
+ nonisolated struct Row: Identifiable, Equatable {
+ var id: UUID
+ var speaker: MeetingLiveSpeaker
+ var text: String
+ var isPartial: Bool
+ var showsLabel: Bool
+ }
+
+ static func rows(for snapshot: MeetingLiveTranscriptSnapshot) -> [Row] {
+ var rows = snapshot.utterances.map {
+ Row(id: $0.id, speaker: $0.speaker, text: $0.text, isPartial: false, showsLabel: false)
+ }
+ let activePartials = [MeetingLiveSpeaker.you, .them]
+ .compactMap { speaker in snapshot.partials[speaker].map { (speaker, $0) } }
+ .sorted { $0.1.start < $1.1.start }
+ for (speaker, partial) in activePartials {
+ rows.append(Row(id: partial.id, speaker: speaker, text: partial.text, isPartial: true, showsLabel: false))
+ }
+
+ var previousSpeaker: MeetingLiveSpeaker?
+ for index in rows.indices {
+ rows[index].showsLabel = rows[index].speaker != previousSpeaker
+ previousSpeaker = rows[index].speaker
+ }
+ return rows
+ }
+}
+
nonisolated enum MeetingLiveTimeConversion {
/// Mirrors the batch pipeline: session time is capture PTS relative to the capture origin,
/// clamped at zero. Never derived from converted-sample counts or wall-clock arrival time.
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift
index 14f8df62..4c2f371c 100644
--- a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTrackEngine.swift
@@ -14,8 +14,8 @@ import os
/// (never from the SCStream callback itself). A polling drain loop pulls off the bounded queue and
/// does all FluidAudio work on this actor, off the capture path entirely.
actor MeetingLiveTrackEngine {
- typealias PartialHandler = @Sendable (MeetingAudioTrackKind, String, CMTime, CMTime) -> Void
- typealias UtteranceHandler = @Sendable (MeetingAudioTrackKind, String, CMTime, CMTime) -> Void
+ typealias PartialHandler = @Sendable (MeetingAudioTrackKind, UUID, String, CMTime, CMTime) -> Void
+ typealias UtteranceHandler = @Sendable (MeetingAudioTrackKind, UUID, String, CMTime, CMTime) -> Void
typealias DegradedHandler = @Sendable (MeetingAudioTrackKind, String) -> Void
typealias ReadyHandler = @Sendable (MeetingAudioTrackKind) -> Void
@@ -36,6 +36,7 @@ actor MeetingLiveTrackEngine {
private var converter: AVAudioConverter?
private var converterSourceFormat: AVAudioFormat?
private var utteranceStartPTS: CMTime?
+ private var utteranceTurnID: UUID?
private var lastConsumedPTS: CMTime?
private var currentFeedPTS: CMTime?
private var lastUtteranceEndPTS: CMTime?
@@ -229,27 +230,30 @@ actor MeetingLiveTrackEngine {
// Backdating must not reach behind the utterance that just closed, or consecutive turns
// render as overlapping spans.
self.utteranceStartPTS = self.lastUtteranceEndPTS.map { max(backdated, $0) } ?? backdated
+ self.utteranceTurnID = UUID()
}
- guard let start = self.utteranceStartPTS else { return }
+ guard let start = self.utteranceStartPTS, let turnID = self.utteranceTurnID else { return }
let end = self.lastConsumedPTS ?? start
self.diagPartials += 1
if self.diagPartials % 10 == 1 {
self.diag("partial #\(self.diagPartials) chars=\(text.count) tail=…\(String(text.suffix(60)))")
}
- self.onPartial?(self.kind, text, start, end)
+ self.onPartial?(self.kind, turnID, text, start, end)
}
private func handleEOU(_ text: String) async {
let start = self.utteranceStartPTS
let end = self.lastConsumedPTS ?? start
+ let turnID = self.utteranceTurnID
let now = ProcessInfo.processInfo.systemUptime
let gap = self.diagLastEouUptime.map { now - $0 }
self.diagLastEouUptime = now
self.utteranceStartPTS = nil
+ self.utteranceTurnID = nil
await self.manager.reset()
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return }
- guard let start, let end else {
+ guard let start, let end, let turnID else {
self.diag("EOU fired but no start PTS — dropped (chars=\(text.count))")
return
}
@@ -261,7 +265,7 @@ actor MeetingLiveTrackEngine {
gap.map { String(format: "%.1fs", $0) } ?? "first",
trimmed
))
- self.onUtterance?(self.kind, trimmed, start, end)
+ self.onUtterance?(self.kind, turnID, trimmed, start, end)
}
/// A saturated queue sheds many samples in a burst. Recording one pending resync instead of
@@ -282,6 +286,7 @@ actor MeetingLiveTrackEngine {
private func resetUtterance() async {
self.utteranceStartPTS = nil
+ self.utteranceTurnID = nil
self.lastConsumedPTS = nil
await self.manager.reset()
}
diff --git a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift
index c38847d1..fea11d56 100644
--- a/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift
+++ b/Sources/Fluid/Services/Meeting/LiveTranscription/MeetingLiveTranscriptionCoordinator.swift
@@ -133,11 +133,11 @@ final nonisolated class MeetingLiveTranscriptionCoordinator: @unchecked Sendable
Task { [weak self] in
guard let self else { return }
await engine.configure(
- onPartial: { [weak self] kind, text, start, end in
- self?.handlePartial(kind: kind, text: text, start: start, end: end)
+ onPartial: { [weak self] kind, id, text, start, end in
+ self?.handlePartial(kind: kind, id: id, text: text, start: start, end: end)
},
- onUtterance: { [weak self] kind, text, start, end in
- self?.handleUtterance(kind: kind, text: text, start: start, end: end)
+ onUtterance: { [weak self] kind, id, text, start, end in
+ self?.handleUtterance(kind: kind, id: id, text: text, start: start, end: end)
},
onDegraded: { [weak self] kind, reason in
self?.handleDegraded(kind: kind, reason: reason)
@@ -150,13 +150,16 @@ final nonisolated class MeetingLiveTranscriptionCoordinator: @unchecked Sendable
}
}
- private func handlePartial(kind: MeetingAudioTrackKind, text: String, start: CMTime, end: CMTime) {
+ private func handlePartial(kind: MeetingAudioTrackKind, id: UUID, text: String, start: CMTime, end: CMTime) {
+ guard let origin = self.originBox.current else { return }
+ let startSeconds = MeetingLiveTimeConversion.sessionSeconds(pts: start, origin: origin)
let speaker = Self.speaker(for: kind)
- self.publish { $0.settingPartial(text, for: speaker) }
+ let partial = MeetingLivePartial(id: id, text: text, start: startSeconds)
+ self.publish { $0.settingPartial(partial, for: speaker) }
}
- /// Not `private`: Phase 4 tests drive it directly.
- func handleUtterance(kind: MeetingAudioTrackKind, text: String, start: CMTime, end: CMTime) {
+ /// Not `private`: Phase 4 tests drive it directly, predating the solidify UUID — hence the default.
+ func handleUtterance(kind: MeetingAudioTrackKind, id: UUID = UUID(), text: String, start: CMTime, end: CMTime) {
guard let origin = self.originBox.current else { return }
let startSeconds = MeetingLiveTimeConversion.sessionSeconds(pts: start, origin: origin)
let endSeconds = MeetingLiveTimeConversion.sessionSeconds(pts: end, origin: origin)
@@ -180,7 +183,7 @@ final nonisolated class MeetingLiveTranscriptionCoordinator: @unchecked Sendable
"[live/ECHO] SUPPRESSED mic utterance [\(String(format: "%.2f", startSeconds))] text=\(text)",
source: "MeetingLive"
)
- self.snapshot = self.snapshot.settingPartial(nil, for: .you)
+ self.snapshot = self.snapshot.settingPartial(nil, for: .you).markingFinalized(id)
return self.snapshot
}
DebugLogger.shared.info(
@@ -189,11 +192,11 @@ final nonisolated class MeetingLiveTranscriptionCoordinator: @unchecked Sendable
)
}
} else {
- let record = MeetingLiveUtterance(id: UUID(), speaker: .them, text: text, start: startSeconds, end: endSeconds)
+ let record = MeetingLiveUtterance(id: id, speaker: .them, text: text, start: startSeconds, end: endSeconds)
self.recentThemUtterances.append(record)
self.recentThemUtterances.removeAll { $0.end < startSeconds - Self.echoWindowSeconds }
}
- let utterance = MeetingLiveUtterance(id: UUID(), speaker: speaker, text: text, start: startSeconds, end: endSeconds)
+ let utterance = MeetingLiveUtterance(id: id, speaker: speaker, text: text, start: startSeconds, end: endSeconds)
self.snapshot = self.snapshot.inserting(utterance).settingPartial(nil, for: speaker)
return self.snapshot
}
diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swift
index 7826bf0a..69831993 100644
--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift
+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift
@@ -2271,6 +2271,8 @@ private struct MeetingLiveTranscriptCard: View {
let snapshot: MeetingLiveTranscriptSnapshot
@Environment(\.theme) private var theme
+ @Environment(\.accessibilityReduceMotion) private var reduceMotion
+ @State private var isPinnedToBottom = true
var body: some View {
ThemedCard(style: .subtle) {
@@ -2288,45 +2290,24 @@ private struct MeetingLiveTranscriptCard: View {
}
}
- if self.lines.isEmpty {
+ if self.rows.isEmpty {
Text("Listening…")
.font(self.theme.typography.bodySmall)
.foregroundStyle(self.theme.palette.secondaryText)
} else {
- ScrollViewReader { proxy in
- ScrollView {
- VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {
- ForEach(Array(self.lines.enumerated()), id: \.offset) { index, line in
- self.lineView(line)
- .id(index)
- }
- }
- }
- .frame(maxHeight: 160)
- .onChange(of: self.lines.count) {
- proxy.scrollTo(self.lines.count - 1, anchor: .bottom)
- }
- }
+ self.scrollingBubbleList
}
}
}
}
- private struct Line {
- let speaker: MeetingLiveSpeaker
- let text: String
- let isPartial: Bool
+ private var rows: [MeetingLiveBubbleComposer.Row] {
+ MeetingLiveBubbleComposer.rows(for: self.snapshot)
}
- /// Newest at the bottom; each engine's partial replaces in place rather than appending.
- private var lines: [Line] {
- var lines = self.snapshot.utterances.map { Line(speaker: $0.speaker, text: $0.text, isPartial: false) }
- for speaker: MeetingLiveSpeaker in [.you, .them] {
- if let partial = self.snapshot.partials[speaker], !partial.isEmpty {
- lines.append(Line(speaker: speaker, text: partial, isPartial: true))
- }
- }
- return lines
+ private var trailingPartialLength: Int {
+ guard let last = self.rows.last, last.isPartial else { return 0 }
+ return last.text.count
}
private var availabilityIndicator: String? {
@@ -2338,17 +2319,106 @@ private struct MeetingLiveTranscriptCard: View {
}
}
- private func lineView(_ line: Line) -> some View {
- HStack(alignment: .top, spacing: self.theme.metrics.spacing.xs) {
- Text(line.speaker == .you ? "You" : "Them")
- .font(self.theme.typography.captionStrong)
- .foregroundStyle(self.theme.palette.secondaryText)
- .frame(width: 44, alignment: .leading)
- Text(line.text)
- .font(self.theme.typography.bodySmall)
- .foregroundStyle(line.isPartial ? self.theme.palette.secondaryText : self.theme.palette.primaryText)
- .italic(line.isPartial)
+ private var scrollingBubbleList: some View {
+ let rows = self.rows
+ let rowIDs = rows.map(\.id)
+ return ScrollViewReader { proxy in
+ ZStack(alignment: .bottomTrailing) {
+ ScrollView {
+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.sm) {
+ ForEach(rows) { row in
+ MeetingLiveBubbleRow(row: row)
+ .equatable()
+ .id(row.id)
+ .transition(.opacity)
+ }
+ }
+ }
+ .animation(self.reduceMotion ? nil : .easeInOut(duration: 0.2), value: rowIDs)
+ .onScrollGeometryChange(for: Bool.self) { geometry in
+ let bottomOffset = geometry.contentSize.height - geometry.containerSize.height
+ return geometry.contentOffset.y >= bottomOffset - 24
+ } action: { _, isPinned in
+ self.isPinnedToBottom = isPinned
+ }
+ .onChange(of: rows.count) {
+ self.scrollToBottomIfPinned(proxy: proxy)
+ }
+ .onChange(of: self.trailingPartialLength) {
+ self.scrollToBottomIfPinned(proxy: proxy)
+ }
+
+ if !self.isPinnedToBottom {
+ Button {
+ self.isPinnedToBottom = true
+ self.scrollToBottom(proxy: proxy, animated: true)
+ } label: {
+ Image(systemName: "chevron.down")
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(self.theme.palette.primaryText)
+ .frame(width: 28, height: 28)
+ .background(self.theme.palette.contentBackground, in: Circle())
+ }
+ .buttonStyle(.plain)
+ .padding(6)
+ }
+ }
}
+ .frame(maxHeight: 280)
+ }
+
+ private func scrollToBottomIfPinned(proxy: ScrollViewProxy) {
+ guard self.isPinnedToBottom else { return }
+ self.scrollToBottom(proxy: proxy, animated: false)
+ }
+
+ private func scrollToBottom(proxy: ScrollViewProxy, animated: Bool) {
+ guard let lastID = self.rows.last?.id else { return }
+ guard animated, !self.reduceMotion else {
+ proxy.scrollTo(lastID, anchor: .bottom)
+ return
+ }
+ withAnimation(.easeInOut(duration: 0.2)) {
+ proxy.scrollTo(lastID, anchor: .bottom)
+ }
+ }
+}
+
+private struct MeetingLiveBubbleRow: View, Equatable {
+ let row: MeetingLiveBubbleComposer.Row
+
+ @Environment(\.theme) private var theme
+
+ static func == (lhs: MeetingLiveBubbleRow, rhs: MeetingLiveBubbleRow) -> Bool {
+ lhs.row == rhs.row
+ }
+
+ private var isYou: Bool { self.row.speaker == .you }
+
+ /// `contentBackground` reads as invisible against this card, so "Them" gets an explicit tint.
+ private var fill: Color {
+ let base = self.isYou ? self.theme.palette.accent : self.theme.palette.secondaryText
+ let strength: Double = self.isYou ? 0.10 : 0.08
+ return base.opacity(self.row.isPartial ? strength / 2 : strength)
+ }
+
+ var body: some View {
+ VStack(alignment: self.isYou ? .trailing : .leading, spacing: 4) {
+ if self.row.showsLabel {
+ Text(self.isYou ? "You" : "Them")
+ .font(self.theme.typography.captionStrong)
+ .foregroundStyle(self.isYou ? self.theme.palette.accent : self.theme.palette.secondaryText)
+ }
+ Text(self.row.text)
+ // The partial→final color swap solidifies in place; it must never animate.
+ .transaction { $0.animation = nil }
+ .meetingBubbleStyle(.live(fill: self.fill, foreground: self.row.isPartial ? self.theme.palette.secondaryText : self.theme.palette.primaryText))
+ }
+ .frame(maxWidth: .infinity, alignment: self.isYou ? .trailing : .leading)
+ .padding(self.isYou ? .leading : .trailing, 32)
+ .accessibilityElement(children: .combine)
+ .accessibilityLabel("\(self.isYou ? "You" : "Them"), \(self.row.text)")
+ .accessibilityHidden(self.row.isPartial)
}
}
@@ -3101,13 +3171,8 @@ private struct MeetingTranscriptSegmentRow: View {
self.speakerLabel
}
Text(self.segment.text)
- .font(.system(size: 15, design: .monospaced))
- .lineSpacing(5)
- .foregroundStyle(self.theme.palette.primaryText)
.textSelection(.enabled)
- .padding(.horizontal, 18)
- .padding(.vertical, 12)
- .background(self.bubbleFill, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
+ .meetingBubbleStyle(MeetingBubbleStyle.final(fill: self.bubbleFill, foreground: self.theme.palette.primaryText))
if self.segment.isEcho {
Text("probable echo")
.font(self.theme.typography.caption)
@@ -3124,13 +3189,8 @@ private struct MeetingTranscriptSegmentRow: View {
self.speakerLabel
}
Text(self.segment.text)
- .font(.system(size: 15, design: .monospaced))
- .lineSpacing(5)
- .foregroundStyle(self.theme.palette.primaryText)
.textSelection(.enabled)
- .padding(.horizontal, 18)
- .padding(.vertical, 12)
- .background(self.bubbleFill, in: RoundedRectangle(cornerRadius: 18, style: .continuous))
+ .meetingBubbleStyle(MeetingBubbleStyle.final(fill: self.bubbleFill, foreground: self.theme.palette.primaryText))
if self.segment.isEcho {
Text("probable echo")
.font(self.theme.typography.caption)
@@ -3142,3 +3202,42 @@ private struct MeetingTranscriptSegmentRow: View {
}
}
+
+/// Shared bubble look for final transcript and live captions; callers own alignment, labels, and insets.
+fileprivate struct MeetingBubbleStyle {
+ var font: Font
+ var lineSpacing: CGFloat
+ var horizontalPadding: CGFloat
+ var verticalPadding: CGFloat
+ var cornerRadius: CGFloat
+ var fill: Color
+ var foreground: Color
+
+ static func final(fill: Color, foreground: Color) -> MeetingBubbleStyle {
+ MeetingBubbleStyle(
+ font: .system(size: 15, design: .monospaced), lineSpacing: 5,
+ horizontalPadding: 18, verticalPadding: 12, cornerRadius: 18,
+ fill: fill, foreground: foreground
+ )
+ }
+
+ static func live(fill: Color, foreground: Color) -> MeetingBubbleStyle {
+ MeetingBubbleStyle(
+ font: .system(size: 13, design: .monospaced), lineSpacing: 3,
+ horizontalPadding: 12, verticalPadding: 8, cornerRadius: 12,
+ fill: fill, foreground: foreground
+ )
+ }
+}
+
+extension View {
+ fileprivate func meetingBubbleStyle(_ style: MeetingBubbleStyle) -> some View {
+ self
+ .font(style.font)
+ .lineSpacing(style.lineSpacing)
+ .foregroundStyle(style.foreground)
+ .padding(.horizontal, style.horizontalPadding)
+ .padding(.vertical, style.verticalPadding)
+ .background(style.fill, in: RoundedRectangle(cornerRadius: style.cornerRadius, style: .continuous))
+ }
+}
diff --git a/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift
index cd9fb5ee..dbe9fc23 100644
--- a/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift
+++ b/Tests/FluidDictationIntegrationTests/MeetingLiveTranscriptionTests.swift
@@ -57,27 +57,114 @@ final class MeetingLiveTranscriptSnapshotTests: XCTestCase {
XCTAssertEqual(snapshot.utterances.first?.text, "arrived second, starts early")
}
+ private func partial(_ text: String, id: UUID = UUID(), start: TimeInterval = 0) -> MeetingLivePartial {
+ MeetingLivePartial(id: id, text: text, start: start)
+ }
+
func testGrowingPartialsReplaceRatherThanConcatenate() {
+ let id = UUID()
var snapshot = MeetingLiveTranscriptSnapshot.empty
- snapshot = snapshot.settingPartial("hel", for: .you)
- snapshot = snapshot.settingPartial("hello", for: .you)
- snapshot = snapshot.settingPartial("hello there", for: .you)
- XCTAssertEqual(snapshot.partials[.you], "hello there")
+ snapshot = snapshot.settingPartial(self.partial("hel", id: id), for: .you)
+ snapshot = snapshot.settingPartial(self.partial("hello", id: id), for: .you)
+ snapshot = snapshot.settingPartial(self.partial("hello there", id: id), for: .you)
+ XCTAssertEqual(snapshot.partials[.you]?.text, "hello there")
}
func testEmptyPartialClearsTheSlot() {
var snapshot = MeetingLiveTranscriptSnapshot.empty
- snapshot = snapshot.settingPartial("hello", for: .them)
- snapshot = snapshot.settingPartial("", for: .them)
+ snapshot = snapshot.settingPartial(self.partial("hello"), for: .them)
+ snapshot = snapshot.settingPartial(nil, for: .them)
XCTAssertNil(snapshot.partials[.them])
}
func testPartialsForEachSpeakerAreIndependent() {
var snapshot = MeetingLiveTranscriptSnapshot.empty
- snapshot = snapshot.settingPartial("you partial", for: .you)
- snapshot = snapshot.settingPartial("them partial", for: .them)
- XCTAssertEqual(snapshot.partials[.you], "you partial")
- XCTAssertEqual(snapshot.partials[.them], "them partial")
+ snapshot = snapshot.settingPartial(self.partial("you partial"), for: .you)
+ snapshot = snapshot.settingPartial(self.partial("them partial"), for: .them)
+ XCTAssertEqual(snapshot.partials[.you]?.text, "you partial")
+ XCTAssertEqual(snapshot.partials[.them]?.text, "them partial")
+ }
+
+ func testStalePartialAfterFinalizeIsDropped() {
+ let id = UUID()
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.inserting(self.utterance(.you, "final text", start: 0, end: 1))
+ snapshot = snapshot.markingFinalized(id)
+ snapshot = snapshot.settingPartial(self.partial("resurrected", id: id), for: .you)
+ XCTAssertNil(snapshot.partials[.you])
+ }
+
+ func testEchoSuppressionFinalizesTurnWithoutUtterance() {
+ let id = UUID()
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.settingPartial(self.partial("in flight", id: id), for: .you)
+ snapshot = snapshot.settingPartial(nil, for: .you).markingFinalized(id)
+ XCTAssertNil(snapshot.partials[.you])
+ XCTAssertTrue(snapshot.utterances.isEmpty)
+
+ let late = snapshot.settingPartial(self.partial("late arrival", id: id), for: .you)
+ XCTAssertNil(late.partials[.you], "a partial for an echo-suppressed turn must not resurrect")
+ }
+
+ func testFinalizedTurnIDCapEvictsOldestWithoutBreakingRecentDedup() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ var ids: [UUID] = []
+ for index in 0..<100 {
+ let id = UUID()
+ ids.append(id)
+ snapshot = snapshot.inserting(self.utterance(.you, "turn \(index)", start: TimeInterval(index), end: TimeInterval(index) + 1))
+ snapshot = snapshot.markingFinalized(id)
+ }
+ let oldest = ids[0]
+ let recent = ids[ids.count - 1]
+ XCTAssertFalse(snapshot.finalizedTurnIDs.contains(oldest), "cap must evict the oldest id")
+ let staleOldPartial = snapshot.settingPartial(self.partial("should not be dropped by cap logic", id: oldest), for: .you)
+ XCTAssertNotNil(staleOldPartial.partials[.you], "an evicted id is no longer recognized as stale")
+
+ let staleRecentPartial = snapshot.settingPartial(self.partial("still dropped", id: recent), for: .you)
+ XCTAssertNil(staleRecentPartial.partials[.you], "a recently finalized id must still be recognized as stale")
+ }
+}
+
+final class MeetingLiveBubbleComposerTests: XCTestCase {
+ private func utterance(_ speaker: MeetingLiveSpeaker, _ text: String, start: TimeInterval, end: TimeInterval, id: UUID = UUID()) -> MeetingLiveUtterance {
+ MeetingLiveUtterance(id: id, speaker: speaker, text: text, start: start, end: end)
+ }
+
+ func testFinalizedThenBottomPinnedPartialsOrderedByStart() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.inserting(self.utterance(.you, "hello", start: 0, end: 1))
+ snapshot = snapshot.settingPartial(MeetingLivePartial(id: UUID(), text: "them partial", start: 5), for: .them)
+ snapshot = snapshot.settingPartial(MeetingLivePartial(id: UUID(), text: "you partial", start: 3), for: .you)
+
+ let rows = MeetingLiveBubbleComposer.rows(for: snapshot)
+ XCTAssertEqual(rows.map(\.text), ["hello", "you partial", "them partial"])
+ XCTAssertEqual(rows.map(\.isPartial), [false, true, true])
+ XCTAssertEqual(rows.map(\.showsLabel), [true, false, true])
+ }
+
+ func testShowsLabelIsFalseWhenSpeakerRepeatsAcrossPartial() {
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.inserting(self.utterance(.you, "first", start: 0, end: 1))
+ snapshot = snapshot.settingPartial(MeetingLivePartial(id: UUID(), text: "still talking", start: 2), for: .you)
+
+ let rows = MeetingLiveBubbleComposer.rows(for: snapshot)
+ XCTAssertEqual(rows.map(\.showsLabel), [true, false])
+ }
+
+ func testSolidifyKeepsRowIdentityStable() {
+ let turnID = UUID()
+ var snapshot = MeetingLiveTranscriptSnapshot.empty
+ snapshot = snapshot.settingPartial(MeetingLivePartial(id: turnID, text: "in flight text", start: 0), for: .you)
+ let partialRows = MeetingLiveBubbleComposer.rows(for: snapshot)
+ XCTAssertEqual(partialRows.first?.id, turnID)
+ XCTAssertEqual(partialRows.first?.isPartial, true)
+
+ snapshot = snapshot.inserting(self.utterance(.you, "in flight text finalized", start: 0, end: 2, id: turnID))
+ .settingPartial(nil, for: .you)
+ let finalRows = MeetingLiveBubbleComposer.rows(for: snapshot)
+ XCTAssertEqual(finalRows.first?.id, turnID)
+ XCTAssertEqual(finalRows.first?.isPartial, false)
}
}
@@ -203,7 +290,7 @@ final class MeetingLiveProvisionalContainmentTests: XCTestCase {
// but nothing ever threads it into the exporter or the session's segments.
let liveSnapshot = MeetingLiveTranscriptSnapshot.empty
.inserting(MeetingLiveUtterance(id: UUID(), speaker: .you, text: "PROVISIONAL_LIVE_ONLY_TEXT", start: 0, end: 1))
- .settingPartial("PROVISIONAL_PARTIAL_ONLY_TEXT", for: .them)
+ .settingPartial(MeetingLivePartial(id: UUID(), text: "PROVISIONAL_PARTIAL_ONLY_TEXT", start: 0), for: .them)
let exported = MeetingTranscriptExporter.text(for: session, includeEchoes: true)
XCTAssertTrue(exported.contains("FINAL_TRANSCRIPT_TEXT"))