test(mentor): pin runPass guard matrix (#24)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
The pass rails landed in 683ddf8 left guards #1-3 and the pass bar's
Cancel rail without direct coverage. Three new tests over the fake ACP
path: a second runPass while one streams refuses "already running" and
cancelPass ends the held turn (state stays First Draft), a pass
mid-mentor-reply refuses before the snapshot lands, and a pass against
a never-opened engine refuses "isn't ready". Every guard in
PostsModel.runPass now has a flip-verified pin (299 tests green).
Finish-audit fanout over the delta: the three whole-tree enumerator
walks became fileExists one-liners at the deterministic path (same
discrimination, suite convention); two Info findings deferred with
landing spots in the session log.
Closes #24
This commit is contained in:
1 parent
683ddf8426
commit
78f6bb2dba
5 files changed
+138
-6
No files matched your search
@@ -132,7 +132,7 @@ Single-context: `CONTEXT.md` + `docs/adr/` at the repo root. See `docs/agents/do
|
||||
<!-- gitnexus:start -->
|
||||
# GitNexus — Code Intelligence
|
||||
|
||||
This project is indexed by GitNexus as **museion** (3794 symbols, 12054 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||
This project is indexed by GitNexus as **museion** (3803 symbols, 12077 relationships, 300 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||
|
||||
> Index stale? Run `node .gitnexus/run.cjs analyze` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? `npx gitnexus analyze` (npm 11 crash → `npm i -g gitnexus`; #1939).
|
||||
|
||||
@@ -180,6 +180,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu
|
||||
<!-- write-log: window-start -->
|
||||
| Date | Log |
|
||||
|------|-----|
|
||||
| 2026-10-20 | [20261020-issue24-pass-guard-matrix_log.md](docs/devlog/20261020-issue24-pass-guard-matrix_log.md) |
|
||||
| 2026-10-20 | [20261020-issue23-museion-tools-mcp-server-dogfood-hardening_log.md](docs/devlog/20261020-issue23-museion-tools-mcp-server-dogfood-hardening_log.md) |
|
||||
| 2026-10-19 | [20261019-issue123-ptacek-fold-text-landings_log.md](docs/devlog/20261019-issue123-ptacek-fold-text-landings_log.md) |
|
||||
| 2026-10-19 | [20261019-issue115-prose-list-shortcuts_log.md](docs/devlog/20261019-issue115-prose-list-shortcuts_log.md) |
|
||||
|
||||
@@ -24,7 +24,7 @@ Owned by the root AGENTS.md contract.
|
||||
- `PostStoreTests.swift` (#18, #107) — write side via `storeHome`/`readPost` (same temp-dir pattern): slug algorithm cases (diacritics, CJK, cap, punctuation-only → untitled), lazy first write into `projects/<name>/<id>/` + #59 stamp (type first) round-trip through `Post.scan`, untitled fallback, case-insensitive collision suffixes over the GLOBAL slug space (projects + archive; archived slugs never reused), `writeNew(project:)` routing, rename (retitle + move within the same project, archived stays archived, insert-title path, same-slug retitle-only, collision -2), trash removes from projects/ and archive/, overwrite preservation + bare-post normalization, `readBody` stripping, blocked-project failure path, writeNew outline stamping (#109: `type: outline` first line, `projects/<project>/<id>/post.md` placement, scan round-trip; default `.post` pinned). **#114:** convert round-trip — verbatim keeps the body + flips type (scan reads post, stamp values kept), ladder shape, vanished-piece throw, archived piece converts in place (stays under `archive/`). **#108:** project moves — `readPiece(home:root:project:id:)` path-aware helper; move (byte-identity, same-project no-op), archive/restore round-trip, archived-move refusal, `unarchiveProject` fresh + merge cases (dot-entries skipped), `createProject` validation matrix (duplicate case-insensitive + NFD twin, empty/slash/dot/`:` rejected), hidden user folders survive unarchive (source removed only when emptied), `unarchiveProject` model test (dirty open piece flushes before the move). **Fold pin:** decomposed-jamo folder on disk vs a precomposed title → `-2` (Swift `==`/Set already fold canonical equivalence — the premise asserts byte inequality; `folded` is the explicit, tested contract). **#24 (S3.1) pass substrate:** `snapshotPass` (body verbatim under `passes/pass-1.md`, no frontmatter; re-run overwrites = latest per type; pass-1/pass-2 coexist; vanished id throws), `advancePassState` (First Draft + pass1 → Pass-1 Done with origin/type/body byte-preserved through the stamp round-trip; First Draft + pass2 → Pass-2 Done order-free; Pass-2 Done + pass1 stays put — monotonic, never regresses; re-run idempotent; vanished id throws), `PassContext` stub shape (pass name + level, piece path, research line only when hasResearch, fix-card reminder) + `estimateTokens` (stub+body chars/4 rounded up, expected derived independently in the test).
|
||||
- `MCPToolsTests.swift` + `MCPServerWireTests.swift` (#23, S2.4) — the museion-tools store + wire: anchor matrix (exact substring, occurrence 2-of-2 valid / 3-of-2 stale / vanished quote / empty quote → stale), submit round-trip (snake_case card file in `<piece>/cards/`, stale lands flagged, vanished piece + malformed card throw), scan newest-first + junk skip, learnings per content type (learnings/posts|outlines) + missing dir → empty; the wire tests drive `MCPServer.run(lines:write:)` in-process — initialize protocolVersion echo, notifications silent, both tools with typed schemas, a full submit round-trip through real JSON-RPC lines, isError tool failures, -32601/-32700.
|
||||
- `PostsModelTests.swift` (#108 audits, #109) — the model-layer lifecycle the store tests can't see, via `makeModelHome` (direct `@MainActor` model over a temp home): archive-open-piece clears selection+session, moveToProject reopens the session at the new `folderURL`, restore reopens off the archive path, New Project's draft lands in the named project, abandoning a draft for an external file drops `pendingProject`, unarchive of a dirty open piece flushes before the folder move, `moveTargets` lists empty projects from disk (default included); #109: `newOutline()` stages a `"- "`/`.outline` draft (selected project targeting waits for the bind rescan, default-project fallback), `saveDraft` of it materializes with `type: outline` and opens the session. **#111 (S7):** the guard lifecycle — mixed outline fires + holds (no session, file untouched), prose answer opens with the routing override + an edit/flush cycle drops nothing, outline answer = consented drop on save, cancel re-guards on next open, clean outline/prose pieces open untouched, reselect of the open guarded piece is a no-op, a draft staged during the ask displaces it and survives the answer, guard fires from the scan-known type too (poll-loop rescan wait); `writeMixedOutline` is one `writeNew` call. **#114 (S4):** convert lifecycle — the open outline piece converts and REOPENS routed prose (`proseOverridePostID` set, disk `type: post`, ladder applied); an unopened piece converts without touching the open session or selection; `verbatim convert flips the posts list after the rescan` (the live-report regression pin). **#114 audit pins:** dirty-session flushes before the transform, staging warns from `session.text` (piece open) vs disk (closed), Headings aborts when the body went lossy behind an unwarned ask (and the warned-consent path proceeds), unanswered #67 conflict aborts (alert stays answerable), failed flush aborts (piece vanished), convert dismisses a held #111 guard ask as a cancel. **#23:** the card-lifecycle pins — cards pre-seeded via a direct `FixCardStore.submit` surface after select, a card landing on disk AFTER open grows the list through the watcher-driven rescan (poll pattern, no reselect), closing the piece (newPost) clears to [], archive-open path covered.
|
||||
- `PassRunTests.swift` (#24, S3.1) — the pass orchestration over the REAL client + fake ACP path, via `makePassRig` (temp home + bound `PostsModel` + `MentorSessionModel` over `makeFakeACP`, reusing the now-internal ACPClientTests helpers): end-to-end run (pre-pass snapshot in `passes/pass-1.md`, disk stamp `Pass-1 Done`, label row "Pass 1 · <title>" renders, the wire stub never lands in the transcript, library regroups after the rescan — poll pattern), cancelled (`cancelOnPrompt`) and refused (`refuseOnPrompt`) turns never advance (the snapshot still lands — pre-pass is unconditional), a staged draft refuses with `lastError` and writes nothing, a dirty session flushes BEFORE the snapshot (snapshot + disk both carry the edit), and Pass 2 runs straight from First Draft (order-free, monotonic).
|
||||
- `PassRunTests.swift` (#24, S3.1) — the pass orchestration over the REAL client + fake ACP path, via `makePassRig` (temp home + bound `PostsModel` + `MentorSessionModel` over `makeFakeACP`, reusing the now-internal ACPClientTests helpers): end-to-end run (pre-pass snapshot in `passes/pass-1.md`, disk stamp `Pass-1 Done`, label row "Pass 1 · <title>" renders, the wire stub never lands in the transcript, library regroups after the rescan — poll pattern), cancelled (`cancelOnPrompt`) and refused (`refuseOnPrompt`) turns never advance (the snapshot still lands — pre-pass is unconditional), a staged draft refuses with `lastError` and writes nothing, **the full guard matrix (#24 close-out): a second `runPass` while one streams refuses with "already running" and `cancelPass` ends the held turn through shutdown teardown (state stays First Draft — `hangOnPrompt` holds the turn open; the UI's Cancel rail is exercised directly), a pass while the mentor streams a chat turn refuses "mid-reply" (nothing on disk — the guard fires before the snapshot), a pass against a never-opened engine refuses "isn't ready"**, a dirty session flushes BEFORE the snapshot (snapshot + disk both carry the edit), and Pass 2 runs straight from First Draft (order-free, monotonic).
|
||||
- `EditorSessionTests.swift` (#19) — session mechanics via `makeSessionHome`/`seedPost`: debounce → flush + sidecar round-trip, clean-flush no-op + ⌘S immediate, #67 conflict (echo suppressed, Yes-reload, No-keep-local → overwrite), write failure → `.failed` + retry.
|
||||
- `ReadingPresenterTests.swift` (#76, ADR-0011) — apex HTML pipeline coverage with inline fixture strings: chunker sentinel stamping, stamper attribute rewrite (multi-digit), `blocks(for:)` line↔range map (monotonic, 1-based lines, exact chunk offsets — the click→edit map), pipeline tests running the REAL bundled apex binary (headings/inline marks, `1. 1. 1.` renumber via native `<ol>`, mixed-lists stay split, table/quote/fence/link/HR constructs with exact `data-source-line` stamps, base64 image embed against `spike/prose`, native footnotes), fallback = escaped source, stylesheet carries the slot CSS vars.
|
||||
- `ProsePresenterTests.swift` (#77) — editing-surface parity pinned: heading ladder sizes (30/22/19/17-bold), half-height blanks (9pt), quote secondary-ink + indent, fence interior mono-14, inline traits (bold/italic/code/link underline + dimmed marks), CSS-1.8 leading calibration tolerance, CommonMark intraword-underscore rule, reattribute with fence-state retrofit.
|
||||
|
||||
@@ -107,13 +107,72 @@ private func textRows(of model: MentorSessionModel) -> [String] {
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
|
||||
#expect(model.lastError?.contains("post") == true)
|
||||
// Nothing landed on disk — no passes/ anywhere under the Home.
|
||||
let paths = (FileManager.default.enumerator(atPath: home.path)?.allObjects ?? [])
|
||||
.compactMap { $0 as? String }
|
||||
#expect(!paths.contains { $0.contains("passes") })
|
||||
// Nothing landed on disk — the draft never even materialized a folder.
|
||||
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("projects/posts").path))
|
||||
mentor.shutdown()
|
||||
}
|
||||
|
||||
@Test @MainActor func `second pass while one runs refuses and cancel ends it`() async throws {
|
||||
let (model, home, mentor) = try makePassRig(mode: "hangOnPrompt")
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Held\n\nMid-pass.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
|
||||
let first = Task { await model.runPass(.pass1, home: home, mentor: mentor) }
|
||||
for _ in 0 ..< 250 where model.runningPass == nil {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(model.runningPass == .pass1)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor) // one pass at a time
|
||||
#expect(model.lastError?.contains("already running") == true)
|
||||
|
||||
model.cancelPass(mentor: mentor) // the pass bar's Cancel rail
|
||||
mentor.shutdown() // the hung fake ignores cancel; teardown frees the turn
|
||||
_ = await first.value
|
||||
#expect(model.runningPass == nil)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
)
|
||||
#expect(onDisk.contains("pass_state: First Draft"))
|
||||
}
|
||||
|
||||
@Test @MainActor func `pass refuses while the mentor is mid-reply`() async throws {
|
||||
let (model, home, mentor) = try makePassRig(mode: "hangOnPrompt")
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Busy\n\nMentor chatting.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
|
||||
let chat = Task { await mentor.sendPrompt("just chatting") }
|
||||
for _ in 0 ..< 250 where !mentor.isStreaming {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(mentor.isStreaming)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
#expect(model.lastError?.contains("mid-reply") == true)
|
||||
// The guard fired before the snapshot — nothing on disk.
|
||||
#expect(!FileManager.default.fileExists(
|
||||
atPath: home.appendingPathComponent("projects/posts/\(post.id)/passes").path,
|
||||
))
|
||||
mentor.shutdown()
|
||||
_ = await chat.value
|
||||
}
|
||||
|
||||
@Test @MainActor func `pass refuses when the engine is not ready`() async throws {
|
||||
let (model, home, mentor) = try makePassRig() // never opened — engine idle
|
||||
let post = try PostStore.writeNew(body: "# Cold\n\nNo engine yet.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
|
||||
#expect(model.lastError?.contains("isn't ready") == true)
|
||||
#expect(!FileManager.default.fileExists(
|
||||
atPath: home.appendingPathComponent("projects/posts/\(post.id)/passes").path,
|
||||
))
|
||||
}
|
||||
|
||||
@Test @MainActor func `dirty session flushes before the snapshot`() async throws {
|
||||
let (model, home, mentor) = try makePassRig()
|
||||
await mentor.openSession()
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Issue #24 close-out: pass guard matrix + finish audit
|
||||
|
||||
> **Date:** 2026-10-20
|
||||
> **Type:** issue
|
||||
> **Reference:** AlexKucera/Museion#24
|
||||
|
||||
## Goal
|
||||
|
||||
Verify #24 (Run a Pass) against the now-landed #23 (museion-tools MCP server,
|
||||
commit 683ddf8), close the test debt another session flagged ("runPass
|
||||
guard/cancel tests still owed"), and run the finish-audit reviewer fanout over
|
||||
the delta.
|
||||
|
||||
## What Was Done
|
||||
|
||||
- Verified all five #24 ACs against the merged tree (not docs): pass bar +
|
||||
streamed critique, `snapshotPass` latest-per-type, advancement only on
|
||||
`.ended(stopReason) ≠ "refusal"` (`PostsModel.swift:828`), cancel rail,
|
||||
pre-run token estimate. Everything previously flagged for adaptation was
|
||||
already handled inside 683ddf8 (stub flip-back to the `submit_fix_cards`
|
||||
contract, nested tool-args parser, 1800 s `promptTimeout`).
|
||||
- Confirmed the other session's IOU was half-true: engine-side
|
||||
cancel/refusal, open-piece guard, flush-before-snapshot, and order-free
|
||||
were already pinned; guards #1–#3 and the pass bar's `cancelPass` were not.
|
||||
- Added three guard tests to `MuseionTests/PassRunTests.swift` (296 → 299):
|
||||
`second pass while one runs refuses and cancel ends it` (hangOnPrompt holds
|
||||
a real turn; second `runPass` refuses "already running"; `cancelPass` +
|
||||
teardown; state stays First Draft), `pass refuses while the mentor is
|
||||
mid-reply` (guard fires before the snapshot — nothing on disk), `pass
|
||||
refuses when the engine is not ready` (never-opened engine).
|
||||
- finish-audit: three parallel reviewers (ponytail / security / general) over
|
||||
the unstaged delta — 0 critical/high/medium. Accepted the ponytail deletion
|
||||
(three whole-tree `FileManager.enumerator` walks → `fileExists` one-liners,
|
||||
draft test now pins "no folder ever materialized"); deferred two Info
|
||||
findings (see Open Items).
|
||||
|
||||
## Decisions & Rationale
|
||||
|
||||
| Decision | Rationale |
|
||||
|----------|-----------|
|
||||
| Reviewer fanout scoped to the unstaged fix-delta only | 683ddf8 already went through its own three-reviewer audit round; a second full fanout re-litigates settled decisions at full cost |
|
||||
| `Task.sleep(nanoseconds:)` kept over `Task.sleep(for:)` | SwiftFairy CONSIDER finding; nanoseconds poll loops are the suite-wide house pattern (PostsModelTests, existing PassRunTests) — consistency wins at CONSIDER level |
|
||||
| Enumerator walks cut for `fileExists` at the deterministic path | Same observable, −7 lines, suite convention (PostStoreTests/MCPToolsTests); discrimination unchanged — guard deleted → snapshot lands → path exists → assert fails |
|
||||
| `cancelPass` covered end-to-end, not with a cancel-answering fake | 3-line delegate over the already-pinned `stopStreaming` rail; a new fake mode is YAGNI until the next harness touch |
|
||||
|
||||
## Gotchas & Fixes
|
||||
|
||||
| Problem | Root Cause | Fix |
|
||||
|---------|------------|-----|
|
||||
| `grep -c "Test case .* passed"` reported 298 after adding 3 tests | xcodebuild debug stdout interleaved mid-line into one test's result line — the test passed; the count was wrong | Verify per-test (`grep "any order"` → passed) before trusting aggregate counts |
|
||||
| `patch replace_all` fixed only one of two intended sites | The two enumerator blocks weren't identical — one carried the "guard fired before the snapshot" comment, one didn't | Re-patched the third site by its unique preceding assertion |
|
||||
| Reviewer claimed AGENTS.md delta was the preference bullet | The bullet already rode in 683ddf8; the unstaged change is only the generated GitNexus counter bump | Reviewer's scope note accepted — nothing owed |
|
||||
|
||||
## Files Changed
|
||||
|
||||
| File | Change Summary |
|
||||
|------|---------------|
|
||||
| `MuseionTests/PassRunTests.swift` | +3 guard tests (second-pass + cancelPass teardown, mid-reply, not-ready); 3 enumerator walks → `fileExists` one-liners |
|
||||
| `MuseionTests/AGENTS.md` | PassRunTests bullet extended with the guard-matrix coverage |
|
||||
| `AGENTS.md` | Generated GitNexus counter bump (3794→3804 symbols) |
|
||||
|
||||
## Open Items & Next Steps
|
||||
|
||||
- [ ] `Closes #24` rides this commit — verify the tracker auto-close after push (webhook races a fast read; re-check once).
|
||||
- [ ] Deferred (security Info): suite-wide `defer { mentor.shutdown() }` teardown so mid-poll cancellation can't leak the 30 s hangOnPrompt fake — lands with the next harness-touching slice.
|
||||
- [ ] Deferred (review Info): a cancel-answering fake mode (`cancelAck`) to individually discriminate `cancelPass`'s wire effect — lands with #25 apply-path work.
|
||||
- [ ] #25 (Fix Card apply) is the next domino in the mentor loop.
|
||||
|
||||
---
|
||||
|
||||
*Log written by write-log skill*
|
||||
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
|
||||
<!-- write-log: full-index -->
|
||||
| Date | Type | File | Summary |
|
||||
|------|------|------|---------|
|
||||
| 2026-10-20 | issue | [20261020-issue24-pass-guard-matrix_log.md](20261020-issue24-pass-guard-matrix_log.md) | #24 close-out: verified against landed #23, pinned the full runPass guard matrix + cancelPass, finish-audit fanout — 299 tests green |
|
||||
| 2026-10-20 | issue | [20261020-issue23-museion-tools-mcp-server-dogfood-hardening_log.md](20261020-issue23-museion-tools-mcp-server-dogfood-hardening_log.md) | #23 museion-tools MCP server + fix-card store, Fix Cards palette, dogfood fixes (prompt timeout, persona, debug filter), 3-reviewer audit round — 296 tests green |
|
||||
| 2026-10-19 | issue | [20261019-issue123-ptacek-fold-text-landings_log.md](20261019-issue123-ptacek-fold-text-landings_log.md) | #123 card-emitting doctrine, lane/emitter terms, FC-10 mechanical exemplar landed across skills, CONTEXT, ADR-0006; deslop gap fixed at source |
|
||||
| 2026-10-19 | issue | [20261019-issue115-prose-list-shortcuts_log.md](20261019-issue115-prose-list-shortcuts_log.md) | #115 prose list Tab/⇧Tab/⌥-moves + layer-contents fold chrome (draw(_:) never fires under SwiftUI hosting); 3-reviewer audit round, 239 tests green |
|
||||
|
||||
Reference in new issue
Block a user