CI / ci (push) Canceled after 0s
Engine lifecycle policy — spawn, handshake, respawn-on-crash, teardown, and the per-surface residency rules (resident chat engine; one-shot pass engines spawned per run, torn down at the verdict, ADR-0014) — moves out of MentorSessionModel into EngineHost behind the EngineTransport seam. The model keeps session + turn coordination and stays the only observable the panes see; ACPEngineClient becomes the seam's production adapter, and a scripted in-process engine (ScriptedEngine) becomes the second adapter — engine-behaviour tests (streaming, crash, cancel, restart, per-surface spawn) now run without child processes, retiring the zsh fake-server rigs from logic tests (#30 flake family). Exactly one real-process wire smoke per LLM surface survives (chat two-act + parameterized pass1/pass2): the held-turn cancel contract, hung-child SIGTERM teardown, handshake, streamed turn, crash, restart. One-shot teardown is structural (withOneShot closes at body end, every exit path); the one-shot slot is claimed before the first suspension so the at-most-one invariant holds across the spawn/handshake awaits. Suite: 652 executed / 652 passed / 0 failed (653 argument cases), counted from the xcresult; swiftformat idempotent, swiftlint clean on touched files. Closes #178
121 lines
4.5 KiB
Swift
121 lines
4.5 KiB
Swift
//
|
||
// ResearchCandidateTests.swift
|
||
// MuseionTests
|
||
//
|
||
// #29 (S8.1–S8.3): the research-candidate pins, own file —
|
||
// SessionLifecycleTests crossed its type-body ceiling (MCPToolsPromoteTests
|
||
// precedent). #178: runs IN-PROCESS over ScriptedEngines rigs at the
|
||
// EngineTransport seam — no child process. The payload SHAPE pins
|
||
// live in ToolPayloadsTests (#177); this file pins the curation behavior.
|
||
//
|
||
|
||
import Foundation
|
||
@testable import Museion
|
||
import Testing
|
||
|
||
// #29 suite: candidate parsing, curation, and replay survival.
|
||
|
||
struct ResearchCandidateTests {
|
||
/// #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
|
||
/// with two notes; the default open RESUMES it, so the candidates are
|
||
/// there without any extra turn.
|
||
@Test @MainActor func `resume re-materializes research candidates from the replay`() async throws {
|
||
let rosterDir = acpTempDir("research-roster")
|
||
let entry = SessionEntry(sessionId: "sess-1", name: "Research", pieceTitle: nil, createdAt: Date())
|
||
SessionRoster.save([entry], directory: rosterDir)
|
||
let engines = ScriptedEngines(mode: "loadReplay")
|
||
let mentor = engines.makeMentor(rosterDirectory: rosterDir)
|
||
defer { mentor.shutdown() }
|
||
await mentor.openSession()
|
||
|
||
var candidates: [ResearchCandidate] = []
|
||
for _ in 0 ..< 500 {
|
||
candidates = mentor.transcriptRows(of: entry).compactMap {
|
||
if case let .researchNote(candidate) = $0.content {
|
||
candidate
|
||
} else {
|
||
nil
|
||
}
|
||
}
|
||
if candidates.count == 2 {
|
||
break
|
||
}
|
||
try await Task.sleep(nanoseconds: 20_000_000)
|
||
}
|
||
// #require (not bare #expect + subscript): a missed settle must fail
|
||
// the test, never trap the runner on an out-of-bounds index.
|
||
try #require(candidates.count == 2, "expected two candidates from the replay, got \(candidates.count)")
|
||
#expect(candidates.allSatisfy { $0.piecePath == "/tmp/piece" })
|
||
#expect(candidates[0].title == "Hinge Study")
|
||
#expect(candidates[0].url == "https://example.org/hinge")
|
||
#expect(candidates[0].quote == "We should stop listening.")
|
||
#expect(candidates[0].note == "Counts the pivot tense.")
|
||
// The second note's absent quote/note default to "".
|
||
#expect(candidates[1].title == "Second Source")
|
||
#expect(candidates[1].quote == "")
|
||
#expect(candidates[1].note == "")
|
||
#expect(candidates.allSatisfy { $0.disposition == .pending })
|
||
}
|
||
|
||
/// #29 (S8.3): the curation mutation — kept/rejected replace the row's
|
||
/// content in the ACTIVE session's transcript; an unknown row id no-ops.
|
||
@Test @MainActor func `research disposition flips the row and no-ops unknown ids`() async throws {
|
||
let rosterDir = acpTempDir("disposition-roster")
|
||
let entry = SessionEntry(sessionId: "sess-1", name: "Research", pieceTitle: nil, createdAt: Date())
|
||
SessionRoster.save([entry], directory: rosterDir)
|
||
let engines = ScriptedEngines(mode: "loadReplay")
|
||
let mentor = engines.makeMentor(rosterDirectory: rosterDir)
|
||
defer { mentor.shutdown() }
|
||
await mentor.openSession()
|
||
|
||
var rows: [SessionRow] = []
|
||
for _ in 0 ..< 500 {
|
||
rows = mentor.transcriptRows(of: entry).filter {
|
||
if case .researchNote = $0.content {
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
if rows.count == 2 {
|
||
break
|
||
}
|
||
try await Task.sleep(nanoseconds: 20_000_000)
|
||
}
|
||
try #require(rows.count == 2, "expected two candidate rows, got \(rows.count)")
|
||
|
||
mentor.setResearchDisposition(rowID: rows[0].id, .kept(fileName: "20261022-hinge-study.md"))
|
||
mentor.setResearchDisposition(rowID: rows[1].id, .rejected)
|
||
mentor.setResearchDisposition(rowID: UUID(), .rejected) // unknown id — no-op
|
||
|
||
let after = mentor.transcriptRows(of: entry)
|
||
#expect(after.contains { row in
|
||
if case let .researchNote(candidate) = row.content {
|
||
return candidate.disposition == .kept(fileName: "20261022-hinge-study.md")
|
||
}
|
||
return false
|
||
})
|
||
#expect(after.contains { row in
|
||
if case let .researchNote(candidate) = row.content {
|
||
return candidate.disposition == .rejected
|
||
}
|
||
return false
|
||
})
|
||
// Exactly two research rows still — the unknown id added nothing.
|
||
#expect(after.filter {
|
||
if case .researchNote = $0.content {
|
||
return true
|
||
}
|
||
return false
|
||
}.count == 2)
|
||
}
|
||
|
||
/// #29 (S8.3): the writing filter keeps candidate cards visible.
|
||
@Test func `writing filter keeps research candidate rows`() {
|
||
#expect(SessionTranscriptView.isWritingRow(SessionRow(content: .researchNote(ResearchCandidate(
|
||
piecePath: "/tmp/piece", title: "A", url: "https://a", quote: "", note: "",
|
||
)))))
|
||
}
|
||
}
|