okami.mom/albedo

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

nekomimi.petapi: zstd responses, streams and request bodies; images served as raw bytes; drop redundant re-encodes7fd8cf5

main
1.1 KiB31 linesraw
1//// Encoded byte boundaries and the first excluded item must stop traversal.
2//// E2E cannot observe redundant encoder calls or force catalog item boundaries.
3
4import albedo/daemon/http_api as api
5import gleam/json
6import gleam/string
7
8pub fn bounded_items_retain_the_measured_prefix_test() -> Nil {
9  let kept =
10    api.bounded_items([1, 2, 3], 1, 0, fn(item) {
11      case item {
12        3 -> panic as "encoding continued after the first excluded item"
13        _ -> json.int(item)
14      }
15    })
16  let assert [#(1, encoded)] = kept
17  let assert "1" = json.to_string(encoded)
18  let assert [] = api.bounded_items([1], 1, 1, json.int)
19  let assert [#(1, _)] = api.bounded_items([1], 2, 1, json.int)
20  Nil
21}
22
23pub fn catalog_limits_include_separator_bytes_test() -> Nil {
24  let assert Ok([]) = api.bounded_catalog([json.int(1)], 1)
25  let assert Ok([_]) = api.bounded_catalog([json.int(1)], 2)
26  let oversized = json.string(string.repeat("x", 65_535))
27  let assert Error(api.Failure(503, "catalog_item_unavailable", _)) =
28    api.bounded_catalog([oversized], 100_000)
29  let assert Ok([]) = api.bounded_catalog([], 0)
30  Nil
31}