fix: fixed behaviour of bundled app for decrypt and ai chat

This commit is contained in:
2026-05-31 17:26:50 +02:00
parent 040b5db37b
commit 5e99cb7a09
16 changed files with 189 additions and 49 deletions

View File

@@ -2,6 +2,8 @@ defmodule BDS.Desktop.ShellLive.SettingsEditor.SettingsSearchTest do
use ExUnit.Case, async: false
alias BDS.Desktop.ShellLive.SettingsEditor
alias BDS.Repo
alias BDS.Settings.Setting
describe "build_settings/1 — search filter" do
setup do
@@ -111,4 +113,62 @@ defmodule BDS.Desktop.ShellLive.SettingsEditor.SettingsSearchTest do
assert SettingsEditor.build_settings(%{projects: %{active_project_id: nil}}) == nil
end
end
describe "build_settings/1 — handles undecryptable API key gracefully" do
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
temp_dir =
Path.join(System.tmp_dir!(), "bds-settings-cipher-#{System.unique_integer([:positive])}")
File.mkdir_p!(temp_dir)
on_exit(fn -> File.rm_rf(temp_dir) end)
{:ok, project} =
BDS.Projects.create_project(%{name: "CipherTest", data_path: temp_dir})
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond)
Repo.insert!(%Setting{
key: "ai.online.url",
value: "https://example.com",
updated_at: now
})
Repo.insert!(%Setting{
key: "ai.online.model",
value: "gpt-4",
updated_at: now
})
Repo.insert!(%Setting{
key: "__encrypted_ai.online.api_key",
value: "NOT_VALID_BASE64",
updated_at: now
})
%{project: project, temp_dir: temp_dir}
end
test "does not crash when encrypted API key cannot be decrypted", %{
project: project,
temp_dir: temp_dir
} do
result =
SettingsEditor.build_settings(%{
projects: %{active_project_id: project.id},
current_project: %{data_path: temp_dir},
settings_editor_search: "",
settings_editor_project_draft: %{},
settings_editor_editor_draft: %{},
settings_editor_ai_draft: %{},
settings_editor_publishing_draft: %{},
current_tab: %{type: :settings, id: "settings"},
tab_meta: %{}
})
assert is_map(result)
assert result.ai_visible?
end
end
end

View File

@@ -119,7 +119,7 @@ defmodule BDS.ProjectsTest do
test "project_cache_dir never falls back into the project data directory" do
# Private app-internal artifacts (the embeddings index) must live under the
# OS private app directory (macOS: ~/Library/Application Support/bds), never
# OS private app directory (macOS: ~/Library/Application Support/BDS2), never
# inside priv/data/projects/<id> — leaving them in the project tree pollutes
# the repository.
saved = Application.get_env(:bds, :project_cache_root)
@@ -134,7 +134,7 @@ defmodule BDS.ProjectsTest do
refute String.starts_with?(cache_dir, Path.expand("../../priv/data", __DIR__))
private_app_dir =
case :filename.basedir(:user_config, "bds") do
case :filename.basedir(:user_config, "BDS2") do
path when is_list(path) -> List.to_string(path)
path -> path
end