Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m9s
Implements plans/migration/data-migration.md (the un-started long-pole) and the data-layer half of slice-01-blog §4. Host-ops migration module composing content-on-sx + persist public APIs; isolated from lib/host and lib/content. - lexical.sx: Ghost lexical (as SX dicts) -> content block list, deterministic ids - import.sx: genesis import into content:<id> op-log, idempotent, + postmeta stream - verify.sx: replay-and-diff vs row-derived oracle (proves round-trip lossless) Inline formatting flattens to plain text (Phase-5 runs swap-point isolated in lex-inline-text); live Postgres source (Q-M4) + improved-converter re-import (Q-M5) flagged in README. 55/55 conformance: lexical 23, import 21, verify 11. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
93 lines
3.8 KiB
Plaintext
93 lines
3.8 KiB
Plaintext
; lib/blogimport/tests/lexical.sx — lexical -> content block converter
|
|
(st-bootstrap-classes!)
|
|
(content-bootstrap-blocks!)
|
|
(content-bootstrap-doc!)
|
|
(content-bootstrap-callout!)
|
|
(content-bootstrap-media!)
|
|
|
|
; ---- a representative lexical document (Ghost editor JSON, as SX dicts) ----
|
|
(define
|
|
doc
|
|
{:root {:children (list
|
|
{:type "heading" :tag "h2" :children (list {:type "text" :text "Title"})}
|
|
{:type "paragraph" :children (list
|
|
{:type "text" :text "plain "}
|
|
{:type "text" :text "bold" :format 1}
|
|
{:type "text" :text " then "}
|
|
{:type "link" :url "/x" :children (list {:type "text" :text "a link"})})}
|
|
{:type "quote" :children (list {:type "text" :text "wise words"})}
|
|
{:type "list" :listType "number" :children (list
|
|
{:type "listitem" :children (list {:type "text" :text "one"})}
|
|
{:type "listitem" :children (list {:type "text" :text "two"})})}
|
|
{:type "codeblock" :language "python" :code "print(1)"}
|
|
{:type "horizontalrule"}
|
|
{:type "image" :src "/c.png" :alt "a cat"}
|
|
{:type "callout" :backgroundColor "blue" :children (list {:type "text" :text "note!"})}
|
|
{:type "twitter" :url "https://t/x"})}})
|
|
|
|
(define blocks (blogimport/lex-blocks doc))
|
|
|
|
; ---- structure ----
|
|
(bi-test "block count" (len blocks) 9)
|
|
(bi-test "ids by position" (map blk-id blocks)
|
|
(list "b0" "b1" "b2" "b3" "b4" "b5" "b6" "b7" "b8"))
|
|
(bi-test "types in order" (map blk-type blocks)
|
|
(list "heading" "text" "quote" "list" "code" "divider" "image" "callout" "embed"))
|
|
|
|
; ---- heading ----
|
|
(bi-test "heading level" (blk-send (nth blocks 0) "level") 2)
|
|
(bi-test "heading text" (str (blk-send (nth blocks 0) "text")) "Title")
|
|
|
|
; ---- paragraph with inline bold + link, flattened to plain concatenation ----
|
|
(bi-test "paragraph flattened text"
|
|
(str (blk-send (nth blocks 1) "text")) "plain bold then a link")
|
|
|
|
; ---- quote ----
|
|
(bi-test "quote text" (str (blk-send (nth blocks 2) "text")) "wise words")
|
|
|
|
; ---- ordered list with items ----
|
|
(bi-test "list ordered" (blk-send (nth blocks 3) "ordered") true)
|
|
(bi-test "list items" (blk-send (nth blocks 3) "items") (list "one" "two"))
|
|
|
|
; ---- code block ----
|
|
(bi-test "code language" (str (blk-send (nth blocks 4) "language")) "python")
|
|
(bi-test "code text" (str (blk-send (nth blocks 4) "text")) "print(1)")
|
|
|
|
; ---- image ----
|
|
(bi-test "image src" (str (blk-send (nth blocks 6) "src")) "/c.png")
|
|
(bi-test "image alt" (str (blk-send (nth blocks 6) "alt")) "a cat")
|
|
|
|
; ---- callout ----
|
|
(bi-test "callout kind" (str (blk-send (nth blocks 7) "kind")) "blue")
|
|
(bi-test "callout text" (str (blk-send (nth blocks 7) "text")) "note!")
|
|
|
|
; ---- unknown card routed to embed, provider records original type ----
|
|
(bi-test "unknown -> embed provider" (str (blk-send (nth blocks 8) "provider")) "twitter")
|
|
|
|
; ---- heading level mapping ----
|
|
(bi-test "h1 level" (lex-heading-level "h1") 1)
|
|
(bi-test "h4 level" (lex-heading-level "h4") 4)
|
|
(bi-test "unknown tag default" (lex-heading-level "hx") 2)
|
|
|
|
; ---- bullet list ----
|
|
(define
|
|
bdoc
|
|
{:children (list {:type "list" :listType "bullet" :children (list
|
|
{:type "listitem" :children (list {:type "text" :text "x"})})})})
|
|
(bi-test "bullet not ordered" (blk-send (nth (blogimport/lex-blocks bdoc) 0) "ordered") false)
|
|
|
|
; ---- empty doc ----
|
|
(bi-test "empty doc -> no blocks" (len (blogimport/lex-blocks {:root {:children (list)}})) 0)
|
|
|
|
; ---- bare-children doc (no :root wrapper) ----
|
|
(bi-test "bare children doc"
|
|
(map blk-type (blogimport/lex-blocks {:children (list {:type "paragraph" :children (list {:type "text" :text "hi"})})}))
|
|
(list "text"))
|
|
|
|
; ---- linebreak/tab in inline flattening ----
|
|
(bi-test "linebreak flatten"
|
|
(str (blk-send (nth (blogimport/lex-blocks
|
|
{:children (list {:type "paragraph" :children (list
|
|
{:type "text" :text "a"} {:type "linebreak"} {:type "text" :text "b"})})}) 0) "text"))
|
|
"a\nb")
|