feat: step 12 is done again. huh?

This commit is contained in:
2026-04-29 20:33:59 +02:00
parent f178b5b207
commit a6033cb86a
11 changed files with 1369 additions and 205 deletions

View File

@@ -119,6 +119,16 @@ defmodule BDS.AITest do
usage: usage(13, 9, 0, 0)
}}
:import_taxonomy_mapping ->
{:ok,
%{
json: %{
"categoryMappings" => %{"General" => "article", "Unknown" => "missing"},
"tagMappings" => %{"News" => "updates", "Ghost" => "missing"}
},
usage: usage(19, 7, 0, 0)
}}
:chat ->
if Enum.any?(request.messages, &(&1["role"] == "tool")) do
{:ok,
@@ -309,6 +319,36 @@ defmodule BDS.AITest do
assert request.model == "gpt-4.1-mini"
end
test "analyze_import_taxonomy uses the selected model override and returns only valid existing-term mappings" do
assert {:ok, _endpoint} =
BDS.AI.put_endpoint(:online, %{
url: "https://api.example.test/v1",
api_key: "online-secret",
model: "gpt-4o-mini"
}, secret_backend: FakeSecretBackend)
assert :ok = BDS.AI.set_airplane_mode(false)
assert :ok = BDS.AI.put_model_preference(:title, "gpt-4.1-mini")
assert {:ok, result} =
BDS.AI.analyze_import_taxonomy(
%{categories: ["General"], tags: ["News"]},
%{categories: ["article", "page"], tags: ["updates"]},
runtime: FakeRuntime,
test_pid: self(),
secret_backend: FakeSecretBackend,
model: "gpt-4o"
)
assert result.category_mappings == %{"General" => "article"}
assert result.tag_mappings == %{"News" => "updates"}
assert_received {:runtime_request, endpoint, request}
assert endpoint.kind == :online
assert request.operation == :import_taxonomy_mapping
assert request.model == "gpt-4o"
end
test "analyze_image requires a vision-capable airplane model before sending image input" do
assert {:ok, _endpoint} =
BDS.AI.put_endpoint(:airplane, %{

View File

@@ -53,8 +53,29 @@ defmodule BDS.Desktop.ImportShellLiveTest do
assert html =~ "Ready to import:"
assert html =~ "Import 5 Items"
assert html =~ "Post Slug Conflicts"
assert html =~ "Analyze with..."
refute html =~ "Desktop workbench content routed through the Elixir shell."
assert html =~ "Analyze with..."
assert html =~ "Posts (2)"
assert html =~ "Pages (1)"
assert html =~ "Media (1)"
assert html =~ "Click to add mapping"
refute html =~ ~s(name="mapped_to")
refute html =~ "Desktop workbench content routed through the Elixir shell."
posts_html =
view
|> element("button[phx-value-section='posts']")
|> render_click()
assert posts_html =~ "Existing Match"
assert posts_html =~ "WP Status"
media_html =
view
|> element("button[phx-value-section='media']")
|> render_click()
assert media_html =~ "Filename"
assert media_html =~ "Path"
end
defp cached_report(wxr_path, uploads_dir) do
@@ -102,6 +123,70 @@ defmodule BDS.Desktop.ImportShellLiveTest do
],
categories: [%{name: "General", exists_in_project: false, mapped_to: nil}],
tags: [%{name: "News", exists_in_project: false, mapped_to: nil}]
},
details: %{
posts: [
%{
item_type: "post",
title: "Hello World",
slug: "hello-world",
status: "new",
wp_status: "publish",
author: "Importer",
categories: ["General"],
tags: ["News"],
published_at: "2024-05-01 12:00:00",
excerpt: "Legacy hello",
content_markdown: "Hello world",
content_preview: "Hello world"
},
%{
item_type: "post",
title: "Conflict Me",
slug: "conflict-me",
status: "conflict",
resolution: "skip",
wp_status: "publish",
author: "Importer",
categories: ["General"],
tags: ["News"],
published_at: "2024-05-02 12:00:00",
excerpt: "Legacy conflict",
existing_title: "Existing Conflict",
content_markdown: "Incoming conflict body",
content_preview: "Incoming conflict body"
}
],
pages: [
%{
item_type: "page",
title: "About",
slug: "about",
status: "new",
wp_status: "publish",
author: "Importer",
categories: ["General"],
tags: [],
published_at: "2024-05-03 12:00:00",
excerpt: "About page",
content_markdown: "About page",
content_preview: "About page"
}
],
media: [
%{
item_type: "media",
title: "Import Asset",
filename: "import-asset.txt",
relative_path: "2024/05/import-asset.txt",
source_file: Path.join(uploads_dir, "2024/05/import-asset.txt"),
status: "new",
mime_type: "text/plain",
description: "Legacy text attachment",
parent_wp_id: 101,
created_at: "2024-05-03 12:00:00"
}
]
}
}
end

