feat(microblog): show Micro.blog publish status
The publish sheet flipped a draft live and remembered nothing, so nothing on disk said a piece was out and the library could not show it. A successful Publish now stamps `micropub_published` in the piece's frontmatter; the row and the sheet read `published <date>` or `draft on Micro.blog`, and a published piece's menu opens the live post. Sending a piece again no longer creates a second post: a piece that remembers its post updates it in place (name and content only, so categories set on Micro.blog survive). An image whose bytes are unchanged rides its earlier upload through a per-piece memo. When Micro.blog answers 404 the piece forgets both keys and the sheet offers a fresh draft; a clear that cannot land says so instead of claiming the link is gone. Museion's micropub keys are dropped at the import boundary. An imported `micropub_url` passes the format gate and would aim the in-place update at one of the writer's own posts under their token, so the keys are treated like `origin`: ours to set, never a foreign file's to carry in. Publish is model-owned and trust-gates its URL before anything is stamped. Tests read recorded requests through an optional accessor: an out-of-range subscript after a failed count expectation trapped the hosted runner and reported every queued test as crashed. +16 tests net (17 new pins in MicropubStatusTests, one retired whose premise the in-place design voids); every new pin was watched fail on its own guard. Rail 752/752; SwiftFormat and SwiftLint clean. Reviews: standards + spec during the build, then a three-reviewer finish audit. Docs: AGENTS.md bullets and learnings, GLOSSARY terms, CHANGELOG [Unreleased], README, and the devlog. Closes #206
This commit is contained in:
1 parent
6938826101
commit
6aa31a419a
21 files changed
+1151
-225
No files matched your search
@@ -23,7 +23,7 @@ struct MicropubModelTests {
|
||||
model.session?.edit("# Flush Me\n\nEdited on the way.") // inside the debounce window
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
let outcome = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/flush-me"], log: log),
|
||||
)
|
||||
@@ -42,7 +42,7 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `sendDraft refuses without an open saved piece`() async throws {
|
||||
let (model, _) = try makeModelHome()
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
let outcome = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
@@ -57,7 +57,7 @@ struct MicropubModelTests {
|
||||
let (model, _) = try makeModelHome()
|
||||
model.newPost() // staged draft — no folder, no session
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
let outcome = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
@@ -76,7 +76,7 @@ struct MicropubModelTests {
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
let outcome = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
@@ -99,7 +99,7 @@ struct MicropubModelTests {
|
||||
.write(to: fileURL, atomically: true, encoding: .utf8)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
_ = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/categorized"], log: log),
|
||||
)
|
||||
@@ -116,7 +116,7 @@ struct MicropubModelTests {
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
_ = await model.micropubSend(
|
||||
token: "tok",
|
||||
transport: micropubCanned(500, body: "{}", log: log),
|
||||
)
|
||||
@@ -124,28 +124,11 @@ struct MicropubModelTests {
|
||||
#expect(Post.scan(home: home).first?.micropubURL == nil)
|
||||
}
|
||||
|
||||
@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)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/first"], log: log),
|
||||
)
|
||||
_ = await model.micropubSendDraft(
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/second"], log: log),
|
||||
)
|
||||
|
||||
#expect(Post.scan(home: home).first?.micropubURL == "https://example.micro.blog/second")
|
||||
}
|
||||
|
||||
// MARK: #34 (S6.2) — illustrations travel with it
|
||||
|
||||
/// 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 {
|
||||
/// Shared with `MicropubStatusTests` (shared-helper convention).
|
||||
@MainActor func plantIllustratedPiece(_ model: PostsModel, _ home: URL, body: String) throws -> URL {
|
||||
let post = try PostStore.writeNew(body: body, home: home)
|
||||
model.select(post.id)
|
||||
let dir = try #require(PostStore.folder(of: post.id, home: home))
|
||||
@@ -162,20 +145,21 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSend(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.
|
||||
#expect(log.requests.count == 3)
|
||||
let config = URLComponents(url: log.requests[0].url ?? Micropub.endpoint, resolvingAgainstBaseURL: false)
|
||||
let config = URLComponents(url: log.request(0)?.url ?? Micropub.endpoint, resolvingAgainstBaseURL: false)
|
||||
#expect(config?.queryItems?.contains(URLQueryItem(name: "q", value: "config")) == true)
|
||||
#expect(log.requests[1].url?.absoluteString == "https://micro.blog/micropub/media")
|
||||
#expect(log.requests[1].httpBody?.firstRange(of: micropubPNG()) != nil) // the PNG rode the multipart
|
||||
#expect(log.request(1)?.url?.absoluteString == "https://micro.blog/micropub/media")
|
||||
#expect(log.request(1)?.httpBody?.firstRange(of: micropubPNG()) != nil) // the PNG rode the multipart
|
||||
// The create: the ref REWRITTEN in place with its uploaded URL
|
||||
// — exactly where the writer placed it (2026-11-01: the photo
|
||||
// PROPERTY rendered at the bottom, position lost), alt in the
|
||||
// markdown, NO photo property keys.
|
||||
let props = try #require(micropubJSON(log.requests[2])["properties"] as? [String: Any])
|
||||
let create = try #require(log.request(2))
|
||||
let props = try #require(micropubJSON(create)["properties"] as? [String: Any])
|
||||
let expected = "# Inked\n\nProse before.\n\n\n\nProse after."
|
||||
#expect(props["content"] as? [String] == [expected])
|
||||
#expect(props["photo"] == nil)
|
||||
@@ -197,7 +181,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSend(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -228,7 +212,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSend(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -246,13 +230,14 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSend(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.
|
||||
#expect(log.requests.count == 3)
|
||||
#expect(log.requests.filter { $0.url?.absoluteString.contains("/micropub/media") == true }.count == 1)
|
||||
let props = try #require(micropubJSON(log.requests[2])["properties"] as? [String: Any])
|
||||
let create = try #require(log.request(2))
|
||||
let props = try #require(micropubJSON(create)["properties"] as? [String: Any])
|
||||
let content = try #require((props["content"] as? [String])?.first)
|
||||
// Both refs share the one uploaded URL.
|
||||
#expect(content.components(separatedBy: "https://micro.blog/uploads/2026/ink.png").count == 3)
|
||||
@@ -266,7 +251,7 @@ struct MicropubModelTests {
|
||||
) // path.png planted, ghost.png never
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSend(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case .refused = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -281,10 +266,10 @@ struct MicropubModelTests {
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
_ = await model.micropubSend(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
// The #33 path unchanged: no config round-trip, straight to the create.
|
||||
#expect(log.requests.count == 1)
|
||||
#expect(log.requests[0].url == Micropub.endpoint)
|
||||
#expect(log.request(0)?.url == Micropub.endpoint)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user