refactor(session): type the transcript rail
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:
AlexKucera committed 2026-11-09 16:01:53 +01:00
1 parent c2eb9573db
commit d14cb40e73
18 files changed
+912 -358

No files matched your search

+2 -43
View File
@@ -4,7 +4,8 @@
//
// #29 (S8.1–S8.3): the research-candidate pins, own file —
// SessionLifecycleTests crossed its type-body ceiling (MCPToolsPromoteTests
// precedent). Reuses the shared fake ACP harness.
// precedent). Reuses the shared fake ACP harness. The payload SHAPE pins
// live in ToolPayloadsTests (#177); this file pins the curation behavior.
//
import Foundation
@@ -14,48 +15,6 @@ import Testing
// #29 suite: candidate parsing, curation, and replay survival.
struct ResearchCandidateTests {
/// #29 (S8.2): the batch parser — two notes → two candidates with ""
/// defaults; a missing piece_path, an empty/absent notes array, or a
/// note missing title/url yields NO candidates (the raw row owns it).
@Test func `research batch parses notes and refuses garbage`() {
let good: JSONValue = .object([
"piece_path": .string("/tmp/piece"),
"notes": .array([
.object(["title": .string("A"), "url": .string("https://a"), "quote": .string("q"), "note": .string("n")]),
.object(["title": .string("B"), "url": .string("https://b")]),
]),
])
let batch = ResearchCandidate.batch(good)
#expect(batch.count == 2)
#expect(batch[0] == ResearchCandidate(piecePath: "/tmp/piece", title: "A", url: "https://a", quote: "q", note: "n"))
#expect(batch[1].quote == "")
#expect(batch[1].note == "")
#expect(batch[1].disposition == .pending)
// Garbage: no piece_path / empty notes / absent notes / note missing url / not an object.
#expect(ResearchCandidate.batch(.object([
"notes": .array([.object(["title": .string("A"), "url": .string("https://a")])]),
])).isEmpty)
#expect(ResearchCandidate.batch(.object(["piece_path": .string("/tmp/piece"), "notes": .array([])])).isEmpty)
#expect(ResearchCandidate.batch(.object(["piece_path": .string("/tmp/piece")])).isEmpty)
#expect(ResearchCandidate.batch(.object([
"piece_path": .string("/tmp/piece"),
"notes": .array([.object(["title": .string("A")])]),
])).isEmpty)
// Audit pin: whitespace-only title/url are the wire's refusal too —
// both boundaries must agree (an invisible-titled card used to be
// keepable as `-untitled.md`).
#expect(ResearchCandidate.batch(.object([
"piece_path": .string("/tmp/piece"),
"notes": .array([.object(["title": .string(" "), "url": .string("https://a")])]),
])).isEmpty)
#expect(ResearchCandidate.batch(.object([
"piece_path": .string("/tmp/piece"),
"notes": .array([.object(["title": .string("A"), "url": .string(" ")])]),
])).isEmpty)
#expect(ResearchCandidate.batch(nil).isEmpty)
}
/// #29 AC (S8.2): candidates live in their session — resume
/// re-materializes them from the replayed transcript (engine-owned
/// cargo). The planted session's history carries one research tool call