refactor(lint): clear the last five error spots (#147)
CI / ci (push) Canceled after 0s

The repo contract "SwiftFormat + SwiftLint must both stay clean" had
five error spots left beyond #146's PostsModel split, all mechanical.

PostStore's enum body spanned 354 against 350 — the cursor-sidecar
group (#66: CursorState + stateURL/readCursor/writeCursor, already its
own MARK section) moves verbatim into a same-file nonisolated
extension slotted chronologically before the #141 ingest MARK; the
enum body lands at 334 and PostStore.CursorState keeps its qualified
name, so no caller changes. Six single-char locals in
ProseListTextView's dropIndex/rectY/isGap get real names (plus lo/hi
in the same function — same violation class), one in ImageIngestTests'
bandedRectY. The 194-char guard in ProseList.indent and the 221-char
guard in OutlineEditorView.endDrag wrap in the house
else-carries-the-brace form (#142 landmine avoided).

PostStoreTests crossed its 1000-line ceiling at 1061 — split at the
Pass substrate MARK per the MicropubModelTests precedent: the
pass-adjacent write sides (#24/#29/#31) move byte-identical into
PostStorePassTests.swift, shared helpers storeHome/readPost/readPiece
stay internal in the original, and the #29 scenario header travels
with its tests. 63 tests in, 63 out.

The split's new parallel schedule exposed two latent test races,
reproduced idle (~50% for the first) and fixed at the root:
EditorSessionTests' sidecar poll inherited loop 1's deadline and timed
out holding flush 1's default-zero sidecar (zeros, never nil — the
telltale) — each loop now arms its own. SessionLifecycleTests' three
stderrTail asserts raced the client's main-queue stderr drain (the #30
class) — a drainStderr bounded poll now precedes each.

swiftlint reports zero errors on both targets; residual warning-tier
notices match the standing #146 posture (the error tier is the bar;
the one new notice is PostStorePassTests at 473/400 — a 1070-line
suite cannot split into two files both under 400). swiftformat clean.

Full suite 574/574 by xcresult executed count (573 unit + 1 UI smoke),
twice consecutively plus the finish-up rerun.

Closes #147
This commit is contained in:
AlexKucera committed 2026-11-03 13:47:01 +01:00
1 parent 012f91727f
commit 4606fd4628
13 files changed
+639 -526

No files matched your search

