CI / ci (push) Canceled after 0s
Two-step publish to Micro.blog over Micropub: Send as Draft (JSON h=entry create — name = the Title, markdown content verbatim, post-status draft), review via the preview link, then Publish (the action=update post-status flip). The piece remembers its draft URL as a frontmatter micropub_url stamp — in-place, body and foreign keys byte-identical — so a draft survives a reopen; Send Again re-drafts after edits. The app token lives in the Keychain (login keychain; entered once in the sheet, re-offered only on auth failure — ADR-0014's no-Keychain rule covers only provider keys hermes reads from .env). Frontmatter category: is permitted but never sent in v1 — pinned on the wire. The draft URL is trust-boundary data landing in frontmatter, so every URL passes a format gate (https + host, no line/control characters) at BOTH ends: the response decode (Location header → body url; the preview link is display-only, never the publish target) and Post.scan's read-back — imported frontmatter rides verbatim, and a newline--- rider would otherwise close the block and reparse as attacker markdown in the writer's piece. Twenty tests pin the wire contract, decode matrix, own-slot keychain round-trip, stamp/scan, and the model flow (flush-first, refusal guards, the category AC); all four audit guards are flip-verified. Full suite 529 passed / 0 failed. Live end-to-end on a real post (needs the owner's app token) remains open on the ticket.
9.7 KiB
9.7 KiB
M6: Micropub draft & publish (S6.1)
Date: 2026-10-31 Type: issue Reference: #33 (PRD S6.1, G11)
Goal
Implement #33: the writer sends a Post to Micro.blog as a draft first, then publishes — Micropub h=entry with markdown content and name for the title; Bearer app-token auth with the token in Keychain, entered once; no OAuth in v1; frontmatter category: permitted but inert (never sent). Followed by a three-reviewer finish-audit fanout and fixes.
What Was Done
Museion/Micropub.swift(new) —Micropubclient (fixed endpointhttps://micro.blog/micropub, ProviderProbe's injected Transport seam):makeDraftRequest= JSON h=entry create (name = Title, markdown content verbatim,post-status: draft, sorted keys,category:never travels);makePublishRequest=action=update+replace.post-status: published; decode = Location header → bodyurl(preview is display-only, never the publish target), every draft URL passestrustworthyURL, 401/403 → authFailed with the server'serror_description, transport throw → unreachable.MicropubTokenStore= SecItem login-keychain store (add-or-replace,accountparam defaulting to the production slot so tests never touch a live token). The file also carries thePostsModel.micropubSendDraftextension (PostsModel.swift sits at its file-length ceiling): runPass's guard set minus the engine gates,flushOrAbortfirst (widened internal), ONE disk read serves both wire fields (Post.title(of: raw)+splitFrontmatter(raw).body— no scan dependency), stampmicropub_urlonly on.drafted(try?: the draft already landed).Museion/MicropubPublishSheet.swift(new) — the G9 ask-before sheet owning both steps (Send as Draft → preview link → Publish, each an explicit click); token SecureField appears when none is saved or after an auth failure (re-entry replaces — no dead end), a fresh entry saves ONCE to the Keychain;Send Againre-drafts after edits;.onAppearseeds from the piece'smicropub_urlso a draft from an earlier session still publishes; refusals inline orange, buttons kept (ApplyAskSheet posture).Museion/PostLibrary.swift—Post.micropubURL: String?(defaulted property — all hand-constructedPost(id:…)sites keep compiling), scan readsmicropub_urlgated onMicropub.trustworthyURL(imported frontmatter rides verbatim; hostile values scan nil and never pre-arm the sheet).Museion/PostStore.swift—stampMicropubURL(id:url:home:): in-placemicropub_urlstamp throughstampingFrontmatter(frontmatter-only, body + foreign keys byte-identical — the open session's readBody echo check never fires); vanished piece throwsCocoaError(.fileReadNoSuchFile)(the 8-sibling convention; finish-audit ponytail finding).Museion/PostEditorView.swift— optionalpublishclosure + mono-11 Publish toolbar button (nil = hidden; drafts/guest/previews carry none).Museion/PostsPaneView.swift—showingPublish@State,.sheetbeside.task(id: home), closure wired in the editor column's session branch.- Tests:
MuseionTests/MicropubTests.swift(wire contract, decode matrix, keychain own-slot round-trip, stamp/scan) +MuseionTests/MicropubModelTests.swift(model flow: flush-first, refusal guards, the category AC pin, stamp lifecycle) — 20 tests. - Finish-audit fanout (ponytail/security/general, fresh-context, read-only) → 6 accepted fixes, 2 declines, 1 parked ceiling; 4 guard flip-verification cycles.
Decisions & Rationale
| Decision | Rationale |
|---|---|
Wire = JSON Micropub create → action=update publish |
Live-verified against microblog.dev/api/posting + book.micro.blog (2026-10-31): draft's final URL rides the Location header; publishing the draft IS the post-status update. No content re-send. |
micropub_url frontmatter key remembers the draft URL |
Publish must work after a reopen; follows the repo's in-place stamp corpus pattern (hand-editable, git-diffable). Not in the ticket verbatim — the two-step AC forces persistence of step 1's handle. |
Legacy login keychain (no kSecUseDataProtectionKeychain) |
DP-keychain SecItemAdd needs keychain-access-groups from a provisioning profile this undistributed app doesn't sign with (macos-keychain-token-storage skill matrix). ADR-0014's no-Keychain rule covers only provider keys hermes reads from .env; this token has no engine consumer. |
Title/body from ONE disk read in micropubSendDraft |
Disk is the truth post-flush; the scan snapshot can lag (the first test run caught title(of: id) returning the id in a fresh home — scan dependency removed, not poll-looped around). GLOSSARY: Title publishes as the entry's name; body never stripped. |
trustworthyURL format gate at BOTH ends (decode + scan) |
Converged security finding: the draft URL is trust-boundary data landing in frontmatter — a \n--- rider closes the block and re-parses as body (attacker markdown ships under the writer's token). Format-only by design: a well-formed foreign URL still passes (ponytail ceiling: host-allowlist when v2's q=config names the blog's domains). |
| Preview link display-only | A server omitting Location+url made the preview URL the publish target and the remembered micropub_url (general-review finding) — a preview page is not the post's address. |
| Publish button in the editor toolbar only | One placement; publish targets the open piece while the writer is looking at it. |
Keychain test slot via account param |
A locked keychain makes read() return nil; the old restore-dance defer then DELETED a real live token (security finding). Tests now run in their own slot. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
Post.scan impact = HIGH before edits |
Pure fan-out through 7 callers on a shared model type | Stated-and-proceed: additive diff (defaulted property + one key read), 509-test baseline green before/after |
First model test failed: name was flush-me (the id) |
title(of: id) reads the scan snapshot, which lags a fresh home |
Derive title AND body from the one post-flush disk read — no scan dependency |
| Two compile-error suite runs (exit 65) | Moving the model extension out of PostsModel.swift hit private members: flushOrAbort, then lastError's private(set) |
flushOrAbort → internal (one cross-file writer, documented); dropped the lastError write from the stamp-failure branch (the draft already landed; sheet holds the URL for the session) |
| Test suite crossed swiftlint's 400/250 ceilings after the audit pins | 5 new tests grew MicropubTests past file- and type-body limits | Split per repo precedent: MicropubModelTests.swift (MCPToolsPromoteTests pattern) |
| Whitespace-body pin failed on first run | Fixture had a heading line — the Title line IS content; the guard is right, the fixture was wrong | All-whitespace body fixture; comment names the distinction (heading-only pieces DO send) |
Scan-gate pin fixture initially used \n--- injection |
Post.frontmatter parses line-bounded — a newline can't ride a scanned value; the injection vector is the STAMP side (already decode-gated) |
Fixture pins the real scan vectors (non-URL value → nil; clean https → reads back) |
| 4 dead background-run notifications | xcresult read raced the run (ls -td grabbed a finalizing bundle); one run raced a visibility fix mid-flight |
Post-run xcresult re-read (the repo's count-not-banner rule); each dead run diagnosed and superseded in-turn |
| First reviewer child died on a provider stall (1251s) | Provider hiccup mid-fanout | Salvaged transcript (no findings recorded), re-dispatched leaner per protocol → PASS |
Files Changed
| File | Change Summary |
|---|---|
Museion/Micropub.swift |
new — client, trustworthyURL gate, token store, model publish flow |
Museion/MicropubPublishSheet.swift |
new — the two-step ask sheet |
Museion/PostLibrary.swift |
Post.micropubURL + gated scan read |
Museion/PostStore.swift |
stampMicropubURL in-place stamp |
Museion/PostsModel.swift |
flushOrAbort private → internal |
Museion/PostEditorView.swift |
optional publish closure + toolbar button |
Museion/PostsPaneView.swift |
sheet hosting + wiring |
MuseionTests/MicropubTests.swift |
new — wire/decode/store/scan pins (15) |
MuseionTests/MicropubModelTests.swift |
new — model-flow pins (5) |
Museion/AGENTS.md, MuseionTests/AGENTS.md, AGENTS.md |
DOX pass (file bullets, test-suite entry, GitNexus stats line) |
Open Items & Next Steps
- AC1 live verification (yours): open a saved post → Publish → paste the Micro.blog app token (needs create+update scopes) → Send as Draft → review via preview link → Publish. Ticket #33 stays open until you've run it on a real post.
ref/opendesign-prompt.mdat the repo root is pre-existing scratch from another session — untouched, excluded from this commit.- v2 (PRD): category round-trip (
q=config+ category create), host-allowlist for remembered URLs, illustrations (S6.2, #34 — separate fence, deliberately not built).
Verification
- Full suite 529 passed / 0 failed (xcresult executed count; baseline 509 + 20 new) — code tree identical since (post-suite edits were docs-only)
- All 4 audit guards flip-verified: guards off → their pins failed; chain flipped → preview pin failed; restored → green
- swiftformat 0 dirty, swiftlint zero findings on all touched files (pre-existing repo violations unchanged from HEAD)
- Reviewer fanout: initial PASS (zero findings) + finish-audit 3-reviewer pass (6 fixed, 2 declined with rationale, 1 parked ceiling)
- GitNexus: impact-before-edit, detect-changes scope check (intended symbols only), index re-analyzed twice
Log written by write-log skill