an http based roguelike rpg about jelqing
Blame: src/tests.rs
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1 | use std::{ |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 2 | sync::Arc, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 3 | time::{Duration, Instant}, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 4 | }; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 5 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 6 | use axum::{ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 7 | Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 8 | body::{Body, to_bytes}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | http::{Method, Request, StatusCode, Version, header}, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 10 | response::Response, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 11 | }; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 12 | use serde_json::Value; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 13 | use tower::ServiceExt; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 14 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | use crate::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | AppState, Config, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 17 | game::{ |
139164489032 | atagen | 2026-10-11 05:46 UTC | 18 | Floor, MumVisit, Run, Story, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 19 | balance::{STORAGE_GIRTH, SUSPICION_LIMIT}, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 20 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | router, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 24 | async fn send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 25 | app: &Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 26 | method: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 27 | uri: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 28 | headers: &[(&str, &str)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 29 | body: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 30 | ) -> Response { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 31 | let mut request = Request::builder() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 32 | .method(Method::from_bytes(method.as_bytes()).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 33 | .uri(uri); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 34 | for (name, value) in headers { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 35 | request = request.header(*name, *value); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 36 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 37 | app.clone() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 38 | .oneshot(request.body(Body::from(body.to_owned())).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 39 | .await |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 40 | .unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 41 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 42 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 43 | async fn json(response: Response) -> Value { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 44 | serde_json::from_slice(&to_bytes(response.into_body(), usize::MAX).await.unwrap()).unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 45 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 46 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | async fn text(response: Response) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | String::from_utf8( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | to_bytes(response.into_body(), usize::MAX) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | .await |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | .to_vec(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | fn header<'a>(response: &'a Response, name: &str) -> &'a str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | response.headers()[name].to_str().unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | fn fixture() -> Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | Run::new("cafebabe".into(), "cafe".into(), 69) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | fn seeded_with(floor: Floor, setup: impl FnOnce(&mut Run)) -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | let mut run = fixture(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | setup(&mut run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | state.insert(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | router(state) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 74 | fn seeded(floor: Floor) -> (Router, String) { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 75 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | let mut run = fixture(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 77 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | let etag = run.origin_etag(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 79 | state.insert(run); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 80 | (router(state), etag) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 81 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 82 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | fn app() -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | crate::app(Config::default()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 87 | fn mum_at_the_door(run: &mut Run) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 88 | run.mum = Some(MumVisit { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | errand: "She heard a noise.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | nonce: "abc".into(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | strikes: 0, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 92 | knocked: false, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 96 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 97 | async fn creating_a_run_returns_location_and_etag() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | let response = send(&app(), "POST", "/runs?seed=1", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 99 | assert_eq!(response.status(), StatusCode::CREATED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | assert!(header(&response, "location").starts_with("/runs/")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 101 | assert!(response.headers().contains_key(header::ETAG)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | assert_eq!(header(&response, "server"), "jelqd/0.6.9"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | async fn bodies_do_not_repeat_the_headers() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | assert!(response.headers().contains_key("x-eq")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | let body = json(response).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | for stat in [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | "eq", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | "girth", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | "foreskin", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | "stamina", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | "cash", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | "self_reported_length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | ] { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | assert!(body.get(stat).is_none(), "{stat} is already a header"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 121 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 122 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 123 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 124 | async fn jelqing_cold_fails_the_precondition() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 125 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 126 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 127 | assert_eq!(response.status(), StatusCode::PRECONDITION_FAILED); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 128 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | header(&response, "content-type"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 130 | "application/problem+json" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 131 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 132 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 133 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 134 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 135 | async fn wet_without_lube_is_unsupported_media() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 136 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 137 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 138 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 139 | assert_eq!(response.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 140 | let images = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 141 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 142 | "JELQ", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 143 | "/runs/cafebabe?technique=wet", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 144 | &[("content-type", "image/jpeg")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 145 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 146 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 147 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 148 | assert_eq!(json(images).await["detail"], "No."); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 149 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 150 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 151 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 152 | async fn unknown_methods_are_not_implemented() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 153 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 154 | let response = send(&app, "MILK", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 155 | assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | let teapot = send(&app, "BREW", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | assert_eq!(teapot.status(), StatusCode::IM_A_TEAPOT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | async fn the_clinic_does_not_advertise_jelq() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | let (app, _) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | let options = send(&app, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | assert!(!header(&options, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | assert_eq!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | assert!(!header(&jelq, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | let (bedroom, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | let options = send(&bedroom, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | assert!(header(&options, "allow").contains("JELQ")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 171 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 172 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 173 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 174 | async fn patch_only_accepts_the_truth() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 175 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 176 | let patch = [("content-type", "application/json-patch+json")]; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 177 | let replace = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 178 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 179 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 180 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 181 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 182 | r#"[{"op":"replace","path":"/length","value":12}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 183 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 184 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 185 | assert_eq!(replace.status(), StatusCode::UNPROCESSABLE_ENTITY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 186 | let lie = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 187 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 188 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 189 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 190 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 191 | r#"[{"op":"test","path":"/length","value":40}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 192 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 193 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 194 | assert_eq!( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 195 | json(lie).await["type"], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 196 | "https://jelq.dev/problems/exaggeration" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 197 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 198 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 199 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 200 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 201 | async fn deleting_the_foreskin_requires_certainty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 202 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 203 | let response = send(&app, "DELETE", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 204 | assert_eq!(response.status(), StatusCode::PRECONDITION_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 205 | let look = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 206 | assert_eq!(look.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 207 | let etag = header(&look, "etag").to_owned(); |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 208 | assert!(text(look).await.contains('~')); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 209 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 210 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 211 | "DELETE", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 212 | "/runs/cafebabe/foreskin", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 213 | &[("if-match", &etag)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 214 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 215 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 216 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 217 | assert_eq!(response.status(), StatusCode::NO_CONTENT); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 218 | let response = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 219 | assert_eq!(response.status(), StatusCode::GONE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 220 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 221 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 222 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 223 | async fn length_is_chunked_until_the_ruler() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 224 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 225 | let lie = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 226 | assert!(!lie.headers().contains_key(header::CONTENT_LENGTH)); |
ad00e0e051a1 | atagen | 2026-10-10 14:00 UTC | 227 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 228 | let truth = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 229 | let declared: usize = header(&truth, "content-length").parse().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 230 | let body = text(truth).await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 231 | assert_eq!(body.len(), declared); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 232 | assert!(body.starts_with("8=") && body.ends_with('D')); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 233 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 235 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | async fn length_supports_inch_ranges() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 240 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 241 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 242 | &[("range", "inches=0-1")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 243 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 246 | assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 247 | assert!(header(&response, "content-range").starts_with("inches 0.00-1.00/")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | assert_eq!(text(response).await.len(), 25); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | let absurd = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 250 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 252 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 253 | &[("range", "inches=40-50")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 254 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 255 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 256 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 257 | assert_eq!(absurd.status(), StatusCode::RANGE_NOT_SATISFIABLE); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 258 | let malformed = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 259 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 260 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 261 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 262 | &[("range", "inches=6.17")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 263 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 264 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 265 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 266 | assert_eq!(malformed.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 267 | let suffix = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 268 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 269 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 270 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 271 | &[("range", "inches=-1")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 272 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 273 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 274 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 275 | assert_eq!(suffix.status(), StatusCode::PARTIAL_CONTENT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 276 | assert!(text(suffix).await.ends_with('D')); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 277 | for (range, status) in [ |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 278 | ("inches=1-", StatusCode::PARTIAL_CONTENT), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 279 | ("inches=40-", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 280 | ("inches=-0", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 281 | ("inches=2-1", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 282 | ("inches=NaN-2", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 283 | ("inches=0-inf", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 284 | ] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 285 | let response = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 286 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 287 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 288 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 289 | &[("range", range)], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 290 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 291 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 292 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 293 | assert_eq!(response.status(), status, "{range}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 294 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 295 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 296 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 297 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 298 | async fn the_clinic_escalates_toward_honesty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 299 | let (app, _) = seeded(Floor::Clinic); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 300 | let mut hints = Vec::new(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 301 | for _ in 0..3 { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 302 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 303 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 304 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 305 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 306 | &[("authorization", "Excuse \"changing\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 307 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 308 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 309 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 310 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 311 | hints.push(header(&response, "www-authenticate").to_owned()); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 312 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 313 | assert!(hints[2].contains("Be honest.")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 314 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 315 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 316 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 317 | async fn the_true_ending_is_not_modified() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | let (early, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 319 | let response = send(&early, "GET", "/runs/cafebabe/diagnosis", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 320 | assert_eq!(response.status(), StatusCode::TOO_EARLY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 321 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 322 | let (app, etag) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 323 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 324 | !etag.contains("cafebabe"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 325 | "the origin ETag must not be derivable from the id" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 326 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 327 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 328 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 329 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 330 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 331 | &[ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 332 | ("authorization", "Bearer honesty"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 333 | ("if-none-match", &etag), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 334 | ], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 335 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 336 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 337 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 338 | assert_eq!(response.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 339 | assert_eq!(header(&response, "x-diagnosis"), "normal"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 340 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 341 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 342 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 343 | async fn mum_accepts_a_known_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 344 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 345 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 346 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 347 | assert_eq!(header(&response, "via"), "1.1 mum"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 348 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 349 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 350 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 351 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 352 | &[("authorization", "Excuse \"homework\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 353 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 354 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 355 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 356 | assert_eq!(response.status(), StatusCode::OK); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 357 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 358 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 359 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 360 | async fn mum_runs_out_of_patience() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 361 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 362 | let lie = [("authorization", "Excuse \"it is for science\"")]; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 363 | for _ in 0..2 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 364 | let response = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 365 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 366 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 367 | let caught = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 368 | assert_eq!(caught.status(), StatusCode::GONE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 369 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 370 | json(caught).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 371 | "https://jelq.dev/problems/caught" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 372 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 373 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 374 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 375 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 376 | async fn mum_remembers_excuses_by_christmas() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 377 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 378 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 379 | run.heard.push("homework".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 380 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 381 | let basic = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 382 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 383 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 384 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 385 | &[("authorization", "Excuse \"changing\"")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 386 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 387 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 388 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 389 | assert_eq!(basic.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 390 | assert!(header(&basic, "www-authenticate").starts_with("Digest")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 391 | let replay = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 392 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 393 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 394 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 395 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 396 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 397 | "Digest username=\"homework\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 398 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 399 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 400 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 401 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 402 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 403 | json(replay).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 404 | "https://jelq.dev/problems/excuse-replayed" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 405 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 406 | let fresh = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 407 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 408 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 409 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 410 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 411 | "authorization", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 412 | "Digest username=\"wrapping presents\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 413 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 414 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 415 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 416 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 417 | assert_eq!(fresh.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 418 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 419 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 420 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 421 | async fn a_pulled_muscle_is_a_true_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 422 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 423 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 424 | run.conditions.pulled_muscle = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 425 | run.heard.push("pulled a muscle".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 426 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 427 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 428 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 429 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 430 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 431 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 432 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 433 | "Digest username=\"pulled a muscle\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 434 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 435 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 436 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 437 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 438 | assert_eq!(response.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 439 | assert!(header(&response, "x-stamina").ends_with("/7")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 440 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 441 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 442 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 443 | async fn floors_end_when_they_end() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 444 | let app = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 445 | let early = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 446 | assert_eq!(early.status(), StatusCode::TOO_EARLY); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 447 | let app = seeded_with(Floor::Bedroom, |run| run.here.turns = 6); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 448 | let next = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 449 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 450 | next.status() == StatusCode::SEE_OTHER || next.status() == StatusCode::CONFLICT, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 451 | "either the floor changed or the zip did" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 452 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 453 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 454 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 455 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 456 | async fn pump_bro_upsells() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 457 | let closed = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 458 | let response = send(&closed, "GET", "/runs/cafebabe/shop", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 459 | assert_eq!(response.status(), StatusCode::NOT_FOUND); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 460 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 461 | let app = seeded_with(Floor::ChangingRoom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 462 | let pump = send(&app, "POST", "/runs/cafebabe/shop/pump", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 463 | assert_eq!(pump.status(), StatusCode::UPGRADE_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 464 | assert_eq!(header(&pump, "upgrade"), "pump-pro/2.0"); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 465 | let pro = send(&app, "POST", "/runs/cafebabe/shop/pump-pro", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 466 | assert_eq!(pro.status(), StatusCode::CREATED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 467 | let broke = send(&app, "POST", "/runs/cafebabe/shop/extender", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 468 | assert_eq!(broke.status(), StatusCode::PAYMENT_REQUIRED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 469 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 470 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 471 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 472 | async fn only_the_key_opens_the_cage() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 473 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 474 | send(&app, "POST", "/runs/cafebabe/shop/ice-pack", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 475 | let still = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 476 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 477 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 478 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 479 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 480 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 481 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 482 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 483 | assert_eq!(still.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 484 | send(&app, "POST", "/runs/cafebabe/shop/cage-key", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 485 | let gone = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 486 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 487 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 488 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 489 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 490 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 491 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 492 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 493 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 494 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 495 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 496 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 497 | async fn combos_are_multi_status_xml() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 498 | let app = seeded_with(Floor::Bathroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 499 | run.foreskin = Some(1.0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 500 | run.items.blinds = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 501 | }); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 502 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 503 | let response = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 504 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 505 | "JELQ", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 506 | "/runs/cafebabe?technique=wet,stretch", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 507 | &[("content-type", "application/baby-oil")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 508 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 509 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 510 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 511 | assert_eq!(response.status(), StatusCode::MULTI_STATUS); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 512 | assert!(text(response).await.contains("<D:multistatus")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 513 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 514 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 515 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 516 | async fn the_elder_is_stale() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 517 | let app = seeded_with(Floor::Forum, |run| run.length = 5.0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 518 | let unverified = send(&app, "GET", "/runs/cafebabe/elder", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 519 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 520 | unverified.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 521 | StatusCode::PROXY_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 522 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 523 | let lie = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 524 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 525 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 526 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 527 | &[("proxy-authorization", "Ruler 9")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 528 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 529 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 530 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 531 | assert_eq!(lie.status(), StatusCode::BAD_REQUEST); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 532 | let csv = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 533 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 534 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 535 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 536 | &[("proxy-authorization", "Ruler 5.0")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 537 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 538 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 539 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 540 | assert_eq!(csv.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 541 | let stale = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 542 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 543 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 544 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 545 | &[("if-modified-since", "Mon, 15 Jun 2009 00:00:00 GMT")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 546 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 547 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 548 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 549 | assert_eq!(stale.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 550 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 551 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 552 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 553 | async fn the_displayed_length_is_accepted_as_honest() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 554 | let app = seeded_with(Floor::Forum, |run| run.length = 5.2496); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 555 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 556 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 557 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 558 | "/runs/cafebabe/elder", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 559 | &[("proxy-authorization", "Ruler 5.25")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 560 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 561 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 562 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 563 | assert_eq!(response.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 564 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 565 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 566 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 567 | async fn the_hotel_has_a_captive_portal() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 568 | let app = seeded_with(Floor::Hotel, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 569 | let blocked = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 570 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 571 | blocked.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 572 | StatusCode::NETWORK_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 573 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 574 | let accepted = send(&app, "POST", "/runs/cafebabe/portal", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 575 | assert_eq!(accepted.status(), StatusCode::SEE_OTHER); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 576 | let online = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 577 | assert_eq!(online.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 578 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 579 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 580 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 581 | async fn the_internet_never_forgets() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 582 | let app = seeded_with(Floor::Bedroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 583 | run.filmed_at = Some(std::time::SystemTime::now()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 584 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 585 | let footage = send(&app, "GET", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 586 | assert_eq!(footage.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 587 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 588 | header(&footage, "cache-control"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 589 | "public, max-age=31536000, immutable" |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 590 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 591 | assert!(footage.headers().contains_key(header::AGE)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 592 | let delete = send(&app, "DELETE", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 593 | assert_eq!(delete.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 594 | assert!(!header(&delete, "allow").contains("DELETE")); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 595 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 596 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 597 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 598 | async fn forged_ruler_cookies_are_lies() { |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 599 | let forged = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 600 | &app(), |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 601 | "GET", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 602 | "/leaderboard?sort=content-length", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 603 | &[("cookie", "ruler=1")], |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 604 | "", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 605 | ) |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 606 | .await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 607 | assert_eq!(forged.status(), StatusCode::BAD_REQUEST); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 608 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 609 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 610 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 611 | async fn listings_never_reveal_the_private_id() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 612 | let app = app(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 613 | let created = send(&app, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 614 | let location = header(&created, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 615 | let board = text(send(&app, "GET", "/leaderboard", &[], "").await).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 616 | let private = location.trim_start_matches("/runs/"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 617 | assert!(!board.contains(private)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 618 | let entry: Value = serde_json::from_str(&board).unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 619 | let public = entry["entries"][0]["public_id"].as_str().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 620 | let guess = send(&app, "DELETE", &format!("/runs/{public}"), &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 621 | assert_eq!(guess.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 622 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 623 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 624 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 625 | async fn seeded_runs_are_unranked() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 626 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 627 | send(&app, "POST", "/runs?seed=7", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 628 | let board = json(send(&app, "GET", "/leaderboard", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 629 | assert_eq!(board["entries"].as_array().unwrap().len(), 0); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 630 | let all = json(send(&app, "GET", "/leaderboard?seeded=include", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 631 | assert_eq!(all["entries"][0]["ranked"], false); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 632 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 633 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 634 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 635 | async fn idle_runs_are_evicted_and_the_server_has_a_limit() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 636 | let forgetful = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 637 | idle_ttl: Duration::ZERO, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 638 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 639 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 640 | let first = send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 641 | let location = header(&first, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 642 | send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 643 | let gone = send(&forgetful, "GET", &location, &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 644 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 645 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 646 | let tiny = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 647 | max_runs: 1, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 648 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 649 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 650 | send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 651 | let full = send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 652 | assert_eq!(full.status(), StatusCode::SERVICE_UNAVAILABLE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 653 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 654 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 655 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 656 | async fn shame_from_two_runs_adds_up() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 657 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 658 | state.insert(fixture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 659 | state.insert(Run::new("deadbeef".into(), "dead".into(), 7)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 660 | let app = router(state); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 661 | let first = send(&app, "TRACE", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 662 | assert_eq!(header(&first, "x-shame"), "1"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 663 | let cookie = header(&first, "set-cookie") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 664 | .split(';') |
782069860236 | atagen | 2026-10-10 12:44 UTC | 665 | .next() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 666 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 667 | .to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 668 | let second = send(&app, "TRACE", "/runs/deadbeef", &[("cookie", &cookie)], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 669 | assert_eq!(header(&second, "x-shame"), "2"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 670 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 671 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 672 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 673 | async fn the_root_negotiates() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 674 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 675 | let browser = send(&app, "GET", "/", &[("accept", "text/html,*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 676 | assert_eq!(browser.status(), StatusCode::SEE_OTHER); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 677 | assert_eq!(header(&browser, "location"), "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 678 | let curl = send(&app, "GET", "/", &[("accept", "*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 679 | assert_eq!(json(curl).await["ui"], "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 680 | let page = send(&app, "GET", "/ui/", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 681 | assert_eq!(page.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 682 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 683 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 684 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 685 | async fn the_ui_replays_what_browsers_cannot_send() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 686 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 687 | let envelope = |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 688 | r#"{"method": "TRACE", "path": "/graveyard", "headers": [["X-Confession", "I did it"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 689 | let traced = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 690 | assert_eq!(traced["status"], 405); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 691 | let envelope = r#"{"method": "GET", "path": "/", "headers": [["Accept", "text/html"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 692 | let redirected = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 693 | assert_eq!(redirected["status"], 303); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 694 | assert_eq!(redirected["reason"], "See Other"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 695 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 696 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 697 | #[tokio::test] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 698 | async fn the_ui_decodes_gzip_for_display() { |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 699 | let app = seeded_with(Floor::Bedroom, |run| run.items.ring = true); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 700 | let envelope = |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 701 | r#"{"method": "GET", "path": "/runs/cafebabe", "headers": [["Accept-Encoding", "gzip"]]}"#; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 702 | let shown = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 703 | assert!( |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 704 | shown["body"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 705 | .as_str() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 706 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 707 | .contains("\"public_id\":\"cafe\"") |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 708 | ); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 709 | let encoding = shown["headers"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 710 | .as_array() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 711 | .unwrap() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 712 | .iter() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 713 | .any(|h| h[0] == "content-encoding" && h[1] == "gzip"); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 714 | assert!(encoding); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 715 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 716 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 717 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 718 | async fn http_1_0_gets_the_pdf_treatment() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 719 | let request = Request::builder() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 720 | .uri("/graveyard") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 721 | .version(Version::HTTP_10) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 722 | .body(Body::empty()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 723 | .unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 724 | let response = app().oneshot(request).await.unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 725 | assert_eq!(response.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 726 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 727 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 728 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 729 | async fn mom_speaks_american() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 730 | let app = seeded_with(Floor::Nans, mum_at_the_door); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 731 | let us = [("accept-language", "en-US")]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 732 | let knock = send(&app, "GET", "/runs/cafebabe", &us, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 733 | assert_eq!(header(&knock, "content-language"), "en-US"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 734 | assert_eq!(header(&knock, "via"), "1.1 mom"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 735 | assert!( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 736 | json(knock).await["detail"] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 737 | .as_str() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 738 | .unwrap() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 739 | .contains("Someone is at the door.") |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 740 | ); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 741 | let excuse = [ |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 742 | ("accept-language", "en-US"), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 743 | ( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 744 | "authorization", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 745 | "Digest username=\"carving the turkey\", nonce=\"abc\"", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 746 | ), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 747 | ]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 748 | let answered = send(&app, "GET", "/runs/cafebabe", &excuse, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 749 | assert_eq!(answered.status(), StatusCode::OK); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 750 | let floor = json(send(&app, "GET", "/runs/cafebabe/floor", &us, "").await).await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 751 | assert_eq!(floor["name"], "Grandma's house for Thanksgiving"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 752 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 753 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 754 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 755 | async fn the_default_locale_is_british() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 756 | let (app, _) = seeded(Floor::Nans); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 757 | let floor = send(&app, "GET", "/runs/cafebabe/floor", &[], "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 758 | assert_eq!(header(&floor, "content-language"), "en-GB"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 759 | assert!(header(&floor, "vary").contains("Accept-Language")); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 760 | assert_eq!(json(floor).await["name"], "Nan's house at Christmas"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 761 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 762 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 763 | fn advertised(response: &Response) -> Vec<String> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 764 | header(response, "link") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 765 | .split(", <") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 766 | .filter(|entry| entry.contains("rels/technique")) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 767 | .filter_map(|entry| { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 768 | entry |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 769 | .split("title=\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 770 | .nth(1)? |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 771 | .split('"') |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 772 | .next() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 773 | .map(str::to_owned) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 774 | }) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 775 | .collect() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 776 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 777 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 778 | #[tokio::test] |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 779 | async fn links_offer_only_usable_techniques() { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 780 | let app = seeded_with(Floor::Bedroom, |run| run.foreskin = Some(1.0)); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 781 | let cold = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 782 | assert_eq!(advertised(&cold), ["warmup", "ice", "meditate"]); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 783 | let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 784 | let usable = advertised(&warm); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 785 | assert!(usable.contains(&"wet".to_owned()) && usable.contains(&"dry".to_owned())); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 786 | assert!(!usable.contains(&"uli".to_owned()), "uli needs the forum"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 787 | assert!(!usable.contains(&"pump".to_owned()), "pump needs a pump"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 788 | assert!( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 789 | header(&warm, "link").contains("title=\"wet\"; allow=\"JELQ\"; lubricant=\"required\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 790 | ); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 791 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 792 | let (forum, _) = seeded(Floor::Forum); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 793 | let response = send(&forum, "GET", "/runs/cafebabe", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 794 | assert!(advertised(&response).is_empty()); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 795 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 796 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 797 | fn linked_rels(response: &Response) -> Vec<String> { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 798 | header(response, "link") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 799 | .split(", <") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 800 | .filter_map(|entry| { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 801 | entry |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 802 | .split("rels/") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 803 | .nth(1)? |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 804 | .split('"') |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 805 | .next() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 806 | .map(str::to_owned) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 807 | }) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 808 | .filter(|rel| rel != "technique") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 809 | .collect() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 810 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 811 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 812 | #[tokio::test] |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 813 | async fn links_hide_resources_that_would_do_nothing() { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 814 | let (bedroom, _) = seeded(Floor::Bedroom); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 815 | let before = linked_rels(&send(&bedroom, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 816 | assert!(before.contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 817 | assert!(!before.contains(&"diagnosis".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 818 | assert!(!before.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 819 | let searched = send(&bedroom, "POST", "/runs/cafebabe/drawer", &[], "").await; |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 820 | assert!(!linked_rels(&searched).contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 821 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 822 | let (clinic, _) = seeded(Floor::Clinic); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 823 | let rels = linked_rels(&send(&clinic, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 824 | assert!(rels.contains(&"diagnosis".to_owned()) && rels.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 825 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 826 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 827 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 828 | async fn ignoring_mum_has_consequences() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 829 | let app = seeded_with(Floor::Bedroom, |run| { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 830 | mum_at_the_door(run); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 831 | run.here.turns = 6; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 832 | }); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 833 | let knock = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 834 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 835 | json(knock).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 836 | "https://jelq.dev/problems/someone-at-the-door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 837 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 838 | let leave = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 839 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 840 | leave.status(), |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 841 | StatusCode::UNAUTHORIZED, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 842 | "no leaving with Mum at the door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 843 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 844 | send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 845 | let opened = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 846 | assert_eq!(opened.status(), StatusCode::GONE); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 847 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 848 | json(opened).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 849 | "https://jelq.dev/problems/opened" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 850 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 851 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 852 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 853 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 854 | async fn caged_drawers_are_noisy_and_eventually_give_up_the_key() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 855 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 856 | let mut statuses = Vec::new(); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 857 | for _ in 0..12 { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 858 | let response = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 859 | statuses.push(response.status()); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 860 | if response.status() == StatusCode::OK { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 861 | break; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 862 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 863 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 864 | assert_eq!(statuses.last(), Some(&StatusCode::OK), "{statuses:?}"); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 865 | assert!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 866 | statuses[..statuses.len() - 1] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 867 | .iter() |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 868 | .all(|s| *s == StatusCode::NO_CONTENT) |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 869 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 870 | } |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 871 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 872 | #[tokio::test] |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 873 | async fn the_ruler_replaces_the_self_report() { |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 874 | let app = seeded_with(Floor::Bedroom, |_| {}); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 875 | let before = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 876 | assert!(before.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 877 | assert!(!before.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 878 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 879 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 880 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 881 | assert!(!after.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 882 | assert!(after.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 883 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 884 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 885 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 886 | async fn an_open_tab_is_linked_and_jelq_still_answers_with_choices() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 887 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 888 | run.story = Story::Pending; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 889 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 890 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 891 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 892 | let links = header(&response, "link"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 893 | assert!(links.contains("/branches/forum>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 894 | assert!(links.contains("/branches/close-tab>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 895 | assert!(links.contains("?technique=wet>")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 896 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 897 | assert_eq!(jelq.status(), StatusCode::MULTIPLE_CHOICES); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 898 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 899 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 900 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 901 | async fn either_story_choice_is_reachable_during_cooldown() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 902 | for choice in ["forum", "close-tab"] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 903 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 904 | run.turn = 9; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 905 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 906 | run.stamina = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 907 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 908 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 909 | let tenth = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 910 | assert_eq!(tenth.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 911 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 912 | assert!(!header(&response, "link").contains("?technique=")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 913 | let path = format!("/runs/cafebabe/branches/{choice}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 914 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 915 | header(&response, "link") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 916 | .contains(&format!("<{path}>; rel=\"https://jelq.dev/rels/branch\"")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 917 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 918 | let chosen = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 919 | assert_eq!(chosen.status(), StatusCode::SEE_OTHER); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 920 | assert!(!header(&chosen, "link").contains("/branches/")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 921 | let repeated = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 922 | assert_eq!(repeated.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 923 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 924 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 925 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 926 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 927 | async fn a_door_lock_says_when_it_was_used() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 928 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 929 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 930 | run.suspicion = SUSPICION_LIMIT; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 931 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 932 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 933 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 934 | assert_ne!(response.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 935 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 936 | response |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 937 | .headers() |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 938 | .get_all("warning") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 939 | .iter() |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 940 | .any(|w| w.to_str().unwrap().contains("your brother tried the door")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 941 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 942 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 943 | |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 944 | #[tokio::test] |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 945 | async fn shopping_survives_browsing_but_not_jelqing() { |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 946 | let app = seeded_with(Floor::ChangingRoom, |run| run.cash = 50); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 947 | send(&app, "GET", "/runs/cafebabe/shop", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 948 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 949 | assert!(header(&view, "link").contains("shop-item")); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 950 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 951 | assert_ne!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 952 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 953 | assert!(!header(&after, "link").contains("shop-item")); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 954 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 955 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 956 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 957 | async fn the_thread_announces_itself_at_the_branch() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 958 | let app = seeded_with(Floor::Bathroom, |run| { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 959 | run.turn = 8; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 960 | run.warmed_up = true; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 961 | run.items.baby_oil = 9; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 962 | }); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 963 | send( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 964 | &app, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 965 | "JELQ", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 966 | "/runs/cafebabe?technique=wet", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 967 | &[("content-type", "application/baby-oil")], |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 968 | "", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 969 | ) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 970 | .await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 971 | let ninth = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 972 | assert!(!header(&ninth, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 973 | let tenth = send( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 974 | &app, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 975 | "JELQ", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 976 | "/runs/cafebabe?technique=wet", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 977 | &[("content-type", "application/baby-oil")], |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 978 | "", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 979 | ) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 980 | .await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 981 | assert!( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 982 | tenth |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 983 | .headers() |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 984 | .get_all("warning") |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 985 | .iter() |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 986 | .any(|w| w.to_str().unwrap().contains("a forum thread from 2009")) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 987 | ); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 988 | assert!(header(&tenth, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 989 | let announced = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 990 | assert!(header(&announced, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 991 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 992 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 993 | #[tokio::test] |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 994 | async fn rereading_the_thread_teaches_uli() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 995 | let mut taught_runs = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 996 | let mut ruptured = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 997 | for seed in 0..100u64 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 998 | let app = app_with(Floor::Bedroom, seed, |run| { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 999 | run.warmed_up = true; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1000 | run.story = Story::ClosedTab; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1001 | }); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1002 | let mut taught = false; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1003 | for _ in 0..40 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1004 | let read = send(&app, "POST", "/runs/cafebabe/re-read", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1005 | match read.status() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1006 | StatusCode::NOT_MODIFIED => { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1007 | assert!(header(&read, "warning").contains("2009")); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1008 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1009 | StatusCode::MULTIPLE_CHOICES => { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1010 | send(&app, "POST", "/runs/cafebabe/branches/close-tab", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1011 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1012 | StatusCode::OK => { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1013 | assert!(header(&read, "location").contains("/techniques")); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1014 | taught = true; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1015 | break; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1016 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1017 | StatusCode::INTERNAL_SERVER_ERROR => break, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1018 | other => panic!("seed {seed} read the thread into {other}"), |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1019 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1020 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1021 | if taught { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1022 | taught_runs += 1; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1023 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=uli", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1024 | assert_ne!(jelq.status(), StatusCode::FORBIDDEN); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1025 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1026 | ruptured += u32::from(!taught); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1027 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1028 | assert!( |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1029 | taught_runs >= 85, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1030 | "{taught_runs}/100 learned uli, {ruptured} ruptured first" |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1031 | ); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1032 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1033 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1034 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1035 | async fn meditation_is_free_but_only_once_per_floor() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1036 | let app = seeded_with(Floor::Bedroom, |_| {}); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1037 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1038 | assert_eq!(response.status(), StatusCode::OK); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1039 | assert_eq!(header(&response, "x-eq"), "10"); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1040 | assert_eq!(header(&response, "x-stamina"), "10/10"); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1041 | let again = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1042 | assert_eq!(again.status(), StatusCode::CONFLICT); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1043 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1044 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1045 | #[tokio::test] |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1046 | async fn meditation_is_listed_from_the_start() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1047 | let app = seeded_with(Floor::Bedroom, |_| {}); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1048 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1049 | assert!(header(&view, "link").contains("technique=meditate")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1050 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1051 | assert_eq!(jelq.status(), StatusCode::OK); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1052 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1053 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1054 | fn app_with(floor: Floor, seed: u64, setup: impl FnOnce(&mut Run)) -> Router { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1055 | let state = Arc::new(AppState::default()); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1056 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1057 | run.floor = floor; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1058 | setup(&mut run); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1059 | state.insert(run); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1060 | router(state) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1061 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1062 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1063 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1064 | async fn hold_is_offered_only_at_the_edges() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1065 | let calm = seeded_with(Floor::Bedroom, |_| {}); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1066 | let refused = send(&calm, "HOLD", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1067 | assert_eq!(refused.status(), StatusCode::METHOD_NOT_ALLOWED); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1068 | assert!(!header(&refused, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1069 | let view = send(&calm, "GET", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1070 | assert!(!header(&view, "link").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1071 | let options = send(&calm, "OPTIONS", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1072 | assert!(!header(&options, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1073 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1074 | let winded = seeded_with(Floor::Bedroom, |run| run.stamina = 2); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1075 | let listed = send(&winded, "GET", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1076 | assert!(header(&listed, "link").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1077 | let options = send(&winded, "OPTIONS", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1078 | assert!(header(&options, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1079 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1080 | let hot = seeded_with(Floor::Bedroom, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1081 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1082 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1083 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1084 | let held = send(&hot, "HOLD", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1085 | assert_eq!(held.status(), StatusCode::NO_CONTENT); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1086 | assert_eq!(header(&held, "x-stamina"), "10/10"); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1087 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1088 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1089 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1090 | async fn holding_calms_and_sometimes_reflects() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1091 | let mut calmed = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1092 | let mut reflected = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1093 | let mut ruptured = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1094 | for seed in 0..120u64 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1095 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1096 | run.eq = 75; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1097 | match run.hold(Instant::now()) { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1098 | Ok(_) if run.eq == 0 => reflected += 1, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1099 | Ok(_) => calmed += 1, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1100 | Err(_) => ruptured += 1, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1101 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1102 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1103 | assert!( |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1104 | calmed > 100 && reflected > 0, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1105 | "one HOLD in twelve should reflect, got {calmed} calm and {reflected} reflective of 120" |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1106 | ); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1107 | assert!( |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1108 | calmed + reflected + ruptured == 120 && ruptured <= 4, |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1109 | "the flat 1 in 250 ruptured {ruptured} of 120 holds" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1110 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1111 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1112 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1113 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1114 | async fn leaving_the_band_warms_the_next_floor() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1115 | let app = seeded_with(Floor::Bedroom, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1116 | run.eq = 60; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1117 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1118 | run.here.turns = 6; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1119 | run.items.baby_oil = 9; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1120 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1121 | let left = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1122 | assert_eq!(left.status(), StatusCode::SEE_OTHER); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1123 | let detail = json(left).await["detail"].as_str().unwrap().to_owned(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1124 | assert!(detail.contains("the warmth came with you")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1125 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1126 | let lube = [("content-type", "application/baby-oil")]; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1127 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1128 | // The shower is a +35 warm-up, so EQ lands in the band and the band bonus rides along. |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1129 | // The arrival bonus is the one point the second jelq loses. |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1130 | let first = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1131 | assert!( |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1132 | header(&first, "server-timing").contains("d20+4"), |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1133 | "the first jelq of a warm arrival rolls with +1, got {}", |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1134 | header(&first, "server-timing") |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1135 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1136 | let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1137 | assert!(header(&second, "server-timing").contains("d20+3")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1138 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1139 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1140 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1141 | async fn greed_multiplies_gains_above_the_band() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1142 | let lube = [("content-type", "application/baby-oil")]; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1143 | for seed in 0..60u64 { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1144 | let app = app_with(Floor::Bedroom, seed, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1145 | run.eq = 60; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1146 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1147 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1148 | let in_band = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1149 | let app = app_with(Floor::Bedroom, seed, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1150 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1151 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1152 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1153 | let greedy = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1154 | if in_band.status() != StatusCode::OK || greedy.status() != StatusCode::OK { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1155 | continue; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1156 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1157 | let steady = json(in_band).await["length"].as_f64().unwrap(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1158 | let eager = json(greedy).await["length"].as_f64().unwrap(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1159 | assert!( |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1160 | (eager - steady * 1.5).abs() < 1e-9, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1161 | "seed {seed} gained {eager} above the band against {steady} inside it" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1162 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1163 | return; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1164 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1165 | panic!("no seed in 60 produced two clean rolls to compare"); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1166 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1167 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1168 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1169 | async fn the_kitchen_is_only_on_the_home_floors() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1170 | let absent = seeded_with(Floor::Bathroom, |_| {}); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1171 | let no_kitchen = send(&absent, "POST", "/runs/cafebabe/kitchen", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1172 | assert_eq!(no_kitchen.status(), StatusCode::NOT_FOUND); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1173 | let view = send(&absent, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1174 | assert!(!header(&view, "link").contains("/kitchen")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1175 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1176 | let app = seeded_with(Floor::Bedroom, |_| {}); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1177 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1178 | assert!(header(&view, "link").contains("/kitchen")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1179 | let raid = send(&app, "POST", "/runs/cafebabe/kitchen", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1180 | assert_ne!(raid.status(), StatusCode::NOT_FOUND); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1181 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1182 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1183 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1184 | async fn raids_cost_the_turn_and_the_fridge_pays_out_sometimes() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1185 | let mut bounties = std::collections::BTreeSet::new(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1186 | let mut told = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1187 | for seed in 0..80u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1188 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1189 | let Ok(outcome) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1190 | panic!("the first raid should never fail"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1191 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1192 | assert_eq!(run.turn, 1, "a raid costs the floor turn"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1193 | assert!(!run.here.melon_offered, "no melon at starting EQ"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1194 | if outcome.status == StatusCode::NO_CONTENT { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1195 | bounties.insert("empty"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1196 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1197 | bounties.insert("loot"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1198 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1199 | told += u32::from(run.kitchen_tellings); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1200 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1201 | assert!(bounties.contains("loot") && bounties.contains("empty")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1202 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1203 | (0..80).any(|seed| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1204 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1205 | run.raid_kitchen().is_ok() && run.kitchen_tellings == 0 |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1206 | }), |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1207 | "most raids go unremarked" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1208 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1209 | assert!(told > 0, "someone should have been told across 80 raids"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1210 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1211 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1212 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1213 | async fn the_watermelon_offers_itself_above_ninety() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1214 | let mut offered = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1215 | let mut caught = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1216 | let mut survived = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1217 | for seed in 0..120u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1218 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1219 | run.eq = 95; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1220 | let Ok(outcome) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1221 | continue; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1222 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1223 | if outcome.status != StatusCode::MULTIPLE_CHOICES { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1224 | continue; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1225 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1226 | offered += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1227 | let gains = run.length; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1228 | let disgrace = run.shame; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1229 | if run.commit_melon().is_err() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1230 | caught += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1231 | assert_eq!(run.ended.as_ref().unwrap().cause.slug(), "watermelon"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1232 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1233 | survived += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1234 | assert_eq!(run.eq, 0); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1235 | assert_eq!(run.shame, disgrace + 5); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1236 | assert_eq!(run.length, gains, "the gains are kept"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1237 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1238 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1239 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1240 | offered > 20, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1241 | "the melon should appear in two fifths of raids" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1242 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1243 | assert!(caught > 0 && survived > 0, "caught is one in three"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1244 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1245 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1246 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1247 | async fn the_kitchen_closes_after_two_tellings() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1248 | let mut closed = None; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1249 | for seed in 0..300u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1250 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1251 | let first = run.raid_kitchen(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1252 | let second = run.raid_kitchen(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1253 | if second.is_err() && first.is_ok() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1254 | assert_eq!(run.kitchen_tellings, 2); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1255 | let Err(third) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1256 | panic!("the kitchen should be gone"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1257 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1258 | assert_eq!(third.status(), StatusCode::GONE); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1259 | closed = Some(seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1260 | break; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1261 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1262 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1263 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1264 | closed.is_some(), |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1265 | "two tellings should occur within 300 seeds" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1266 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1267 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1268 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1269 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1270 | async fn lubes_run_out_but_spit_never_does() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1271 | let app = seeded_with(Floor::Bedroom, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1272 | run.warmed_up = true; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1273 | run.items.baby_oil = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1274 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1275 | let lube = [("content-type", "application/baby-oil")]; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1276 | let first = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1277 | assert_ne!(first.status(), StatusCode::PRECONDITION_FAILED); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1278 | let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1279 | assert_eq!(second.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1280 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1281 | let spit = [("content-type", "text/plain; charset=spit")]; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1282 | for _ in 0..3 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1283 | let wet = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &spit, "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1284 | assert_ne!(wet.status(), StatusCode::PRECONDITION_FAILED); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1285 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1286 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1287 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1288 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1289 | async fn energy_drinks_add_three_stamina() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1290 | let app = seeded_with(Floor::Bedroom, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1291 | run.stamina = 2; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1292 | run.items.energy_drinks = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1293 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1294 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1295 | assert!(header(&view, "link").contains("technique=energy")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1296 | let drink = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1297 | assert_eq!(drink.status(), StatusCode::OK); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1298 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1299 | assert_eq!(header(&view, "x-stamina"), "5/10"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1300 | let again = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1301 | assert_eq!(again.status(), StatusCode::FAILED_DEPENDENCY); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1302 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1303 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1304 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1305 | async fn the_working_supplement_resets_stamina() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1306 | let mut worked = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1307 | let mut bunk = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1308 | for seed in 0..60u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1309 | let app = app_with(Floor::Bedroom, seed, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1310 | run.stamina = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1311 | run.items.supplements = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1312 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1313 | let taken = send(&app, "JELQ", "/runs/cafebabe?technique=supplement", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1314 | if taken.status() == StatusCode::OK { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1315 | worked += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1316 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1317 | assert_eq!(header(&view, "x-stamina"), "10/10"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1318 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1319 | assert_eq!(taken.status(), StatusCode::BAD_GATEWAY); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1320 | bunk += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1321 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1322 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1323 | assert!(worked > 0 && bunk > 0, "one in five should work too well"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1324 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1325 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1326 | #[tokio::test] |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1327 | async fn dry_jelqs_build_friction_and_real_lube_does_not() { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1328 | let app = seeded_with(Floor::Bedroom, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1329 | run.warmed_up = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1330 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1331 | let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1332 | assert_eq!(header(&dry, "x-friction"), "2/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1333 | let lube = [("content-type", "application/baby-oil")]; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1334 | let wet = send( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1335 | &app, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1336 | "JELQ", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1337 | "/runs/cafebabe?technique=wet&intensity=5", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1338 | &lube, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1339 | "", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1340 | ) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1341 | .await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1342 | assert_eq!(header(&wet, "x-friction"), "2/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1343 | let spit = [("content-type", "text/plain; charset=spit")]; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1344 | let glisten = send( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1345 | &app, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1346 | "JELQ", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1347 | "/runs/cafebabe?technique=wet&intensity=5", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1348 | &spit, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1349 | "", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1350 | ) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1351 | .await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1352 | assert_eq!(header(&glisten, "x-friction"), "3/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1353 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1354 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1355 | #[tokio::test] |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1356 | async fn switching_grips_makes_the_friction_cheaper() { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1357 | let app = seeded_with(Floor::Bedroom, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1358 | run.warmed_up = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1359 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1360 | let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1361 | assert_eq!(header(&dry, "x-friction"), "2/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1362 | send( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1363 | &app, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1364 | "GET", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1365 | "/runs/cafebabe/grip", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1366 | &[("upgrade", "underhand"), ("connection", "upgrade")], |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1367 | "", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1368 | ) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1369 | .await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1370 | let switched = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1371 | assert_eq!(header(&switched, "x-friction"), "3/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1372 | let settled = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1373 | assert_eq!(header(&settled, "x-friction"), "5/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1374 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1375 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1376 | #[tokio::test] |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1377 | async fn holding_and_meditating_shed_friction() { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1378 | let app = seeded_with(Floor::Bedroom, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1379 | run.eq = 80; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1380 | run.friction = 5; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1381 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1382 | let held = send(&app, "HOLD", "/runs/cafebabe", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1383 | assert_eq!(held.status(), StatusCode::NO_CONTENT); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1384 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1385 | assert_eq!(header(&view, "x-friction"), "3/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1386 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1387 | let taught = seeded_with(Floor::Bedroom, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1388 | run.friction = 5; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1389 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1390 | let calmed = send( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1391 | &taught, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1392 | "JELQ", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1393 | "/runs/cafebabe?technique=meditate", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1394 | &[], |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1395 | "", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1396 | ) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1397 | .await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1398 | assert_eq!(calmed.status(), StatusCode::OK); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1399 | let view = send(&taught, "GET", "/runs/cafebabe", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1400 | assert_eq!(header(&view, "x-friction"), "3/10"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1401 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1402 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1403 | #[tokio::test] |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1404 | async fn a_friction_burn_halves_the_gains() { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1405 | let lube = [("content-type", "application/baby-oil")]; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1406 | let path = "/runs/cafebabe?technique=wet&intensity=5"; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1407 | for seed in 0..60u64 { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1408 | let steady = app_with(Floor::Bedroom, seed, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1409 | run.warmed_up = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1410 | run.eq = 60; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1411 | run.items.baby_oil = 9; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1412 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1413 | let hurt_app = app_with(Floor::Bedroom, seed, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1414 | run.warmed_up = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1415 | run.eq = 60; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1416 | run.items.baby_oil = 9; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1417 | run.conditions.friction_burn = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1418 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1419 | let calm = send(&steady, "JELQ", path, &lube, "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1420 | let hurt = send(&hurt_app, "JELQ", path, &lube, "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1421 | if calm.status() != StatusCode::OK || hurt.status() != StatusCode::OK { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1422 | continue; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1423 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1424 | let calm_gain = json(calm).await["length"].as_f64().unwrap(); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1425 | let hurt_gain = json(hurt).await["length"].as_f64().unwrap(); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1426 | assert!( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1427 | (hurt_gain * 2.0 - calm_gain).abs() < 1e-9, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1428 | "seed {seed} burned {hurt_gain} against {calm_gain}" |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1429 | ); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1430 | return; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1431 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1432 | panic!("no seed in 60 produced two clean rolls to compare"); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1433 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1434 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1435 | #[tokio::test] |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1436 | async fn the_burn_warns_and_the_ice_treats_it() { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1437 | let app = seeded_with(Floor::Bedroom, |run| { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1438 | run.warmed_up = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1439 | run.eq = 60; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1440 | run.items.baby_oil = 9; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1441 | run.friction = 7; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1442 | run.conditions.friction_burn = true; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1443 | }); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1444 | let lube = [("content-type", "application/baby-oil")]; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1445 | let jelq = send( |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1446 | &app, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1447 | "JELQ", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1448 | "/runs/cafebabe?technique=wet&intensity=5", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1449 | &lube, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1450 | "", |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1451 | ) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1452 | .await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1453 | let warnings: Vec<_> = jelq |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1454 | .headers() |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1455 | .get_all("warning") |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1456 | .iter() |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1457 | .filter_map(|w| w.to_str().ok()) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1458 | .collect(); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1459 | assert!(warnings.contains(&"199 - \"friction burn\"")); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1460 | send(&app, "JELQ", "/runs/cafebabe?technique=ice", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1461 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1462 | let warnings: Vec<_> = view |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1463 | .headers() |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1464 | .get_all("warning") |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1465 | .iter() |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1466 | .filter_map(|w| w.to_str().ok()) |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1467 | .collect(); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1468 | assert!(!warnings.contains(&"199 - \"friction burn\"")); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 1469 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1470 | |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1471 | #[tokio::test] |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1472 | async fn the_burn_shifts_the_rupture_tiers() { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1473 | async fn ruptures(burned: bool) -> u32 { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1474 | let mut gone = 0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1475 | for seed in 0..400u64 { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1476 | let app = app_with(Floor::Bedroom, seed, |run| { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1477 | run.warmed_up = true; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1478 | run.eq = 60; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1479 | run.items.baby_oil = 9; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1480 | run.conditions.friction_burn = burned; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1481 | }); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1482 | let lube = [("content-type", "application/baby-oil")]; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1483 | let jelq = send( |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1484 | &app, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1485 | "JELQ", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1486 | "/runs/cafebabe?technique=wet&intensity=5", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1487 | &lube, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1488 | "", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1489 | ) |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1490 | .await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1491 | if jelq.status() == StatusCode::INTERNAL_SERVER_ERROR { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1492 | gone += 1; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1493 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1494 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1495 | gone |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1496 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1497 | let burned = ruptures(true).await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1498 | let calm = ruptures(false).await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1499 | assert!( |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1500 | burned >= 8 && calm <= 4, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1501 | "burned {burned} ruptures against {calm}" |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1502 | ); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1503 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1504 | |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1505 | #[tokio::test] |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1506 | async fn meditation_respects_the_priapism_floor() { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1507 | let app = seeded_with(Floor::Bedroom, |run| { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1508 | run.eq = 80; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1509 | run.conditions.priapism_turns = 3; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1510 | }); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1511 | let calmed = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1512 | assert_eq!(calmed.status(), StatusCode::OK); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1513 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1514 | assert_eq!(header(&view, "x-eq"), "75"); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1515 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1516 | |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1517 | #[tokio::test] |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1518 | async fn the_kitchen_pays_out_at_the_documented_odds() { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1519 | let mut oil = 0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1520 | let mut drinks = 0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1521 | let mut packs = 0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1522 | for seed in 0..600u64 { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1523 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1524 | run.kitchen_tellings = 0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1525 | let held = ( |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1526 | run.items.coconut_oil, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1527 | run.items.energy_drinks, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1528 | run.items.ice_packs, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1529 | ); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1530 | let _ = run.raid_kitchen(); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1531 | oil += u32::from(run.items.coconut_oil > held.0); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1532 | drinks += u32::from(run.items.energy_drinks > held.1); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1533 | packs += u32::from(run.items.ice_packs > held.2); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1534 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1535 | assert!((170..=230).contains(&oil), "coconut {oil} in 600"); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1536 | assert!((90..=150).contains(&drinks), "energy {drinks} in 600"); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1537 | assert!((45..=105).contains(&packs), "ice {packs} in 600"); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1538 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1539 | |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1540 | #[tokio::test] |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1541 | async fn a_refused_jelq_leaves_the_lube_alone() { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1542 | let app = seeded_with(Floor::Bedroom, |run| { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1543 | run.warmed_up = true; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1544 | run.items.extender = true; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1545 | run.girth = STORAGE_GIRTH + 1.0; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1546 | }); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1547 | let lube = [("content-type", "application/baby-oil")]; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1548 | let full = send( |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1549 | &app, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1550 | "JELQ", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1551 | "/runs/cafebabe?technique=wet&intensity=5", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1552 | &lube, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1553 | "", |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1554 | ) |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1555 | .await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1556 | assert_eq!(full.status(), StatusCode::INSUFFICIENT_STORAGE); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1557 | let inv = send(&app, "GET", "/runs/cafebabe/inventory", &[], "").await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1558 | let body = json(inv).await; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1559 | let held = body["items"].as_array().unwrap(); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1560 | assert!(held.iter().any(|i| i["name"] == "baby-oil")); |
139164489032 | atagen | 2026-10-11 05:46 UTC | 1561 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1562 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1563 | #[tokio::test] |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1564 | async fn an_empty_bottle_is_declined_before_the_enemy_stirs() { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1565 | let control = seeded_with(Floor::ChangingRoom, |run| { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1566 | run.warmed_up = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1567 | run.suspicion = SUSPICION_LIMIT; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1568 | }); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1569 | let lube = [("content-type", "application/baby-oil")]; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1570 | let caught = send( |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1571 | &control, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1572 | "JELQ", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1573 | "/runs/cafebabe?technique=wet&intensity=5", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1574 | &lube, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1575 | "", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1576 | ) |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1577 | .await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1578 | assert_eq!(caught.status(), StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1579 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1580 | let app = seeded_with(Floor::ChangingRoom, |run| { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1581 | run.warmed_up = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1582 | run.suspicion = SUSPICION_LIMIT; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1583 | run.items.baby_oil = 0; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1584 | }); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1585 | let refused = send( |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1586 | &app, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1587 | "JELQ", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1588 | "/runs/cafebabe?technique=wet&intensity=5", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1589 | &lube, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1590 | "", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1591 | ) |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1592 | .await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1593 | assert_eq!(refused.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1594 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1595 | assert_eq!(header(&view, "x-suspicion"), "5/5"); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1596 | assert_eq!(header(&view, "x-shame"), "0"); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1597 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1598 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1599 | #[tokio::test] |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1600 | async fn the_top_tier_rolls_a_single_third() { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1601 | let mut ruptures = 0; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1602 | let mut early = 0; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1603 | for seed in 0..400u64 { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1604 | let app = app_with(Floor::Bedroom, seed, |run| { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1605 | run.warmed_up = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1606 | run.eq = 96; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1607 | run.items.baby_oil = 9; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1608 | run.items.blinds = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1609 | }); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1610 | let lube = [("content-type", "application/baby-oil")]; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1611 | let jelq = send( |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1612 | &app, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1613 | "JELQ", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1614 | "/runs/cafebabe?technique=wet&intensity=5", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1615 | &lube, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1616 | "", |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1617 | ) |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1618 | .await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1619 | match jelq.status() { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1620 | StatusCode::INTERNAL_SERVER_ERROR => ruptures += 1, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1621 | StatusCode::TOO_EARLY => early += 1, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1622 | other => panic!("seed {seed} ended in {other}"), |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1623 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1624 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1625 | assert!( |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1626 | (90..=175).contains(&ruptures), |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1627 | "ruptures {ruptures} of 400 against {early} early" |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1628 | ); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1629 | assert!( |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1630 | (225..=310).contains(&early), |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1631 | "early {early} of 400 against {ruptures} ruptures" |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1632 | ); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1633 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1634 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1635 | #[tokio::test] |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1636 | async fn priapism_holds_the_floor_through_every_reset() { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1637 | let exit = seeded_with(Floor::Bedroom, |run| { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1638 | run.warmed_up = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1639 | run.eq = 90; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1640 | run.here.turns = 99; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1641 | run.conditions.priapism_turns = 3; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1642 | }); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1643 | let out = send(&exit, "POST", "/runs/cafebabe/floor", &[], "").await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1644 | assert_eq!(out.status(), StatusCode::SEE_OTHER); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1645 | let view = send(&exit, "GET", "/runs/cafebabe", &[], "").await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1646 | assert_eq!(header(&view, "x-eq"), "75"); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1647 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1648 | let melon = seeded_with(Floor::Bedroom, |run| { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1649 | run.eq = 95; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1650 | run.here.melon_offered = true; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1651 | run.conditions.priapism_turns = 2; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1652 | }); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1653 | let bite = send(&melon, "POST", "/runs/cafebabe/kitchen/watermelon", &[], "").await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1654 | assert_eq!(bite.status(), StatusCode::OK); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1655 | let view = send(&melon, "GET", "/runs/cafebabe", &[], "").await; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1656 | assert_eq!(header(&view, "x-eq"), "75"); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 1657 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1658 | |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1659 | #[tokio::test] |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1660 | async fn holding_rolls_a_flat_rupture_chance() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1661 | async fn ruptures(eq: i32, stamina: i32) -> u32 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1662 | let mut gone = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1663 | for seed in 0..600u64 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1664 | let app = app_with(Floor::Bedroom, seed, |run| { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1665 | run.warmed_up = true; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1666 | run.eq = eq; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1667 | run.stamina = stamina; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1668 | }); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1669 | let held = send(&app, "HOLD", "/runs/cafebabe", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1670 | if held.status() == StatusCode::INTERNAL_SERVER_ERROR { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1671 | gone += 1; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1672 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1673 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1674 | gone |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1675 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1676 | let high = ruptures(90, 10).await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1677 | let low = ruptures(30, 2).await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1678 | assert!((0..=9).contains(&high), "high holds ruptured {high}/600"); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1679 | assert!((0..=9).contains(&low), "low holds ruptured {low}/600"); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1680 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1681 | |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1682 | #[tokio::test] |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1683 | async fn the_kitchen_rolls_the_normal_tiers() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1684 | async fn ruptures(eq: i32) -> u32 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1685 | let mut gone = 0; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1686 | for seed in 0..600u64 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1687 | let app = app_with(Floor::Bedroom, seed, |run| run.eq = eq); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1688 | let raid = send(&app, "POST", "/runs/cafebabe/kitchen", &[], "").await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1689 | if raid.status() == StatusCode::INTERNAL_SERVER_ERROR { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1690 | gone += 1; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1691 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1692 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1693 | gone |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1694 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1695 | let hot = ruptures(96).await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1696 | let cool = ruptures(40).await; |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1697 | assert!((40..=80).contains(&hot), "hot kitchen ruptured {hot}/600"); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1698 | assert!((0..=9).contains(&cool), "cool kitchen ruptured {cool}/600"); |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 1699 | } |