okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffix(antigravity): decode verification links before error truncatione6935de

main
3.0 KiB93 linesraw
1//// Verification errors need escaped and malformed provider envelopes that a
2//// model-turn E2E fixture cannot inject into the authenticated discovery flow.
3
4import albedo/harness/extensions/antigravity/errors
5import gleam/json
6import gleam/string
7import gleeunit/should
8
9fn body(details: List(json.Json)) -> String {
10  json.object([
11    #("error", json.object([#("details", json.array(details, fn(x) { x }))])),
12  ])
13  |> json.to_string
14}
15
16fn required(url: json.Json) -> json.Json {
17  json.object([
18    #("reason", json.string("VALIDATION_REQUIRED")),
19    #("metadata", json.object([#("validation_url", url)])),
20  ])
21}
22
23pub fn escaped_verification_url_is_decoded_before_display_test() -> Nil {
24  let response =
25    "{\"error\":{\"details\":[{\"reason\":\"VALIDATION_REQUIRED\",\"metadata\":{\"validation_url\":\"https:\\/\\/example.com\\/verify?q=\\\"yes\\\"\"}}]}}"
26  errors.verification_url(response)
27  |> should.equal(Ok("https://example.com/verify?q=\"yes\""))
28  discover(response)
29  |> should.equal(Error(
30    "Account verification required. Visit https://example.com/verify?q=\"yes\" to continue, then sign in again.",
31  ))
32}
33
34pub fn verification_links_beyond_display_limit_survive_test() -> Nil {
35  let response =
36    body([
37      json.object([#("reason", json.string(string.repeat("x", 3000)))]),
38      required(json.string("https://example.com/verify")),
39    ])
40  discover(response)
41  |> should.equal(Error(
42    "Account verification required. Visit https://example.com/verify to continue, then sign in again.",
43  ))
44}
45
46pub fn missing_empty_or_invalid_links_use_account_fallback_test() -> Nil {
47  let responses = [
48    body([json.object([#("reason", json.string("VALIDATION_REQUIRED"))])]),
49    body([required(json.string(""))]),
50    body([required(json.int(12))]),
51  ]
52  let assert [a, b, c] = responses
53  for_fallback(a)
54  for_fallback(b)
55  for_fallback(c)
56}
57
58fn for_fallback(response: String) -> Nil {
59  errors.verification_url(response) |> should.equal(Ok(""))
60  discover(response)
61  |> should.equal(Error(
62    "Account verification required. Visit https://accounts.google.com to continue, then sign in again.",
63  ))
64}
65
66pub fn later_usable_link_wins_over_missing_metadata_test() -> Nil {
67  errors.verification_url(
68    body([
69      json.int(1),
70      required(json.null()),
71      required(json.string("https://example.com/verify")),
72    ]),
73  )
74  |> should.equal(Ok("https://example.com/verify"))
75}
76
77pub fn malformed_and_unrelated_errors_keep_failure_format_test() -> Nil {
78  let malformed = "invalid VALIDATION_REQUIRED"
79  let unrelated = body([json.object([#("reason", json.string("OTHER"))])])
80  errors.verification_url(malformed) |> should.equal(Error(Nil))
81  errors.verification_url(unrelated) |> should.equal(Error(Nil))
82  discover(malformed)
83  |> should.equal(Error(
84    "/v1internal:loadCodeAssist failed (403): " <> malformed,
85  ))
86  discover(unrelated)
87  |> should.equal(Error(
88    "/v1internal:loadCodeAssist failed (403): " <> unrelated,
89  ))
90}
91
92@external(erlang, "albedo_antigravity_error_support", "discover")
93fn discover(body: String) -> Result(String, String)