test(folds): pin the typing budget at N/2N
CI / ci (push) Canceled after 0s

The #142 in-place re-key had correctness coverage but no typing-cost
guard — a quiet fallback to the full pass keeps every correctness
pin green while restoring O(buffer) work per keystroke. Add an
operation-count instrument (never wall-time): ProseList.parents
gains an observeLines reporter, refreshFolds/refreshFoldRendering
thread a per-call observer, and a per-instance onLineScan hook
windows the paths that call refreshFolds() bare (the PostEditorView
coordinator tail). No shared state — the hosted suite is parallel.

Three pins: zero scanned lines for typing beside a fold at N=204
and 2N=404 lines; an exact-count control (206/406) proving the
instrument is live and scaling; and a through-seam pin driving real
insertText through a real ProseTextView.Coordinator into
refreshFolds() — zero scans, fold survives, self-controlling with
its own 206 liveness assert. Mutation-checked: severing the single
observer firing fails the control and the through-seam pin.
This commit is contained in:
AlexKucera committed 2026-11-13 17:21:16 +01:00
1 parent 7ed304124e
commit c460545c59
3 files changed
+126 -5

No files matched your search

+6 -1
View File
@@ -121,8 +121,13 @@ nonisolated enum ProseList {
let hiddenLineCount: Int
}
static func parents(in text: String) -> [ParentHint] {
/// `observeLines` (brief-24): reports how many lines the scan visited —
/// the typing-budget instrument. Nil in production; tests inject it to
/// pin that single-line typing edits scan ZERO lines (the #142 in-place
/// re-key) while full passes scan O(lines). Per-call, no shared state.
static func parents(in text: String, observeLines: ((Int) -> Void)? = nil) -> [ParentHint] {
let scanned = lines(in: text)
observeLines?(scanned.count)
var out: [ParentHint] = []
for (idx, line) in scanned.enumerated() where line.isList {
let bounds = blockBounds(scanned, from: idx, indent: line.indent)
+14 -4
View File
@@ -90,6 +90,12 @@ final class ProseListTextView: NSTextView {
/// rejected, or none) → the full pass.
var pendingPlainEdit: (range: NSRange, delta: Int)?
/// Brief-24 typing-budget window for paths that call `refreshFolds()`
/// bare (the PostEditorView coordinator's textDidChange tail) — a
/// per-instance, test-owned hook; nil in production. The per-call
/// `observeScan` parameter takes precedence when both are set.
var onLineScan: ((Int) -> Void)?
override func shouldChangeText(in affectedRange: NSRange, replacementString: String?) -> Bool {
let accepted = super.shouldChangeText(in: affectedRange, replacementString: replacementString)
pendingPlainEdit = nil
@@ -202,7 +208,11 @@ final class ProseListTextView: NSTextView {
/// recorded single-line edit takes the in-place re-key (no rescan, no
/// storage swap); no folds → chrome-only refresh, everything else → the
/// full pass.
func refreshFolds() {
/// `observeScan` (brief-24): the typing-budget instrument — reports the
/// line count of every full-buffer scan this refresh performs. Nil in
/// production; the typing-budget pins inject it to prove single-line
/// edits take the in-place re-key (zero scans) at any buffer size.
func refreshFolds(observeScan: ((Int) -> Void)? = nil) {
defer { pendingPlainEdit = nil }
if let edit = pendingPlainEdit, !folds.isEmpty, rekeyAfterPlainEdit(edit) {
return
@@ -211,7 +221,7 @@ final class ProseListTextView: NSTextView {
chrome.refresh()
return
}
refreshFoldRendering()
refreshFoldRendering(observeScan: observeScan)
}
func toggleFold(_ parent: ProseList.ParentHint) {
@@ -227,8 +237,8 @@ final class ProseListTextView: NSTextView {
/// same marker text; no match → the fold dies), restyle the document,
/// re-hide every live scope, and park a caret that landed inside a
/// hidden scope at its parent's marker end.
func refreshFoldRendering() {
let parents = ProseList.parents(in: string)
func refreshFoldRendering(observeScan: ((Int) -> Void)? = nil) {
let parents = ProseList.parents(in: string, observeLines: observeScan ?? onLineScan)
// ponytail: nearest-same-marker re-key can move a fold across duplicate
// marker texts — track the edit delta in shouldChangeText if that bites.
var seenKeys = Set<Int>()