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:
1 parent
804b5889f6
commit
765d32d4d4
10 files changed
+158
-101
No files matched your search
@@ -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`() {
|
||||
|
||||
Reference in new issue
Block a user