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

+1 -1
View File
@@ -22,7 +22,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
- One runnable check per non-trivial fact: the smallest test that fails if the logic breaks. No fixtures or per-function suites unless asked.
- Never touch the real machine: throwaway Homes in temp dirs (`makeHome`, `storeHome`, `makeModelHome`, `makeSessionHome`, `importHome`); every `ProfileProvisioner.perform` call injects `masterRoot` (the default writes the REAL Application Support); keychain tests inject their OWN account slot (a live production token is never read, replaced, or deleted); roster/defaults under hosted tests redirect to temp or assert `.standard` byte-unchanged; `psScan` is stubbed (a dev machine may run the real engine).
- Shared helpers are `internal` in the founding file. When a suite crosses a file-length or type-body ceiling, split the new pins into their own file and keep the helpers where they are (PostStorePassTests, MicropubModelTests, MCPToolsPromoteTests, SettingsModelWritePathTests precedents).
- Engine tests run IN-PROCESS at the `EngineTransport` seam (#178): `ScriptedEngine.swift` holds the scripted adapter (mode strings mirroring the retired zsh fake: full/crashAfterHandshake/hangOnPrompt/cancelOnPrompt/refuseOnPrompt/noStopReason/strayResearchOnPrompt/loadReplay*/strictMcp), the shared payloads (`ScriptedPayloads`), and the rig roots — build rigs there, never duplicate. Spawn observables: the rig's spawned-profiles record (which engine ran), transport identity (`mentor.host.chat`/`oneShot`) where pid pins used to live, `isClosed` for reaped. Child processes appear in EXACTLY ONE suite — `EngineSmokeTests`, one real-process wire smoke per LLM Surface (chat/pass1/pass2, ADR-0014) over the zsh fake (`makeFakeACP`/`acpTempDir`, defined in ACPClientTests.swift, kept as the wire fixture). The fake-`hermes` CLI harness (ProfileProvisioner/Backup suites) still speaks real `Process` with base64 payloads, `<name>-spawn-log`, `<name>-prompt-log`, and `defer` teardown at rig creation.
- Engine tests run IN-PROCESS at the `EngineTransport` seam (#178): `ScriptedEngine.swift` holds the scripted adapter (mode strings mirroring the retired zsh fake: full/crashAfterHandshake/hangOnPrompt/hangOnPromptLoad/cancelOnPrompt/refuseOnPrompt/noStopReason/strayResearchOnPrompt/loadReplay*/strictMcp), the shared payloads (`ScriptedPayloads`), and the rig roots — build rigs there, never duplicate. Spawn observables: the rig's spawned-profiles record (which engine ran), transport identity (`mentor.host.chat`/`oneShot`) where pid pins used to live, `isClosed` for reaped. Child processes appear in EXACTLY ONE suite — `EngineSmokeTests`, one real-process wire smoke per LLM Surface (chat/pass1/pass2, ADR-0014) over the zsh fake (`makeFakeACP`/`acpTempDir`, defined in ACPClientTests.swift, kept as the wire fixture). The fake-`hermes` CLI harness (ProfileProvisioner/Backup suites) still speaks real `Process` with base64 payloads, `<name>-spawn-log`, `<name>-prompt-log`, and `defer` teardown at rig creation.
- Waiting: bounded poll loops, each arming its OWN deadline; poll for the watcher rescan after disk writes. Lock/goal machine tests pass `spawnsTicker: false` — the real 1 s ticker could complete a met goal before an injected tick (the #30/#147 flake family).
- Suite-name filters (`-only-testing:MuseionTests/<Suite>`) do not run free functions — pin things as suite members.
+3 -3
View File
@@ -210,7 +210,7 @@ final class ScriptedEngine: EngineTransport, @unchecked Sendable {
self.onStderrLine?("cancel received")
// #124: the cancel-acknowledging hold — the real engine answers
// its hanging prompt the moment session/cancel arrives.
guard self.mode == "hangOnPrompt", let id = self.heldPromptID,
guard self.mode.hasPrefix("hangOnPrompt"), let id = self.heldPromptID,
let continuation = self.parked.removeValue(forKey: id) else { return }
self.heldPromptID = nil
continuation.resume(returning: .object(["stopReason": .string("cancelled")]))
@@ -357,7 +357,7 @@ extension ScriptedEngine {
return
}
toolCall(sid, title: "submit_fix_cards", rawInput: ScriptedPayloads.fixCard)
if mode == "hangOnPrompt" {
if mode.hasPrefix("hangOnPrompt") {
park(id: id, continuation: continuation)
heldPromptID = id
return
@@ -370,7 +370,7 @@ extension ScriptedEngine {
params: JSONValue?,
continuation: CheckedContinuation<JSONValue?, any Error>,
) {
guard mode.hasPrefix("loadReplay") else {
guard mode.hasPrefix("loadReplay") || mode == "hangOnPromptLoad" else {
park(id: id, continuation: continuation) // the zsh never answers
return
}
+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