refactor(posts): route every library write through the write rail (#179)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
One internal seam (PostsModelRail.swift) now pairs every library verb store write with exactly one library rescan and owns the error strip: saveDraft, newPostFromSession, rename, trash, createProject, moveToProject, archivePost, restorePost, unarchiveProject, importFiles, convertToPost, and runPass pass-state advance (12 sites on this base; the pass snapshot/stats writes, the publish stamp, and the editor flush stay outside by design). The model owns the Home: boundHome is set by bind() alone (app construction + Settings repoint); every public verb lost its home: parameter (create post/outline/session-born, rename, move, archive, restore, trash, convert, project creation, import, select, cards, passes, blind read, publish). The three rail entries are railWrite/railWriteReturningReason/ railWriteKeepingStrip — deliberately NOT overloads: a shared base name let unlabeled trailing-closure calls resolve into the labeled non-generic entry (Swift binds trailing closures to labeled first parameters), silently bypassing the strip and the pairing. Views + 11 test files swept to the homeless signatures (160 sites). RED suite green: 3/3. Full unit suite: 654/654. Fixes #179
This commit is contained in:
1 parent
8c5ceffa3c
commit
06283b6287
23 files changed
+364
-363
No files matched your search
@@ -19,12 +19,12 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `sendDraft flushes the open piece and sends the disk body with the title`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Flush Me\n\nOriginal.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Flush Me\n\nEdited on the way.") // inside the debounce window
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/flush-me"], log: log),
|
||||
)
|
||||
|
||||
@@ -43,7 +43,7 @@ struct MicropubModelTests {
|
||||
let (model, home) = try makeModelHome()
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -58,7 +58,7 @@ struct MicropubModelTests {
|
||||
model.newPost() // staged draft — no folder, no session
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -73,11 +73,11 @@ struct MicropubModelTests {
|
||||
// All-whitespace body — no Title, no content (a heading-only
|
||||
// piece DOES send: the Title line is content on Micro.blog).
|
||||
let post = try PostStore.writeNew(body: " \n", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -91,7 +91,7 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `frontmatter category never travels`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Categorized\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// The writer's own category frontmatter — permitted, inert.
|
||||
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
|
||||
let raw = try String(contentsOf: fileURL, encoding: .utf8)
|
||||
@@ -100,7 +100,7 @@ struct MicropubModelTests {
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/categorized"], log: log),
|
||||
)
|
||||
|
||||
@@ -113,11 +113,11 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `a failed draft stamps nothing`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Fails\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(500, body: "{}", log: log),
|
||||
)
|
||||
|
||||
@@ -127,15 +127,15 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `re-drafting overwrites the remembered url`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Again\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/first"], log: log),
|
||||
)
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/second"], log: log),
|
||||
)
|
||||
|
||||
@@ -147,7 +147,7 @@ struct MicropubModelTests {
|
||||
/// Plants a PNG beside the piece; returns the piece's post.md URL.
|
||||
@MainActor private func plantIllustratedPiece(_ model: PostsModel, _ home: URL, body: String) throws -> URL {
|
||||
let post = try PostStore.writeNew(body: body, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
let dir = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FileManager.default.createDirectory(at: dir.appendingPathComponent("assets", isDirectory: true), withIntermediateDirectories: true)
|
||||
try micropubPNG().write(to: dir.appendingPathComponent("assets/path.png"))
|
||||
@@ -162,7 +162,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||
// The three hops, in order: q=config → upload → create.
|
||||
@@ -197,7 +197,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -228,7 +228,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -246,7 +246,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||
// config + ONE upload + create — the FILE uploads once, not once per ref.
|
||||
@@ -266,7 +266,7 @@ struct MicropubModelTests {
|
||||
) // path.png planted, ghost.png never
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case .refused = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -278,10 +278,10 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `a piece without illustrations sends exactly one request`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Plain\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
_ = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
// The #33 path unchanged: no config round-trip, straight to the create.
|
||||
#expect(log.requests.count == 1)
|
||||
|
||||
Reference in new issue
Block a user