test(session): finish-audit closeout for #184
CI / ci (pull_request) Canceled after 0s
CI / ci (push) Canceled after 0s

Three-reviewer fanout over PR #184's deferred nil-scope fix:

- pin the titled drain's APPLY half (unpinned suite-wide) over a new
  hangOnPromptLoad rig mode (prompt parks, load answers);
  flip-verified against a nil-only drain guard
- cut the dead Equatable on PendingScope (converged finding)
- name the same-turn pendingRestart ceiling on the drain: respawn's
  .starting window drops the consumed scope; consume-at-apply is the
  upgrade path (follow-up ticket)
- changelog + devlog for the PR; AGENTS.md rails refreshed

Suite 654 executed / 0 failed; swiftformat clean; swiftlint
unchanged (both warnings pre-exist on main).
This commit was merged in pull request #184.
This commit is contained in:
AlexKucera committed 2026-11-10 16:25:58 +01:00
1 parent 704e7a83fd
commit a3ef007562
8 files changed
+123 -8

No files matched your search

+51
View File
@@ -143,6 +143,57 @@ struct SessionScopeTests {
#expect(cleared)
}
/// The titled twin of (a), pinning the drain's APPLY half — no test
/// anywhere drove a deferred NON-nil switch to its applied state (the
/// replay-deferral pin never releases its hold; the nil pins activate
/// nothing). Same rig shape over the `hangOnPromptLoad` mode (prompt
/// parks, load answers): stopStreaming ends the turn, the drain must
/// activate the target piece's session.
@MainActor
@Test func `deferred titled scope during a stream applies at turn end`() async throws {
let rosterDir = acpTempDir("scope-titled-stream")
let engines = ScriptedEngines(mode: "hangOnPromptLoad")
let model = engines.makeMentor(rosterDirectory: rosterDir)
defer { model.shutdown() }
await model.openSession() // empty roster — creates the default session, completes
guard case .ready = model.phase else {
Issue.record("expected ready, got \(model.phase)")
return
}
// B first, then A — A is the active surface (newest), B the target.
guard await model.newSession(name: "On B", pieceTitle: "Piece B") != nil,
await model.newSession(name: "On A", pieceTitle: "Piece A") != nil
else {
Issue.record("session creation refused")
return
}
#expect(model.activeEntry?.pieceTitle == "Piece A")
// The turn parks mid-stream (hangOnPrompt) — isStreaming holds.
_ = Task { await model.sendPrompt("hold this") }
var streaming = false
for _ in 0 ..< 250 where !streaming {
streaming = model.isStreaming
if !streaming {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(streaming)
// The writer switches to B mid-stream — the switch defers to
// turn end; A stays the pane's surface.
await model.scopeHostedSession(toOpenPieceTitle: "Piece B")
#expect(model.activeEntry?.pieceTitle == "Piece A")
// Cancel ends the turn — the deferred switch must apply now.
model.stopStreaming()
var applied = false
for _ in 0 ..< 250 where !applied {
applied = !model.isStreaming && model.activeEntry?.pieceTitle == "Piece B"
if !applied {
try await Task.sleep(nanoseconds: 20_000_000)
}
}
#expect(applied)
}
/// deferred-empty-piece-scope-lost (b): the same nil-scope loss when the
/// request arrives while a session/load REPLAYS — the replay's
/// completion drains the pending scope; the explicit nil target must