fix: more work on metadata diff
This commit is contained in:
@@ -99,6 +99,45 @@ defmodule BDS.Desktop.ShellCommandsTest do
|
||||
assert is_map(completed.result.payload.summary)
|
||||
end
|
||||
|
||||
test "repair_metadata_diff exposes live in-task progress from the repair worker", %{project: project} do
|
||||
original = Application.get_env(:bds, :tasks, [])
|
||||
|
||||
Application.put_env(
|
||||
:bds,
|
||||
:tasks,
|
||||
original
|
||||
|> Keyword.put(:max_concurrent, 1)
|
||||
|> Keyword.put(:progress_throttle_ms, 0)
|
||||
)
|
||||
|
||||
on_exit(fn -> Application.put_env(:bds, :tasks, original) end)
|
||||
|
||||
items =
|
||||
Enum.map(1..40, fn _index ->
|
||||
%{"entity_type" => "project", "entity_id" => project.id}
|
||||
end)
|
||||
|
||||
assert {:ok, result} =
|
||||
ShellCommands.execute("repair_metadata_diff", %{
|
||||
"direction" => "file_to_db",
|
||||
"items" => items
|
||||
})
|
||||
|
||||
progressed =
|
||||
wait_for_task(
|
||||
result.task_id,
|
||||
&(&1.status == :running and is_number(&1.progress) and &1.progress > 0.2 and &1.progress < 1.0),
|
||||
5_000
|
||||
)
|
||||
|
||||
assert progressed.group_name == "Maintenance"
|
||||
assert String.contains?(progressed.message, "Repairing")
|
||||
assert String.contains?(progressed.message, "/")
|
||||
|
||||
assert wait_for_task(result.task_id, &(&1.status == :completed and &1.progress == 1.0), 5_000).status ==
|
||||
:completed
|
||||
end
|
||||
|
||||
test "find_duplicates queues a tracked embeddings task and returns the report as an editor payload" do
|
||||
assert {:ok, result} = ShellCommands.execute("find_duplicates")
|
||||
|
||||
|
||||
@@ -1034,6 +1034,72 @@ defmodule BDS.Desktop.ShellLiveTest do
|
||||
refute Enum.any?(diff.diff_reports, &(&1.entity_id == published_post.id))
|
||||
end
|
||||
|
||||
test "metadata diff refresh reruns the diff and replaces the current result", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
} do
|
||||
:ok = BDS.Tasks.clear_finished()
|
||||
|
||||
assert {:ok, post} =
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Database Post",
|
||||
content: "Body",
|
||||
excerpt: "Summary",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, published_post} = Posts.publish_post(post.id)
|
||||
post_path = Path.join(temp_dir, published_post.file_path)
|
||||
|
||||
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
|
||||
|
||||
assert {:ok, queued} = BDS.Desktop.ShellCommands.execute("metadata_diff")
|
||||
completed_task!(queued.task_id)
|
||||
send(view.pid, :refresh_task_status)
|
||||
|
||||
html = render(view)
|
||||
refute html =~ "Filesystem Post"
|
||||
|
||||
File.write!(
|
||||
post_path,
|
||||
[
|
||||
"---",
|
||||
"id: #{published_post.id}",
|
||||
"title: Filesystem Post",
|
||||
"slug: #{published_post.slug}",
|
||||
"excerpt: Summary",
|
||||
"status: published",
|
||||
"language: en",
|
||||
"createdAt: #{published_post.created_at}",
|
||||
"updatedAt: #{published_post.updated_at + 1}",
|
||||
"publishedAt: #{published_post.published_at}",
|
||||
"tags:",
|
||||
"categories:",
|
||||
"---",
|
||||
"Body",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
|
||||
existing_ids = MapSet.new(Enum.map(BDS.Tasks.list_tasks(), & &1.id))
|
||||
|
||||
html =
|
||||
view
|
||||
|> element("button[phx-click='rerun_misc_editor']")
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Metadata Diff"
|
||||
|
||||
refresh_task = new_task!(existing_ids, "Metadata Diff")
|
||||
completed_task!(refresh_task.id)
|
||||
send(view.pid, :refresh_task_status)
|
||||
|
||||
html = render(view)
|
||||
assert html =~ "Filesystem Post"
|
||||
end
|
||||
|
||||
test "metadata diff orphan import action queues an import task and removes the orphan", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
|
||||
@@ -328,6 +328,49 @@ defmodule BDS.MaintenanceTest do
|
||||
assert_incremental_progress(collect_progress_events())
|
||||
end
|
||||
|
||||
test "metadata_diff reports incremental progress across comparison phases", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
} do
|
||||
parent = self()
|
||||
on_progress = fn value, message -> send(parent, {:rebuild_progress, value, message}) end
|
||||
|
||||
posts_dir = Path.join([temp_dir, "posts", "2026", "04"])
|
||||
File.mkdir_p!(posts_dir)
|
||||
|
||||
Enum.each(1..40, fn index ->
|
||||
slug = "diff-progress-post-#{index}"
|
||||
|
||||
File.write!(
|
||||
Path.join(posts_dir, "#{slug}.md"),
|
||||
[
|
||||
"---",
|
||||
"id: #{slug}",
|
||||
"title: Diff Progress Post #{index}",
|
||||
"slug: #{slug}",
|
||||
"status: published",
|
||||
"createdAt: 1711843200",
|
||||
"updatedAt: 1711929600",
|
||||
"publishedAt: 1712016000",
|
||||
"tags:",
|
||||
"categories:",
|
||||
"---",
|
||||
"Body #{index}",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
end)
|
||||
|
||||
assert {:ok, _posts} = BDS.Maintenance.rebuild_from_filesystem(project.id, "post")
|
||||
|
||||
assert {:ok, _diff} = BDS.Maintenance.metadata_diff(project.id, on_progress: on_progress)
|
||||
|
||||
events = collect_progress_events()
|
||||
assert_incremental_progress(events)
|
||||
assert Enum.any?(events, fn {_value, message} -> String.contains?(message, "Comparing") end)
|
||||
end
|
||||
|
||||
test "maintenance rebuilds and diffs embedding state explicitly", %{project: project} do
|
||||
assert {:ok, _metadata} =
|
||||
BDS.Metadata.update_project_metadata(project.id, %{semantic_similarity_enabled: true})
|
||||
@@ -749,6 +792,51 @@ defmodule BDS.MaintenanceTest do
|
||||
end)
|
||||
end
|
||||
|
||||
test "metadata_diff accepts legacy snake_case post frontmatter keys for status and timestamps", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
} do
|
||||
assert {:ok, post} =
|
||||
BDS.Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Legacy Keys Post",
|
||||
content: "Body",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, published_post} = BDS.Posts.publish_post(post.id)
|
||||
|
||||
post_path = Path.join(temp_dir, published_post.file_path)
|
||||
|
||||
File.write!(
|
||||
post_path,
|
||||
[
|
||||
"---",
|
||||
"id: #{published_post.id}",
|
||||
"title: #{published_post.title}",
|
||||
"slug: #{published_post.slug}",
|
||||
"status: published",
|
||||
"language: en",
|
||||
"created_at: #{published_post.created_at}",
|
||||
"updated_at: #{published_post.updated_at}",
|
||||
"published_at: #{published_post.published_at}",
|
||||
"tags:",
|
||||
"categories:",
|
||||
"---",
|
||||
"Body",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
|
||||
assert {:ok, %{diff_reports: diff_reports}} = BDS.Maintenance.metadata_diff(project.id)
|
||||
|
||||
refute Enum.any?(diff_reports, fn report ->
|
||||
report.entity_type == "post" and report.entity_id == published_post.id and
|
||||
Enum.any?(report.differences, &(&1.name in ["status", "created_at", "updated_at", "published_at"]))
|
||||
end)
|
||||
end
|
||||
|
||||
test "metadata_diff includes project-level metadata drift", %{project: project, temp_dir: temp_dir} do
|
||||
assert {:ok, _metadata} =
|
||||
BDS.Metadata.update_project_metadata(project.id, %{
|
||||
|
||||
Reference in New Issue
Block a user