Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test: remove hosted orchestration integration suites\n\n

Steven Enamakelea71818261fa
diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.md
index 2bc66b1c27..0f5b3f666b 100644
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@ -496,7 +496,7 @@ End-to-end coverage of the agent harness via the web-chat RPC surface against an
| 11.2.2 | Memory Graph Controls | WD | `insights-dashboard.spec.ts` | ✅ | Brain Graph tab actions toolbar |
| 11.2.3 | Memory Graph Surface | WD | `insights-dashboard.spec.ts` | ✅ | Populated SVG or empty-state graph surface |
-### 11.3 Hosted Orchestration
+### 11.3 Local Medulla Supervision
| ID | Feature | Layer | Test path(s) | Status | Notes |
| ------ | --------------------------------------------------------------------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
diff --git a/docs/tinyagents-drift-ledger.md b/docs/tinyagents-drift-ledger.md
index e1b0164cc1..b1a2864afa 100644
--- a/docs/tinyagents-drift-ledger.md
+++ b/docs/tinyagents-drift-ledger.md
@@ -179,14 +179,6 @@ struct with the old field. Because no PR existed pre-#4769, this was never
CI-tested; the lib-test target (`cargo test --lib`) did not compile, which would
fail CI `rust-core-coverage`. Fixed by wrapping each site in
`TurnModelSource::new(provider)` and correcting the `AgentBuilder` field access.
-Touching `agent_orchestration/` test files pulled the orchestration domain into
-CI `rust-core-coverage`'s scope, which surfaced a **separate pre-existing**
-upstream breakage: `tests/orchestration_effect_executor_e2e.rs` (added by #4738)
-still called `dispatch_device_tool`/`handle_tool_call` with the old sync 2-arg
-signatures after #4753 made them `async`/3-arg — broken identically on
-`upstream/main`. Fixed the two tests to `#[tokio::test]` + `.await` + the
-`cycle_id` arg (gate-bypassed for non-local-exec tools).
-
**Behavior-level test failures (5, surfaced once the suite compiled): all stale
tests, no code regression.** Motion A's "zero behavior change" holds for the
actual runtime contract — the failing tests were written against pre-migration
diff --git a/tests/orchestration_effect_executor_e2e.rs b/tests/orchestration_effect_executor_e2e.rs
deleted file mode 100644
index 9b07a375b9..0000000000
--- a/tests/orchestration_effect_executor_e2e.rs
+++ /dev/null
@@ -1,110 +0,0 @@
-//! Phase 1 client effect-executor coverage: parsing the hosted brain's
-//! `orch:effect:send_dm` frame, the ack frame it returns, the at-least-once
-//! callId dedupe, and the device-tool manifest. Lives in an integration crate
-//! (links the compiled lib) because the root cfg(test) build is blocked by
-//! unrelated stale test modules at this checkout.
-
-use openhuman_core::openhuman::hosted::orchestration::effect_executor::{
- device_tool_manifest, dispatch_device_tool, effect_result_frame, handle_tool_call,
- is_duplicate_call, parse_send_dm, parse_tool_call, tool_result_frame,
-};
-use serde_json::json;
-
-#[test]
-fn parses_a_well_formed_send_dm_frame() {
- let frame = json!({
- "cycleId": "cyc:agent-alice:sess-1:3",
- "callId": "cyc:agent-alice:sess-1:3:send_dm:0",
- "counterpartAgentId": "agent-alice",
- "sessionId": "sess-1",
- "body": "on it"
- });
- let effect = parse_send_dm(&frame).expect("parse");
- assert_eq!(effect.call_id, "cyc:agent-alice:sess-1:3:send_dm:0");
- assert_eq!(effect.counterpart_agent_id, "agent-alice");
- assert_eq!(effect.session_id, "sess-1");
- assert_eq!(effect.body, "on it");
-}
-
-#[test]
-fn rejects_a_frame_missing_required_fields() {
- let frame = json!({ "cycleId": "c", "body": "hi" }); // no callId / counterpartAgentId
- assert!(parse_send_dm(&frame).is_err());
-}
-
-#[test]
-fn ack_frame_shapes_ok_and_error_cases() {
- assert_eq!(
- effect_result_frame("call-1", true, None),
- json!({ "callId": "call-1", "ok": true, "error": null })
- );
- assert_eq!(
- effect_result_frame("call-2", false, Some("device offline")),
- json!({ "callId": "call-2", "ok": false, "error": "device offline" })
- );
-}
-
-#[test]
-fn dedupe_reports_first_call_new_and_repeat_duplicate() {
- // Unique id so the process-global dedupe set can't collide with other tests.
- let id = "dedupe-test-unique-call-id-abc123";
- assert!(!is_duplicate_call(id), "first sighting is not a duplicate");
- assert!(is_duplicate_call(id), "second sighting is a duplicate");
-}
-
-#[test]
-fn manifest_declares_a_queryable_device_tool() {
- let manifest = device_tool_manifest();
- let tools = manifest["tools"].as_array().expect("tools array");
- assert!(tools.iter().any(|t| t["name"] == "device_status"));
-}
-
-#[test]
-fn parses_a_tool_call_frame() {
- let frame = json!({
- "cycleId": "c",
- "callId": "c:tool_call:0",
- "name": "device_status",
- "args": {}
- });
- let parsed = parse_tool_call(&frame).expect("parse");
- assert_eq!(parsed.call_id, "c:tool_call:0");
- assert_eq!(parsed.name, "device_status");
-}
-
-#[tokio::test]
-async fn dispatches_device_status_and_rejects_unknown_tools() {
- let status = dispatch_device_tool("device_status", &json!({}), "master:session:cycle")
- .await
- .expect("ok");
- assert!(status["version"].is_string());
- assert!(status["platform"].is_string());
-
- assert!(
- dispatch_device_tool("rm_rf", &json!({}), "master:session:cycle")
- .await
- .is_err()
- );
-}
-
-#[tokio::test]
-async fn handle_tool_call_builds_result_frame() {
- let frame = json!({
- "cycleId": "master:session:cycle",
- "callId": "c:tool_call:0",
- "name": "device_status",
- "args": {}
- });
- let (call_id, result) = handle_tool_call(&frame).await.expect("handled");
- assert_eq!(call_id, "c:tool_call:0");
- assert_eq!(result["ok"], json!(true));
- assert!(result["result"]["platform"].is_string());
-}
-
-#[test]
-fn tool_result_frame_shapes_error_case() {
- assert_eq!(
- tool_result_frame("c1", false, json!(null), Some("boom")),
- json!({ "callId": "c1", "ok": false, "result": null, "error": "boom" })
- );
-}
diff --git a/tests/orchestration_exec_gate.rs b/tests/orchestration_exec_gate.rs
deleted file mode 100644
index dcacd32a82..0000000000
--- a/tests/orchestration_exec_gate.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-//! Integration coverage for the local-execution trust gate (`exec_gate`).
-//!
-//! Links the compiled lib (the root crate's `cfg(test)` build is blocked by
-//! unrelated stale test modules at this checkout — same reason the pushers are
-//! tested from integration tests). Asserts the device-authoritative rule: a
-//! local-execution device tool is authorized only for a Master-chat cycle.
-
-use openhuman_core::openhuman::hosted::orchestration::exec_gate::{
- cycle_is_master, cycle_target, is_local_execution_tool, record_cycle_origin,
-};
-use openhuman_core::openhuman::hosted::orchestration::types::LOCAL_MASTER_AGENT;
-
-#[test]
-fn master_cycle_is_authorized_a2a_and_unknown_are_denied() {
- // A Master-chat forward records the sentinel counterpart + its session.
- record_cycle_origin("gate-cyc-master", LOCAL_MASTER_AGENT, "master");
- // An A2A forward records the peer's real (base58) address + session.
- record_cycle_origin("gate-cyc-peer", "8xPeerBase58AddressExample", "sess-peer");
-
- assert!(
- cycle_is_master("gate-cyc-master"),
- "master cycle must authorize"
- );
- assert!(
- !cycle_is_master("gate-cyc-peer"),
- "A2A cycle must be denied"
- );
- // Fail closed: a cycle we never recorded (or a forged id) is not master.
- assert!(
- !cycle_is_master("gate-cyc-forged"),
- "unknown cycle must be denied"
- );
- // The completion router resolves the recorded (counterpart, session).
- assert_eq!(
- cycle_target("gate-cyc-master"),
- Some((LOCAL_MASTER_AGENT.to_string(), "master".to_string()))
- );
- assert_eq!(cycle_target("gate-cyc-forged"), None);
-}
-
-#[test]
-fn only_local_execution_tools_are_gated() {
- assert!(is_local_execution_tool("run_local_agent"));
- assert!(!is_local_execution_tool("device_status"));
-}
diff --git a/tests/orchestration_hosted_client.rs b/tests/orchestration_hosted_client.rs
deleted file mode 100644
index 0a69d61037..0000000000
--- a/tests/orchestration_hosted_client.rs
+++ /dev/null
@@ -1,193 +0,0 @@
-//! Unit coverage for the device-side hosted-orchestration client: the world-diff
-//! observation buffer, the world-observation note builder, and the evict-effect
-//! parsing. These paths need no backend, so they run in the plain integration
-//! crate (the root crate's `cfg(test)` build is gated elsewhere).
-
-use openhuman_core::openhuman::hosted::orchestration::effect_executor::{
- effect_result_frame, is_duplicate_call, parse_evict, release_call,
-};
-use openhuman_core::openhuman::hosted::orchestration::store;
-use openhuman_core::openhuman::hosted::orchestration::wire::OrchestrationEventEnvelopeWire;
-use openhuman_core::openhuman::hosted::orchestration::world_model::observe_ingest_note;
-
-// ── world_model: bounded, single-line, never leaks the body ───────────────────
-
-#[test]
-fn observe_ingest_note_summarises_without_the_body() {
- let note = observe_ingest_note("h-1", "@peer", "dm", "super secret plaintext body");
- // The body is summarised to a char count, never copied.
- assert!(!note.contains("super secret plaintext body"));
- assert!(note.contains("@peer"));
- assert!(note.contains("h-1"));
- assert!(note.contains("chars"));
- // Single line, bounded.
- assert!(!note.contains('\n'));
- assert!(note.chars().count() <= 240);
-}
-
-#[test]
-fn observe_ingest_note_defaults_empty_session_and_kind() {
- let note = observe_ingest_note("", "@peer", "", "");
- assert!(note.contains("master")); // empty session → master
- assert!(note.contains("message")); // empty kind → message
- assert!(note.contains("empty")); // empty body → "empty"
-}
-
-#[test]
-fn observe_ingest_note_collapses_newlines_and_clamps() {
- let long = "x".repeat(5000);
- let note = observe_ingest_note("h-1", "line1\nline2", "dm", &long);
- assert!(!note.contains('\n'));
- assert!(note.chars().count() <= 240);
-}
-
-// ── evict effect parsing + ack frame ──────────────────────────────────────────
-
-#[test]
-fn parse_evict_reads_the_backend_frame_shape() {
- let frame = serde_json::json!({
- "cycleId": "cyc:1",
- "callId": "cyc:1:evict:0",
- "sessionId": "h-1",
- "entries": [
- { "cycleId": "cyc:0", "summary": "user asked about billing" },
- { "cycleId": "cyc:1", "summary": "resolved via refund" },
- ],
- });
- let effect = parse_evict(&frame).expect("valid evict frame");
- assert_eq!(effect.call_id, "cyc:1:evict:0");
- assert_eq!(effect.session_id, "h-1");
- assert_eq!(effect.entries.len(), 2);
- assert_eq!(effect.entries[0].summary, "user asked about billing");
-}
-
-#[test]
-fn parse_evict_rejects_a_frame_without_call_id() {
- let frame = serde_json::json!({ "sessionId": "h-1", "entries": [] });
- assert!(parse_evict(&frame).is_err());
-}
-
-#[test]
-fn effect_result_frame_has_the_ack_shape() {
- let ok = effect_result_frame("c-1", true, None);
- assert_eq!(ok["callId"], "c-1");
- assert_eq!(ok["ok"], true);
- let err = effect_result_frame("c-2", false, Some("boom"));
- assert_eq!(err["ok"], false);
- assert_eq!(err["error"], "boom");
-}
-
-#[test]
-fn is_duplicate_call_is_true_only_on_the_second_sight() {
- let id = "unique-call-id-orchestration-hosted-test";
- assert!(!is_duplicate_call(id), "first sight is not a duplicate");
- assert!(is_duplicate_call(id), "second sight is a duplicate");
-}
-
-#[test]
-fn release_call_lets_a_failed_effect_be_retried() {
- // A claim whose effect FAILS is released so the hosted brain's redelivery
- // re-executes it, rather than the guard re-acking a stale success and dropping
- // the work. (Unique id so it can't collide with the other dedupe test's id in
- // the process-global set.)
- let id = "unique-call-id-orchestration-release-test";
- assert!(!is_duplicate_call(id), "first claim");
- assert!(
- is_duplicate_call(id),
- "still claimed while the effect is in flight"
- );
- release_call(id);
- assert!(
- !is_duplicate_call(id),
- "a released (failed) id is claimable again"
- );
-}
-
-// ── world_obs device buffer round-trip ────────────────────────────────────────
-
-#[test]
-fn world_obs_buffer_appends_monotonic_drains_fifo_and_deletes() {
- let tmp = tempfile::tempdir().unwrap();
- let ws = tmp.path().to_path_buf();
-
- // Append three observations; seq is globally monotonic.
- let (s1, s2, s3) = store::with_connection(&ws, |conn| {
- let s1 = store::append_world_obs(conn, "h-1", "note-1", 100)?;
- let s2 = store::append_world_obs(conn, "h-1", "note-2", 200)?;
- let s3 = store::append_world_obs(conn, "h-2", "note-3", 300)?;
- Ok((s1, s2, s3))
- })
- .unwrap();
- assert_eq!((s1, s2, s3), (1, 2, 3));
-
- // Drain FIFO by insert order.
- let rows = store::with_connection(&ws, |conn| store::drain_world_obs(conn, 10)).unwrap();
- assert_eq!(rows.len(), 3);
- assert_eq!(rows[0].note, "note-1");
- assert_eq!(rows[0].session_id, "h-1");
- assert_eq!(rows[2].session_id, "h-2");
-
- // Delete the first two; the third remains buffered (retry semantics).
- let keep = rows[2].id;
- store::with_connection(&ws, |conn| {
- store::delete_world_obs(conn, &[rows[0].id, rows[1].id])
- })
- .unwrap();
- let remaining = store::with_connection(&ws, |conn| store::drain_world_obs(conn, 10)).unwrap();
- assert_eq!(remaining.len(), 1);
- assert_eq!(remaining[0].id, keep);
- assert_eq!(remaining[0].note, "note-3");
-}
-
-#[test]
-fn forwarded_counterpart_id_is_not_re_encoded() {
- // Load-bearing invariant for sync's re-paging guard: the device forwards
- // `counterpartAgentId` as the exact base64 `envelope.from` it also stores as the
- // local `agent_id`, and sync keys on the backend's verbatim echo of that string.
- // Pin that the client never transforms the encoding here — if it did (or if the
- // backend re-encoded), `next_session_seq` would miss the device's own rows and
- // re-page every hosted turn under a second encoding, duplicating the session.
- let agent = "ZCAAuA+2GVoRrT08Gt8JUVnxnISTelSxnDuyScze334=";
- let env =
- OrchestrationEventEnvelopeWire::build(agent, "sess-1", 3, "user", agent, "hi", 100, "dm");
- assert_eq!(env.counterpart_agent_id, agent);
- assert_eq!(env.event.sender, agent);
-}
-
-#[test]
-fn world_obs_seq_never_resets_after_a_full_drain() {
- // Regression: `seq` must be a persistent monotonic counter, not `MAX(seq)+1`
- // over the table. The uploader deletes every row after a successful push, so a
- // table-scoped max would restart at 1 once the buffer empties and reuse seqs the
- // backend already saw — its `(userId, sessionId, seq)` dedupe would then silently
- // drop the fresh observation.
- let tmp = tempfile::tempdir().unwrap();
- let ws = tmp.path().to_path_buf();
-
- let s1 =
- store::with_connection(&ws, |conn| store::append_world_obs(conn, "h-1", "n1", 1)).unwrap();
- // Drain and delete everything, emptying the buffer.
- let rows = store::with_connection(&ws, |conn| store::drain_world_obs(conn, 10)).unwrap();
- let ids: Vec<i64> = rows.iter().map(|o| o.id).collect();
- store::with_connection(&ws, |conn| store::delete_world_obs(conn, &ids)).unwrap();
-
- // The next ordinal must climb past s1, not reset to 1.
- let s2 =
- store::with_connection(&ws, |conn| store::append_world_obs(conn, "h-1", "n2", 2)).unwrap();
- assert!(s2 > s1, "seq reset after a full drain: s1={s1} s2={s2}");
-}
-
-#[test]
-fn world_obs_drain_respects_the_limit() {
- let tmp = tempfile::tempdir().unwrap();
- let ws = tmp.path().to_path_buf();
- store::with_connection(&ws, |conn| {
- for i in 0..5 {
- store::append_world_obs(conn, "h-1", &format!("n{i}"), i)?;
- }
- Ok(())
- })
- .unwrap();
- let rows = store::with_connection(&ws, |conn| store::drain_world_obs(conn, 2)).unwrap();
- assert_eq!(rows.len(), 2);
-}
diff --git a/tests/orchestration_shadow_push_e2e.rs b/tests/orchestration_shadow_push_e2e.rs
deleted file mode 100644
index 3ac161d026..0000000000
--- a/tests/orchestration_shadow_push_e2e.rs
+++ /dev/null
@@ -1,223 +0,0 @@
-//! Phase 0 shadow-migration coverage: the sanitized wire DTO (the security
-//! allowlist gate) and the cloud event pusher's transport.
-//!
-//! These live in an integration crate rather than inline `#[cfg(test)]` modules
-//! because the root crate's test build is currently blocked by unrelated stale
-//! test modules at this checkout. An integration test links the *compiled* lib
-//! (no `cfg(test)` siblings), so it runs cleanly here.
-
-use std::time::Duration;
-
-use openhuman_core::api::rest::BackendOAuthClient;
-use openhuman_core::openhuman::hosted::orchestration::cloud::{
- push_event_with, push_world_diff_with,
-};
-use openhuman_core::openhuman::hosted::orchestration::wire::{
- parse_ts_ms, OrchestrationEventEnvelopeWire, WorldDiffBatchWire, WorldDiffEntryWire,
- ORCH_WIRE_PROTOCOL,
-};
-use wiremock::matchers::{body_json, header, method, path};
-use wiremock::{Mock, MockServer, ResponseTemplate};
-
-fn envelope() -> OrchestrationEventEnvelopeWire {
- OrchestrationEventEnvelopeWire::build(
- "agent-alice",
- "sess-1",
- 3,
- "user",
- "agent-alice",
- "hey there",
- 1_700_000_000_000,
- "dm",
- )
-}
-
-// ── Wire DTO: the security allowlist gate ──────────────────────────────────
-
-#[test]
-fn wire_envelope_has_exactly_the_allowlisted_keys() {
- let value = envelope().to_value();
- let obj = value.as_object().expect("object");
-
- let mut top: Vec<&str> = obj.keys().map(String::as_str).collect();
- top.sort_unstable();
- assert_eq!(
- top,
- ["counterpartAgentId", "event", "protocol", "sessionId"]
- );
-
- let event = obj["event"].as_object().expect("event object");
- let mut event_keys: Vec<&str> = event.keys().map(String::as_str).collect();
- event_keys.sort_unstable();
- assert_eq!(event_keys, ["body", "kind", "role", "sender", "seq", "ts"]);
-
- assert_eq!(obj["protocol"], serde_json::json!(ORCH_WIRE_PROTOCOL));
-}
-
-#[test]
-fn wire_envelope_never_carries_credential_or_path_keys() {
- let value = envelope().to_value();
- let obj = value.as_object().unwrap();
- let event = obj["event"].as_object().unwrap();
- for forbidden in [
- "path",
- "cwd",
- "workspace",
- "workspaceDir",
- "credentials",
- "token",
- "apiKey",
- "key",
- "signalKey",
- "identityKey",
- "ratchet",
- "secret",
- ] {
- assert!(!obj.contains_key(forbidden), "top-level leaked {forbidden}");
- assert!(!event.contains_key(forbidden), "event leaked {forbidden}");
- }
-}
-
-#[test]
-fn wire_build_clamps_unknown_role_and_negative_scalars() {
- let env = OrchestrationEventEnvelopeWire::build("a", "s", -5, "robot", "a", "", -1, "");
- assert_eq!(env.event.role, "user");
- assert_eq!(env.event.seq, 0);
- assert_eq!(env.event.ts, 0);
- assert_eq!(env.event.kind, "message");
- assert_eq!(env.protocol, 1);
-}
-
-#[test]
-fn wire_build_preserves_valid_roles() {
- for role in ["user", "assistant", "system"] {
- let env = OrchestrationEventEnvelopeWire::build("a", "s", 1, role, "a", "b", 1, "dm");
- assert_eq!(env.event.role, role);
- }
-}
-
-#[test]
-fn parse_ts_ms_parses_rfc3339_and_rejects_garbage() {
- assert_eq!(parse_ts_ms("1970-01-01T00:00:01Z"), Some(1000));
- assert_eq!(parse_ts_ms("not-a-timestamp"), None);
-}
-
-// ── Cloud pusher transport ─────────────────────────────────────────────────
-
-#[tokio::test]
-async fn push_posts_sanitized_event_with_bearer_and_accepts_202() {
- let server = MockServer::start().await;
- Mock::given(method("POST"))
- .and(path("/orchestration/v1/events"))
- .and(header("authorization", "Bearer test-token"))
- .and(body_json(serde_json::json!({
- "protocol": 1,
- "counterpartAgentId": "agent-alice",
- "sessionId": "sess-1",
- "event": {
- "seq": 3,
- "role": "user",
- "sender": "agent-alice",
- "body": "hey there",
- "ts": 1_700_000_000_000i64,
- "kind": "dm"
- }
- })))
- .respond_with(ResponseTemplate::new(202).set_body_json(serde_json::json!({
- "success": true,
- "data": { "accepted": true, "cycleId": "cyc:agent-alice:sess-1:3" }
- })))
- .expect(1)
- .mount(&server)
- .await;
-
- let client = BackendOAuthClient::new(&server.uri()).unwrap();
- let res = push_event_with(&client, "test-token", &envelope(), &[]).await;
- assert!(res.is_ok(), "expected ok, got {res:?}");
-}
-
-#[test]
-fn world_diff_batch_has_exactly_the_allowlisted_keys() {
- let batch = WorldDiffBatchWire::build(
- "sess-1",
- vec![WorldDiffEntryWire::build(0, "peer online", 1)],
- );
- let value = batch.to_value();
- let obj = value.as_object().unwrap();
- let mut top: Vec<&str> = obj.keys().map(String::as_str).collect();
- top.sort_unstable();
- assert_eq!(top, ["entries", "protocol", "sessionId"]);
-
- let entry = obj["entries"][0].as_object().unwrap();
- let mut ek: Vec<&str> = entry.keys().map(String::as_str).collect();
- ek.sort_unstable();
- assert_eq!(ek, ["note", "seq", "ts"]);
- assert_eq!(obj["protocol"], serde_json::json!(ORCH_WIRE_PROTOCOL));
-}
-
-#[tokio::test]
-async fn push_world_diff_posts_the_batch() {
- let server = MockServer::start().await;
- Mock::given(method("POST"))
- .and(path("/orchestration/v1/world-diff"))
- .and(header("authorization", "Bearer test-token"))
- .and(body_json(serde_json::json!({
- "protocol": 1,
- "sessionId": "sess-1",
- "entries": [{ "seq": 0, "note": "peer online", "ts": 1i64 }]
- })))
- .respond_with(ResponseTemplate::new(202).set_body_json(serde_json::json!({
- "success": true, "data": { "accepted": 1, "duplicates": 0, "tickScheduled": false }
- })))
- .expect(1)
- .mount(&server)
- .await;
-
- let client = BackendOAuthClient::new(&server.uri()).unwrap();
- let batch = WorldDiffBatchWire::build(
- "sess-1",
- vec![WorldDiffEntryWire::build(0, "peer online", 1)],
- );
- let res = push_world_diff_with(&client, "test-token", &batch, &[]).await;
- assert!(res.is_ok(), "expected ok, got {res:?}");
-}
-
-#[tokio::test]
-async fn push_returns_err_when_backend_5xxs_and_retries_exhausted() {
- let server = MockServer::start().await;
- Mock::given(method("POST"))
- .and(path("/orchestration/v1/events"))
- .respond_with(ResponseTemplate::new(500))
- .mount(&server)
- .await;
-
- let client = BackendOAuthClient::new(&server.uri()).unwrap();
- // No backoffs → single attempt, fails fast (no real sleeps).
- let res = push_event_with(&client, "test-token", &envelope(), &[]).await;
- assert!(res.is_err(), "expected err on 500");
-}
-
-#[tokio::test]
-async fn push_retries_then_succeeds() {
- let server = MockServer::start().await;
- Mock::given(method("POST"))
- .and(path("/orchestration/v1/events"))
- .respond_with(ResponseTemplate::new(503))
- .up_to_n_times(1)
- .expect(1)
- .mount(&server)
- .await;
- Mock::given(method("POST"))
- .and(path("/orchestration/v1/events"))
- .respond_with(ResponseTemplate::new(202).set_body_json(serde_json::json!({
- "success": true, "data": { "accepted": true, "cycleId": "c" }
- })))
- .expect(1)
- .mount(&server)
- .await;
-
- let client = BackendOAuthClient::new(&server.uri()).unwrap();
- // Zero-duration backoff → immediate retry, still exercises the loop.
- let res = push_event_with(&client, "test-token", &envelope(), &[Duration::ZERO]).await;
- assert!(res.is_ok(), "expected ok after retry, got {res:?}");
-}