View File

@@ -149,6 +149,28 @@ defmodule BDS.ImportAnalysisTest do
assert Enum.any?(report.items.media, &(&1.filename == "missing-asset.txt" and &1.status == "missing"))
end
test "analyze_wxr reports legacy progress steps while building the import report", %{project: project, temp_dir: temp_dir} do
uploads_dir = Path.join(temp_dir, "uploads")
File.mkdir_p!(Path.join(uploads_dir, "2024/05"))
File.write!(Path.join(uploads_dir, "2024/05/import-asset.txt"), "legacy attachment")
wxr_path = Path.join(temp_dir, "legacy.xml")
File.write!(wxr_path, basic_wxr_xml())
assert {:ok, _report} =
ImportAnalysis.analyze_wxr(project.id, wxr_path, uploads_dir,
on_progress: fn step, detail ->
send(self(), {:analysis_progress, step, detail})
end
)
assert_received {:analysis_progress, "Loading existing posts...", nil}
assert_received {:analysis_progress, "Analyzing posts...", "1 posts to analyze"}
assert_received {:analysis_progress, "Analyzing pages...", "1 pages to analyze"}
assert_received {:analysis_progress, "Analyzing media files...", "1 media files to analyze"}
assert_received {:analysis_progress, "Discovering macros...", nil}
end
defp sha256(value) do
:sha256
|> :crypto.hash(value)

View File

@@ -97,6 +97,32 @@ defmodule BDS.ImportExecutionTest do
assert Enum.any?(slugs, &(&1 != "conflict-me"))
end
test "execute_import reports phase progress while importing", %{project: project, temp_dir: temp_dir} do
uploads_dir = Path.join(temp_dir, "uploads")
File.mkdir_p!(Path.join(uploads_dir, "2024/05"))
File.write!(Path.join(uploads_dir, "2024/05/import-asset.txt"), "legacy attachment")
wxr_path = Path.join(temp_dir, "legacy.xml")
File.write!(wxr_path, basic_wxr_xml())
assert {:ok, report} = ImportAnalysis.analyze_wxr(project.id, wxr_path, uploads_dir)
assert {:ok, _result} =
ImportExecution.execute_import(project.id, report,
uploads_folder_path: uploads_dir,
default_author: "Imported Author",
on_progress: fn phase, current, total, detail ->
send(self(), {:execution_progress, phase, current, total, detail})
end
)
assert_received {:execution_progress, "tags", 0, 2, "Creating tags..."}
assert_received {:execution_progress, "posts", 0, 1, "Importing posts..."}
assert_received {:execution_progress, "media", 0, 1, "Importing media..."}
assert_received {:execution_progress, "pages", 0, 1, "Importing pages..."}
assert_received {:execution_progress, "complete", 1, 1, "Import complete"}
end
defp sha256(value) do
:sha256
|> :crypto.hash(value)