feat(mentor): research & library-light (S8) (#29)
CI / ci (push) Canceled after 0s

The mentor researches mid-pass and its findings arrive as candidate
source-notes with provenance inside their Session. A third museion-
tools tool, submit_research_notes, is the typed rail (ADR-0006
posture): decode-validate only, reply {"received": N}, write NOTHING
— the session is the holding area, and keeping is the writer's act.

Candidates ride the transcript as first-class rows (researchNote):
parsed from the tool call's rawInput by payload shape — the notes
array routes before the fix-card parse, titles are display text —
one row per note, all-or-nothing per batch, the wire's whitespace
rule mirrored so both boundaries agree. Resume re-materializes them
for free: replays re-run the same parse; dispositions reset honestly
(they were never persisted — engine-owned cargo, ADR-0007).

The writer curates in place (full cards in the shared transcript, no
palette — a handful curates where it lands): Keep opens the
ask-before sheet (G9; PromoteAskSheet posture — inline refusal,
buttons kept) and ONE confirm lands one plain markdown note with
provenance into the piece's research/ via writeResearchNote — the
one folder(of:) id lookup anchors it inside this Home, a symlinked
research/ refuses, collision -2; Reject vanishes, recording nothing.
The pass stub names the rail and forbids the engine writing
candidates itself; kept notes flip hasResearch, so every later pass
sees the research/ path (S8.3 at v1 depth).

Finish-audit (three reviewers) drove the whitespace-parity and
shape-routing fixes, the ResearchNoteContent dedup, and a poll-loop
fix for the debounce rig's sidecar half that the larger suite's load
had pushed past its fixed sleep — full suite green (373 tests).

Closes #29
This commit is contained in:
AlexKucera committed 2026-10-22 14:06:16 +02:00
1 parent 9895614b7e
commit b02d36bb5d
22 files changed
+977 -33

No files matched your search

+94 -2
View File
@@ -9,6 +9,16 @@
// -32601 unknown method, -32700 garbage. Wire facts verified live
// against the real hermes MCP client.
//
// ## Scenario: candidate rail and the keep write
// From #29 (S8.1/S8.2)
// Given a piece in the library and the mentor researching mid-pass
// When the engine delivers findings as submit_research_notes tool calls
// Then well-formed candidates are accepted with a received count and
// nothing is written anywhere; malformed ones answer a tool error
// And the pass prompt names that rail
// And when the writer keeps one, one plain markdown note with provenance
// lands in the piece's research/ — nothing else auto-saves.
//
import Foundation
@testable import Museion
@@ -70,11 +80,14 @@ struct MCPServerWireTests {
#expect(result.isEmpty)
}
@Test func `tools list exposes both tools with schemas`() throws {
@Test func `tools list exposes all three tools with schemas`() throws {
let replies = try runWire([toolsListLine])
let result = try #require(replies[0]["result"] as? [String: Any])
let tools = try #require(result["tools"] as? [[String: Any]])
#expect(Set(tools.compactMap { $0["name"] as? String }) == ["query_learnings", "submit_fix_cards"])
#expect(
Set(tools.compactMap { $0["name"] as? String })
== ["query_learnings", "submit_fix_cards", "submit_research_notes"],
)
let submit = try #require(tools.first { $0["name"] as? String == "submit_fix_cards" })
let schema = try #require(submit["inputSchema"] as? [String: Any])
@@ -100,6 +113,20 @@ struct MCPServerWireTests {
let query = try #require(tools.first { $0["name"] as? String == "query_learnings" })
let querySchema = try #require(query["inputSchema"] as? [String: Any])
#expect(try #require(querySchema["required"] as? [String]) == ["piece_path"])
// #29 (S8.1): the research rail requires piece_path + notes, and a
// note item requires title + url.
let research = try #require(tools.first { $0["name"] as? String == "submit_research_notes" })
let researchSchema = try #require(research["inputSchema"] as? [String: Any])
let researchRequired = try #require(researchSchema["required"] as? [String])
#expect(researchRequired.contains("piece_path"))
#expect(researchRequired.contains("notes"))
let researchProps = try #require(researchSchema["properties"] as? [String: Any])
let notesProp = try #require(researchProps["notes"] as? [String: Any])
let noteItems = try #require(notesProp["items"] as? [String: Any])
let noteRequired = try #require(noteItems["required"] as? [String])
#expect(noteRequired.contains("title"))
#expect(noteRequired.contains("url"))
}
/// One throwaway wire piece: home + `projects/posts/<name>/post.md`
@@ -224,4 +251,69 @@ struct MCPServerWireTests {
)) ?? []).filter { $0.hasSuffix(".json") }
#expect(onDisk.count == 10)
}
/// #29 (S8.1): one submit_research_notes wire line over the given
/// arguments (JSONSerialization-built — no line_length fights).
private func researchCall(id: Int, arguments: [String: Any]) throws -> String {
let request: [String: Any] = [
"jsonrpc": "2.0",
"id": id,
"method": "tools/call",
"params": ["name": "submit_research_notes", "arguments": arguments] as [String: Any],
]
return try #require(String(data: JSONSerialization.data(withJSONObject: request), encoding: .utf8))
}
/// #29 (S8.1): well-formed candidates answer a received count — and
/// create NOTHING on disk (candidates live in their session; keeping
/// is the writer's separate act).
@Test func `research notes reply received and write nothing`() throws {
let (_, piece) = try seedWirePiece("research-piece")
let note = [
"title": "The Long Now",
"url": "https://example.org/long-now",
"quote": "pace layers",
"note": "Supports the slowness claim.",
] as [String: Any]
let line = try researchCall(id: 21, arguments: ["piece_path": piece.path, "notes": [note]])
let replies = try runWire([initializeLine, initializedLine, line])
#expect(replies.count == 2)
let result = try #require(replies[1]["result"] as? [String: Any])
#expect(result["isError"] == nil)
let payload = try #require(
try JSONSerialization.jsonObject(with: Data(toolText(result).utf8)) as? [String: Any],
)
#expect(payload["received"] as? Int == 1)
#expect(!FileManager.default.fileExists(atPath: piece.appendingPathComponent("research").path))
}
/// #29 (S8.1): malformed candidates answer a tool error — the trust
/// boundary. Missing fields fail decode; a whitespace-only title is
/// refused; none of them writes anything.
@Test func `malformed research notes answer a tool error`() throws {
let (_, piece) = try seedWirePiece("research-error-piece")
let lines = try [
// notes item missing url → decode fails.
researchCall(id: 31, arguments: ["notes": [["title": "T"]]]),
// notes item missing title → decode fails.
researchCall(id: 32, arguments: ["notes": [["url": "https://example.org"]]]),
// whitespace-only title → CardError.
researchCall(id: 33, arguments: [
"piece_path": piece.path,
"notes": [["title": " ", "url": "https://example.org"]],
]),
// piece_path missing → decode fails.
researchCall(id: 34, arguments: [
"notes": [["title": "T", "url": "https://example.org"]],
]),
]
for line in lines {
let replies = try runWire([line])
let result = try #require(replies[0]["result"] as? [String: Any])
#expect(result["isError"] as? Bool == true, "expected isError for: \(line)")
#expect(replies[0]["error"] == nil)
#expect(!FileManager.default.fileExists(atPath: piece.appendingPathComponent("research").path))
}
}
}