refactor(session): type the transcript rail
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
SessionRow text rows carry (body, speaker, notice) as data — agent/
user/system plus refused/interrupted/connectionLost/kickoff/failed/
plain — typed at every append site; no stored row holds a speaker
prefix (pinned). The two wire-only classifications are sniffed once at
the append seam: a replayed pass kick-off ('Pass Pass N…') and the
engine's 'Operation interrupted:' notice. The transcript view, the
writing-session filter, and the New Post prefill switch on typed data;
rendering is identical (refusal/connection-lost rows stay agent prose
by pinned render).
Fix Card and Research Note payloads decode through one shared
ToolPayloads decoder: lenient for the transcript rail (both the nested
card-rail shape and the flat #14-era fake kept), strict for the
museion-tools MCP trust boundary with named CardErrors. Three
intentional wire tightenings at the strict entry: empty cards/notes
arrays throw instead of no-op succeeding, the camelCase
diagnosticQuestion alias is rejected (schema is snake_case), and
decode failures answer short named errors instead of DecodingError
dumps. quote/note type parity restored (present-but-wrong-type throws).
Every wire-shape fact is pinned in ToolPayloadsTests.
Full suite 653/653, swiftformat/swiftlint clean. Audit flip-verified.
Closes #177
This commit is contained in:
1 parent
c2eb9573db
commit
d14cb40e73
18 files changed
+912
-358
No files matched your search
@@ -364,7 +364,7 @@ struct ACPClientTests {
|
||||
let outcome = await model.sendPrompt("hello mentor")
|
||||
#expect(outcome == .ended(stopReason: "end_turn"))
|
||||
let streamed = model.rows.contains { row in
|
||||
if case let .text(text) = row.content {
|
||||
if case let .text(text, _, _) = row.content {
|
||||
return text.contains("Hello mentor.")
|
||||
}
|
||||
return false
|
||||
@@ -382,7 +382,7 @@ struct ACPClientTests {
|
||||
await model.sendPrompt("STUB-WIRE-PROMPT that must never surface", label: "Pass 1 · My Post")
|
||||
var texts: [String] = []
|
||||
for row in model.rows {
|
||||
if case let .text(text) = row.content {
|
||||
if case let .text(text, _, _) = row.content {
|
||||
texts.append(text)
|
||||
}
|
||||
}
|
||||
@@ -423,7 +423,7 @@ struct ACPClientTests {
|
||||
/// #23 dogfood: the writing-session filter — prose + card events stay,
|
||||
/// raw session/tool rows and thinking are debug-only.
|
||||
@Test func `writing-session filter keeps prose and cards, hides raw and thought`() {
|
||||
#expect(SessionTranscriptView.isWritingRow(SessionRow(content: .text("Pass 1 · The piece"))))
|
||||
#expect(SessionTranscriptView.isWritingRow(SessionRow(content: .text("Pass 1 · The piece", .system, .plain))))
|
||||
#expect(SessionTranscriptView.isWritingRow(SessionRow(content: .fixCard(
|
||||
FixCard(pattern: "p", problem: "q", diagnosticQuestion: "", fix: "", anchor: "", provenance: "", status: ""),
|
||||
))))
|
||||
@@ -431,25 +431,12 @@ struct ACPClientTests {
|
||||
#expect(!SessionTranscriptView.isWritingRow(SessionRow(content: .raw(kind: "tool_call_update", json: "{}"))))
|
||||
}
|
||||
|
||||
/// #155 (map #153): the editorial-voice classifier — the model's speaker
|
||||
/// prefixes map onto the contract's three voices (agent prose / user
|
||||
/// capsule / system status box); everything else is the system's mono
|
||||
/// voice (refusals, pass kick-off labels, reveals).
|
||||
@Test func `speaker classifier maps prefixes onto the contract voices`() {
|
||||
#expect(SessionTranscriptView.speaker(of: "Mentor: The opening earns its place.") == .agent)
|
||||
#expect(SessionTranscriptView.speaker(of: "Mentor: (refused the prompt)") == .agent)
|
||||
#expect(SessionTranscriptView.speaker(of: "You: What would you cut first?") == .user)
|
||||
#expect(SessionTranscriptView.speaker(of: "Pass 1 · The piece") == .system)
|
||||
#expect(SessionTranscriptView.speaker(of: "Session refused — the mentor is mid-turn.") == .system)
|
||||
#expect(SessionTranscriptView.speaker(of: "A = Pass 1 start snapshot · B = current document") == .system)
|
||||
}
|
||||
|
||||
/// Round-6 ui-polish (all seats): the warning row's headline/detail
|
||||
/// split — speaker prefix dropped, then the first ": " separates the
|
||||
/// headline from the muted detail line (no ": " → headline only).
|
||||
/// split — the first ": " separates the headline from the muted detail
|
||||
/// line (no ": " → headline only). #177 (S2): bodies arrive unprefixed.
|
||||
@Test func `warningParts splits headline from detail`() {
|
||||
let interrupted = SessionTranscriptView.warningParts(
|
||||
"Mentor: Operation interrupted: waiting for model response (61.6s elapsed).",
|
||||
"Operation interrupted: waiting for model response (61.6s elapsed).",
|
||||
)
|
||||
#expect(interrupted.headline == "Operation interrupted")
|
||||
#expect(interrupted.detail == "waiting for model response (61.6s elapsed).")
|
||||
@@ -458,6 +445,14 @@ struct ACPClientTests {
|
||||
#expect(lost.detail == nil)
|
||||
}
|
||||
|
||||
/// #177 (S2): the kick-off pill's display text — first line only, the
|
||||
/// doubled "Pass Pass N" collapsed to "Pass N". Precondition: the body
|
||||
/// of a .kickoff row (the append seam already sniffed it — the prefix
|
||||
/// is unconditional here).
|
||||
@Test func `kickoffDisplayText collapses to first line`() {
|
||||
#expect(SessionTranscriptView.kickoffDisplayText("Pass Pass 2 — deep.\nThe full prompt never renders.") == "Pass 2 — deep.")
|
||||
}
|
||||
|
||||
/// Round-8 ui-polish (argon#8 — calm copy): the engine's own
|
||||
/// interruption detail, rephrased verbatim-safe — only the known
|
||||
/// "waiting for model response (X elapsed)" phrasing rewrites; any
|
||||
@@ -507,7 +502,7 @@ struct ACPClientTests {
|
||||
let outcome = await model.sendPrompt("hello mentor")
|
||||
#expect(outcome == .ended(stopReason: "refusal"))
|
||||
let refused = model.rows.contains { row in
|
||||
if case let .text(text) = row.content {
|
||||
if case let .text(text, _, _) = row.content {
|
||||
return text.contains("(refused the prompt)")
|
||||
}
|
||||
return false
|
||||
@@ -571,14 +566,14 @@ struct ACPClientTests {
|
||||
#expect(thought)
|
||||
// The critique text stays clean — thinking never bleeds into it.
|
||||
let critique = model.rows.contains { row in
|
||||
if case let .text(text) = row.content {
|
||||
return text == "Mentor: Hello mentor."
|
||||
if case let .text(text, _, _) = row.content {
|
||||
return text == "Hello mentor."
|
||||
}
|
||||
return false
|
||||
}
|
||||
#expect(critique)
|
||||
#expect(!model.rows.contains { row in
|
||||
if case let .text(text) = row.content {
|
||||
if case let .text(text, _, _) = row.content {
|
||||
return text.contains("weighing")
|
||||
}
|
||||
return false
|
||||
@@ -637,7 +632,7 @@ struct ACPClientTests {
|
||||
}
|
||||
#expect(hasCard)
|
||||
let hasText = model.rows.contains { row in
|
||||
if case let .text(text) = row.content {
|
||||
if case let .text(text, _, _) = row.content {
|
||||
return text.contains("Hello mentor.")
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user