feat: metadata, frontmatter, write atomicity should now be in
This commit is contained in:
@@ -51,6 +51,9 @@ defmodule BDS.MediaTest do
|
||||
assert sidecar =~ "author: Writer\n"
|
||||
assert sidecar =~ "language: en\n"
|
||||
assert sidecar =~ "tags:\n - alpha\n"
|
||||
assert sidecar =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert sidecar =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
refute File.exists?(Path.join(temp_dir, media.sidecar_path <> ".tmp"))
|
||||
end
|
||||
|
||||
test "update_media rewrites the sidecar metadata", %{project: project, temp_dir: temp_dir} do
|
||||
@@ -137,8 +140,8 @@ defmodule BDS.MediaTest do
|
||||
"caption: Recovered caption",
|
||||
"author: Writer",
|
||||
"language: en",
|
||||
"created_at: 1711843200",
|
||||
"updated_at: 1711929600",
|
||||
"created_at: 2024-03-30T21:20:00.000Z",
|
||||
"updated_at: 2024-03-31T21:20:00.000Z",
|
||||
"tags:",
|
||||
" - alpha",
|
||||
""
|
||||
@@ -175,6 +178,8 @@ defmodule BDS.MediaTest do
|
||||
assert media.author == "Writer"
|
||||
assert media.language == "en"
|
||||
assert media.tags == ["alpha"]
|
||||
assert media.created_at == 1_711_833_600_000
|
||||
assert media.updated_at == 1_711_920_000_000
|
||||
assert media.file_path == "media/2026/04/asset.jpg"
|
||||
assert media.sidecar_path == "media/2026/04/asset.jpg.meta"
|
||||
|
||||
|
||||
@@ -138,4 +138,26 @@ defmodule BDS.MetadataTest do
|
||||
assert BDS.Repo.get_by(BDS.Embeddings.Key, project_id: project.id, post_id: post.id) != nil
|
||||
assert File.exists?(BDS.Embeddings.index_path(project.id))
|
||||
end
|
||||
|
||||
test "sync_project_metadata_from_filesystem materializes the canonical metadata files when missing",
|
||||
%{project: project, temp_dir: temp_dir} do
|
||||
meta_dir = Path.join(temp_dir, "meta")
|
||||
refute File.exists?(Path.join(meta_dir, "project.json"))
|
||||
refute File.exists?(Path.join(meta_dir, "categories.json"))
|
||||
refute File.exists?(Path.join(meta_dir, "category-meta.json"))
|
||||
refute File.exists?(Path.join(meta_dir, "publishing.json"))
|
||||
|
||||
assert {:ok, metadata} = BDS.Metadata.sync_project_metadata_from_filesystem(project.id)
|
||||
|
||||
assert metadata.name == project.name
|
||||
assert File.exists?(Path.join(meta_dir, "project.json"))
|
||||
assert File.exists?(Path.join(meta_dir, "categories.json"))
|
||||
assert File.exists?(Path.join(meta_dir, "category-meta.json"))
|
||||
assert File.exists?(Path.join(meta_dir, "publishing.json"))
|
||||
|
||||
refute File.exists?(Path.join(meta_dir, "project.json.tmp"))
|
||||
refute File.exists?(Path.join(meta_dir, "categories.json.tmp"))
|
||||
refute File.exists?(Path.join(meta_dir, "category-meta.json.tmp"))
|
||||
refute File.exists?(Path.join(meta_dir, "publishing.json.tmp"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ defmodule BDS.PostLinksTest do
|
||||
end
|
||||
|
||||
defp canonical_post_href(post) do
|
||||
datetime = DateTime.from_unix!(post.created_at)
|
||||
datetime = DateTime.from_unix!(post.created_at, :millisecond)
|
||||
|
||||
Path.join([
|
||||
"",
|
||||
|
||||
@@ -151,7 +151,12 @@ defmodule BDS.PostsTest do
|
||||
assert file_contents =~ "template_slug: article\n"
|
||||
assert file_contents =~ "tags:\n - alpha\n"
|
||||
assert file_contents =~ "categories:\n - notes\n"
|
||||
assert file_contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert file_contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert file_contents =~ ~r/published_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert file_contents =~ "\n---\nHello from markdown\n"
|
||||
|
||||
refute File.exists?(full_path <> ".tmp")
|
||||
end
|
||||
|
||||
test "delete_post removes the database row and published markdown file when present" do
|
||||
@@ -271,9 +276,9 @@ defmodule BDS.PostsTest do
|
||||
"language: en",
|
||||
"do_not_translate: true",
|
||||
"template_slug: article",
|
||||
"created_at: 1711843200",
|
||||
"updated_at: 1711929600",
|
||||
"published_at: 1712016000",
|
||||
"created_at: 2024-03-30T21:20:00.000Z",
|
||||
"updated_at: 2024-03-31T21:20:00.000Z",
|
||||
"published_at: 2024-04-01T21:20:00.000Z",
|
||||
"tags:",
|
||||
" - alpha",
|
||||
"categories:",
|
||||
@@ -299,9 +304,9 @@ defmodule BDS.PostsTest do
|
||||
assert post.language == "en"
|
||||
assert post.do_not_translate == true
|
||||
assert post.template_slug == "article"
|
||||
assert post.created_at == 1_711_843_200
|
||||
assert post.updated_at == 1_711_929_600
|
||||
assert post.published_at == 1_712_016_000
|
||||
assert post.created_at == 1_711_833_600_000
|
||||
assert post.updated_at == 1_711_920_000_000
|
||||
assert post.published_at == 1_712_006_400_000
|
||||
assert post.tags == ["alpha"]
|
||||
assert post.categories == ["notes"]
|
||||
assert post.file_path == "posts/2026/04/recovered-post.md"
|
||||
|
||||
@@ -312,7 +312,7 @@ defmodule BDS.RenderingTest do
|
||||
end
|
||||
|
||||
defp canonical_post_href(post) do
|
||||
datetime = DateTime.from_unix!(post.created_at)
|
||||
datetime = DateTime.from_unix!(post.created_at, :millisecond)
|
||||
|
||||
"/#{datetime.year}/#{String.pad_leading(Integer.to_string(datetime.month), 2, "0")}/#{String.pad_leading(Integer.to_string(datetime.day), 2, "0")}/#{post.slug}/"
|
||||
end
|
||||
|
||||
@@ -71,9 +71,10 @@ defmodule BDS.ScriptsTest do
|
||||
assert contents =~ "entrypoint: main\n"
|
||||
assert contents =~ "enabled: true\n"
|
||||
assert contents =~ "version: 1\n"
|
||||
assert contents =~ "created_at: #{published.created_at}\n"
|
||||
assert contents =~ "updated_at: #{published.updated_at}\n"
|
||||
assert contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert contents =~ "\n---\nfunction main() return 'ok' end\n"
|
||||
refute File.exists?(full_path <> ".tmp")
|
||||
end
|
||||
|
||||
test "update_script bumps version and reopens a published script when content changes", %{
|
||||
@@ -144,8 +145,8 @@ defmodule BDS.ScriptsTest do
|
||||
"entrypoint: main",
|
||||
"enabled: true",
|
||||
"version: 4",
|
||||
"created_at: 301",
|
||||
"updated_at: 404",
|
||||
"created_at: 1970-01-01T00:00:00.301Z",
|
||||
"updated_at: 1970-01-01T00:00:00.404Z",
|
||||
"---",
|
||||
"function main() return 'restored' end",
|
||||
""
|
||||
|
||||
@@ -71,9 +71,10 @@ defmodule BDS.TemplatesTest do
|
||||
assert contents =~ "kind: list\n"
|
||||
assert contents =~ "enabled: true\n"
|
||||
assert contents =~ "version: 1\n"
|
||||
assert contents =~ "created_at: #{published.created_at}\n"
|
||||
assert contents =~ "updated_at: #{published.updated_at}\n"
|
||||
assert contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
|
||||
assert contents =~ "\n---\n<section>{{ page_title }}</section>\n"
|
||||
refute File.exists?(full_path <> ".tmp")
|
||||
end
|
||||
|
||||
test "update_template bumps version and reopens a published template when content changes", %{
|
||||
@@ -235,8 +236,8 @@ defmodule BDS.TemplatesTest do
|
||||
"kind: list",
|
||||
"enabled: true",
|
||||
"version: 3",
|
||||
"created_at: 101",
|
||||
"updated_at: 202",
|
||||
"created_at: 1970-01-01T00:00:00.101Z",
|
||||
"updated_at: 1970-01-01T00:00:00.202Z",
|
||||
"---",
|
||||
"<section>Recovered</section>",
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user