feat(library): projects & archive substrate — S1 (#107)
CI / ci (push) Canceled after 0s

Pieces re-root from posts/<id>/ to projects/<name>/<id>/ with an
archive/ twin root (ADR-0012): scan walks both levels, New Piece and
Import land in the selected project else the default posts, the slug
namespace is global across projects and archive (an archived slug is
never reused), and every piece carries type: post frontmatter —
stamped by New/Import, read leniently (absent or unknown reads as
post), the file stays post.md for every content type. Write paths
resolve the folder from the id alone (folder(of:)); sessions and
sidecars never thread (project, id).

Finish-audit hardening: duplicate ids on disk (Finder copy) dedupe in
scan to the same first-match folder(of:) writes to; folder(of:) skips
hidden/symlinked projects like scan does.

Dev posts moved by hand to projects/posts/ — no migration machinery,
the app never reads the old posts/ root (#103). Full suite green
(128 unit + UI), swiftlint clean on changed files.

Closes #107
This commit is contained in:
AlexKucera committed 2026-10-13 17:44:44 +02:00
1 parent 50eecc6dcb
commit 3ca9d4e601
17 files changed
+608 -197

No files matched your search

+14 -3
View File
@@ -21,7 +21,7 @@ private func makeSessionHome() -> URL {
@MainActor
private func seedPost(_ home: URL, id: String, body: String) {
let dir = home.appendingPathComponent("posts/\(id)", isDirectory: true)
let dir = home.appendingPathComponent("projects/posts/\(id)", isDirectory: true)
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
try? PostStore.stamped(body: body, passState: .firstDraft, origin: .writer)
.write(to: dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
@@ -132,7 +132,7 @@ struct EditorSessionTests {
// #83: Keep Local with the post vanished mid-alert — the session must
// stay dirty (never a lying "Saved"), ⌘S still attempts the write.
try? FileManager.default.removeItem(
at: home.appendingPathComponent("posts/eta", isDirectory: true),
at: home.appendingPathComponent("projects/posts/eta", isDirectory: true),
)
session.diskDidChange(diskText: "# Eta\n\nExternal 2.") // alert raised; disk now unreadable
session.keepLocal()
@@ -148,7 +148,7 @@ struct EditorSessionTests {
// Vanish the post: overwrite throws (no resurrection), state = failed.
try FileManager.default.removeItem(
at: home.appendingPathComponent("posts/delta", isDirectory: true),
at: home.appendingPathComponent("projects/posts/delta", isDirectory: true),
)
var reported: String?
session.onError = { reported = $0 }
@@ -210,4 +210,15 @@ struct EditorSessionTests {
#expect(PostStore.readBody(id: "zeta", home: home) == "# Zeta\n\nReworked.") // unwritten
#expect(session.saveState != .failed) // no spurious failure fired
}
@Test func `unresolvable id falls back to the default-project path`() {
// #107: folderURL is resolved once at init; a piece that exists
// nowhere still gets a sane path (image resolution, crumbs) — the
// default-project shape, never a crash.
let home = makeSessionHome()
let session = EditorSession(postID: "ghost", home: home)
let expected = home.appendingPathComponent("projects/posts/ghost", isDirectory: true)
#expect(session.folderURL == expected)
#expect(session.loadFailed) // nothing to read there either
}
}