fix: more work on metadata diff

This commit is contained in:
2026-04-27 10:38:36 +02:00
parent e7ccf02d40
commit 07730dc93e
10 changed files with 384 additions and 94 deletions

View File

@@ -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")

View File

@@ -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