fix: ai preferences crashed and deleted stuff in preferences

This commit is contained in:
2026-07-07 22:43:05 +02:00
parent 4a03fc0ba2
commit dc35518bad
21 changed files with 1883 additions and 261 deletions

View File

@@ -385,6 +385,28 @@ defmodule BDS.AITest do
assert Repo.get(Setting, "__encrypted_ai.online.api_key") == nil
end
test "put_endpoint clears fields on nil instead of crashing" do
assert {:ok, _endpoint} =
BDS.AI.put_endpoint(
:online,
%{url: "https://api.example.test/v1", api_key: "secret", model: "gpt-4o-mini"},
secret_backend: FakeSecretBackend
)
# A partial config (blank URL/model) must not raise — it clears those keys.
assert {:ok, endpoint} =
BDS.AI.put_endpoint(
:online,
%{url: nil, api_key: nil, model: nil},
secret_backend: FakeSecretBackend
)
assert endpoint.url == nil
assert Repo.get(Setting, "ai.online.url") == nil
assert Repo.get(Setting, "ai.online.model") == nil
assert Repo.get(Setting, "__encrypted_ai.online.api_key") == nil
end
test "airplane_endpoint_configured? reflects the airplane endpoint url and model" do
refute BDS.AI.airplane_endpoint_configured?()