From 2cfde0342c00f220773a07792e041f4b9d2347b7 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Sat, 22 Aug 2026 19:36:04 +0100 Subject: [PATCH] feat(meta): TMDB search and movie lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Search and detail lookup, carrying the two fields the policy engine needs and that are easy to lose at the edge. `original_language` arrives as bare ISO 639-1, which has one code for both Portuguese variants, so the dub rule in §5.2 cannot be expressed against it alone. `Movie` therefore also carries `origin_countries`, from `origin_country` where TMDB has it and `production_countries` otherwise, which is what separates a Brazilian film from a Portuguese one. Digital release dates come back appended to the detail call rather than costing a second round trip, reduced to the earliest type-4 entry across every country: a release existing in one region is a release that exists on the indexers. `Movie::is_digitally_released` puts the §6.2 gate in one tested place. Responses are cached in process for a day, matching the metadata refresh tick. Failures are never cached, so an outage cannot pin a title into a bad state until tomorrow. Tests are wiremock-backed, per §12. --- Cargo.lock | 1659 +++++++++++++++++ crates/arr-meta/Cargo.toml | 10 + crates/arr-meta/src/cache.rs | 62 + crates/arr-meta/src/client.rs | 246 +++ crates/arr-meta/src/error.rs | 56 + crates/arr-meta/src/lib.rs | 27 +- crates/arr-meta/src/model.rs | 257 +++ .../tests/fixtures/movie_cidade_de_deus.json | 51 + .../arr-meta/tests/fixtures/movie_dune.json | 83 + .../tests/fixtures/movie_future_digital.json | 51 + .../tests/fixtures/movie_theatrical_only.json | 43 + .../tests/fixtures/movie_unreleased.json | 27 + .../arr-meta/tests/fixtures/search_dune.json | 39 + crates/arr-meta/tests/tmdb.rs | 400 ++++ 14 files changed, 3010 insertions(+), 1 deletion(-) create mode 100644 crates/arr-meta/src/cache.rs create mode 100644 crates/arr-meta/src/client.rs create mode 100644 crates/arr-meta/src/error.rs create mode 100644 crates/arr-meta/src/model.rs create mode 100644 crates/arr-meta/tests/fixtures/movie_cidade_de_deus.json create mode 100644 crates/arr-meta/tests/fixtures/movie_dune.json create mode 100644 crates/arr-meta/tests/fixtures/movie_future_digital.json create mode 100644 crates/arr-meta/tests/fixtures/movie_theatrical_only.json create mode 100644 crates/arr-meta/tests/fixtures/movie_unreleased.json create mode 100644 crates/arr-meta/tests/fixtures/search_dune.json create mode 100644 crates/arr-meta/tests/tmdb.rs diff --git a/Cargo.lock b/Cargo.lock index 5452d24..318bbf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,24 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + [[package]] name = "arr-api" version = "0.1.0" @@ -37,6 +55,16 @@ version = "0.1.0" [[package]] name = "arr-meta" version = "0.1.0" +dependencies = [ + "chrono", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "wiremock", +] [[package]] name = "arr-parse" @@ -45,3 +73,1634 @@ version = "0.1.0" [[package]] name = "arr-probe" version = "0.1.0" + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad534f4357a5264cce5019c989cf66a4f0dc4e0d1b1d15f8aacec0ff7360273" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "deadpool" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0be2b1d1d6ec8d846f05e137292d0b89133caf95ef33695424c09568bdd39b1b" +dependencies = [ + "deadpool-runtime", + "lazy_static", + "num_cpus", + "tokio", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "rand_core", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "839c0e8a181239723652be9062bb56ca5bf5f64011f73b623f6f4fc59086a228" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22053281f852e11534f5198498373cbb59295120a20771d90f7ed1897490a72" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mio" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustls" +version = "0.23.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c435338968042f4f59a557f690a253676d47ce13ceb55d70100e7facf6620a30" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wiremock" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08db1edfb05d9b3c1542e521aea074442088292f00b5f28e435c714a98f85031" +dependencies = [ + "assert-json-diff", + "base64", + "deadpool", + "futures", + "http", + "http-body-util", + "hyper", + "hyper-util", + "log", + "once_cell", + "regex", + "serde", + "serde_json", + "tokio", + "url", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/crates/arr-meta/Cargo.toml b/crates/arr-meta/Cargo.toml index ef9c70f..d6e9525 100644 --- a/crates/arr-meta/Cargo.toml +++ b/crates/arr-meta/Cargo.toml @@ -7,6 +7,16 @@ repository.workspace = true publish = false [dependencies] +chrono.workspace = true +reqwest.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +tracing.workspace = true + +[dev-dependencies] +tokio.workspace = true +wiremock.workspace = true [lints] workspace = true diff --git a/crates/arr-meta/src/cache.rs b/crates/arr-meta/src/cache.rs new file mode 100644 index 0000000..25ce596 --- /dev/null +++ b/crates/arr-meta/src/cache.rs @@ -0,0 +1,62 @@ +//! A small time-to-live cache over raw response bodies. +//! +//! Keyed on a logical request key rather than the URL, so the API key never +//! becomes part of a cache key. Bodies are stored unparsed: parsing again on a +//! hit costs microseconds and keeps one cache serving every endpoint. + +use std::collections::HashMap; +use std::sync::Arc; +use std::sync::{Mutex, PoisonError}; +use std::time::{Duration, Instant}; + +#[derive(Debug)] +struct Entry { + stored_at: Instant, + body: Arc, +} + +#[derive(Debug)] +pub(crate) struct Cache { + ttl: Duration, + entries: Mutex>, +} + +impl Cache { + pub(crate) fn new(ttl: Duration) -> Self { + Self { + ttl, + entries: Mutex::new(HashMap::new()), + } + } + + /// The cached body for `key`, if one is present and still fresh. + pub(crate) fn get(&self, key: &str) -> Option> { + let mut entries = self.entries.lock().unwrap_or_else(PoisonError::into_inner); + let entry = entries.get(key)?; + if entry.stored_at.elapsed() < self.ttl { + return Some(Arc::clone(&entry.body)); + } + entries.remove(key); + None + } + + pub(crate) fn insert(&self, key: String, body: Arc) { + let mut entries = self.entries.lock().unwrap_or_else(PoisonError::into_inner); + entries.insert( + key, + Entry { + stored_at: Instant::now(), + body, + }, + ); + } + + /// Drop everything. The daily metadata refresh does not need this — entries + /// expire on their own — but a forced refresh from the UI does. + pub(crate) fn clear(&self) { + self.entries + .lock() + .unwrap_or_else(PoisonError::into_inner) + .clear(); + } +} diff --git a/crates/arr-meta/src/client.rs b/crates/arr-meta/src/client.rs new file mode 100644 index 0000000..44f908b --- /dev/null +++ b/crates/arr-meta/src/client.rs @@ -0,0 +1,246 @@ +//! The TMDB HTTP client. + +use std::sync::Arc; +use std::time::Duration; + +use reqwest::{StatusCode, Url}; + +use crate::cache::Cache; +use crate::error::{Error, Result}; +use crate::model::{Movie, MovieSearchResult, RawMovie, RawSearchPage}; + +/// TMDB's v3 API root. +pub const DEFAULT_BASE_URL: &str = "https://api.themoviedb.org/3/"; + +/// One day. Metadata refresh is a daily tick (§8), not a per-request cost. +pub const DEFAULT_CACHE_TTL: Duration = Duration::from_hours(24); + +const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10); + +/// How much of an unexpected response body is worth keeping in an error. +const MAX_ERROR_BODY: usize = 512; + +/// A TMDB client with an in-process response cache. +/// +/// Deliberately not `Clone`: the cache lives inside it, so build one and share +/// it behind an `Arc` rather than handing out copies that each miss. +pub struct TmdbClient { + http: reqwest::Client, + base_url: Url, + api_key: String, + cache: Cache, +} + +/// Deliberately hand-written: a derived `Debug` would print the API key. +impl std::fmt::Debug for TmdbClient { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("TmdbClient") + .field("http", &self.http) + .field("base_url", &self.base_url.as_str()) + .field("api_key", &"") + .field("cache", &self.cache) + .finish() + } +} + +impl TmdbClient { + /// A client against the real TMDB with default timeouts and cache lifetime. + /// + /// # Errors + /// + /// Fails if the HTTP client cannot be constructed. + pub fn new(api_key: impl Into) -> Result { + Self::builder(api_key).build() + } + + /// Start configuring a client. + #[must_use] + pub fn builder(api_key: impl Into) -> TmdbClientBuilder { + TmdbClientBuilder { + api_key: api_key.into(), + base_url: DEFAULT_BASE_URL.to_owned(), + cache_ttl: DEFAULT_CACHE_TTL, + timeout: DEFAULT_TIMEOUT, + } + } + + /// Search TMDB for movies by title, optionally narrowed to a year. + /// + /// Returns the first page of results, which is what a search box shows. + /// + /// # Errors + /// + /// Any of [`Error`]; see its variants for what callers should distinguish. + pub async fn search_movies( + &self, + query: &str, + year: Option, + ) -> Result> { + let query = query.trim(); + let mut params = vec![ + ("query", query.to_owned()), + ("include_adult", "false".to_owned()), + ]; + if let Some(year) = year { + params.push(("year", year.to_string())); + } + + let key = match year { + Some(year) => format!("search/movie?query={query}&year={year}"), + None => format!("search/movie?query={query}"), + }; + + let body = self.get("search/movie", &key, ¶ms).await?; + let page: RawSearchPage = serde_json::from_str(&body)?; + Ok(page.results.into_iter().map(Into::into).collect()) + } + + /// Full detail for one movie, including the digital release date. + /// + /// One HTTP call: release dates come back appended to the same response + /// rather than costing a second round trip. + /// + /// # Errors + /// + /// [`Error::NotFound`] when TMDB has no such id, otherwise any of [`Error`]. + pub async fn movie(&self, tmdb_id: u32) -> Result { + let path = format!("movie/{tmdb_id}"); + let params = [("append_to_response", "release_dates".to_owned())]; + let body = self.get(&path, &path, ¶ms).await?; + let raw: RawMovie = serde_json::from_str(&body)?; + Ok(raw.into()) + } + + /// Drop every cached response. For a user-initiated "refresh metadata". + pub fn clear_cache(&self) { + self.cache.clear(); + } + + /// `cache_key` is separate from `path` so the API key never lands in a key + /// and so equivalent requests share an entry. + async fn get( + &self, + path: &str, + cache_key: &str, + params: &[(&str, String)], + ) -> Result> { + if let Some(hit) = self.cache.get(cache_key) { + tracing::trace!(cache_key, "TMDB cache hit"); + return Ok(hit); + } + + let mut url = self + .base_url + .join(path) + .map_err(|err| Error::BaseUrl(err.to_string()))?; + { + let mut pairs = url.query_pairs_mut(); + pairs.append_pair("api_key", &self.api_key); + for (name, value) in params { + pairs.append_pair(name, value); + } + } + + tracing::debug!(path, "TMDB request"); + let response = self.http.get(url).send().await?; + let status = response.status(); + + if status.is_success() { + let body: Arc = Arc::from(response.text().await?); + self.cache.insert(cache_key.to_owned(), Arc::clone(&body)); + return Ok(body); + } + + // Failures are never cached: a rate limit or an outage must not pin a + // title into a bad state for a day. + Err(match status { + StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Error::Unauthorized, + StatusCode::NOT_FOUND => Error::NotFound { + resource: cache_key.to_owned(), + }, + StatusCode::TOO_MANY_REQUESTS => Error::RateLimited { + retry_after: retry_after(&response), + }, + other => { + let body = response.text().await.unwrap_or_default(); + Error::Unexpected { + status: other.as_u16(), + body: body.chars().take(MAX_ERROR_BODY).collect(), + } + } + }) + } +} + +fn retry_after(response: &reqwest::Response) -> Option { + response + .headers() + .get(reqwest::header::RETRY_AFTER)? + .to_str() + .ok()? + .trim() + .parse::() + .ok() + .map(Duration::from_secs) +} + +/// Configuration for a [`TmdbClient`]. +#[derive(Debug, Clone)] +pub struct TmdbClientBuilder { + api_key: String, + base_url: String, + cache_ttl: Duration, + timeout: Duration, +} + +impl TmdbClientBuilder { + /// Point the client somewhere other than TMDB. Tests use this; nothing else + /// should. + #[must_use] + pub fn base_url(mut self, base_url: impl Into) -> Self { + self.base_url = base_url.into(); + self + } + + /// How long a cached response stays fresh. + #[must_use] + pub fn cache_ttl(mut self, cache_ttl: Duration) -> Self { + self.cache_ttl = cache_ttl; + self + } + + /// Per-request timeout. + #[must_use] + pub fn timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } + + /// Build the client. + /// + /// # Errors + /// + /// [`Error::BaseUrl`] if the base URL will not parse, [`Error::Transport`] + /// if the HTTP client cannot be built. + pub fn build(self) -> Result { + // Without a trailing slash `Url::join` replaces the last path segment + // instead of appending, which silently drops the `/3`. + let mut base_url = self.base_url; + if !base_url.ends_with('/') { + base_url.push('/'); + } + let base_url = Url::parse(&base_url).map_err(|err| Error::BaseUrl(err.to_string()))?; + + let http = reqwest::Client::builder() + .timeout(self.timeout) + .user_agent(concat!("arr/", env!("CARGO_PKG_VERSION"))) + .build()?; + + Ok(TmdbClient { + http, + base_url, + api_key: self.api_key, + cache: Cache::new(self.cache_ttl), + }) + } +} diff --git a/crates/arr-meta/src/error.rs b/crates/arr-meta/src/error.rs new file mode 100644 index 0000000..38716da --- /dev/null +++ b/crates/arr-meta/src/error.rs @@ -0,0 +1,56 @@ +//! Errors the TMDB client can produce. + +use std::time::Duration; + +/// Result alias for every fallible operation in this crate. +pub type Result = std::result::Result; + +/// Everything that can go wrong talking to TMDB. +/// +/// The distinction that matters to callers is between "this title does not +/// exist" ([`Error::NotFound`]), "back off" ([`Error::RateLimited`]) and +/// "TMDB is unreachable" ([`Error::Transport`]) — the last is a §9.5 *broken* +/// notification, the first two are not. +#[derive(Debug, thiserror::Error)] +#[non_exhaustive] +pub enum Error { + /// The request never completed: DNS, TLS, connection or timeout. + #[error("TMDB request failed")] + Transport(#[from] reqwest::Error), + + /// TMDB rejected the API key. + #[error("TMDB rejected the API key")] + Unauthorized, + + /// TMDB has no record of the thing that was asked for. + #[error("TMDB has no record of {resource}")] + NotFound { + /// The logical resource that was requested, e.g. `movie/693134`. + resource: String, + }, + + /// TMDB is rate limiting. `retry_after` is the `Retry-After` header when + /// TMDB sent one. + #[error("TMDB rate limit reached")] + RateLimited { + /// How long TMDB asked us to wait, when it said. + retry_after: Option, + }, + + /// Any other non-success status. + #[error("TMDB returned HTTP {status}")] + Unexpected { + /// The HTTP status code. + status: u16, + /// The response body, truncated to something loggable. + body: String, + }, + + /// The response parsed as JSON but not into the shape expected. + #[error("TMDB response did not match the expected shape")] + Decode(#[from] serde_json::Error), + + /// The configured base URL is not a URL. + #[error("invalid TMDB base URL: {0}")] + BaseUrl(String), +} diff --git a/crates/arr-meta/src/lib.rs b/crates/arr-meta/src/lib.rs index 551be62..aa218ff 100644 --- a/crates/arr-meta/src/lib.rs +++ b/crates/arr-meta/src/lib.rs @@ -1 +1,26 @@ -//! arr-meta — see DESIGN.md. +//! arr-meta — TMDB client. See `DESIGN.md` §5.2, §6.2 and §12. +//! +//! Two fields carry the weight here and neither is decoration: +//! +//! - `original_language` (plus the origin country that disambiguates `pt`) is +//! what the whole dub rule in §5.2 is expressed against. +//! - The digital release date gates targeted search (§6.2). A movie with no +//! digital release date must get zero searches. +//! +//! Responses are cached in process with a time-to-live, defaulting to a day, +//! because metadata refresh is a daily tick (§8) and not a per-request cost. + +// `unused_crate_dependencies` is a per-target lint and the library's own test +// target links the dev-dependencies without using them. The real uses are in +// `tests/`. +#[cfg(test)] +use {tokio as _, wiremock as _}; + +mod cache; +mod client; +mod error; +mod model; + +pub use client::{TmdbClient, TmdbClientBuilder, DEFAULT_BASE_URL, DEFAULT_CACHE_TTL}; +pub use error::{Error, Result}; +pub use model::{Movie, MovieSearchResult}; diff --git a/crates/arr-meta/src/model.rs b/crates/arr-meta/src/model.rs new file mode 100644 index 0000000..a1d8cd9 --- /dev/null +++ b/crates/arr-meta/src/model.rs @@ -0,0 +1,257 @@ +//! The slice of TMDB's schema this project actually reads. +//! +//! TMDB returns a great deal more than this. Everything kept here is either +//! shown to a person or fed to the policy engine; the rest is dropped at the +//! edge so nothing downstream has to know TMDB's field names. + +use chrono::{Datelike, NaiveDate}; +use serde::{Deserialize, Serialize}; + +/// TMDB's release-date type for a digital release. See §6.2 — this is the one +/// that gates targeted search. +const RELEASE_TYPE_DIGITAL: u8 = 4; + +/// One row of a TMDB search. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct MovieSearchResult { + /// TMDB's own id, the key everything else hangs off. + pub tmdb_id: u32, + /// Title in the requested language. + pub title: String, + /// Title in the original language. + pub original_title: String, + /// ISO 639-1, e.g. `en` or `pt`. See [`Movie::original_language`] for why + /// this alone is not enough for Portuguese. + pub original_language: String, + /// Primary (theatrical) release date. Absent for announced-but-undated + /// titles, where TMDB sends an empty string. + pub release_date: Option, + /// TMDB's synopsis, empty string normalised away. + pub overview: Option, + /// Path fragment, not a URL. TMDB's image base is a separate concern. + pub poster_path: Option, +} + +impl MovieSearchResult { + /// Release year, when TMDB has a release date at all. + #[must_use] + pub fn year(&self) -> Option { + self.release_date.map(|date| date.year()) + } +} + +/// A movie as TMDB describes it, reduced to what this project uses. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Movie { + /// TMDB's own id. + pub tmdb_id: u32, + /// `IMDb` id, when TMDB knows one. Torznab `t=movie` searches take it. + pub imdb_id: Option, + /// Title in the requested language. + pub title: String, + /// Title in the original language. + pub original_title: String, + /// ISO 639-1, e.g. `en` or `pt`. + /// + /// The dub rule in §5.2 compares a track's language against this. ISO + /// 639-1 has one code for both Portuguese variants, so `pt` on its own + /// cannot tell a Brazilian film from a Portuguese one — pair it with + /// [`Movie::origin_countries`] to resolve that. + pub original_language: String, + /// ISO 3166-1 alpha-2 country codes the title originates from. Needed to + /// read `pt` as pt-BR or pt-PT. + pub origin_countries: Vec, + /// Primary (theatrical) release date. + pub release_date: Option, + /// Earliest digital release date TMDB records, across every country. + /// + /// §6.2: a movie with no digital release date gets zero targeted searches. + /// Earliest-anywhere is the right reading of that — a release existing in + /// one region is a release that exists on the indexers. + pub digital_release: Option, + /// Runtime in minutes, when known. + pub runtime: Option, + /// TMDB's own status string: `Released`, `Post Production`, and so on. + pub status: String, + /// TMDB's synopsis, empty string normalised away. + pub overview: Option, + /// Path fragment, not a URL. + pub poster_path: Option, +} + +impl Movie { + /// Release year, when TMDB has a release date at all. + #[must_use] + pub fn year(&self) -> Option { + self.release_date.map(|date| date.year()) + } + + /// Whether a digital release exists as of `on`. + /// + /// This is the §6.2 gate in one place: no digital date at all, or a date + /// still in the future, means the release does not exist yet and searching + /// for it is a wasted query. + #[must_use] + pub fn is_digitally_released(&self, on: NaiveDate) -> bool { + self.digital_release.is_some_and(|date| date <= on) + } +} + +// --- TMDB wire types ------------------------------------------------------- +// +// Private on purpose. TMDB's field names stop here. + +#[derive(Debug, Deserialize)] +pub(crate) struct RawSearchPage { + #[serde(default)] + pub(crate) results: Vec, +} + +#[derive(Debug, Deserialize)] +pub(crate) struct RawSearchResult { + id: u32, + #[serde(default)] + title: String, + #[serde(default)] + original_title: String, + #[serde(default)] + original_language: String, + #[serde(default)] + release_date: Option, + #[serde(default)] + overview: Option, + #[serde(default)] + poster_path: Option, +} + +impl From for MovieSearchResult { + fn from(raw: RawSearchResult) -> Self { + Self { + tmdb_id: raw.id, + title: raw.title, + original_title: raw.original_title, + original_language: raw.original_language, + release_date: raw.release_date.as_deref().and_then(parse_date), + overview: non_empty(raw.overview), + poster_path: non_empty(raw.poster_path), + } + } +} + +#[derive(Debug, Deserialize)] +pub(crate) struct RawMovie { + id: u32, + #[serde(default)] + imdb_id: Option, + #[serde(default)] + title: String, + #[serde(default)] + original_title: String, + #[serde(default)] + original_language: String, + #[serde(default)] + origin_country: Vec, + #[serde(default)] + production_countries: Vec, + #[serde(default)] + release_date: Option, + #[serde(default)] + runtime: Option, + #[serde(default)] + status: String, + #[serde(default)] + overview: Option, + #[serde(default)] + poster_path: Option, + #[serde(default)] + release_dates: Option, +} + +#[derive(Debug, Deserialize)] +struct RawProductionCountry { + iso_3166_1: String, +} + +#[derive(Debug, Deserialize)] +struct RawReleaseDates { + #[serde(default)] + results: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawCountryReleaseDates { + #[serde(default)] + release_dates: Vec, +} + +#[derive(Debug, Deserialize)] +struct RawReleaseDate { + #[serde(rename = "type")] + kind: u8, + #[serde(default)] + release_date: Option, +} + +impl From for Movie { + fn from(raw: RawMovie) -> Self { + let digital_release = raw + .release_dates + .as_ref() + .and_then(|dates| earliest_digital(&dates.results)); + + // `origin_country` is the newer field and the more precise one; + // `production_countries` is the fallback for records that predate it. + let origin_countries = if raw.origin_country.is_empty() { + raw.production_countries + .into_iter() + .map(|country| country.iso_3166_1) + .collect() + } else { + raw.origin_country + }; + + Self { + tmdb_id: raw.id, + imdb_id: non_empty(raw.imdb_id), + title: raw.title, + original_title: raw.original_title, + original_language: raw.original_language, + origin_countries, + release_date: raw.release_date.as_deref().and_then(parse_date), + digital_release, + runtime: raw.runtime, + status: raw.status, + overview: non_empty(raw.overview), + poster_path: non_empty(raw.poster_path), + } + } +} + +fn earliest_digital(countries: &[RawCountryReleaseDates]) -> Option { + countries + .iter() + .flat_map(|country| country.release_dates.iter()) + .filter(|entry| entry.kind == RELEASE_TYPE_DIGITAL) + .filter_map(|entry| entry.release_date.as_deref().and_then(parse_datetime)) + .min() +} + +/// TMDB sends `""` rather than `null` for a date it does not have. +fn parse_date(raw: &str) -> Option { + NaiveDate::parse_from_str(raw, "%Y-%m-%d").ok() +} + +/// Release-date entries are timestamps: `2024-04-16T00:00:00.000Z`. The clock +/// part is meaningless — TMDB stamps a local date as UTC midnight — so only +/// the date survives. +fn parse_datetime(raw: &str) -> Option { + chrono::DateTime::parse_from_rfc3339(raw) + .ok() + .map(|stamp| stamp.date_naive()) + .or_else(|| parse_date(raw)) +} + +/// TMDB uses `""` where `null` is meant, in most string fields. +fn non_empty(value: Option) -> Option { + value.filter(|text| !text.is_empty()) +} diff --git a/crates/arr-meta/tests/fixtures/movie_cidade_de_deus.json b/crates/arr-meta/tests/fixtures/movie_cidade_de_deus.json new file mode 100644 index 0000000..f24f58d --- /dev/null +++ b/crates/arr-meta/tests/fixtures/movie_cidade_de_deus.json @@ -0,0 +1,51 @@ +{ + "adult": false, + "backdrop_path": "/pdtzEreKvKAlqa2YEBaGwiA45V8.jpg", + "budget": 3300000, + "genres": [{ "id": 18, "name": "Drama" }, { "id": 80, "name": "Crime" }], + "homepage": "", + "id": 598, + "imdb_id": "tt0317248", + "origin_country": ["BR"], + "original_language": "pt", + "original_title": "Cidade de Deus", + "overview": "In the slums of Rio, two kids' paths diverge as one struggles to become a photographer and the other a kingpin.", + "popularity": 38.9, + "poster_path": "/k7eYdWvhYQyRQoU2TB2A2Xu2TfD.jpg", + "production_countries": [{ "iso_3166_1": "BR", "name": "Brazil" }], + "release_date": "2002-02-05", + "revenue": 30641770, + "runtime": 130, + "spoken_languages": [{ "english_name": "Portuguese", "iso_639_1": "pt", "name": "Português" }], + "status": "Released", + "tagline": "If you run you're dead. If you stay, you're dead again. Period.", + "title": "City of God", + "video": false, + "vote_average": 8.4, + "vote_count": 8123, + "release_dates": { + "results": [ + { + "iso_3166_1": "BR", + "release_dates": [ + { + "certification": "18", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2002-08-30T00:00:00.000Z", + "type": 3 + }, + { + "certification": "", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2016-05-10T00:00:00.000Z", + "type": 4 + } + ] + } + ] + } +} diff --git a/crates/arr-meta/tests/fixtures/movie_dune.json b/crates/arr-meta/tests/fixtures/movie_dune.json new file mode 100644 index 0000000..2d98628 --- /dev/null +++ b/crates/arr-meta/tests/fixtures/movie_dune.json @@ -0,0 +1,83 @@ +{ + "adult": false, + "backdrop_path": "/xOMo8BRK7PfcJv9JCnx7s5hj0PX.jpg", + "budget": 190000000, + "genres": [{ "id": 878, "name": "Science Fiction" }, { "id": 12, "name": "Adventure" }], + "homepage": "https://www.dunemovie.com", + "id": 693134, + "imdb_id": "tt15239678", + "origin_country": ["US"], + "original_language": "en", + "original_title": "Dune: Part Two", + "overview": "Follow the mythic journey of Paul Atreides as he unites with Chani and the Fremen while on a path of revenge against the conspirators who destroyed his family.", + "popularity": 234.53, + "poster_path": "/1pdfLvkbY9ohJlCjQH2CZjjYVvJ.jpg", + "production_countries": [ + { "iso_3166_1": "US", "name": "United States of America" }, + { "iso_3166_1": "CA", "name": "Canada" } + ], + "release_date": "2024-02-27", + "revenue": 711844358, + "runtime": 167, + "spoken_languages": [{ "english_name": "English", "iso_639_1": "en", "name": "English" }], + "status": "Released", + "tagline": "Long live the fighters.", + "title": "Dune: Part Two", + "video": false, + "vote_average": 8.157, + "vote_count": 6104, + "release_dates": { + "results": [ + { + "iso_3166_1": "US", + "release_dates": [ + { + "certification": "PG-13", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2024-03-01T00:00:00.000Z", + "type": 3 + }, + { + "certification": "", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2024-04-16T00:00:00.000Z", + "type": 4 + }, + { + "certification": "PG-13", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2024-05-14T00:00:00.000Z", + "type": 5 + } + ] + }, + { + "iso_3166_1": "PT", + "release_dates": [ + { + "certification": "M/12", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2024-02-28T00:00:00.000Z", + "type": 3 + }, + { + "certification": "", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2024-04-10T00:00:00.000Z", + "type": 4 + } + ] + } + ] + } +} diff --git a/crates/arr-meta/tests/fixtures/movie_future_digital.json b/crates/arr-meta/tests/fixtures/movie_future_digital.json new file mode 100644 index 0000000..f7a4225 --- /dev/null +++ b/crates/arr-meta/tests/fixtures/movie_future_digital.json @@ -0,0 +1,51 @@ +{ + "adult": false, + "backdrop_path": null, + "budget": 0, + "genres": [{ "id": 28, "name": "Action" }], + "homepage": "", + "id": 1211073, + "imdb_id": "tt31852248", + "origin_country": ["GB"], + "original_language": "en", + "original_title": "Dated For Later", + "overview": "A film with an announced but not yet reached digital release date.", + "popularity": 88.0, + "poster_path": "/placeholder.jpg", + "production_countries": [{ "iso_3166_1": "GB", "name": "United Kingdom" }], + "release_date": "2026-07-10", + "revenue": 0, + "runtime": 110, + "spoken_languages": [{ "english_name": "English", "iso_639_1": "en", "name": "English" }], + "status": "Released", + "tagline": "", + "title": "Dated For Later", + "video": false, + "vote_average": 6.4, + "vote_count": 40, + "release_dates": { + "results": [ + { + "iso_3166_1": "GB", + "release_dates": [ + { + "certification": "15", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2026-07-10T00:00:00.000Z", + "type": 3 + }, + { + "certification": "", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2026-11-20T00:00:00.000Z", + "type": 4 + } + ] + } + ] + } +} diff --git a/crates/arr-meta/tests/fixtures/movie_theatrical_only.json b/crates/arr-meta/tests/fixtures/movie_theatrical_only.json new file mode 100644 index 0000000..583ae7a --- /dev/null +++ b/crates/arr-meta/tests/fixtures/movie_theatrical_only.json @@ -0,0 +1,43 @@ +{ + "adult": false, + "backdrop_path": null, + "budget": 0, + "genres": [{ "id": 18, "name": "Drama" }], + "homepage": "", + "id": 1022789, + "imdb_id": "tt27675327", + "origin_country": ["US"], + "original_language": "en", + "original_title": "Still In Cinemas", + "overview": "A film that has opened theatrically and has no digital release yet.", + "popularity": 120.4, + "poster_path": "/placeholder.jpg", + "production_countries": [{ "iso_3166_1": "US", "name": "United States of America" }], + "release_date": "2026-08-01", + "revenue": 0, + "runtime": 96, + "spoken_languages": [{ "english_name": "English", "iso_639_1": "en", "name": "English" }], + "status": "Released", + "tagline": "", + "title": "Still In Cinemas", + "video": false, + "vote_average": 7.1, + "vote_count": 210, + "release_dates": { + "results": [ + { + "iso_3166_1": "US", + "release_dates": [ + { + "certification": "PG", + "descriptors": [], + "iso_639_1": "", + "note": "", + "release_date": "2026-08-01T00:00:00.000Z", + "type": 3 + } + ] + } + ] + } +} diff --git a/crates/arr-meta/tests/fixtures/movie_unreleased.json b/crates/arr-meta/tests/fixtures/movie_unreleased.json new file mode 100644 index 0000000..c933a35 --- /dev/null +++ b/crates/arr-meta/tests/fixtures/movie_unreleased.json @@ -0,0 +1,27 @@ +{ + "adult": false, + "backdrop_path": null, + "budget": 0, + "genres": [{ "id": 878, "name": "Science Fiction" }], + "homepage": "", + "id": 1156593, + "imdb_id": "", + "origin_country": [], + "original_language": "en", + "original_title": "Dune: Part Three", + "overview": "", + "popularity": 41.2, + "poster_path": null, + "production_countries": [], + "release_date": "", + "revenue": 0, + "runtime": null, + "spoken_languages": [], + "status": "Post Production", + "tagline": "", + "title": "Dune: Part Three", + "video": false, + "vote_average": 0.0, + "vote_count": 0, + "release_dates": { "results": [] } +} diff --git a/crates/arr-meta/tests/fixtures/search_dune.json b/crates/arr-meta/tests/fixtures/search_dune.json new file mode 100644 index 0000000..51cf033 --- /dev/null +++ b/crates/arr-meta/tests/fixtures/search_dune.json @@ -0,0 +1,39 @@ +{ + "page": 1, + "results": [ + { + "adult": false, + "backdrop_path": "/xOMo8BRK7PfcJv9JCnx7s5hj0PX.jpg", + "genre_ids": [878, 12], + "id": 693134, + "original_language": "en", + "original_title": "Dune: Part Two", + "overview": "Follow the mythic journey of Paul Atreides as he unites with Chani and the Fremen while on a path of revenge against the conspirators who destroyed his family.", + "popularity": 234.53, + "poster_path": "/1pdfLvkbY9ohJlCjQH2CZjjYVvJ.jpg", + "release_date": "2024-02-27", + "title": "Dune: Part Two", + "video": false, + "vote_average": 8.157, + "vote_count": 6104 + }, + { + "adult": false, + "backdrop_path": null, + "genre_ids": [878], + "id": 1156593, + "original_language": "en", + "original_title": "Dune: Part Three", + "overview": "", + "popularity": 41.2, + "poster_path": null, + "release_date": "", + "title": "Dune: Part Three", + "video": false, + "vote_average": 0.0, + "vote_count": 0 + } + ], + "total_pages": 1, + "total_results": 2 +} diff --git a/crates/arr-meta/tests/tmdb.rs b/crates/arr-meta/tests/tmdb.rs new file mode 100644 index 0000000..fafb46b --- /dev/null +++ b/crates/arr-meta/tests/tmdb.rs @@ -0,0 +1,400 @@ +//! TMDB client tests. Everything runs against `wiremock` — DESIGN.md §12 rules +//! out live calls, which would rate-limit and leak a key into CI. + +// Same per-target quirk as in `lib.rs`: an integration test links the library's +// dependencies without using them directly. +use {reqwest as _, serde as _, serde_json as _, thiserror as _, tracing as _}; + +use std::time::Duration; + +use arr_meta::{Error, TmdbClient}; +use chrono::NaiveDate; +use wiremock::matchers::{header_exists, method, path, query_param}; +use wiremock::{Mock, MockServer, ResponseTemplate}; + +const SEARCH_DUNE: &str = include_str!("fixtures/search_dune.json"); +const MOVIE_DUNE: &str = include_str!("fixtures/movie_dune.json"); +const MOVIE_CIDADE_DE_DEUS: &str = include_str!("fixtures/movie_cidade_de_deus.json"); +const MOVIE_UNRELEASED: &str = include_str!("fixtures/movie_unreleased.json"); +const MOVIE_THEATRICAL_ONLY: &str = include_str!("fixtures/movie_theatrical_only.json"); +const MOVIE_FUTURE_DIGITAL: &str = include_str!("fixtures/movie_future_digital.json"); + +fn client(server: &MockServer) -> TmdbClient { + TmdbClient::builder("test-key") + .base_url(format!("{}/3", server.uri())) + .build() + .expect("client builds") +} + +fn date(year: i32, month: u32, day: u32) -> NaiveDate { + NaiveDate::from_ymd_opt(year, month, day).expect("valid date") +} + +async fn mount_movie(server: &MockServer, tmdb_id: u32, body: &str) { + Mock::given(method("GET")) + .and(path(format!("/3/movie/{tmdb_id}"))) + .respond_with(ResponseTemplate::new(200).set_body_string(body)) + .mount(server) + .await; +} + +#[tokio::test] +async fn search_parses_results_and_normalises_empty_strings() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/search/movie")) + .respond_with(ResponseTemplate::new(200).set_body_string(SEARCH_DUNE)) + .mount(&server) + .await; + + let results = client(&server) + .search_movies("dune", None) + .await + .expect("search succeeds"); + + assert_eq!(results.len(), 2); + + let released = &results[0]; + assert_eq!(released.tmdb_id, 693_134); + assert_eq!(released.title, "Dune: Part Two"); + assert_eq!(released.original_language, "en"); + assert_eq!(released.release_date, Some(date(2024, 2, 27))); + assert_eq!(released.year(), Some(2024)); + assert!(released.poster_path.is_some()); + + // TMDB sends "" rather than null for a date it does not have, and for an + // overview it does not have either. + let announced = &results[1]; + assert_eq!(announced.release_date, None); + assert_eq!(announced.year(), None); + assert_eq!(announced.overview, None); + assert_eq!(announced.poster_path, None); +} + +#[tokio::test] +async fn search_sends_the_query_year_and_api_key() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/search/movie")) + .and(query_param("query", "dune")) + .and(query_param("year", "2024")) + .and(query_param("api_key", "test-key")) + .and(query_param("include_adult", "false")) + .respond_with(ResponseTemplate::new(200).set_body_string(SEARCH_DUNE)) + .expect(1) + .mount(&server) + .await; + + client(&server) + .search_movies(" dune ", Some(2024)) + .await + .expect("search succeeds"); +} + +#[tokio::test] +async fn movie_detail_asks_for_release_dates_in_one_call() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .and(query_param("append_to_response", "release_dates")) + .and(header_exists("user-agent")) + .respond_with(ResponseTemplate::new(200).set_body_string(MOVIE_DUNE)) + .expect(1) + .mount(&server) + .await; + + client(&server) + .movie(693_134) + .await + .expect("lookup succeeds"); +} + +#[tokio::test] +async fn movie_detail_carries_the_policy_relevant_fields() { + let server = MockServer::start().await; + mount_movie(&server, 693_134, MOVIE_DUNE).await; + + let movie = client(&server) + .movie(693_134) + .await + .expect("lookup succeeds"); + + assert_eq!(movie.tmdb_id, 693_134); + assert_eq!(movie.imdb_id.as_deref(), Some("tt15239678")); + assert_eq!(movie.title, "Dune: Part Two"); + assert_eq!(movie.original_title, "Dune: Part Two"); + assert_eq!(movie.original_language, "en"); + assert_eq!(movie.origin_countries, vec!["US".to_owned()]); + assert_eq!(movie.release_date, Some(date(2024, 2, 27))); + assert_eq!(movie.runtime, Some(167)); + assert_eq!(movie.status, "Released"); + assert_eq!(movie.year(), Some(2024)); +} + +/// §5.2: a Brazilian film's own soundtrack must pass the pt-BR dub rule, which +/// only works if the origin country survives alongside the bare `pt` code. +#[tokio::test] +async fn brazilian_film_keeps_its_language_and_origin_country() { + let server = MockServer::start().await; + mount_movie(&server, 598, MOVIE_CIDADE_DE_DEUS).await; + + let movie = client(&server).movie(598).await.expect("lookup succeeds"); + + assert_eq!(movie.original_language, "pt"); + assert_eq!(movie.origin_countries, vec!["BR".to_owned()]); +} + +/// §6.2. Earliest digital date anywhere: the release existing in one region is +/// a release that exists on the indexers. +#[tokio::test] +async fn digital_release_is_the_earliest_across_every_country() { + let server = MockServer::start().await; + mount_movie(&server, 693_134, MOVIE_DUNE).await; + + let movie = client(&server) + .movie(693_134) + .await + .expect("lookup succeeds"); + + // US digital is 2024-04-16, PT digital is 2024-04-10. Theatrical (type 3) + // and physical (type 5) entries must not be mistaken for it. + assert_eq!(movie.digital_release, Some(date(2024, 4, 10))); + assert!(movie.is_digitally_released(date(2024, 4, 10))); + assert!(movie.is_digitally_released(date(2026, 1, 1))); + assert!(!movie.is_digitally_released(date(2024, 4, 9))); +} + +/// §6.2, the case that costs Radarr the most queries: no digital date means no +/// targeted search at all. +#[tokio::test] +async fn theatrical_only_movie_has_no_digital_release() { + let server = MockServer::start().await; + mount_movie(&server, 1_022_789, MOVIE_THEATRICAL_ONLY).await; + + let movie = client(&server) + .movie(1_022_789) + .await + .expect("lookup succeeds"); + + assert_eq!(movie.release_date, Some(date(2026, 8, 1))); + assert_eq!(movie.digital_release, None); + assert!(!movie.is_digitally_released(date(2026, 8, 22))); +} + +#[tokio::test] +async fn announced_digital_date_does_not_count_until_it_arrives() { + let server = MockServer::start().await; + mount_movie(&server, 1_211_073, MOVIE_FUTURE_DIGITAL).await; + + let movie = client(&server) + .movie(1_211_073) + .await + .expect("lookup succeeds"); + + assert_eq!(movie.digital_release, Some(date(2026, 11, 20))); + assert!(!movie.is_digitally_released(date(2026, 8, 22))); + assert!(movie.is_digitally_released(date(2026, 11, 20))); +} + +#[tokio::test] +async fn unreleased_movie_has_no_dates_and_no_imdb_id() { + let server = MockServer::start().await; + mount_movie(&server, 1_156_593, MOVIE_UNRELEASED).await; + + let movie = client(&server) + .movie(1_156_593) + .await + .expect("lookup succeeds"); + + assert_eq!(movie.release_date, None); + assert_eq!(movie.digital_release, None); + assert_eq!(movie.imdb_id, None); + assert_eq!(movie.runtime, None); + assert!(movie.origin_countries.is_empty()); + assert!(!movie.is_digitally_released(date(2026, 8, 22))); +} + +/// §8: metadata refresh is a daily tick, so repeated lookups within a day must +/// not become repeated requests. +#[tokio::test] +async fn responses_are_served_from_the_cache() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with(ResponseTemplate::new(200).set_body_string(MOVIE_DUNE)) + .expect(1) + .mount(&server) + .await; + + let client = client(&server); + let first = client.movie(693_134).await.expect("lookup succeeds"); + let second = client.movie(693_134).await.expect("cached lookup succeeds"); + + assert_eq!(first, second); +} + +#[tokio::test] +async fn cache_entries_expire_and_can_be_cleared() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with(ResponseTemplate::new(200).set_body_string(MOVIE_DUNE)) + .expect(3) + .mount(&server) + .await; + + let client = TmdbClient::builder("test-key") + .base_url(format!("{}/3", server.uri())) + .cache_ttl(Duration::from_millis(50)) + .build() + .expect("client builds"); + + client.movie(693_134).await.expect("lookup succeeds"); + tokio::time::sleep(Duration::from_millis(120)).await; + client.movie(693_134).await.expect("lookup succeeds"); + + client.clear_cache(); + client.movie(693_134).await.expect("lookup succeeds"); +} + +#[tokio::test] +async fn different_searches_do_not_share_a_cache_entry() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/search/movie")) + .respond_with(ResponseTemplate::new(200).set_body_string(SEARCH_DUNE)) + .expect(3) + .mount(&server) + .await; + + let client = client(&server); + client.search_movies("dune", None).await.expect("succeeds"); + client + .search_movies("dune", Some(2024)) + .await + .expect("succeeds"); + client.search_movies("bluey", None).await.expect("succeeds"); + // A repeat of the first is the cached one. + client.search_movies("dune", None).await.expect("succeeds"); +} + +#[tokio::test] +async fn unknown_id_is_not_found() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/1")) + .respond_with(ResponseTemplate::new(404).set_body_string( + r#"{"success":false,"status_code":34,"status_message":"The resource you requested could not be found."}"#, + )) + .mount(&server) + .await; + + let error = client(&server).movie(1).await.expect_err("404 is an error"); + + match error { + Error::NotFound { resource } => assert_eq!(resource, "movie/1"), + other => panic!("expected NotFound, got {other:?}"), + } +} + +#[tokio::test] +async fn rejected_key_is_unauthorized() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with(ResponseTemplate::new(401).set_body_string( + r#"{"success":false,"status_code":7,"status_message":"Invalid API key: You must be granted a valid key."}"#, + )) + .mount(&server) + .await; + + let error = client(&server) + .movie(693_134) + .await + .expect_err("401 is an error"); + + assert!(matches!(error, Error::Unauthorized), "got {error:?}"); +} + +#[tokio::test] +async fn rate_limit_surfaces_retry_after() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with( + ResponseTemplate::new(429) + .insert_header("retry-after", "13") + .set_body_string(r#"{"status_code":25,"status_message":"Your request count is over the allowed limit."}"#), + ) + .mount(&server) + .await; + + let error = client(&server) + .movie(693_134) + .await + .expect_err("429 is an error"); + + match error { + Error::RateLimited { retry_after } => { + assert_eq!(retry_after, Some(Duration::from_secs(13))); + } + other => panic!("expected RateLimited, got {other:?}"), + } +} + +/// A TMDB outage must not pin a title into a bad state for a whole day. +#[tokio::test] +async fn failures_are_not_cached() { + let server = MockServer::start().await; + let client = client(&server); + + { + let _failing = Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with(ResponseTemplate::new(500).set_body_string("upstream is down")) + .expect(1) + .mount_as_scoped(&server) + .await; + + let error = client.movie(693_134).await.expect_err("500 is an error"); + match error { + Error::Unexpected { status, body } => { + assert_eq!(status, 500); + assert_eq!(body, "upstream is down"); + } + other => panic!("expected Unexpected, got {other:?}"), + } + } + + Mock::given(method("GET")) + .and(path("/3/movie/693134")) + .respond_with(ResponseTemplate::new(200).set_body_string(MOVIE_DUNE)) + .expect(1) + .mount(&server) + .await; + + let movie = client.movie(693_134).await.expect("retry succeeds"); + assert_eq!(movie.tmdb_id, 693_134); +} + +#[tokio::test] +async fn malformed_json_is_a_decode_error() { + let server = MockServer::start().await; + mount_movie(&server, 693_134, "{ not json").await; + + let error = client(&server) + .movie(693_134) + .await + .expect_err("garbage is an error"); + + assert!(matches!(error, Error::Decode(_)), "got {error:?}"); +} + +#[tokio::test] +async fn debug_output_does_not_leak_the_api_key() { + let server = MockServer::start().await; + let rendered = format!("{:?}", client(&server)); + + assert!(!rendered.contains("test-key"), "{rendered}"); + assert!(rendered.contains("redacted"), "{rendered}"); +}