Files
museion/MuseionTests/WordBoundaryTruncationTests.swift
AlexKucera efad422e03
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
fix(ui): finish-audit fixes — blank search glyph, quadratic truncation, scope-rail refusal leak
Three-reviewer audit of the polish overhaul:
- magnifyinglass -> magnifyingglass (blank SF Symbol, all 3 seats)
- WordBoundaryTruncation.fit measures each word once (O(n^2) -> O(n)
  on pathological imported titles; live-title pins unchanged)
- scopeHostedSession defers behind an in-flight replay instead of
  refusing (automatic actions never leak a 'Resume refused' row);
  replay completion re-fires the pending scope — pinned over the real
  client path with loadReplayHold, flip-verified
- transcript ForEach on stable row ids, not indices
- delete dead softBorder param; fold caretPastLeadingBlanks onto
  firstContentLocation; native TextField prompt for the search field
- ElidedPathText.candidates/elide nonisolated (off-actor first(where:)
  trapped the host); new pins: degenerate truncation shapes,
  firstContentLocation, elide ladder
2026-11-07 21:13:31 +01:00

70 lines
3.4 KiB
Swift

//
// WordBoundaryTruncationTests.swift
// MuseionTests
//
// Round-5 (mercury#4/sol#8/argon#16) → Round-6 glyph-measured
// (mercury#4/sol#9) → Round-7 middle-eliding (argon#14/sol#32/47) →
// Round-8 head-biased split (sol#3): the roster title's truncation
// seam. The r7 split kept only the "Pass N ·" label and maximized the
// suffix — the unique head (the topic) died at the same elision point
// as before; the seam now grows the head into ~60% of the glyph budget
// (label + leading words) and fits the longest suffix in what remains.
// Pins: short-string passthrough, the mid-word head cut landing at a
// word edge, and the exact strings for the two live Handoff roster
// titles.
//
import CoreGraphics
import Foundation
@testable import Museion
import Testing
@Suite("WordBoundaryTruncationTests")
struct WordBoundaryTruncationTests {
@Test func `short string passes through`() {
#expect(WordBoundaryTruncation.fit("Brainstorm", maxWidth: 192) == "Brainstorm")
#expect(WordBoundaryTruncation.fit("Pass 1 · The expected value of showing up", maxWidth: 192)
== "Pass 1 · The expected value of showing up")
#expect(WordBoundaryTruncation.fit("", maxWidth: 192) == "")
}
@Test func `mid word cut lands at word boundary`() {
// The native cut rendered "Markdo…" — with no suffix fitting
// beside the head, the head truncates at its word edge.
let out = WordBoundaryTruncation.fit("Markdown Notes", maxWidth: 80, lines: 1)
#expect(out == "Markdown…")
#expect(!out.hasSuffix("Markdo…"))
}
@Test func `handoff titles split head biased`() {
// Round-7 (argon#14/sol#32/47): the two live Handoff roster
// titles died at the shared "Reading-Mode Pivot:…" boilerplate —
// the distinguishing tail never rendered. Round-8 (sol#3): the
// split biases toward the TOPIC — the head keeps the label plus
// the leading words ("Museion Handoff —", ~60% of the glyph
// budget, measured serif-13 semibold against the roster's 192pt
// two-line width); the shared tail shrinks to the longest suffix
// that still fits ("apex) vs. Hand-rolled TextKit" — r7's was
// the full "→ HTML (+ apex) vs. Hand-rolled TextKit").
let pass2 = "Pass 2 · Museion Handoff — Reading-Mode Pivot: Markdown → HTML (+ apex) vs. Hand-rolled TextKit"
let pass1 = "Pass 1 · Museion Handoff — Reading-Mode Pivot: Markdown → HTML (+ apex) vs. Hand-rolled TextKit"
#expect(WordBoundaryTruncation.fit(pass2, maxWidth: 192, lines: 2)
== "Pass 2 · Museion Handoff — … apex) vs. Hand-rolled TextKit")
#expect(WordBoundaryTruncation.fit(pass1, maxWidth: 192, lines: 2)
== "Pass 1 · Museion Handoff — … apex) vs. Hand-rolled TextKit")
}
/// Finish-audit edge pins: the seam passes degenerate shapes through
/// untouched — whitespace-only splits to no words, a space-free CJK
/// title is ONE word, and a single word wider than the line keeps its
/// own line (lineLimit(2) renders it). None may crash or mangle.
@Test func `degenerate shapes pass through unchanged`() {
let whitespace = " "
#expect(WordBoundaryTruncation.fit(whitespace, maxWidth: 192, lines: 2) == whitespace)
let cjk = "静かなウェブの再考" // no spaces — ONE word, wider than the line
#expect(WordBoundaryTruncation.fit(cjk, maxWidth: 40, lines: 2) == cjk)
let singleLongWord = "Supercalifragilisticexpialidocious"
#expect(WordBoundaryTruncation.fit(singleLongWord, maxWidth: 50, lines: 2) == singleLongWord)
}
}