+4 -1
View File
@@ -678,7 +678,10 @@ extension OutlineEditorView {
private func endDrag(at point: CGPoint?, frames: [UUID: CGRect]?) {
let info = drag
drag = nil
guard let point, let info, let frames, let target = OutlinePresenter.hitTestDrop(point: point, rows: materializedRows(frames: frames)), OutlinePresenter.applyDrop(target, moving: info.moving, in: &nodes) else { return }
guard let point, let info, let frames,
let target = OutlinePresenter.hitTestDrop(point: point, rows: materializedRows(frames: frames)),
OutlinePresenter.applyDrop(target, moving: info.moving, in: &nodes)
else { return }
selectionAnchor = info.moving.first
focusedID = info.moving.last
pendingCaret = nil
+37 -32
View File
@@ -338,38 +338,6 @@ nonisolated enum PostStore {
.write(to: piece.dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
}
// MARK: Cursor-state sidecar (#66)
/// Cursor state for one post: selection + scroll, `.museion-state.json`
/// in the post folder — Finder-invisible, human-diffable, dies with the
/// folder on Trash. Drafts skip it (#62).
struct CursorState: Codable, Equatable {
var selectionLocation: Int = 0
var selectionLength: Int = 0
var scrollOffset: Double = 0
}
private static func stateURL(id: String, home: URL) -> URL? {
folder(of: id, home: home)?.appendingPathComponent(".museion-state.json")
}
/// Read the sidecar; nil when absent or corrupt (a fresh cursor is fine).
static func readCursor(id: String, home: URL) -> CursorState? {
guard let url = stateURL(id: id, home: home),
let data = try? Data(contentsOf: url)
else { return nil }
return try? JSONDecoder().decode(CursorState.self, from: data)
}
/// Write the sidecar. Best-effort by design — a failed cursor write must
/// never read as a failed content save, so failures are swallowed here.
static func writeCursor(_ state: CursorState, id: String, home: URL) {
guard let url = stateURL(id: id, home: home),
let data = try? JSONEncoder().encode(state)
else { return }
try? data.write(to: url, options: .atomic)
}
/// Explicit Rename (#60): rewrite the `# Title` line as the first
/// non-empty body line, then move the folder to the new slug — within
/// the SAME parent (ADR-0012: the piece stays in its project, archived
@@ -789,6 +757,43 @@ nonisolated extension PostStore {
}
}
// MARK: Cursor-state sidecar (#66)
/// #66: the sidecar group, moved to a same-file extension at the enum's
/// type-body ceiling (#147) — the PostsModel treatment. Same file as the
/// enum: `private` members stay reachable at file scope.
nonisolated extension PostStore {
/// Cursor state for one post: selection + scroll, `.museion-state.json`
/// in the post folder — Finder-invisible, human-diffable, dies with the
/// folder on Trash. Drafts skip it (#62).
struct CursorState: Codable, Equatable {
var selectionLocation: Int = 0
var selectionLength: Int = 0
var scrollOffset: Double = 0
}
private static func stateURL(id: String, home: URL) -> URL? {
folder(of: id, home: home)?.appendingPathComponent(".museion-state.json")
}
/// Read the sidecar; nil when absent or corrupt (a fresh cursor is fine).
static func readCursor(id: String, home: URL) -> CursorState? {
guard let url = stateURL(id: id, home: home),
let data = try? Data(contentsOf: url)
else { return nil }
return try? JSONDecoder().decode(CursorState.self, from: data)
}
/// Write the sidecar. Best-effort by design — a failed cursor write must
/// never read as a failed content save, so failures are swallowed here.
static func writeCursor(_ state: CursorState, id: String, home: URL) {
guard let url = stateURL(id: id, home: home),
let data = try? JSONEncoder().encode(state)
else { return }
try? data.write(to: url, options: .atomic)
}
}
// MARK: - #141 Illustration ingest
/// #141's refusal reasons — the drop surface shows `localizedDescription`
+3 -1
View File
@@ -153,7 +153,9 @@ nonisolated extension ProseList {
/// minus our indent. No previous sibling → nil (boundary no-op).
static func indent(_ item: Item, caret: Int, in text: String) -> Edit? {
let scanned = lines(in: text)
guard let idx = lineIndex(of: item.markerLine.location, in: scanned), let sibIdx = adjacentSiblingLine(scanned, from: idx, through: idx, indent: item.indent, direction: -1) else { return nil }
guard let idx = lineIndex(of: item.markerLine.location, in: scanned),
let sibIdx = adjacentSiblingLine(scanned, from: idx, through: idx, indent: item.indent, direction: -1)
else { return nil }
let delta = contentColumn(scanned[sibIdx].text) - item.indent
guard delta > 0 else { return nil }
let body = blockBody(text, item.block)
+23 -23
View File
@@ -295,37 +295,37 @@ final class ProseListTextView: NSTextView {
guard length > 0 else { return 0 }
var lastAbove: Int?
var firstInBand = -1
for s in 0 ... sampleCount {
let i = min(length - 1, s * length / sampleCount)
let y = rectY(i)
guard y >= bandMinY, y <= bandMaxY else { continue }
for sample in 0 ... sampleCount {
let index = min(length - 1, sample * length / sampleCount)
let sampleY = rectY(index)
guard sampleY >= bandMinY, sampleY <= bandMaxY else { continue }
if firstInBand < 0 {
firstInBand = i
firstInBand = index
}
if y >= targetY {
lastAbove = i // at-or-above the drop on screen
} else if let above = lastAbove, above < i {
// Bracket [above, i] straddles the drop; both ends are
if sampleY >= targetY {
lastAbove = index // at-or-above the drop on screen
} else if let above = lastAbove, above < index {
// Bracket [above, index] straddles the drop; both ends are
// in-band (laid out, monotone) so the search probes real rects.
var lo = above
var hi = i
while lo < hi {
let mid = (lo + hi) / 2
var lowerBound = above
var upperBound = index
while lowerBound < upperBound {
let mid = (lowerBound + upperBound) / 2
if rectY(mid) >= targetY {
lo = mid + 1
lowerBound = mid + 1
} else {
hi = mid
upperBound = mid
}
}
return min(lo, length)
return min(lowerBound, length)
}
}
return min(lastAbove ?? max(firstInBand, 0), length)
}
private func rectY(_ i: Int, of length: Int) -> CGFloat {
guard window != nil, i >= 0, i < length else { return -1 } // viewless (tests): land at index 0
return firstRect(forCharacterRange: NSRange(location: i, length: 1), actualRange: nil).midY
private func rectY(_ charIndex: Int, of length: Int) -> CGFloat {
guard window != nil, charIndex >= 0, charIndex < length else { return -1 } // viewless (tests): land at index 0
return firstRect(forCharacterRange: NSRange(location: charIndex, length: 1), actualRange: nil).midY
}
/// #141's SwiftUI entry — the window `.dropDestination`'s perform
@@ -357,14 +357,14 @@ final class ProseListTextView: NSTextView {
targetY: mouse.y,
bandMinY: screenVisible.minY,
bandMaxY: screenVisible.maxY,
) { i in
rectY(i, of: length)
) { charIndex in
rectY(charIndex, of: length)
}
// Never splice inside a word or link — slide to the next gap
// (a drop ON an existing ref appends after it, dogfood 2026-11-02).
let buffer = string as NSString
func isGap(_ c: unichar) -> Bool {
guard let scalar = Unicode.Scalar(Int(c)) else { return false }
func isGap(_ char: unichar) -> Bool {
guard let scalar = Unicode.Scalar(Int(char)) else { return false }
return CharacterSet.whitespacesAndNewlines.contains(scalar)
}
if index > 0, index < length,