refactor(workspace): finish-audit fixes — off-main scan, parser edges, dead code out

Reviewers' findings on 804b588: scan moved off MainActor (Task.detached),
PostLibrary struct folded into Post.scan, hidden dirs and symlinked dirs
now actually skipped (test de-vacuated), unterminated frontmatter no longer
leaks as the Title, quoted YAML values unquoted, leading blank line before
--- tolerated, #-only body reads untitled, persisted Home validated
isFileURL. Dead code deleted: radiusLarge, editorMinWidth, homeKey,
PaneHeader trailing slot, Settings ScrollView, PostRow fill dance.
Tests 56/56, lint 0.

[Generated by AI]
This commit is contained in:
AlexKucera committed 2026-10-01 13:43:25 +02:00
1 parent 804b5889f6
commit 765d32d4d4
10 files changed
+158 -101

No files matched your search

+3 -3
View File
@@ -19,12 +19,12 @@ Owned by the root AGENTS.md contract. The `.xcodeproj` uses **filesystem-synchro
## Workspace shell (M1, #17 / S1.1)
- `DesignTokens.swift` — palette/geometry from the design contract (`ref/Web-Prototype/museion-workspace.html` `:root` + grid): background/surface/foreground/muted/border/accent colors, radius 10/14, column widths (rail 56, library 232, editor min 420, mentor 356), serif/mono font designs. Light-only — the export defines one palette.
- `DesignTokens.swift` — palette/geometry from the design contract (`ref/Web-Prototype/museion-workspace.html` `:root` + grid): background/surface/foreground/muted/border/accent colors, radius 10, column widths (rail 56, library 232, mentor 356; the export's editor min 420 lands with #19's editor column), serif/mono font designs. Light-only — the export defines one palette.
- `WorkspaceView.swift` — post-gate main surface (replaces the M0 mentor pane as root): nav rail (Posts/Sessions/Learnings + Settings at bottom) + active pane. `RailButton` per the export (44×44, muted icon, hover wash, surface card + 2px edge bar when current). Sessions/Learnings are honest placeholders until #28/#26. Posts renders the full grid; **column collapse mirrors the export's media queries** (library hides < 1100 px, mentor hides < 920 px budget) as macOS pane collapse — never a fixed four-column minWidth that clips. `PaneHeader` = 52pt serif-15 title row + border.
- `PostsPaneView.swift` — Posts destination: library column (Pass State groups in mono-11 uppercase labels, post rows with title + passState/origin meta), empty state, editor placeholder until #19–#21, mentor column (`MentorPaneView`, fixed 356). Selecting a post sets `selectedPostID` (editor shows its title; no editing yet).
- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `PostLibrary.scan(home:)`: reads `posts/<id>/post.md`, skips dirs without post.md (lazy folders), loose files, hidden dirs; Title = first non-empty line after frontmatter, `#` stripped, `untitled` when blank; `pass_state`/`origin` frontmatter keys read leniently (First Draft/writer defaults — corpus posts ship bare; key format pinned by #18). Read-only — lifecycle is #18.
- `PostLibrary.swift` — `Post` (nonisolated: id/title/passState/origin) + `Post.scan(home:) -> [Post]`: reads `posts/<id>/post.md`, skips dirs without post.md (lazy folders), loose files, hidden dirs (dot-prefix), and symlinked dirs; Title = first non-empty line after frontmatter (`untitled` on blank, marker-only, or unterminated-frontmatter bodies); `pass_state`/`origin` frontmatter keys read leniently (First Draft/writer defaults, quoted YAML values unquoted, leading blank line before `---` tolerated — corpus posts ship bare; write-side key format pinned by #18). Read-only — lifecycle is #18. Scan runs off-main via `Task.detached` in PostsPaneView (big Homes must not freeze the UI).
- `SettingsPaneView.swift` — Home control (NSOpenPanel folder pick; files/canCreate on). Repoint-only semantics stated in-UI.
- `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error).
- `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`; non-file URLs read back as nil — the Home is always a folder). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error).
- `MentorPaneView` no longer carries a root min-frame — it lives in the 356pt mentor column.
## Engine gate (launch gate, tickets #35–#41)
+2 -3
View File
@@ -18,13 +18,12 @@ enum DesignTokens {
static let accent = Color(red: 0xC9 / 255, green: 0x64 / 255, blue: 0x42 / 255)
static let radius: CGFloat = 10
static let radiusLarge: CGFloat = 14
/// The workspace grid: rail | posts library | editor | mentor (grid-template-columns
/// `56px 232px minmax(420px, 1fr) 356px`).
/// `56px 232px minmax(420px, 1fr) 356px`). Editor min (420) has no enforcement
/// yet — the editor column arrives with #19.
static let railWidth: CGFloat = 56
static let libraryWidth: CGFloat = 232
static let editorMinWidth: CGFloat = 420
static let mentorWidth: CGFloat = 356
/// The serif display face maps to the system serif design (export stack:
+5 -4
View File
@@ -24,7 +24,8 @@ final class AppGateState {
let mentor = MentorSessionModel()
/// #17: the Museion Home — repoint-only (ADR-0004). Defaults to
/// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is
/// a plain folder, nothing app-owned to put in a database.
/// a plain folder, nothing app-owned to put in a database. Non-file URLs
/// read back as nil (the default wins) — the Home is always a folder.
var museionHome: URL {
didSet { UserDefaults.standard.set(museionHome.absoluteString, forKey: "museionHome") }
}
@@ -32,7 +33,9 @@ final class AppGateState {
init() {
// Explicit init: `Self` in a stored-property initializer trips
// @ObservationTracked's macro expansion (covariant Self).
museionHome = UserDefaults.standard.string(forKey: "museionHome").flatMap(URL.init(string:))
museionHome = UserDefaults.standard.string(forKey: "museionHome")
.flatMap(URL.init(string:))
.flatMap { $0.isFileURL ? $0 : nil }
?? Self.defaultMuseionHome
}
@@ -40,8 +43,6 @@ final class AppGateState {
/// (b3daac9: Documents, not the account root; TCC note in ADR-0004).
nonisolated static let defaultMuseionHome = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Documents/Museion", isDirectory: true)
private static let homeKey = "museionHome"
}
@main
+29 -34
View File
@@ -8,12 +8,10 @@
import Foundation
/// One Post on disk: `<home>/posts/<id>/post.md` (ADR-0004 shape).
/// A Post directory with no post.md yet is skipped — folders are created lazily
/// on first write, so an empty folder is not a Post.
nonisolated struct Post: Identifiable, Equatable {
/// The post folder's name — the Post's durable identity (CONTEXT.md).
let id: String
/// The Post's Title: first non-empty line, heading markers stripped.
/// The Post's Title: first non-empty line after any frontmatter, heading markers stripped.
var title: String
/// Pass State from frontmatter; First Draft when absent (explicit, never inferred).
var passState: PassState
@@ -32,76 +30,73 @@ nonisolated struct Post: Identifiable, Equatable {
// swiftlint:disable:next identifier_name
case ai
}
}
/// Scans `<home>/posts/` and parses each Post's frontmatter leniently.
/// Read-only for #17 — create/rename/delete round-trips are #18.
/// Nonisolated: a pure synchronous disk scan, safe from any executor.
nonisolated struct PostLibrary: Equatable {
private(set) var posts: [Post] = []
/// Reads every `posts/<id>/post.md`. Frontmatter keys (`pass_state:`, `origin:`)
/// are read leniently — corpus posts ship bare, so absent or unknown values fall
/// back to First Draft / writer. Keys outside a frontmatter block are ignored;
/// Reads every `posts/<id>/post.md` into Posts (sorted by title, Finder order).
/// Read-only for #17 — create/rename/delete round-trips are #18. Symlinks and
/// hidden dirs are skipped; folders without `post.md` (lazy) aren't Posts;
/// a malformed folder can't crash the list.
static func scan(home: URL) -> PostLibrary {
static func scan(home: URL) -> [Post] {
let postsURL = home.appendingPathComponent("posts", isDirectory: true)
guard let entries = try? FileManager.default.contentsOfDirectory(
at: postsURL,
includingPropertiesForKeys: [.isDirectoryKey],
) else { return PostLibrary() }
includingPropertiesForKeys: [.isDirectoryKey, .isSymbolicLinkKey],
) else { return [] }
var posts: [Post] = []
for dir in entries where (try? dir.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true {
for dir in entries {
let values = try? dir.resourceValues(forKeys: [.isDirectoryKey, .isSymbolicLinkKey])
guard values?.isDirectory ?? false, !(values?.isSymbolicLink ?? false),
!dir.lastPathComponent.hasPrefix(".") else { continue }
let fileURL = dir.appendingPathComponent("post.md")
guard let text = try? String(contentsOf: fileURL, encoding: .utf8) else { continue }
let frontmatter = Self.frontmatter(of: text)
let frontmatter = frontmatter(of: text)
posts.append(
Post(
id: dir.lastPathComponent,
title: Self.title(of: text),
passState: Post.PassState(rawValue: frontmatter["pass_state"] ?? "") ?? .firstDraft,
origin: Post.Origin(rawValue: frontmatter["origin"] ?? "") ?? .writer,
title: title(of: text),
passState: PassState(rawValue: frontmatter["pass_state"] ?? "") ?? .firstDraft,
origin: Origin(rawValue: frontmatter["origin"] ?? "") ?? .writer,
),
)
}
return PostLibrary(posts: posts.sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending })
return posts.sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }
}
/// The `---`-delimited frontmatter block if present; empty otherwise.
/// Quoted scalar values (`origin: "ai"`) are unquoted — lenient YAML.
static func frontmatter(of text: String) -> [String: String] {
let lines = text.split(separator: "\n", omittingEmptySubsequences: false)
guard lines.first?.trimmed() == "---" else { return [:] }
guard lines.first(where: { !$0.trimmed().isEmpty })?.trimmed() == "---" else { return [:] }
var map: [String: String] = [:]
for line in lines.dropFirst() {
for line in lines.drop(while: { $0.trimmed() != "---" }).dropFirst() {
let trimmed = line.trimmed()
guard trimmed != "---" else { break }
guard let colon = trimmed.firstIndex(of: ":") else { continue }
let key = trimmed[..<colon].trimmingCharacters(in: .whitespaces)
let value = trimmed[trimmed.index(after: colon)...].trimmingCharacters(in: .whitespaces)
let value = trimmed[trimmed.index(after: colon)...]
.trimmingCharacters(in: .whitespaces)
.trimmingCharacters(in: CharacterSet(charactersIn: "\"'"))
map[key] = value
}
return map
}
/// The Post's Title: first non-empty line after any frontmatter block,
/// `#` heading markers stripped. A body with no text at all reads as
/// `untitled` (the blank-draft id).
/// `#` heading markers stripped; `untitled` when nothing readable remains.
static func title(of text: String) -> String {
var lines = text.split(separator: "\n", omittingEmptySubsequences: false)[...]
if lines.first?.trimmed() == "---" {
if let close = lines.dropFirst().firstIndex(where: { $0.trimmed() == "---" }) {
if let open = lines.firstIndex(where: { !$0.trimmed().isEmpty }), lines[open].trimmed() == "---" {
if let close = lines[(open + 1)...].firstIndex(where: { $0.trimmed() == "---" }) {
lines = lines[(close + 1)...]
} else {
lines = lines.dropFirst() // unterminated block: no title inside it
return "untitled" // unterminated block: nothing trustworthy follows
}
}
for line in lines {
let trimmed = line.trimmed()
if trimmed.isEmpty {
continue
}
return trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "#").union(.whitespaces))
guard !trimmed.isEmpty else { continue }
let stripped = trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "#").union(.whitespaces))
return stripped.isEmpty ? "untitled" : stripped
}
return "untitled"
}
+15 -15
View File
@@ -17,8 +17,8 @@ struct PostsPaneView: View {
var mentorBinaryPath: String?
/// Width budget after the rail — drives column collapse (export media queries:
/// library hides ≤1100, mentor hides ≤920).
var availableWidth: CGFloat = .infinity
@State private var library = PostLibrary()
var availableWidth: CGFloat
@State private var posts: [Post] = []
@State private var selectedPostID: String?
private var showsLibrary: Bool {
@@ -41,7 +41,10 @@ struct PostsPaneView: View {
mentorColumn
}
}
.task(id: home) { library = PostLibrary.scan(home: home) }
.task(id: home) {
// Scan off-main: .task inherits MainActor; a big Home must not freeze the UI.
posts = await Task.detached(priority: .userInitiated) { Post.scan(home: home) }.value
}
}
private var paneBorder: some View {
@@ -54,18 +57,16 @@ struct PostsPaneView: View {
private var libraryColumn: some View {
VStack(spacing: 0) {
PaneHeader(title: "Posts") {
// New Post arrives with #18 (Post lifecycle: lazy folder + slug).
EmptyView()
}
if library.posts.isEmpty {
// New Post arrives with #18 (Post lifecycle: lazy folder + slug).
PaneHeader(title: "Posts")
if posts.isEmpty {
emptyState
} else {
ScrollView {
LazyVStack(alignment: .leading, spacing: 4) {
ForEach(Post.PassState.allCases, id: \.self) { state in
let posts = library.posts.filter { $0.passState == state }
if !posts.isEmpty {
let grouped = posts.filter { $0.passState == state }
if !grouped.isEmpty {
Text(state.rawValue.uppercased())
.font(.system(size: 11, design: DesignTokens.mono))
.kerning(0.6)
@@ -73,7 +74,7 @@ struct PostsPaneView: View {
.padding(.horizontal, 14)
.padding(.top, 18)
.padding(.bottom, 7)
ForEach(posts) { post in
ForEach(grouped) { post in
PostRow(post: post, selected: post.id == selectedPostID) {
selectedPostID = post.id
}
@@ -105,7 +106,7 @@ struct PostsPaneView: View {
private var editorPlaceholder: some View {
VStack(spacing: 10) {
if let post = library.posts.first(where: { $0.id == selectedPostID }) {
if let post = posts.first(where: { $0.id == selectedPostID }) {
Text(post.title)
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
}
@@ -151,10 +152,9 @@ private struct PostRow: View {
.buttonStyle(.plain)
.foregroundStyle(DesignTokens.foreground)
.background {
let fill: Color? = selected ? DesignTokens.surface : (hover ? DesignTokens.foreground.opacity(0.06) : nil)
if let fill {
if selected || hover {
RoundedRectangle(cornerRadius: DesignTokens.radius)
.fill(fill)
.fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06))
.overlay(
RoundedRectangle(cornerRadius: DesignTokens.radius)
.strokeBorder(selected ? DesignTokens.border : .clear),
+18 -20
View File
@@ -15,28 +15,26 @@ struct SettingsPaneView: View {
@Binding var home: URL
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
Text("Content")
.font(.system(size: 13, weight: .semibold))
HStack(spacing: 8) {
Text(home.path(percentEncoded: false))
.font(.system(size: 12, design: DesignTokens.mono))
.lineLimit(1)
.truncationMode(.middle)
.textSelection(.enabled)
Spacer(minLength: 12)
Button("Choose…") { chooseHome() }
}
Text(
"Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.",
)
.font(.callout)
.foregroundStyle(DesignTokens.muted)
VStack(alignment: .leading, spacing: 12) {
Text("Content")
.font(.system(size: 13, weight: .semibold))
HStack(spacing: 8) {
Text(home.path(percentEncoded: false))
.font(.system(size: 12, design: DesignTokens.mono))
.lineLimit(1)
.truncationMode(.middle)
.textSelection(.enabled)
Spacer(minLength: 12)
Button("Choose…") { chooseHome() }
}
.padding(24)
.frame(maxWidth: .infinity, alignment: .leading)
Text(
"Repoint-only: Museion never moves content. The Posts list reads this folder's posts/ directory.",
)
.font(.callout)
.foregroundStyle(DesignTokens.muted)
}
.padding(24)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(DesignTokens.background)
}
+3 -4
View File
@@ -51,7 +51,7 @@ struct WorkspaceView: View {
}
.background(DesignTokens.background)
}
// Collapsed floor: rail 56 + editor 420 (export ≤920 layout).
// Collapsed floor: rail 56 + editor placeholder (export ≤920 layout).
.frame(minWidth: 480, minHeight: 320)
}
@@ -125,9 +125,9 @@ private struct RailButton: View {
}
/// Pane-head row per the export (52pt, serif 15 semibold title, bottom border).
struct PaneHeader<Trailing: View>: View {
/// Trailing slot returns with #18's New Post button.
struct PaneHeader: View {
let title: String
@ViewBuilder var trailing: () -> Trailing
var body: some View {
VStack(spacing: 0) {
@@ -135,7 +135,6 @@ struct PaneHeader<Trailing: View>: View {
Text(title)
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
Spacer()
trailing()
}
.padding(.horizontal, 14)
.frame(minHeight: 52)
+1 -1
View File
@@ -20,7 +20,7 @@ Owned by the root AGENTS.md contract.
- `EngineGateTests.swift` builds fake `hermes` shell scripts in temp dirs and runs them through the real `Process` path — copy that pattern for any future child-process testing.
- `ACPClientTests.swift` extends it into a full fake ACP *server*: a zsh script speaking real NDJSON JSON-RPC over stdio (`makeFakeACP`), with a per-binary mode file (`crashAfterHandshake`, `hangOnPrompt`, default full) and a base64-encoded fix-card payload — shell quoting can never break the wire JSON. Only `acpTempDir` remains as a helper; crash assertions use Swift Testing's `confirmation` (hook the callback BEFORE triggering the crash).
- `ProfileProvisionerTests.swift` extends it: the fake creates the profile at `<binaryDir>/profiles/<name>` (self-locating, race-free under parallel tests); payload dirs are built at runtime; the bundled-payload test asserts manifest ↔ payload correspondence. #48 failure-path tests live in `ProfileProvisionerFailureTests.swift` (own file — Not-Now defer + re-fail, config.yaml byte-identity + fresh-profile no-config (mcp_servers negative invariant), state.json engine-gate-only, copy-phase catch branch, path-traversal rejection, orphaned-temp sweep). Shared helpers (`makeFakeHermes`, `makePayload`, `defaultSkills`, `provTempDir`) are internal in `ProfileProvisionerTests.swift`. `ProfileBackupTests.swift` (own helpers `backupTempDir`/`makeProfileFixture`) injects profile/backups roots, a fixed clock, and a `psScan` stub — a dev machine may run the real engine, so the ps scan is never trusted in tests.
- `PostLibraryTests.swift` (#17) — throwaway Homes via `makeHome`/`writePost` in temp dirs: bare corpus posts (First Draft/writer defaults), lenient frontmatter (`pass_state`/`origin`), lazy folders + noise not surfacing, localizedStandardCompare title sort, blank-draft `untitled`, default Home = `~/Documents/Museion`.
- `PostLibraryTests.swift` (#17) — throwaway Homes via `makeHome`/`writePost` in temp dirs: bare corpus posts (First Draft/writer defaults), lenient + quoted frontmatter (`pass_state`/`origin`), lazy folders / hidden dirs / symlinks / noise not surfacing, localizedStandardCompare title sort, `untitled` edges (blank, marker-only, unterminated frontmatter), leading-blank-line frontmatter, default Home = `~/Documents/Museion`.
## Verification
+60 -17
View File
@@ -30,9 +30,9 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws {
let home = try makeHome { home in
try writePost(home, "the-new-reeder", "## The New Reeder\n\nBody text.")
}
let library = PostLibrary.scan(home: home)
#expect(library.posts.count == 1)
let post = try #require(library.posts.first)
let posts = Post.scan(home: home)
#expect(posts.count == 1)
let post = try #require(posts.first)
#expect(post.id == "the-new-reeder")
#expect(post.title == "The New Reeder")
#expect(post.passState == .firstDraft)
@@ -47,22 +47,31 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws {
"---\npass_state: Pass-1 Done\norigin: ai\ntitle: ignored — body wins\n---\n\n# A Short Defence of Footnotes\n\nBody.",
)
}
let post = try #require(PostLibrary.scan(home: home).posts.first)
let post = try #require(Post.scan(home: home).first)
#expect(post.passState == .pass1Done)
#expect(post.origin == .ai)
#expect(post.title == "A Short Defence of Footnotes")
}
@Test func `quoted frontmatter values are unquoted`() throws {
let home = try makeHome { home in
try writePost(home, "quoted", "---\npass_state: \"Pass-2 Done\"\norigin: 'ai'\n---\n\n## Quoted\n")
}
let post = try #require(Post.scan(home: home).first)
#expect(post.passState == .pass2Done)
#expect(post.origin == .ai)
}
@Test func `empty home is empty and missing home is empty`() throws {
let empty = try makeHome { _ in }
#expect(PostLibrary.scan(home: empty).posts.isEmpty)
#expect(Post.scan(home: empty).isEmpty)
let missing = FileManager.default.temporaryDirectory
.appendingPathComponent("postlib-missing-\(UUID().uuidString)")
#expect(PostLibrary.scan(home: missing).posts.isEmpty)
#expect(Post.scan(home: missing).isEmpty)
}
@Test func `lazy folders and noise are not posts`() throws {
@Test func `lazy folders, hidden dirs and noise are not posts`() throws {
let home = try makeHome { home in
try writePost(home, "one", "One")
// Lazy folder: no post.md yet (created lazily on first write, #18).
@@ -70,18 +79,36 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws {
at: home.appendingPathComponent("posts/not-yet", isDirectory: true),
withIntermediateDirectories: true,
)
// Noise: loose file at posts/ root, hidden dir.
// Hidden dir WITH a post.md — must not surface.
try writePost(home, ".trash", "---\n---\n## Hidden\n")
// Noise: loose file at posts/ root.
try "loose".write(
to: home.appendingPathComponent("posts/loose.md"),
atomically: true,
encoding: .utf8,
)
try FileManager.default.createDirectory(
at: home.appendingPathComponent("posts/.DS_Store-dir", isDirectory: true),
withIntermediateDirectories: true,
}
#expect(Post.scan(home: home).map(\.id) == ["one"])
}
@Test func `symlinked post dir is not followed`() throws {
let home = try makeHome { home in
try writePost(home, "one", "One")
// A post.md outside the Home, linked into posts/ by symlink.
let outside = home.deletingLastPathComponent()
.appendingPathComponent("postlib-outside-\(UUID().uuidString)", isDirectory: true)
try FileManager.default.createDirectory(at: outside, withIntermediateDirectories: true)
try "## Stolen\n".write(
to: outside.appendingPathComponent("post.md"),
atomically: true,
encoding: .utf8,
)
try FileManager.default.createSymbolicLink(
at: home.appendingPathComponent("posts/linked", isDirectory: true),
withDestinationURL: outside,
)
}
#expect(PostLibrary.scan(home: home).posts.map(\.id) == ["one"])
#expect(Post.scan(home: home).map(\.id) == ["one"])
}
@Test func `posts sort by title locally`() throws {
@@ -91,15 +118,31 @@ private func writePost(_ home: URL, _ id: String, _ body: String) throws {
try writePost(home, "m-id", "## beta 10\n")
}
// localizedStandardCompare: case-insensitive, numeric-aware (Finder order).
#expect(PostLibrary.scan(home: home).posts.map(\.title) == ["Alpha", "Beta 2", "beta 10"])
#expect(Post.scan(home: home).map(\.title) == ["Alpha", "Beta 2", "beta 10"])
}
@Test func `blank draft title is untitled`() {
#expect(PostLibrary.title(of: "\n\n \n") == "untitled")
#expect(PostLibrary.title(of: "---\npass_state: Pass-2 Done\n---\n") == "untitled")
#expect(PostLibrary.title(of: "") == "untitled")
#expect(Post.title(of: "\n\n \n") == "untitled")
#expect(Post.title(of: "---\npass_state: Pass-2 Done\n---\n") == "untitled")
#expect(Post.title(of: "") == "untitled")
#expect(Post.title(of: "#\n") == "untitled") // heading marker only, no text
// Frontmatter-first title: first non-empty line after the block.
#expect(PostLibrary.title(of: "---\norigin: writer\n---\n\n## Named\n\nBody") == "Named")
#expect(Post.title(of: "---\norigin: writer\n---\n\n## Named\n\nBody") == "Named")
}
@Test func `unterminated frontmatter is untitled, never leaked`() {
// No closing ---: frontmatter lines must never leak as the Title.
#expect(Post.title(of: "---\npass_state: First Draft\norigin: writer\n") == "untitled")
#expect(Post.frontmatter(of: "---\npass_state: First Draft\n")["pass_state"] == "First Draft")
}
@Test func `leading blank line still opens frontmatter`() throws {
// A leading newline before --- must not defeat frontmatter detection.
let text = "\n---\npass_state: Pass-1 Done\n---\n\n## After Blank\n"
let home = try makeHome { try writePost($0, "blank-open", text) }
let post = try #require(Post.scan(home: home).first)
#expect(post.passState == .pass1Done)
#expect(post.title == "After Blank")
}
@Test func `home default is documents museion`() {
@@ -47,6 +47,28 @@ Ship #17 (S1.1): the workspace shell from the design contract — nav rail (Post
- Lint: `swiftlint Museion/ MuseionTests/` → 0 violations; SwiftFormat clean on changed files
- Live: app launched, gate sheet passed and dismissed via AX, workspace rendered (rail/Posts/editor/mentor verified by screenshot); window-resize collapse fix built but final visual pass blocked by a fullscreen break timer — needs one manual look
## Finish Audit (same day)
Three fresh-context reviewers (ponytail / security / general) over `804b588`. Accepted and fixed:
| Fix | Source |
|-----|--------|
| Scan off-main: `Task.detached { Post.scan(home:) }` in `.task(id:)` — MainActor-inherited synchronous scan froze the UI on big Homes | security MEDIUM-1 + review |
| `PostLibrary` struct → `Post.scan(home:) -> [Post]` (wrapper with one field, unused Equatable) | ponytail |
| Hidden-dir skip now real (dot-prefix guard) — the AGENTS.md claim was code-less and the test vacuous; test now writes a `post.md` into `.trash/` | review MEDIUM + security INFO-5 |
| Unterminated frontmatter returns `untitled` (was leaking `pass_state: …` as Title) | review MEDIUM |
| Quoted YAML values unquoted (`origin: "ai"` → `.ai`) | review MEDIUM |
| Leading blank line before `---` no longer defeats frontmatter detection (both parser funcs) | review LOW |
| `#`-only body → `untitled` (was empty string) | review LOW |
| Symlinked post dirs skipped (one resourceValues guard, single fetch) | security LOW-3 |
| Persisted home validated `isFileURL` (fails closed to default; hygiene) | security LOW-2 |
| Dead code out: `radiusLarge`, `editorMinWidth`, `homeKey`; `PaneHeader` trailing slot; Settings ScrollView; PostRow optional-fill dance; `availableWidth` default | ponytail |
Discarded as speculative: read-cap on file heads (detached hop fixes the hang; #18 owns growth), UserDefaults round-trip test (shared test host).
Tests 56/56 (4 new: quoted values, symlink, unterminated frontmatter, leading blank). Lint 0.
## Files Changed
| File | Change Summary |