diff --git a/apps/albedo/test/albedo/accounts/rotation_test.gleam b/apps/albedo/test/albedo/accounts/rotation_test.gleam index 15db0e0a7..06d5f4d8e 100644 --- a/apps/albedo/test/albedo/accounts/rotation_test.gleam +++ b/apps/albedo/test/albedo/accounts/rotation_test.gleam @@ -11,11 +11,9 @@ import albedo_ext_codex/wire as codex_wire import albedo_ext_openai/extension as openai import albedo_ext_opencode_go/extension as opencode_go import albedo_ext_opencode_go/wire as opencode_go_wire -import albedo_gemini/stream as gemini_stream import albedo_model as types import albedo_model/refusal import albedo_openai -import albedo_openai/opencode as gateway import albedo_sdk/accounts import albedo_sdk/auth_accounts import albedo_sdk/credential_store @@ -759,126 +757,6 @@ pub fn opencode_go_missing_rotation_member_is_an_error_test() -> Nil { cleanup(root) } -pub fn opencode_go_oauth_account_sends_org_header_test() -> Nil { - let #(root, _, home) = fixture() - let token = "oauth-go-" <> int.to_string(unique()) - let _ = - write( - home, - "config.json", - "{\"providers\":{\"go\":{\"extension\":\"opencode-go\",\"protocol\":\"chat_completions\",\"model\":\"glm-5.3-flash\"}}}", - ) - let _ = - write( - home, - "creds.json", - "{\"accounts\":{\"opencode-go\":[{\"type\":\"oauth\",\"access\":\"" - <> token - <> "\",\"refresh\":\"ref-1\",\"expires\":9999999999999,\"accountId\":\"usr_1\",\"email\":\"dawn@example.com\",\"orgId\":\"org_42\",\"orgName\":\"Personal\"}]}}", - ) - let pool = - opencode_go.pool(home, "go", "go-oauth-session", key_environment.empty()) - let assert Ok(client) = pool.current() - client.client.connection.api_key |> should.equal(token) - let sent_headers = opencode_go_wire.headers(client.client) - sent_headers - |> list.contains(#("x-opencode-session", "go-oauth-session")) - |> should.be_true - sent_headers - |> list.contains(#("x-opencode-org-id", "org_42")) - |> should.be_true - let assert [account] = auth_accounts.accounts(home, opencode_go.login()) - account.label |> should.equal("dawn@example.com ยท Personal") - cleanup(root) -} - -pub fn opencode_go_dispatches_each_model_family_to_its_wire_route_test() -> Nil { - opencode_go_wire.route("glm-5.3-flash") - |> should.equal(opencode_go_wire.ChatRoute) - opencode_go_wire.route("qwen3.8-max") - |> should.equal(opencode_go_wire.ChatRoute) - opencode_go_wire.route("gpt-5.6-luna") - |> should.equal(opencode_go_wire.ResponsesRoute) - opencode_go_wire.route("grok-4.7") - |> should.equal(opencode_go_wire.ResponsesRoute) - opencode_go_wire.route("muse-spark-1.2-contributor") - |> should.equal(opencode_go_wire.ResponsesRoute) - opencode_go_wire.route("claude-haiku-5-5") - |> should.equal(opencode_go_wire.MessagesRoute) - opencode_go_wire.route("minimax-m2.7") - |> should.equal(opencode_go_wire.MessagesRoute) - opencode_go_wire.route("gemini-4-argon-contributor") - |> should.equal(opencode_go_wire.GeminiRoute) - - let client = - opencode_go_wire.client( - "https://opencode.ai/zen/go/v1", - "test-token", - "sess-1", - "org-1", - ) - let req = - types.Request( - "gemini-4-argon-contributor", - Some("be brief"), - [types.User("hi")], - [], - Some(256), - types.Options(..types.defaults, effort: Some(types.Low)), - ) - let assert Ok(gem_ex) = - opencode_go_wire.encode_gemini( - client.connection, - opencode_go_wire.headers(client), - req, - ) - gem_ex.url - |> should.equal( - "https://opencode.ai/inference/go/v1/models/gemini-4-argon-contributor:streamGenerateContent?alt=sse", - ) - gem_ex.headers - |> list.contains(#("x-opencode-org-id", "org-1")) - |> should.be_true - - let reducer = gemini_stream.reducer() - let assert Ok(#(reducer, _, None)) = - reducer.feed( - "{\"candidates\":[{\"content\":{\"role\":\"model\",\"parts\":[{\"text\":\"pong\"}]},\"finishReason\":\"STOP\"}],\"usageMetadata\":{\"promptTokenCount\":4,\"candidatesTokenCount\":1}}", - ) - let assert Ok(turn) = reducer.finish() - let assert [replay_item] = turn.output - types.replay_protocol(replay_item) |> should.equal(types.ChatCompletions) - - // Replay that portable item into a Responses-routed model and a Messages-routed model. - let follow_up = - types.Request( - "gpt-5.6-luna", - None, - [types.User("hi"), types.Replay(replay_item), types.User("again")], - [], - Some(128), - types.defaults, - ) - let assert Ok(resp_ex) = - gateway.encode_responses( - client.connection, - opencode_go_wire.headers(client), - follow_up, - ) - resp_ex.url - |> should.equal("https://opencode.ai/inference/go/v1/responses") - - let msg_req = types.Request(..follow_up, model: "claude-haiku-5-5") - let assert Ok(msg_ex) = - opencode_go_wire.encode_messages( - client.connection, - opencode_go_wire.headers(client), - msg_req, - ) - msg_ex.url - |> should.equal("https://opencode.ai/inference/go/v1/messages") -} - /// Google's body for a suspended account, from oh-my-pi issue 18341. const suspension = "{\"error\":{\"code\":403,\"message\":\"This service has been disabled in this account for violation of Terms of Service. Please submit an appeal to continue using this product.\",\"status\":\"PERMISSION_DENIED\",\"details\":[{\"@type\":\"type.googleapis.com/google.rpc.ErrorInfo\",\"reason\":\"TOS_VIOLATION\",\"domain\":\"cloudcode-pa.googleapis.com\",\"metadata\":{\"uiMessage\":\"true\",\"appeal_url\":\"https://forms.gle/hGzM9MEUv2azZsrb9\",\"appeal_url_link_text\":\"Submit Appeal\"}}]}}" @@ -988,16 +866,6 @@ pub fn account_order_keeps_selected_limited_and_tied_deadlines_distinct_test() - accounts.order([], "session", None, 100) |> should.equal([]) } -pub fn account_spreading_preserves_fnv1a_byte_hash_test() -> Nil { - let entries = - list.map([0, 1, 2, 3, 4, 5, 6], fn(value) { - accounts.Entry(value, int.to_string(value), False, 0) - }) - // FNV-1a over these bytes is 0x4F9F2CAB, including 32-bit overflow. - accounts.order(entries, "hello", None, 0) - |> should.equal([2, 3, 4, 5, 6, 0, 1]) -} - fn native_order( scope: String, values: List(Dict(String, Dynamic)), diff --git a/apps/albedo/test/albedo/session/child_failure_test.gleam b/apps/albedo/test/albedo/session/child_failure_test.gleam index 1be4a9ed5..85caec004 100644 --- a/apps/albedo/test/albedo/session/child_failure_test.gleam +++ b/apps/albedo/test/albedo/session/child_failure_test.gleam @@ -51,17 +51,6 @@ pub fn refusals_read_as_their_reason_test() -> Nil { |> should.equal(mail_value.ProviderUnavailable) } -pub fn a_rate_limit_reads_plainly_test() -> Nil { - child_failure.format(mail_value.RateLimited, None) - |> should.equal( - "agent stopped due to rate limit (its provider does not have enough usage room right now).", - ) - child_failure.format(mail_value.QuotaSpent, None) - |> should.equal( - "agent stopped because its provider's quota does not have enough usage left.", - ) -} - pub fn an_unknown_error_is_one_short_line_test() -> Nil { child_failure.reason(loop.RunFailed("context window\nis full")) |> should.equal(mail_value.Errored("context window is full")) @@ -74,9 +63,11 @@ pub fn an_unknown_error_is_one_short_line_test() -> Nil { } pub fn last_words_follow_the_reason_test() -> Nil { - child_failure.format(mail_value.RateLimited, Some("half way through")) - |> string.contains("\n\nLast message before stopping:\nhalf way through") - |> should.be_true + let reason = child_failure.format(mail_value.RateLimited, None) + let with_words = + child_failure.format(mail_value.RateLimited, Some("half way through")) + string.starts_with(with_words, reason) |> should.be_true + string.ends_with(with_words, "half way through") |> should.be_true } fn letter( diff --git a/apps/albedo/test/albedo/session/configuration_test.gleam b/apps/albedo/test/albedo/session/configuration_test.gleam index ccca5afd0..b973a1e33 100644 --- a/apps/albedo/test/albedo/session/configuration_test.gleam +++ b/apps/albedo/test/albedo/session/configuration_test.gleam @@ -1,7 +1,6 @@ //// Bedrock API selection is extension-owned. Replay keeps chat_completions. //// Saved profiles preserve omitted Messages mode and explicit API selection. -import albedo/settings/projection import albedo/settings/settings import albedo_env import albedo_model as types @@ -43,57 +42,6 @@ pub fn bedrock_default_api_stays_omitted_test() -> Nil { decode.run(model, decode.string) |> should.equal(Ok("amazon.nova-pro-v1:0")) } -pub fn bedrock_explicit_apis_survive_normalization_test() -> Nil { - check_mode("messages") - check_mode("converse") -} - -fn check_mode(api: String) -> Nil { - let raw = - profile([ - #("api", dynamic.string(api)), - #( - "accountIds", - dynamic.list([dynamic.string("first"), dynamic.string("second")]), - ), - ]) - let assert Ok(saved) = configuration.validate_profile("bedrock", raw) - saved.api |> should.equal(Some(api)) - saved.account_id |> should.equal(None) - saved.account_ids |> should.equal(Some(["first", "second"])) - saved.protocol |> should.equal(types.ChatCompletions) - let assert Ok(normalized) = configuration.normalize_profile("bedrock", raw) - let assert Ok(value) = dict.get(normalized, "api") - decode.run(value, decode.string) |> should.equal(Ok(api)) - let assert Ok(ids) = dict.get(normalized, "accountIds") - decode.run(ids, decode.list(decode.string)) - |> should.equal(Ok(["first", "second"])) - let assert Ok(protocol) = dict.get(normalized, "protocol") - decode.run(protocol, decode.string) |> should.equal(Ok("chat_completions")) -} - -pub fn unknown_bedrock_apis_are_invalid_test() -> Nil { - reject_mode(dynamic.string("")) - reject_mode(dynamic.string("converse_stream")) - reject_mode(dynamic.string("Converse")) - reject_mode(dynamic.string(" converse")) - reject_mode(dynamic.string("converse ")) - reject_mode(dynamic.string("responses")) - reject_mode(dynamic.int(1)) - reject_mode(dynamic.bool(True)) - reject_mode(null()) -} - -fn reject_mode(api: Dynamic) -> Nil { - let raw = profile([#("api", api)]) - configuration.validate_profile("bedrock", raw) - |> result.is_error - |> should.be_true - configuration.normalize_profile("bedrock", raw) - |> result.is_error - |> should.be_true -} - pub fn saved_config_validation_rejects_unknown_bedrock_api_test() -> Nil { let named = dynamic.properties([ @@ -113,40 +61,6 @@ pub fn saved_config_validation_rejects_unknown_bedrock_api_test() -> Nil { |> should.be_true } -pub fn bedrock_api_survives_http_projection_test() -> Nil { - let saved = profile([#("api", dynamic.string("converse"))]) - let config = - dynamic.properties([ - #(dynamic.string("active"), dynamic.string("bedrock")), - #( - dynamic.string("providers"), - dynamic.properties([ - #(dynamic.string("bedrock"), saved), - ]), - ), - ]) - let empty = dynamic.properties([]) - let documents = - dict.from_list([ - #("config.json", config), - #("creds.json", empty), - #("extensions.json", empty), - #("capabilities.json", empty), - #("picker.json", empty), - ]) - let assert Ok(projected) = projection.groups(documents, []) - decode.run( - projected, - decode.at(["providers", "profiles", "bedrock", "api"], decode.string), - ) - |> should.equal(Ok("converse")) - decode.run( - projected, - decode.at(["providers", "profiles", "bedrock", "protocol"], decode.string), - ) - |> should.equal(Ok("chat_completions")) -} - /// Direct settings publisher checks use a disposable home, with no daemon or /// listener. Failed validation and stale ETags cannot change its documents. pub fn http_profile_patch_roundtrip_and_cas_test() -> Nil {