feat(sessions): new post from session & drills (S2.7-8) (#30)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
A freeform Session births a Post. "New Post" in the Sessions pane opens an ask-before sheet prefilled with the session's last mentor reply (editable, G9); ONE confirm materializes the piece under projects/posts/ stamped origin: ai - immutable frontmatter, never stats-eligible - and opens it in Posts; a failed write keeps the sheet up with the reason inline and the draft intact. writeNew gains an origin parameter (additive default .writer, every existing caller compiles). "New Brainstorm" is a session started with an opener prompt - no new machinery (beginBrainstormSession over the normal new+prompt rails). The freeform composer (input, liveness, Stop) moved from MentorPaneView into the shared SessionTranscriptView: one conversation surface, two panes - the Sessions pane stops being a read-only transcript. Drill offers (S2.8) wire as one pass-persona section (v1.4): the seeded micro-drill doctrine owns the motivation moment, the two-minute bound, the single shelf, and the vanish - session flavor, no machinery beyond S2.3. Resume now speaks the real adapter wire. Live-probed against the engine: 0.21.5 answers session/load with the id at _meta.hermes.sessionProvenance.acpSessionId and NO top-level sessionId - resumeSession accepts both shapes; every prior real-engine resume misread as "engine does not know this session". The fake ACP server answers load in the real shape (a loadReplayLegacy knob pins the older contract), so the whole resume suite guards the live wire. New pins: draft-candidate extraction (last mentor row wins; thought/ card/research/raw lanes and refusal/connection rows never prefill), ai-stamp write + immutability through overwrite, brainstorm roster + labeled opener, legacy-shape resume. Finish-audit (three reviewers, parallel) converged on the confirm() dismissal that destroyed the edited draft on a failed write - fixed with sheet-local error state (stale-refusal re-show dies with the presentation) - and surfaced the missing brainstorm and legacy-shape pins; the resume fix was flip-verified (removing the provenance fallback fails the provenance pins). Full suite green (379 tests). Closes #30
This commit is contained in:
1 parent
b02d36bb5d
commit
ae234350ef
16 files changed
+521
-128
No files matched your search
@@ -217,6 +217,55 @@ struct SessionLifecycleTests {
|
||||
_ = await chat.value
|
||||
}
|
||||
|
||||
// Scenario: Brainstorm session — from #30 (S2.7). Given a ready engine,
|
||||
// when the writer picks "New Brainstorm", then a rostered "Brainstorm"
|
||||
// session activates and the mentor receives the opener — a session
|
||||
// started with a prompt, no new machinery.
|
||||
@Test @MainActor func `brainstorm opens a rostered session with the labeled opener`() async throws {
|
||||
let (model, home, mentor) = try makePassRig()
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
_ = model
|
||||
_ = home
|
||||
|
||||
let entry = try #require(await mentor.beginBrainstormSession(pieceTitle: "Draft Piece"))
|
||||
|
||||
// Rostered newest-first, named "Brainstorm", piece-associated, active.
|
||||
#expect(mentor.roster.first?.name == "Brainstorm")
|
||||
#expect(entry.pieceTitle == "Draft Piece")
|
||||
#expect(mentor.activeEntry?.id == entry.id)
|
||||
// The opener rides the labeled rail — the raw prompt never renders.
|
||||
#expect(texts(in: mentor.transcriptRows(of: entry)).contains("Brainstorm"))
|
||||
#expect(!texts(in: mentor.transcriptRows(of: entry)).contains { $0.contains("Let's brainstorm together") })
|
||||
// The mentor's reply streams into the NEW session's transcript.
|
||||
var streamed = false
|
||||
for _ in 0 ..< 250 {
|
||||
streamed = texts(in: mentor.transcriptRows(of: entry)).contains { $0.contains("Hello mentor.") }
|
||||
if streamed {
|
||||
break
|
||||
}
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(streamed)
|
||||
}
|
||||
|
||||
/// #30 audit pin: the real 0.21.5 wire answers load with the provenance
|
||||
/// shape (pinned by every other resume test via the fake's default);
|
||||
/// the OLDER top-level-sessionId contract stays accepted — the knob
|
||||
/// flips the fake to that shape and the resume must still succeed.
|
||||
@Test @MainActor func `resume accepts the legacy top-level sessionId shape`() async throws {
|
||||
let (model, home, mentor) = try makePassRig(mode: "loadReplayLegacy")
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
_ = model
|
||||
_ = home
|
||||
|
||||
let entry = try #require(await mentor.newSession(name: "Legacy", pieceTitle: nil))
|
||||
let resumed = await mentor.resumeSession(entry)
|
||||
#expect(resumed)
|
||||
#expect(mentor.activeEntry?.id == entry.id)
|
||||
}
|
||||
|
||||
/// #28 AC4 (ownership) + review fix (the default open RESUMES): a new
|
||||
/// model over the same roster directory restores every entry — the
|
||||
/// roster FILE carries no transcript payload (pinned against the raw
|
||||
@@ -406,6 +455,51 @@ struct SessionLifecycleTests {
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
// Scenario: draft candidate — from #30 (S2.7). Given a session
|
||||
// transcript, when the sheet prefills, then the last mentor text row is
|
||||
// the draft candidate; thought/card/research/raw rows never prefill.
|
||||
@Test @MainActor func `draft candidate is the last mentor text row`() {
|
||||
let rows: [SessionRow] = [
|
||||
SessionRow(content: .text("You: help me draft this")),
|
||||
SessionRow(content: .thought("thinking hard about angles")),
|
||||
SessionRow(content: .text("Mentor: first reply")),
|
||||
SessionRow(content: .researchNote(ResearchCandidate(
|
||||
piecePath: "/tmp/piece", title: "T", url: "https://x", quote: "", note: "",
|
||||
))),
|
||||
SessionRow(content: .fixCard(FixCard(
|
||||
pattern: "p", problem: "pr", diagnosticQuestion: "d", fix: "f",
|
||||
anchor: "a", provenance: "engine", status: "open",
|
||||
))),
|
||||
SessionRow(content: .raw(kind: "tool call", json: "{}")),
|
||||
SessionRow(content: .text("Mentor: second and latest reply")),
|
||||
]
|
||||
#expect(MentorSessionModel.draftCandidateText(in: rows) == "second and latest reply")
|
||||
}
|
||||
|
||||
@Test @MainActor func `no mentor text yields no draft candidate`() {
|
||||
// Empty transcript, user-only, and non-text lanes never prefill.
|
||||
#expect(MentorSessionModel.draftCandidateText(in: []) == nil)
|
||||
#expect(MentorSessionModel.draftCandidateText(in: [
|
||||
SessionRow(content: .text("You: hello")),
|
||||
SessionRow(content: .thought("hm")),
|
||||
]) == nil)
|
||||
// A trailing blank mentor row doesn't blank the prefill — the
|
||||
// earlier real reply is still the candidate.
|
||||
#expect(MentorSessionModel.draftCandidateText(in: [
|
||||
SessionRow(content: .text("Mentor: the real reply")),
|
||||
SessionRow(content: .text("Mentor: ")),
|
||||
]) == "the real reply")
|
||||
// Refusal/connection rows share the display prefix — an error is
|
||||
// not the draft; an earlier reply still wins, error-only yields nil.
|
||||
#expect(MentorSessionModel.draftCandidateText(in: [
|
||||
SessionRow(content: .text("Mentor: the real reply")),
|
||||
SessionRow(content: .text("Mentor: connection lost — broken pipe")),
|
||||
]) == "the real reply")
|
||||
#expect(MentorSessionModel.draftCandidateText(in: [
|
||||
SessionRow(content: .text("Mentor: (refused the prompt)")),
|
||||
]) == nil)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
Reference in new issue
Block a user