refactor(posts): one frontmatter read/write codec
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
#180: one PostFrontmatter module now owns the lenient read (parse/split/decoded) and every write posture — fresh stamp, merge-import, update-keys — behind one known-key table (type, pass_state, origin; one insertion order). The three near-twin walkers are deleted byte-identically: PostStore.stamped/splitFrontmatter/ mergedFrontmatter, LearningDecay.stampingFrontmatter, Post.frontmatter(of:) — 21 call sites swept across seven production files and eight test files. The Unaided First Draft eligibility is named once and consumed by both gates: isUnaidedFirstDraftPair (writer ∧ post — the scan's read-back gate) and isCaptureEligible (pair ∧ First Draft — the capture gate at pass invocation). The lenient ?? default stamp decode is extracted with it (the third copy's deferred extraction). One deliberate divergence from the absorbed writer, doc-commented and pinned: mergingImport now preserves hand-edit lines above the opening --- on import where the old split-first shape silently dropped them — lossless through every posture is the ticket's contract. Seven codec pins (PostFrontmatterTests) cover the posture round-trip (foreign keys verbatim through import → save → advance → micropub), the lenient unknown-type decode, and the predicates' truth table. Existing pieces are untouched on disk: every posture moved verbatim and the full suite pins the byte shapes (664/664 green; the one under-load flake in the #179 repoint pin is pre-existing on main, proven by a stashed-tree control run). Closes #180
This commit is contained in:
1 parent
5bf09552f6
commit
218e2db397
22 files changed
+479
-221
No files matched your search
@@ -575,7 +575,7 @@ func readPiece(_ home: URL, root: String, project: String, _ id: String) throws
|
||||
#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")
|
||||
#expect(PostFrontmatter.split(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)
|
||||
@@ -584,7 +584,7 @@ func readPiece(_ home: URL, root: String, project: String, _ id: String) throws
|
||||
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")
|
||||
#expect(PostFrontmatter.split(ladder).body == "# Chapter\n## one\n### nested")
|
||||
|
||||
// a vanished piece throws, never resurrects
|
||||
#expect(throws: CocoaError(.fileReadNoSuchFile)) {
|
||||
|
||||
Reference in new issue
Block a user