From 48177f18751ae0ec4c545f1c4d277f7ee8a525ab Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Wed, 27 May 2026 01:43:02 +0300 Subject: [PATCH] fix(brainbar): title injection bursts from chunk content --- .../BrainBar/InjectionPresentation.swift | 6 ++++- .../InjectionPresentationTests.swift | 25 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/brain-bar/Sources/BrainBar/InjectionPresentation.swift b/brain-bar/Sources/BrainBar/InjectionPresentation.swift index 880e165..b98df54 100644 --- a/brain-bar/Sources/BrainBar/InjectionPresentation.swift +++ b/brain-bar/Sources/BrainBar/InjectionPresentation.swift @@ -36,8 +36,12 @@ struct InjectionPresentation { var tokenCount: Int { events.reduce(0) { $0 + $1.tokenCount } } var summaryTitle: String { + if let chunkTitle = InjectionPresentation.previewChunks(for: events, limit: 1).first?.displayText, + !chunkTitle.isEmpty { + return chunkTitle + } let chunkNoun = chunkCount == 1 ? "chunk" : "chunks" - return "\(chunkCount) \(chunkNoun) injected from \"\(topicOrSource)\"" + return "\(chunkCount) \(chunkNoun) injected" } var chunkPreviewIDs: [String] { diff --git a/brain-bar/Tests/BrainBarTests/InjectionPresentationTests.swift b/brain-bar/Tests/BrainBarTests/InjectionPresentationTests.swift index f60fb00..5b54b06 100644 --- a/brain-bar/Tests/BrainBarTests/InjectionPresentationTests.swift +++ b/brain-bar/Tests/BrainBarTests/InjectionPresentationTests.swift @@ -80,12 +80,35 @@ final class InjectionPresentationTests: XCTestCase { XCTAssertEqual(snapshot.bursts.count, 1) XCTAssertEqual(snapshot.bursts[0].sessionID, "brain-c7a8") XCTAssertEqual(snapshot.bursts[0].topicOrSource, "auth refactor") - XCTAssertEqual(snapshot.bursts[0].summaryTitle, "5 chunks injected from \"auth refactor\"") + XCTAssertEqual(snapshot.bursts[0].summaryTitle, "5 chunks injected") XCTAssertEqual(snapshot.bursts[0].events.map(\.id), [1, 2, 3, 4, 5]) XCTAssertEqual(snapshot.bursts[0].chunkPreviewIDs, ["chunk-1", "chunk-2"]) XCTAssertEqual(snapshot.bursts[0].remainingChunkCount(after: 2), 3) } + func testBurstSummaryTitleUsesChunkContentInsteadOfSourcePrompt() { + let now = isoDate("2026-04-18T10:00:00Z") + let event = makeEvent( + id: 1, + sessionID: "sess-a", + timestamp: "2026-04-18T09:58:00Z", + query: "[orc gen-7 s:1 — researchLead monitor v2 — prompts-deliverable workflow]", + chunkIDs: ["chunk-1"], + tokenCount: 10, + chunks: [ + makeChunk(id: "chunk-1", content: "Coverage moved to terminal-status semantics after the dashboard fix") + ] + ) + + let snapshot = InjectionPresentation.snapshot(events: [event], filterText: "", now: now) + + XCTAssertEqual( + snapshot.bursts[0].summaryTitle, + "Coverage moved to terminal-status semantics after the dashboard fix" + ) + XCTAssertEqual(snapshot.bursts[0].topicOrSource, event.query) + } + func testBurstAggregationSplitsDifferentSessions() { let now = isoDate("2026-04-18T10:00:00Z") let events = [