A hang names itself - bounded frame waits + nextest slow-timeout
Browse files at this commitb7a80177a0eb86e983dce92949078961de77063eParent: 61960a5- test
- a hang names itself - bounded frame waits + nextest slow-timeout
4 changed files +206 -55
- .config/nextest.toml +14 -0
- tests/ai_bridge.rs +156 -43
- tests/ai_protocol.rs +17 -7
- tests/podcast.rs +19 -5
.config/nextest.tomlmodified+14 -0
| @@ -1,3 +1,17 @@ | |||
| 1 | # One flake must not hide the rest. Deploy still requires the job to be green. | 1 | # One flake must not hide the rest. Deploy still requires the job to be green. |
| 2 | [profile.default] | 2 | [profile.default] |
| 3 | fail-fast = false | 3 | fail-fast = false |
| 4 | + | ||
| 5 | +# A hang must name itself. Without this, one test stuck on an unbounded | ||
| 6 | +# `await` holds the whole Test step — and, because Deploy is serialized behind | ||
| 7 | +# it, every later push queues behind a job that will never finish (observed: | ||
| 8 | +# 3h38m on run 35251780342, `1bc23aa`). With it, a test that makes no progress | ||
| 9 | +# for one period is *marked slow* and after two periods is terminated and | ||
| 10 | +# reported by name as a timeout, so the run ends in minutes with the culprit | ||
| 11 | +# in the log instead of hanging until somebody cancels it. | ||
| 12 | +# | ||
| 13 | +# The period is 120s: the slowest honest test in this suite is a bridge round | ||
| 14 | +# trip on a loaded CI box (a handful of seconds), so 2x120s of no progress is | ||
| 15 | +# a hang, not slowness. A test that legitimately needs longer raises this | ||
| 16 | +# deliberately, with the reason in its own comment. | ||
| 17 | +slow-timeout = { period = "120s", terminate-after = 2 } | ||
tests/ai_bridge.rsmodified+156 -43
| @@ -116,17 +116,42 @@ async fn shake_hands( | |||
| 116 | Greeting, | 116 | Greeting, |
| 117 | ) { | 117 | ) { |
| 118 | let endpoint = client_endpoint(bridge); | 118 | let endpoint = client_endpoint(bridge); |
| 119 | - let conn = endpoint | 119 | + let conn = connect_or_fail(&endpoint, bridge.local_addr().unwrap()).await; |
| 120 | - .connect(bridge.local_addr().unwrap(), "localhost") | ||
| 121 | - .expect("dial") | ||
| 122 | - .await | ||
| 123 | - .expect("QUIC handshake"); | ||
| 124 | let (mut send, mut recv) = conn.open_bi().await.expect("control stream"); | 120 | let (mut send, mut recv) = conn.open_bi().await.expect("control stream"); |
| 125 | write_frame(&mut send, &hello).await.expect("send Hello"); | 121 | write_frame(&mut send, &hello).await.expect("send Hello"); |
| 126 | - let greeting: Greeting = read_frame(&mut recv).await.expect("read Greeting"); | 122 | + let greeting: Greeting = frame_or_fail(&mut recv, "read Greeting").await; |
| 127 | (endpoint, conn, send, recv, greeting) | 123 | (endpoint, conn, send, recv, greeting) |
| 128 | } | 124 | } |
| 129 | 125 | ||
| 126 | +/// One answer frame, **bounded**: a bridge that never answers must fail this | ||
| 127 | +/// test with a name in seconds, not hang the run. A hanging test holds the | ||
| 128 | +/// whole Test step, and Deploy is serialized behind it, so one unbounded | ||
| 129 | +/// `await` here can stall every later push (observed on CI). | ||
| 130 | +async fn frame_or_fail<T: serde::de::DeserializeOwned>( | ||
| 131 | + recv: &mut quinn::RecvStream, | ||
| 132 | + what: &str, | ||
| 133 | +) -> T { | ||
| 134 | + match tokio::time::timeout(Duration::from_secs(10), read_frame(recv)).await { | ||
| 135 | + Ok(Ok(frame)) => frame, | ||
| 136 | + Ok(Err(err)) => panic!("{what}: the frame could not be read: {err}"), | ||
| 137 | + Err(_) => panic!("{what}: no frame arrived within 10s — the bridge did not answer"), | ||
| 138 | + } | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +/// The same bound for a client-side handshake: dialling a listener that never | ||
| 142 | +/// completes its QUIC handshake must name itself too. | ||
| 143 | +async fn connect_or_fail( | ||
| 144 | + endpoint: &quinn::Endpoint, | ||
| 145 | + addr: std::net::SocketAddr, | ||
| 146 | +) -> quinn::Connection { | ||
| 147 | + let connecting = endpoint.connect(addr, "localhost").expect("dial"); | ||
| 148 | + match tokio::time::timeout(Duration::from_secs(10), connecting).await { | ||
| 149 | + Ok(Ok(conn)) => conn, | ||
| 150 | + Ok(Err(err)) => panic!("the QUIC handshake failed: {err}"), | ||
| 151 | + Err(_) => panic!("the QUIC handshake did not complete within 10s"), | ||
| 152 | + } | ||
| 153 | +} | ||
| 154 | + | ||
| 130 | /// What the fake service does with each request it receives. | 155 | /// What the fake service does with each request it receives. |
| 131 | #[derive(Clone)] | 156 | #[derive(Clone)] |
| 132 | enum Behaviour { | 157 | enum Behaviour { |
| @@ -483,7 +508,7 @@ async fn an_unreadable_hello_is_rejected_as_malformed() { | |||
| 483 | .unwrap(); | 508 | .unwrap(); |
| 484 | send.write_all(body).await.unwrap(); | 509 | send.write_all(body).await.unwrap(); |
| 485 | 510 | ||
| 486 | - let greeting: Greeting = read_frame(&mut recv).await.expect("a rejection came back"); | 511 | + let greeting: Greeting = frame_or_fail(&mut recv, "a rejection came back").await; |
| 487 | assert!( | 512 | assert!( |
| 488 | matches!( | 513 | matches!( |
| 489 | greeting, | 514 | greeting, |
| @@ -819,7 +844,12 @@ async fn closing_the_bridge_stops_accepting_services() { | |||
| 819 | bridge.close(); | 844 | bridge.close(); |
| 820 | 845 | ||
| 821 | let endpoint = client_endpoint(&bridge); | 846 | let endpoint = client_endpoint(&bridge); |
| 822 | - let result = endpoint.connect(addr, "localhost").unwrap().await; | 847 | + let result = tokio::time::timeout( |
| 848 | + Duration::from_secs(10), | ||
| 849 | + endpoint.connect(addr, "localhost").unwrap(), | ||
| 850 | + ) | ||
| 851 | + .await | ||
| 852 | + .expect("the handshake must settle within 10s"); | ||
| 823 | assert!(result.is_err(), "a closed bridge accepts nothing"); | 853 | assert!(result.is_err(), "a closed bridge accepts nothing"); |
| 824 | } | 854 | } |
| 825 | 855 | ||
| @@ -933,7 +963,8 @@ async fn the_certificate_endpoint_publishes_a_usable_trust_anchor() { | |||
| 933 | write_frame(&mut send, &hello("ocr", &["ocr.extract"])) | 963 | write_frame(&mut send, &hello("ocr", &["ocr.extract"])) |
| 934 | .await | 964 | .await |
| 935 | .unwrap(); | 965 | .unwrap(); |
| 936 | - let greeting: Greeting = read_frame(&mut recv).await.unwrap(); | 966 | + let greeting: Greeting = |
| 967 | + frame_or_fail(&mut recv, "read Greeting after the certificate was fetched").await; | ||
| 937 | assert!(matches!(greeting, Greeting::Welcome { .. }), "{greeting:?}"); | 968 | assert!(matches!(greeting, Greeting::Welcome { .. }), "{greeting:?}"); |
| 938 | } | 969 | } |
| 939 | 970 | ||
| @@ -983,7 +1014,9 @@ fn payloads_are_opaque(v: Value) -> Value { | |||
| 983 | 1014 | ||
| 984 | use axum::Router; | 1015 | use axum::Router; |
| 985 | use axum::http::StatusCode; | 1016 | use axum::http::StatusCode; |
| 986 | -use hezarfen_backend::constant::{AI_CHAT_CAPABILITY, AI_RAG_CHAT_CAPABILITY, DEFAULT_MAX_CHATBOT_MESSAGE_LEN}; | 1017 | +use hezarfen_backend::constant::{ |
| 1018 | + AI_CHAT_CAPABILITY, AI_RAG_CHAT_CAPABILITY, DEFAULT_MAX_CHATBOT_MESSAGE_LEN, | ||
| 1019 | +}; | ||
| 987 | use hezarfen_backend::database::Database; | 1020 | use hezarfen_backend::database::Database; |
| 988 | use uuid::Uuid; | 1021 | use uuid::Uuid; |
| 989 | 1022 | ||
| @@ -1481,7 +1514,7 @@ async fn api_read(conn: &quinn::Connection, request: ApiRequest) -> ApiResponse | |||
| 1481 | .await | 1514 | .await |
| 1482 | .expect("write ApiRequest"); | 1515 | .expect("write ApiRequest"); |
| 1483 | let _ = send.finish(); | 1516 | let _ = send.finish(); |
| 1484 | - read_frame(&mut recv).await.expect("read ApiResponse") | 1517 | + frame_or_fail(&mut recv, "read ApiResponse").await |
| 1485 | } | 1518 | } |
| 1486 | 1519 | ||
| 1487 | /// A `GET` of `path` as `on_behalf_of` (or as the service itself). | 1520 | /// A `GET` of `path` as `on_behalf_of` (or as the service itself). |
| @@ -2128,7 +2161,7 @@ async fn blob_read(conn: &quinn::Connection, request: BlobRequest) -> (BlobRespo | |||
| 2128 | .await | 2161 | .await |
| 2129 | .expect("write BlobRequest"); | 2162 | .expect("write BlobRequest"); |
| 2130 | let _ = send.finish(); | 2163 | let _ = send.finish(); |
| 2131 | - let header: BlobResponse = read_frame(&mut recv).await.expect("read BlobResponse"); | 2164 | + let header: BlobResponse = frame_or_fail(&mut recv, "read BlobResponse").await; |
| 2132 | let bytes = recv | 2165 | let bytes = recv |
| 2133 | .read_to_end(16 * 1024 * 1024) | 2166 | .read_to_end(16 * 1024 * 1024) |
| 2134 | .await | 2167 | .await |
| @@ -2343,7 +2376,7 @@ async fn a_body_nobody_reads_is_reset_rather_than_left_streaming_forever() { | |||
| 2343 | .await | 2376 | .await |
| 2344 | .expect("write BlobRequest"); | 2377 | .expect("write BlobRequest"); |
| 2345 | let _ = send.finish(); | 2378 | let _ = send.finish(); |
| 2346 | - let header: BlobResponse = read_frame(&mut recv).await.expect("read BlobResponse"); | 2379 | + let header: BlobResponse = frame_or_fail(&mut recv, "read BlobResponse").await; |
| 2347 | assert!( | 2380 | assert!( |
| 2348 | matches!(header, BlobResponse::Ok { .. }), | 2381 | matches!(header, BlobResponse::Ok { .. }), |
| 2349 | "the read was authorized: {}", | 2382 | "the read was authorized: {}", |
| @@ -2770,7 +2803,6 @@ async fn a_dispatch_is_traced_by_capability_and_a_refused_handshake_is_counted() | |||
| 2770 | ); | 2803 | ); |
| 2771 | } | 2804 | } |
| 2772 | 2805 | ||
| 2773 | - | ||
| 2774 | // ---------------------------------------------------------------- rag ----- | 2806 | // ---------------------------------------------------------------- rag ----- |
| 2775 | 2807 | ||
| 2776 | /// Open a RAG thread for a fresh user. Returns (session cookie, thread id). | 2808 | /// Open a RAG thread for a fresh user. Returns (session cookie, thread id). |
| @@ -2829,7 +2861,9 @@ async fn the_rag_request_carries_the_askers_scope_and_role() { | |||
| 2829 | let service = connect_service( | 2861 | let service = connect_service( |
| 2830 | &bridge, | 2862 | &bridge, |
| 2831 | hello("rag", &[AI_RAG_CHAT_CAPABILITY]), | 2863 | hello("rag", &[AI_RAG_CHAT_CAPABILITY]), |
| 2832 | - Behaviour::Answer(json!({ "text": "cevap", "abstained": false, "reason": "", "citations": [] })), | 2864 | + Behaviour::Answer( |
| 2865 | + json!({ "text": "cevap", "abstained": false, "reason": "", "citations": [] }), | ||
| 2866 | + ), | ||
| 2833 | ) | 2867 | ) |
| 2834 | .await; | 2868 | .await; |
| 2835 | await_workers(&bridge, 1).await; | 2869 | await_workers(&bridge, 1).await; |
| @@ -3081,7 +3115,10 @@ async fn a_rag_reply_past_the_citation_caps_fails_the_turn() { | |||
| 3081 | let turn = rag_settled(&app, &cookie, &thread, &mid).await; | 3115 | let turn = rag_settled(&app, &cookie, &thread, &mid).await; |
| 3082 | assert_eq!(turn["status"], "failed", "{turn}"); | 3116 | assert_eq!(turn["status"], "failed", "{turn}"); |
| 3083 | assert_eq!(turn["error_code"], "bad_reply", "{turn}"); | 3117 | assert_eq!(turn["error_code"], "bad_reply", "{turn}"); |
| 3084 | - assert_eq!(turn["content"], "", "nothing of the over-cap answer is stored"); | 3118 | + assert_eq!( |
| 3119 | + turn["content"], "", | ||
| 3120 | + "nothing of the over-cap answer is stored" | ||
| 3121 | + ); | ||
| 3085 | } | 3122 | } |
| 3086 | 3123 | ||
| 3087 | /// The second axis of the same bound: **one** citation is under the | 3124 | /// The second axis of the same bound: **one** citation is under the |
| @@ -3530,9 +3567,11 @@ async fn capability_call( | |||
| 3530 | request: CapabilityRequest, | 3567 | request: CapabilityRequest, |
| 3531 | ) -> CapabilityResponse { | 3568 | ) -> CapabilityResponse { |
| 3532 | let (mut send, mut recv) = conn.open_bi().await.expect("capability stream"); | 3569 | let (mut send, mut recv) = conn.open_bi().await.expect("capability stream"); |
| 3533 | - write_frame(&mut send, &request).await.expect("write CapabilityRequest"); | 3570 | + write_frame(&mut send, &request) |
| 3571 | + .await | ||
| 3572 | + .expect("write CapabilityRequest"); | ||
| 3534 | let _ = send.finish(); | 3573 | let _ = send.finish(); |
| 3535 | - read_frame(&mut recv).await.expect("read CapabilityResponse") | 3574 | + frame_or_fail(&mut recv, "read CapabilityResponse").await |
| 3536 | } | 3575 | } |
| 3537 | 3576 | ||
| 3538 | fn insight_call(capability: &str, school: &str, payload: Value) -> CapabilityRequest { | 3577 | fn insight_call(capability: &str, school: &str, payload: Value) -> CapabilityRequest { |
| @@ -3584,7 +3623,13 @@ fn summary_payload(student: &str, retain_until: i64) -> Value { | |||
| 3584 | /// student's id — the fixture every test below needs. | 3623 | /// student's id — the fixture every test below needs. |
| 3585 | async fn insight_fixture( | 3624 | async fn insight_fixture( |
| 3586 | bridge: &AiBridge, | 3625 | bridge: &AiBridge, |
| 3587 | -) -> (FakeService, Router, hezarfen_backend::database::Database, String, String) { | 3626 | +) -> ( |
| 3627 | + FakeService, | ||
| 3628 | + Router, | ||
| 3629 | + hezarfen_backend::database::Database, | ||
| 3630 | + String, | ||
| 3631 | + String, | ||
| 3632 | +) { | ||
| 3588 | let service = | 3633 | let service = |
| 3589 | connect_service(bridge, hello("zeka", &["insight.refresh"]), Behaviour::Echo).await; | 3634 | connect_service(bridge, hello("zeka", &["insight.refresh"]), Behaviour::Echo).await; |
| 3590 | await_workers(bridge, 1).await; | 3635 | await_workers(bridge, 1).await; |
| @@ -3609,11 +3654,19 @@ async fn a_capability_call_writes_the_row_the_schools_own_read_door_serves() { | |||
| 3609 | ), | 3654 | ), |
| 3610 | ) | 3655 | ) |
| 3611 | .await; | 3656 | .await; |
| 3612 | - let CapabilityResponse::Ok { payload, school, id } = answer else { | 3657 | + let CapabilityResponse::Ok { |
| 3658 | + payload, | ||
| 3659 | + school, | ||
| 3660 | + id, | ||
| 3661 | + } = answer | ||
| 3662 | + else { | ||
| 3613 | panic!("expected the write to land: {answer:?}"); | 3663 | panic!("expected the write to land: {answer:?}"); |
| 3614 | }; | 3664 | }; |
| 3615 | assert_eq!(id, format!("trace-{AI_INSIGHT_SUMMARY_UPSERT_CAPABILITY}")); | 3665 | assert_eq!(id, format!("trace-{AI_INSIGHT_SUMMARY_UPSERT_CAPABILITY}")); |
| 3616 | - assert_eq!(school, DEMO_SLUG, "the answer echoes the school the frame named"); | 3666 | + assert_eq!( |
| 3667 | + school, DEMO_SLUG, | ||
| 3668 | + "the answer echoes the school the frame named" | ||
| 3669 | + ); | ||
| 3617 | assert_eq!(payload["written"], 1); | 3670 | assert_eq!(payload["written"], 1); |
| 3618 | 3671 | ||
| 3619 | // The same row is what the nest's own read door serves the school's staff | 3672 | // The same row is what the nest's own read door serves the school's staff |
| @@ -3658,7 +3711,10 @@ async fn the_insight_ledger_and_pending_list_round_trip_over_the_bridge() { | |||
| 3658 | "failed_modules": ["segment"], | 3711 | "failed_modules": ["segment"], |
| 3659 | } }), | 3712 | } }), |
| 3660 | ); | 3713 | ); |
| 3661 | - assert_eq!(ok_capability(capability_call(&service.conn, run).await)["written"], 1); | 3714 | + assert_eq!( |
| 3715 | + ok_capability(capability_call(&service.conn, run).await)["written"], | ||
| 3716 | + 1 | ||
| 3717 | + ); | ||
| 3662 | 3718 | ||
| 3663 | let pending = ok_capability( | 3719 | let pending = ok_capability( |
| 3664 | capability_call( | 3720 | capability_call( |
| @@ -3730,8 +3786,12 @@ async fn the_sweep_and_purge_capabilities_answer_per_table_verdicts() { | |||
| 3730 | #[tokio::test] | 3786 | #[tokio::test] |
| 3731 | async fn a_capability_call_cannot_touch_another_schools_rows() { | 3787 | async fn a_capability_call_cannot_touch_another_schools_rows() { |
| 3732 | let bridge = bridge().await; | 3788 | let bridge = bridge().await; |
| 3733 | - let service = | 3789 | + let service = connect_service( |
| 3734 | - connect_service(&bridge, hello("zeka", &["insight.refresh"]), Behaviour::Echo).await; | 3790 | + &bridge, |
| 3791 | + hello("zeka", &["insight.refresh"]), | ||
| 3792 | + Behaviour::Echo, | ||
| 3793 | + ) | ||
| 3794 | + .await; | ||
| 3735 | await_workers(&bridge, 1).await; | 3795 | await_workers(&bridge, 1).await; |
| 3736 | let (app, demo_db, tenants) = common::app_with_ai_tenants(Some(bridge.clone())).await; | 3796 | let (app, demo_db, tenants) = common::app_with_ai_tenants(Some(bridge.clone())).await; |
| 3737 | let _mudur = common::login_as(&app, &demo_db, "mudur", "manager").await; | 3797 | let _mudur = common::login_as(&app, &demo_db, "mudur", "manager").await; |
| @@ -3739,7 +3799,12 @@ async fn a_capability_call_cannot_touch_another_schools_rows() { | |||
| 3739 | let student = common::me_id(&app, &ayse).await; | 3799 | let student = common::me_id(&app, &ayse).await; |
| 3740 | let beta = Slug::try_new("beta").unwrap(); | 3800 | let beta = Slug::try_new("beta").unwrap(); |
| 3741 | let beta_db = tenants | 3801 | let beta_db = tenants |
| 3742 | - .create(SchoolId::generate(), &beta, "Beta College", ModuleSet::all()) | 3802 | + .create( |
| 3803 | + SchoolId::generate(), | ||
| 3804 | + &beta, | ||
| 3805 | + "Beta College", | ||
| 3806 | + ModuleSet::all(), | ||
| 3807 | + ) | ||
| 3743 | .await | 3808 | .await |
| 3744 | .expect("beta"); | 3809 | .expect("beta"); |
| 3745 | 3810 | ||
| @@ -3777,7 +3842,11 @@ async fn a_capability_call_refuses_unknown_names_and_payloads_that_do_not_fit() | |||
| 3777 | 3842 | ||
| 3778 | // A name nobody serves — no prefix match, no fallback: the shape that | 3843 | // A name nobody serves — no prefix match, no fallback: the shape that |
| 3779 | // would make this a generic door is the shape that is missing. | 3844 | // would make this a generic door is the shape that is missing. |
| 3780 | - let unknown = insight_call("insight.database.query", DEMO_SLUG, json!({ "sql": "SELECT 1" })); | 3845 | + let unknown = insight_call( |
| 3846 | + "insight.database.query", | ||
| 3847 | + DEMO_SLUG, | ||
| 3848 | + json!({ "sql": "SELECT 1" }), | ||
| 3849 | + ); | ||
| 3781 | let (code, message) = refused_capability(capability_call(&service.conn, unknown).await); | 3850 | let (code, message) = refused_capability(capability_call(&service.conn, unknown).await); |
| 3782 | assert_eq!(code, "unknown_capability"); | 3851 | assert_eq!(code, "unknown_capability"); |
| 3783 | assert!(message.contains("insight.database.query"), "{message}"); | 3852 | assert!(message.contains("insight.database.query"), "{message}"); |
| @@ -3806,13 +3875,22 @@ async fn a_capability_call_refuses_unknown_names_and_payloads_that_do_not_fit() | |||
| 3806 | #[tokio::test] | 3875 | #[tokio::test] |
| 3807 | async fn the_school_directory_is_the_one_deployment_scoped_operation() { | 3876 | async fn the_school_directory_is_the_one_deployment_scoped_operation() { |
| 3808 | let bridge = bridge().await; | 3877 | let bridge = bridge().await; |
| 3809 | - let service = | 3878 | + let service = connect_service( |
| 3810 | - connect_service(&bridge, hello("zeka", &["insight.refresh"]), Behaviour::Echo).await; | 3879 | + &bridge, |
| 3880 | + hello("zeka", &["insight.refresh"]), | ||
| 3881 | + Behaviour::Echo, | ||
| 3882 | + ) | ||
| 3883 | + .await; | ||
| 3811 | await_workers(&bridge, 1).await; | 3884 | await_workers(&bridge, 1).await; |
| 3812 | let (app, _db, tenants) = common::app_with_ai_tenants(Some(bridge.clone())).await; | 3885 | let (app, _db, tenants) = common::app_with_ai_tenants(Some(bridge.clone())).await; |
| 3813 | let beta = Slug::try_new("beta").unwrap(); | 3886 | let beta = Slug::try_new("beta").unwrap(); |
| 3814 | tenants | 3887 | tenants |
| 3815 | - .create(SchoolId::generate(), &beta, "Beta College", ModuleSet::all()) | 3888 | + .create( |
| 3889 | + SchoolId::generate(), | ||
| 3890 | + &beta, | ||
| 3891 | + "Beta College", | ||
| 3892 | + ModuleSet::all(), | ||
| 3893 | + ) | ||
| 3816 | .await | 3894 | .await |
| 3817 | .expect("beta"); | 3895 | .expect("beta"); |
| 3818 | 3896 | ||
| @@ -3882,7 +3960,14 @@ async fn the_storage_doors_are_manager_only_and_write_the_callers_own_school() { | |||
| 3882 | ) | 3960 | ) |
| 3883 | .await; | 3961 | .await; |
| 3884 | assert_eq!(refused.status, StatusCode::FORBIDDEN, "{}", refused.body); | 3962 | assert_eq!(refused.status, StatusCode::FORBIDDEN, "{}", refused.body); |
| 3885 | - let anonymous = common::send(&app, "POST", "/insights/summaries", None, Some(body.clone())).await; | 3963 | + let anonymous = common::send( |
| 3964 | + &app, | ||
| 3965 | + "POST", | ||
| 3966 | + "/insights/summaries", | ||
| 3967 | + None, | ||
| 3968 | + Some(body.clone()), | ||
| 3969 | + ) | ||
| 3970 | + .await; | ||
| 3886 | assert_eq!(anonymous.status, StatusCode::UNAUTHORIZED); | 3971 | assert_eq!(anonymous.status, StatusCode::UNAUTHORIZED); |
| 3887 | 3972 | ||
| 3888 | // The same operation the bridge serves, on the caller's own school. | 3973 | // The same operation the bridge serves, on the caller's own school. |
| @@ -3913,7 +3998,12 @@ async fn the_storage_doors_are_manager_only_and_write_the_callers_own_school() { | |||
| 3913 | Some(json!({ "rows": over })), | 3998 | Some(json!({ "rows": over })), |
| 3914 | ) | 3999 | ) |
| 3915 | .await; | 4000 | .await; |
| 3916 | - assert_eq!(too_many.status, StatusCode::PAYLOAD_TOO_LARGE, "{}", too_many.body); | 4001 | + assert_eq!( |
| 4002 | + too_many.status, | ||
| 4003 | + StatusCode::PAYLOAD_TOO_LARGE, | ||
| 4004 | + "{}", | ||
| 4005 | + too_many.body | ||
| 4006 | + ); | ||
| 3917 | 4007 | ||
| 3918 | // The run ledger's POST and the existing GET share one path. | 4008 | // The run ledger's POST and the existing GET share one path. |
| 3919 | let run = common::send( | 4009 | let run = common::send( |
| @@ -4062,7 +4152,7 @@ async fn podcast_upload( | |||
| 4062 | .expect("write BlobUploadRequest"); | 4152 | .expect("write BlobUploadRequest"); |
| 4063 | send.write_all(body).await.expect("write the bytes"); | 4153 | send.write_all(body).await.expect("write the bytes"); |
| 4064 | let _ = send.finish(); | 4154 | let _ = send.finish(); |
| 4065 | - read_frame(&mut recv).await.expect("read BlobUploadResponse") | 4155 | + frame_or_fail(&mut recv, "read BlobUploadResponse").await |
| 4066 | } | 4156 | } |
| 4067 | 4157 | ||
| 4068 | fn upload_key(answer: BlobUploadResponse) -> (String, u64) { | 4158 | fn upload_key(answer: BlobUploadResponse) -> (String, u64) { |
| @@ -4112,7 +4202,11 @@ async fn the_report_and_upload_handshake_lands_on_the_backends_own_row() { | |||
| 4112 | // `done` means a stored episode: a report that claims one before the | 4202 | // `done` means a stored episode: a report that claims one before the |
| 4113 | // upload is refused, and nothing about the row moves. | 4203 | // upload is refused, and nothing about the row moves. |
| 4114 | let (code, _) = refused_capability( | 4204 | let (code, _) = refused_capability( |
| 4115 | - capability_call(conn, report_call(DEMO_SLUG, &job, &user, "done", "done", 1.0)).await, | 4205 | + capability_call( |
| 4206 | + conn, | ||
| 4207 | + report_call(DEMO_SLUG, &job, &user, "done", "done", 1.0), | ||
| 4208 | + ) | ||
| 4209 | + .await, | ||
| 4116 | ); | 4210 | ); |
| 4117 | assert_eq!(code, "audio_missing"); | 4211 | assert_eq!(code, "audio_missing"); |
| 4118 | assert_eq!(podcast_row(&db, &job).await.0, "running"); | 4212 | assert_eq!(podcast_row(&db, &job).await.0, "running"); |
| @@ -4143,9 +4237,8 @@ async fn the_report_and_upload_handshake_lands_on_the_backends_own_row() { | |||
| 4143 | // The upload: bytes on disk exactly as sent, key keyed by the job id, row | 4237 | // The upload: bytes on disk exactly as sent, key keyed by the job id, row |
| 4144 | // stamped with the reference and the duration. | 4238 | // stamped with the reference and the duration. |
| 4145 | let body = blob_bytes(200 * 1024); | 4239 | let body = blob_bytes(200 * 1024); |
| 4146 | - let (key, size) = upload_key( | 4240 | + let (key, size) = |
| 4147 | - podcast_upload(conn, DEMO_SLUG, &job, "bolum.mp3", "audio/mpeg", &body).await, | 4241 | + upload_key(podcast_upload(conn, DEMO_SLUG, &job, "bolum.mp3", "audio/mpeg", &body).await); |
| 4148 | - ); | ||
| 4149 | assert_eq!(size, body.len() as u64); | 4242 | assert_eq!(size, body.len() as u64); |
| 4150 | assert_eq!(key, format!("podcast/{job}.mp3")); | 4243 | assert_eq!(key, format!("podcast/{job}.mp3")); |
| 4151 | let stored = common::files_dir().join(DEMO_SLUG).join(&key); | 4244 | let stored = common::files_dir().join(DEMO_SLUG).join(&key); |
| @@ -4157,7 +4250,11 @@ async fn the_report_and_upload_handshake_lands_on_the_backends_own_row() { | |||
| 4157 | // Now — and only now — `done` is accepted. | 4250 | // Now — and only now — `done` is accepted. |
| 4158 | assert_eq!( | 4251 | assert_eq!( |
| 4159 | ok_capability( | 4252 | ok_capability( |
| 4160 | - capability_call(conn, report_call(DEMO_SLUG, &job, &user, "done", "done", 1.0)).await | 4253 | + capability_call( |
| 4254 | + conn, | ||
| 4255 | + report_call(DEMO_SLUG, &job, &user, "done", "done", 1.0) | ||
| 4256 | + ) | ||
| 4257 | + .await | ||
| 4161 | )["stored"], | 4258 | )["stored"], |
| 4162 | true | 4259 | true |
| 4163 | ); | 4260 | ); |
| @@ -4166,8 +4263,11 @@ async fn the_report_and_upload_handshake_lands_on_the_backends_own_row() { | |||
| 4166 | // And a job the backend never minted is `unknown_job`. | 4263 | // And a job the backend never minted is `unknown_job`. |
| 4167 | let stranger = hezarfen_backend::domain::monotonic_id::next_uuid().to_string(); | 4264 | let stranger = hezarfen_backend::domain::monotonic_id::next_uuid().to_string(); |
| 4168 | let (code, _) = refused_capability( | 4265 | let (code, _) = refused_capability( |
| 4169 | - capability_call(conn, report_call(DEMO_SLUG, &stranger, &user, "running", "ocr", 0.1)) | 4266 | + capability_call( |
| 4170 | - .await, | 4267 | + conn, |
| 4268 | + report_call(DEMO_SLUG, &stranger, &user, "running", "ocr", 0.1), | ||
| 4269 | + ) | ||
| 4270 | + .await, | ||
| 4171 | ); | 4271 | ); |
| 4172 | assert_eq!(code, "unknown_job"); | 4272 | assert_eq!(code, "unknown_job"); |
| 4173 | } | 4273 | } |
| @@ -4213,7 +4313,15 @@ async fn a_report_or_upload_cannot_reach_another_schools_job() { | |||
| 4213 | 4313 | ||
| 4214 | let body = blob_bytes(4096); | 4314 | let body = blob_bytes(4096); |
| 4215 | let (code, _) = upload_refusal( | 4315 | let (code, _) = upload_refusal( |
| 4216 | - podcast_upload(&service.conn, DEMO_SLUG, &job, "bolum.mp3", "audio/mpeg", &body).await, | 4316 | + podcast_upload( |
| 4317 | + &service.conn, | ||
| 4318 | + DEMO_SLUG, | ||
| 4319 | + &job, | ||
| 4320 | + "bolum.mp3", | ||
| 4321 | + "audio/mpeg", | ||
| 4322 | + &body, | ||
| 4323 | + ) | ||
| 4324 | + .await, | ||
| 4217 | ); | 4325 | ); |
| 4218 | assert_eq!(code, "unknown_job"); | 4326 | assert_eq!(code, "unknown_job"); |
| 4219 | let leaked = common::files_dir() | 4327 | let leaked = common::files_dir() |
| @@ -4256,13 +4364,18 @@ async fn an_upload_past_the_audio_ceiling_is_refused_before_a_byte_is_read() { | |||
| 4256 | size: PODCAST_AUDIO_MAX_BYTES as u64 + 1, | 4364 | size: PODCAST_AUDIO_MAX_BYTES as u64 + 1, |
| 4257 | duration_secs: None, | 4365 | duration_secs: None, |
| 4258 | }; | 4366 | }; |
| 4259 | - write_frame(&mut send, &request).await.expect("write the frame"); | 4367 | + write_frame(&mut send, &request) |
| 4260 | - let answer: BlobUploadResponse = read_frame(&mut recv).await.expect("read the answer"); | 4368 | + .await |
| 4369 | + .expect("write the frame"); | ||
| 4370 | + let answer: BlobUploadResponse = frame_or_fail(&mut recv, "read the upload answer").await; | ||
| 4261 | let (code, _) = upload_refusal(answer); | 4371 | let (code, _) = upload_refusal(answer); |
| 4262 | assert_eq!(code, "invalid_payload"); | 4372 | assert_eq!(code, "invalid_payload"); |
| 4263 | let _ = send.finish(); | 4373 | let _ = send.finish(); |
| 4264 | 4374 | ||
| 4265 | - assert!(podcast_row(&db, &job).await.3.is_none(), "the row names no audio"); | 4375 | + assert!( |
| 4376 | + podcast_row(&db, &job).await.3.is_none(), | ||
| 4377 | + "the row names no audio" | ||
| 4378 | + ); | ||
| 4266 | let stored = common::files_dir().join(format!("podcast/{job}.mp3")); | 4379 | let stored = common::files_dir().join(format!("podcast/{job}.mp3")); |
| 4267 | assert!(!stored.exists(), "an oversize upload stores nothing"); | 4380 | assert!(!stored.exists(), "an oversize upload stores nothing"); |
| 4268 | } | 4381 | } |
tests/ai_protocol.rsmodified+17 -7
| @@ -138,7 +138,7 @@ mod raw { | |||
| 138 | send.write_all(&frame(hello_body)) | 138 | send.write_all(&frame(hello_body)) |
| 139 | .await | 139 | .await |
| 140 | .expect("write Hello"); | 140 | .expect("write Hello"); |
| 141 | - let (greeting, _) = read_frame(&mut recv).await.expect("read Greeting"); | 141 | + let (greeting, _) = frame_or_fail(&mut recv, "read Greeting").await; |
| 142 | Service { | 142 | Service { |
| 143 | _endpoint: endpoint, | 143 | _endpoint: endpoint, |
| 144 | conn, | 144 | conn, |
| @@ -164,7 +164,7 @@ mod raw { | |||
| 164 | .accept_bi() | 164 | .accept_bi() |
| 165 | .await | 165 | .await |
| 166 | .expect("bridge opened a request stream"); | 166 | .expect("bridge opened a request stream"); |
| 167 | - let (request, bytes) = read_frame(&mut recv).await.expect("read Request"); | 167 | + let (request, bytes) = frame_or_fail(&mut recv, "read Request").await; |
| 168 | (request, bytes, send, recv) | 168 | (request, bytes, send, recv) |
| 169 | } | 169 | } |
| 170 | 170 | ||
| @@ -185,7 +185,7 @@ mod raw { | |||
| 185 | .await | 185 | .await |
| 186 | .expect("write ApiRequest"); | 186 | .expect("write ApiRequest"); |
| 187 | let _ = send.finish(); | 187 | let _ = send.finish(); |
| 188 | - read_frame(&mut recv).await.expect("read ApiResponse") | 188 | + frame_or_fail(&mut recv, "read ApiResponse").await |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | /// Send one frame verbatim on a fresh *client*-initiated stream, read the | 191 | /// Send one frame verbatim on a fresh *client*-initiated stream, read the |
| @@ -198,7 +198,7 @@ mod raw { | |||
| 198 | .await | 198 | .await |
| 199 | .expect("write BlobRequest"); | 199 | .expect("write BlobRequest"); |
| 200 | let _ = send.finish(); | 200 | let _ = send.finish(); |
| 201 | - let (header, bytes) = read_frame(&mut recv).await.expect("read BlobResponse"); | 201 | + let (header, bytes) = frame_or_fail(&mut recv, "read BlobResponse").await; |
| 202 | // Deliberately asks for more than the header promised: a stream that | 202 | // Deliberately asks for more than the header promised: a stream that |
| 203 | // wrote one byte too many would show up here, not as a silent pass. | 203 | // wrote one byte too many would show up here, not as a silent pass. |
| 204 | let body = recv | 204 | let body = recv |
| @@ -208,6 +208,17 @@ mod raw { | |||
| 208 | (header, bytes, body) | 208 | (header, bytes, body) |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | + /// One frame, **bounded**: the raw client must fail a stalled bridge by | ||
| 212 | + /// name in seconds rather than hang the run (and the serialized deploy | ||
| 213 | + /// behind it). `what` is the wait this call is doing, for the panic. | ||
| 214 | + pub async fn frame_or_fail(recv: &mut quinn::RecvStream, what: &str) -> (Value, Vec<u8>) { | ||
| 215 | + match tokio::time::timeout(Duration::from_secs(10), read_frame(recv)).await { | ||
| 216 | + Ok(Ok(frame)) => frame, | ||
| 217 | + Ok(Err(err)) => panic!("{what}: the frame could not be read: {err}"), | ||
| 218 | + Err(_) => panic!("{what}: no frame arrived within 10s — the bridge did not answer"), | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + | ||
| 211 | /// The set of top-level keys of a JSON object, sorted. | 222 | /// The set of top-level keys of a JSON object, sorted. |
| 212 | pub fn keys(value: &Value) -> Vec<String> { | 223 | pub fn keys(value: &Value) -> Vec<String> { |
| 213 | let mut k: Vec<String> = value | 224 | let mut k: Vec<String> = value |
| @@ -326,7 +337,7 @@ async fn a_frame_split_across_many_writes_is_reassembled() { | |||
| 326 | tokio::task::yield_now().await; | 337 | tokio::task::yield_now().await; |
| 327 | } | 338 | } |
| 328 | 339 | ||
| 329 | - let (greeting, _) = raw::read_frame(&mut recv).await.expect("still welcomed"); | 340 | + let (greeting, _) = raw::frame_or_fail(&mut recv, "still welcomed").await; |
| 330 | assert_eq!(greeting["type"], "welcome"); | 341 | assert_eq!(greeting["type"], "welcome"); |
| 331 | await_workers(&bridge, 1).await; | 342 | await_workers(&bridge, 1).await; |
| 332 | } | 343 | } |
| @@ -1733,8 +1744,7 @@ async fn the_capability_shape_does_not_steal_the_shapes_that_existed_before() { | |||
| 1733 | assert_eq!(answer["payload"]["students"], json!([]), "{answer}"); | 1744 | assert_eq!(answer["payload"]["students"], json!([]), "{answer}"); |
| 1734 | 1745 | ||
| 1735 | // Neither: the same api-read refusal as before this shape existed. | 1746 | // Neither: the same api-read refusal as before this shape existed. |
| 1736 | - let (answer, _) = | 1747 | + let (answer, _) = raw::api_read(&service.conn, br#"{"id":"t-neither","school":"demo"}"#).await; |
| 1737 | - raw::api_read(&service.conn, br#"{"id":"t-neither","school":"demo"}"#).await; | ||
| 1738 | assert_eq!(answer["outcome"], "err", "{answer}"); | 1748 | assert_eq!(answer["outcome"], "err", "{answer}"); |
| 1739 | assert_eq!(answer["code"], "malformed"); | 1749 | assert_eq!(answer["code"], "malformed"); |
| 1740 | } | 1750 | } |
tests/podcast.rsmodified+19 -5
| @@ -39,6 +39,22 @@ use uuid::Uuid; | |||
| 39 | 39 | ||
| 40 | const TOKEN: &str = "shared-ai-token"; | 40 | const TOKEN: &str = "shared-ai-token"; |
| 41 | 41 | ||
| 42 | +/// One answer frame, **bounded**: the podcast service's ingest waits on a | ||
| 43 | +/// reporter/uploader handshake, and a bridge that never answers must fail | ||
| 44 | +/// this test by name in seconds rather than hang the run — a hung Test step | ||
| 45 | +/// holds the serialized deploy lock behind it. | ||
| 46 | +async fn frame_or_fail<T: serde::de::DeserializeOwned>( | ||
| 47 | + recv: &mut quinn::RecvStream, | ||
| 48 | + what: &str, | ||
| 49 | +) -> T { | ||
| 50 | + match tokio::time::timeout(std::time::Duration::from_secs(10), read_frame(recv)).await { | ||
| 51 | + Ok(Ok(frame)) => frame, | ||
| 52 | + Ok(Err(err)) => panic!("{what}: the frame could not be read: {err}"), | ||
| 53 | + Err(_) => panic!("{what}: no frame arrived within 10s — the bridge did not answer"), | ||
| 54 | + } | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | + | ||
| 42 | /// The two capabilities a live podcast worker offers. Status and result are | 58 | /// The two capabilities a live podcast worker offers. Status and result are |
| 43 | /// not capabilities any more — the backend answers those from its own row — so | 59 | /// not capabilities any more — the backend answers those from its own row — so |
| 44 | /// a service declaring only these serves every reading door. | 60 | /// a service declaring only these serves every reading door. |
| @@ -150,7 +166,7 @@ async fn connect_service(bridge: &AiBridge, hello: Hello, behaviour: Behaviour) | |||
| 150 | .expect("QUIC handshake"); | 166 | .expect("QUIC handshake"); |
| 151 | let (mut send, mut recv) = conn.open_bi().await.expect("control stream"); | 167 | let (mut send, mut recv) = conn.open_bi().await.expect("control stream"); |
| 152 | write_frame(&mut send, &hello).await.expect("send Hello"); | 168 | write_frame(&mut send, &hello).await.expect("send Hello"); |
| 153 | - let greeting: Greeting = read_frame(&mut recv).await.expect("read Greeting"); | 169 | + let greeting: Greeting = frame_or_fail(&mut recv, "read Greeting").await; |
| 154 | match greeting { | 170 | match greeting { |
| 155 | Greeting::Welcome { protocol, .. } => assert_eq!(protocol, AI_PROTOCOL), | 171 | Greeting::Welcome { protocol, .. } => assert_eq!(protocol, AI_PROTOCOL), |
| 156 | other => panic!("expected a welcome, got {other:?}"), | 172 | other => panic!("expected a welcome, got {other:?}"), |
| @@ -380,7 +396,7 @@ async fn capability_call(conn: &quinn::Connection, request: Value) -> Value { | |||
| 380 | let (mut send, mut recv) = conn.open_bi().await.expect("client-initiated stream"); | 396 | let (mut send, mut recv) = conn.open_bi().await.expect("client-initiated stream"); |
| 381 | write_frame(&mut send, &request).await.expect("write the call"); | 397 | write_frame(&mut send, &request).await.expect("write the call"); |
| 382 | let _ = send.finish(); | 398 | let _ = send.finish(); |
| 383 | - read_frame::<_, Value>(&mut recv).await.expect("read the answer") | 399 | + frame_or_fail::<Value>(&mut recv, "read the answer").await |
| 384 | } | 400 | } |
| 385 | 401 | ||
| 386 | /// One audio upload on a fresh client-initiated stream: the header frame, | 402 | /// One audio upload on a fresh client-initiated stream: the header frame, |
| @@ -392,9 +408,7 @@ async fn blob_upload(conn: &quinn::Connection, frame: Value, body: &[u8]) -> Val | |||
| 392 | .expect("write the upload frame"); | 408 | .expect("write the upload frame"); |
| 393 | send.write_all(body).await.expect("write the audio bytes"); | 409 | send.write_all(body).await.expect("write the audio bytes"); |
| 394 | let _ = send.finish(); | 410 | let _ = send.finish(); |
| 395 | - read_frame::<_, Value>(&mut recv) | 411 | + frame_or_fail::<Value>(&mut recv, "read the upload answer").await |
| 396 | - .await | ||
| 397 | - .expect("read the upload answer") | ||
| 398 | } | 412 | } |
| 399 | 413 | ||
| 400 | /// Assert one report was stored: the answer's payload echoes the job and says | 414 | /// Assert one report was stored: the answer's payload echoes the job and says |