feat(outline): convert to post — S4 (#114)
CI / ci (push) Canceled after 0s

In-place outline→post conversion on the piece: id, folder, Pass
State, origin kept, type frontmatter flips to post, body transforms
once. The ask picks the transform — Verbatim Bullets (default,
lossless) or Headings ladder (roots ##, stepping to the ###### floor,
deeper stays bullets), with a warning when the ladder would drop
paragraph lines between bullets.

The open session flushes first, then reopens routed to prose via
proseOverridePostID (lastDraftWasOutline's machinery reversed).
An outline that went lossy on disk behind an unwarned ask aborts
the convert; an unanswered #67 conflict aborts every flush-first
op (shared flushOrAbort seam); rescan no longer hands a same-id
reopened session its predecessor's stale disk text; a held #111
guard ask dies with the outline it pointed at.

Audit round (finish-audit, three reviewers) included: 13 new pins,
206 tests green, pin discrimination verified. Record:
docs/devlog/20261016-issue114-convert-to-post_log.md
This commit is contained in:
AlexKucera committed 2026-10-16 18:03:41 +02:00
1 parent 21e2f27450
commit c0513aae85
14 files changed
+547 -19

No files matched your search

+40
View File
@@ -517,3 +517,43 @@ private func readPiece(_ home: URL, root: String, project: String, _ id: String)
try PostStore.createProject(named: ".x", home: home) // hidden — scan skips dot-dirs
}
}
@Test func `convert flips type transforms the body once and keeps identity`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Chapter\n- one\n - nested", type: .outline, home: home)
// verbatim: body unchanged, type flips, stamp keeps its own values
try PostStore.convert(id: post.id, headingsLadder: false, home: home)
let verbatim = try readPost(home, post.id)
#expect(verbatim.hasPrefix("---\ntype: post\n"))
#expect(verbatim.contains("pass_state: First Draft"))
#expect(verbatim.contains("origin: writer"))
#expect(PostStore.splitFrontmatter(verbatim).body == "# Chapter\n- one\n - nested")
// folder never moved; scan reads the new type on rescan
#expect(Post.scan(home: home).first?.id == post.id)
#expect(Post.scan(home: home).first?.type == .post)
// ladder: the headings mapping, preamble above
try PostStore.convert(id: post.id, headingsLadder: true, home: home)
let ladder = try readPost(home, post.id)
#expect(ladder.hasPrefix("---\ntype: post\n"))
#expect(PostStore.splitFrontmatter(ladder).body == "# Chapter\n## one\n### nested")
// a vanished piece throws, never resurrects
#expect(throws: CocoaError(.fileReadNoSuchFile)) {
try PostStore.convert(id: "no-such-piece", headingsLadder: true, home: home)
}
}
@Test func `convert works on an archived piece without moving it`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Filed\n- one", type: .outline, home: home)
try PostStore.archive(post, home: home)
try PostStore.convert(id: post.id, headingsLadder: true, home: home)
let onDisk = try String(contentsOf: home.appendingPathComponent("archive/posts/\(post.id)/post.md"), encoding: .utf8)
#expect(onDisk.hasPrefix("---\ntype: post\n"))
#expect(onDisk.contains("## one"))
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("projects/posts/\(post.id)").path))
}