tuitbot-server 0.1.49

HTTP API server for Tuitbot autonomous X growth assistant
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
//! `GET /api/vault/evidence` — unified semantic evidence endpoint.
//!
//! Serves all evidence consumers (Ghostwriter, hook picker, thread editor,
//! selection review) through a single endpoint with optional scope filters
//! and mode selection. Falls back cleanly to keyword-only when the semantic
//! index is unavailable.

use std::sync::Arc;

use axum::extract::{Query, State};
use axum::Json;
use serde::{Deserialize, Serialize};

use tuitbot_core::context::hybrid_retrieval::{self, EvidenceResult};
use tuitbot_core::context::retrieval::MatchReason;
use tuitbot_core::context::semantic_search;
use tuitbot_core::storage::watchtower::embeddings;

use crate::account::AccountContext;
use crate::error::ApiError;
use crate::state::AppState;

/// Default result limit.
const DEFAULT_LIMIT: u32 = 8;

/// Maximum result limit.
const MAX_LIMIT: u32 = 20;

#[derive(Deserialize)]
pub struct EvidenceQuery {
    /// Search query text (required, non-empty).
    pub q: Option<String>,
    /// Maximum results to return (default 8, max 20).
    pub limit: Option<u32>,
    /// Retrieval mode: "hybrid" (default), "semantic", "keyword".
    pub mode: Option<String>,
    /// Optional scope filter, e.g. "selection:{session_id}".
    pub scope: Option<String>,
}

#[derive(Serialize)]
pub struct EvidenceResponse {
    pub results: Vec<EvidenceResultItem>,
    pub query: String,
    pub mode: String,
    pub index_status: IndexStatusSummary,
}

#[derive(Serialize)]
pub struct EvidenceResultItem {
    pub chunk_id: i64,
    pub node_id: i64,
    pub heading_path: String,
    pub snippet: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub relative_path: Option<String>,
    pub match_reason: MatchReason,
    pub score: f64,
    pub node_title: Option<String>,
}

#[derive(Serialize, Clone)]
pub struct IndexStatusSummary {
    pub total_chunks: i64,
    pub embedded_chunks: i64,
    pub freshness_pct: f64,
}

pub async fn search_evidence(
    State(state): State<Arc<AppState>>,
    ctx: AccountContext,
    Query(params): Query<EvidenceQuery>,
) -> Result<Json<EvidenceResponse>, ApiError> {
    // Validate query
    let query = params.q.unwrap_or_default();
    if query.trim().is_empty() {
        return Err(ApiError::BadRequest(
            "query parameter 'q' is required and must be non-empty".to_string(),
        ));
    }

    let limit = params
        .limit
        .map(|l| if l == 0 { DEFAULT_LIMIT } else { l })
        .unwrap_or(DEFAULT_LIMIT)
        .min(MAX_LIMIT);

    let mode = params.mode.as_deref().unwrap_or("hybrid");

    let is_cloud = matches!(
        state.deployment_mode,
        tuitbot_core::config::DeploymentMode::Cloud
    );

    // Resolve scope for graph context
    let selected_node_ids: Option<Vec<i64>> = if let Some(scope) = &params.scope {
        if let Some(session_id) = scope.strip_prefix("selection:") {
            resolve_selection_node_ids(&state, &ctx.account_id, session_id).await
        } else {
            None
        }
    } else {
        None
    };

    // Semantic search (if mode != "keyword" and provider is available)
    let search_start = std::time::Instant::now();
    let semantic_hits = if mode != "keyword" {
        embed_and_search(&state, &query, limit).await
    } else {
        None
    };
    let semantic_elapsed = search_start.elapsed();
    let did_fallback =
        mode != "keyword" && semantic_hits.is_none() && state.embedding_provider.is_some();

    tracing::info!(
        latency_ms = semantic_elapsed.as_millis() as u64,
        fallback = did_fallback,
        mode = mode,
        result_count = semantic_hits.as_ref().map(|h| h.len()).unwrap_or(0),
        "evidence_search_completed"
    );

    // In semantic-only mode, skip keyword search (pass empty query to hybrid_search)
    let effective_query = if mode == "semantic" { "" } else { &query };

    let results = hybrid_retrieval::hybrid_search(
        &state.db,
        &ctx.account_id,
        effective_query,
        semantic_hits.as_deref(),
        selected_node_ids.as_deref(),
        limit,
    )
    .await?;

    // Fetch index stats for the response
    let index_status = get_index_status_summary(&state.db, &ctx.account_id).await;

    let items: Vec<EvidenceResultItem> = results
        .into_iter()
        .map(|r| evidence_to_item(r, is_cloud))
        .collect();

    Ok(Json(EvidenceResponse {
        results: items,
        query,
        mode: mode.to_string(),
        index_status,
    }))
}

fn evidence_to_item(r: EvidenceResult, is_cloud: bool) -> EvidenceResultItem {
    EvidenceResultItem {
        chunk_id: r.chunk_id,
        node_id: r.node_id,
        heading_path: r.heading_path,
        snippet: r.snippet,
        relative_path: if is_cloud { None } else { Some(r.source_path) },
        match_reason: r.match_reason,
        score: r.score,
        node_title: r.node_title,
    }
}

/// Embed the query and search the semantic index. Returns `None` on any failure.
async fn embed_and_search(
    state: &AppState,
    query: &str,
    limit: u32,
) -> Option<Vec<semantic_search::SemanticHit>> {
    let provider = state.embedding_provider.as_ref()?;
    let index_lock = state.semantic_index.as_ref()?;

    let response = match provider.embed(vec![query.to_string()]).await {
        Ok(r) => r,
        Err(e) => {
            tracing::warn!("evidence: embedding query failed: {e}");
            return None;
        }
    };

    let embedding = response.embeddings.into_iter().next()?;
    let index = index_lock.read().await;
    let hits = semantic_search::semantic_search(&index, &embedding, limit as usize);

    if hits.is_empty() {
        None
    } else {
        Some(hits)
    }
}

/// Resolve a selection session_id to its node_ids for graph context.
async fn resolve_selection_node_ids(
    state: &AppState,
    account_id: &str,
    session_id: &str,
) -> Option<Vec<i64>> {
    use tuitbot_core::storage::vault_selections;

    let selection = vault_selections::get_selection_by_session(&state.db, account_id, session_id)
        .await
        .ok()
        .flatten()?;

    selection.resolved_node_id.map(|nid| vec![nid])
}

/// Build index status summary from DB stats.
async fn get_index_status_summary(
    pool: &tuitbot_core::storage::DbPool,
    account_id: &str,
) -> IndexStatusSummary {
    match embeddings::get_index_stats_for(pool, account_id).await {
        Ok(stats) => IndexStatusSummary {
            total_chunks: stats.total_chunks,
            embedded_chunks: stats.embedded_chunks,
            freshness_pct: stats.freshness_pct,
        },
        Err(_) => IndexStatusSummary {
            total_chunks: 0,
            embedded_chunks: 0,
            freshness_pct: 0.0,
        },
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::collections::HashMap;
    use std::path::PathBuf;

    use axum::body::Body;
    use axum::http::{Request, StatusCode};
    use axum::routing::get;
    use axum::Router;
    use tokio::sync::{broadcast, Mutex, RwLock};
    use tower::ServiceExt;

    use crate::ws::AccountWsEvent;

    async fn test_state() -> Arc<AppState> {
        let db = tuitbot_core::storage::init_test_db()
            .await
            .expect("init test db");
        let (event_tx, _) = broadcast::channel::<AccountWsEvent>(16);
        Arc::new(AppState {
            db,
            config_path: PathBuf::from("test-config.toml"),
            data_dir: PathBuf::from(std::env::temp_dir()),
            event_tx,
            api_token: "test-token".to_string(),
            passphrase_hash: RwLock::new(None),
            passphrase_hash_mtime: RwLock::new(None),
            bind_host: "127.0.0.1".to_string(),
            bind_port: 3001,
            login_attempts: Mutex::new(HashMap::new()),
            runtimes: Mutex::new(HashMap::new()),
            content_generators: Mutex::new(HashMap::new()),
            circuit_breaker: None,
            scraper_health: None,
            watchtower_cancel: RwLock::new(None),
            content_sources: RwLock::new(Default::default()),
            connector_config: Default::default(),
            deployment_mode: Default::default(),
            pending_oauth: Mutex::new(HashMap::new()),
            token_managers: Mutex::new(HashMap::new()),
            x_client_id: String::new(),
            semantic_index: None,
            embedding_provider: None,
        })
    }

    fn test_router(state: Arc<AppState>) -> Router {
        Router::new()
            .route("/vault/evidence", get(search_evidence))
            .with_state(state)
    }

    #[tokio::test]
    async fn empty_query_returns_400() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
    }

    #[tokio::test]
    async fn missing_query_returns_400() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
    }

    #[tokio::test]
    async fn keyword_mode_works_without_embedding_provider() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=keyword")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert_eq!(body["mode"], "keyword");
        assert!(body["results"].as_array().unwrap().is_empty());
        assert!(body["index_status"]["freshness_pct"].as_f64().is_some());
    }

    #[tokio::test]
    async fn hybrid_mode_falls_back_without_provider() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=hybrid")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert_eq!(body["mode"], "hybrid");
    }

    #[tokio::test]
    async fn semantic_mode_returns_empty_without_provider() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=semantic")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert_eq!(body["mode"], "semantic");
        assert!(body["results"].as_array().unwrap().is_empty());
    }

    #[tokio::test]
    async fn default_limit_applied() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn cloud_mode_omits_relative_path() {
        let db = tuitbot_core::storage::init_test_db()
            .await
            .expect("init test db");
        let (event_tx, _) = broadcast::channel::<AccountWsEvent>(16);
        let state = Arc::new(AppState {
            db,
            config_path: PathBuf::from("test-config.toml"),
            data_dir: PathBuf::from(std::env::temp_dir()),
            event_tx,
            api_token: "test-token".to_string(),
            passphrase_hash: RwLock::new(None),
            passphrase_hash_mtime: RwLock::new(None),
            bind_host: "127.0.0.1".to_string(),
            bind_port: 3001,
            login_attempts: Mutex::new(HashMap::new()),
            runtimes: Mutex::new(HashMap::new()),
            content_generators: Mutex::new(HashMap::new()),
            circuit_breaker: None,
            scraper_health: None,
            watchtower_cancel: RwLock::new(None),
            content_sources: RwLock::new(Default::default()),
            connector_config: Default::default(),
            deployment_mode: tuitbot_core::config::DeploymentMode::Cloud,
            pending_oauth: Mutex::new(HashMap::new()),
            token_managers: Mutex::new(HashMap::new()),
            x_client_id: String::new(),
            semantic_index: None,
            embedding_provider: None,
        });
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=keyword")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn limit_zero_defaults_to_8() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&limit=0")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn limit_over_max_clamped_to_20() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&limit=50")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn invalid_scope_returns_ok_with_empty_results() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=keyword&scope=selection:nonexistent-session")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert!(body["results"].as_array().unwrap().is_empty());
    }

    #[tokio::test]
    async fn index_status_included_in_response() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=keyword")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert!(body["index_status"].is_object());
        assert_eq!(body["index_status"]["total_chunks"], 0);
        assert_eq!(body["index_status"]["embedded_chunks"], 0);
    }

    // --- evidence_to_item tests ---

    fn make_evidence_result() -> EvidenceResult {
        EvidenceResult {
            chunk_id: 42,
            node_id: 7,
            heading_path: "# Intro > Details".to_string(),
            source_path: "notes/test.md".to_string(),
            source_title: Some("Test Note".to_string()),
            snippet: "some snippet".to_string(),
            score: 0.5,
            match_reason: MatchReason::Semantic,
            node_title: Some("Test Note".to_string()),
        }
    }

    #[test]
    fn evidence_to_item_local_mode_includes_path() {
        let r = make_evidence_result();
        let item = evidence_to_item(r, false);
        assert_eq!(item.relative_path, Some("notes/test.md".to_string()));
        assert_eq!(item.chunk_id, 42);
        assert_eq!(item.node_id, 7);
        assert_eq!(item.heading_path, "# Intro > Details");
        assert_eq!(item.snippet, "some snippet");
        assert!((item.score - 0.5).abs() < f64::EPSILON);
        assert_eq!(item.match_reason, MatchReason::Semantic);
        assert_eq!(item.node_title, Some("Test Note".to_string()));
    }

    #[test]
    fn evidence_to_item_cloud_mode_omits_path() {
        let r = make_evidence_result();
        let item = evidence_to_item(r, true);
        assert!(item.relative_path.is_none());
    }

    #[test]
    fn evidence_to_item_no_node_title() {
        let mut r = make_evidence_result();
        r.node_title = None;
        let item = evidence_to_item(r, false);
        assert!(item.node_title.is_none());
    }

    // --- DTO serialization tests ---

    #[test]
    fn evidence_result_item_serializes_correctly() {
        let item = EvidenceResultItem {
            chunk_id: 1,
            node_id: 2,
            heading_path: "# H".to_string(),
            snippet: "text".to_string(),
            relative_path: Some("path.md".to_string()),
            match_reason: MatchReason::Keyword,
            score: 0.123,
            node_title: None,
        };
        let json = serde_json::to_value(&item).unwrap();
        assert_eq!(json["chunk_id"], 1);
        assert_eq!(json["node_id"], 2);
        assert_eq!(json["heading_path"], "# H");
        assert_eq!(json["snippet"], "text");
        assert_eq!(json["relative_path"], "path.md");
        assert_eq!(json["score"], 0.123);
        // node_title should be present as null
        assert!(json["node_title"].is_null());
    }

    #[test]
    fn evidence_result_item_skips_none_relative_path() {
        let item = EvidenceResultItem {
            chunk_id: 1,
            node_id: 2,
            heading_path: "# H".to_string(),
            snippet: "text".to_string(),
            relative_path: None,
            match_reason: MatchReason::Graph,
            score: 0.5,
            node_title: Some("Title".to_string()),
        };
        let json = serde_json::to_value(&item).unwrap();
        // skip_serializing_if = "Option::is_none" means the key is absent
        assert!(json.get("relative_path").is_none());
        assert_eq!(json["node_title"], "Title");
    }

    #[test]
    fn index_status_summary_serializes() {
        let status = IndexStatusSummary {
            total_chunks: 100,
            embedded_chunks: 75,
            freshness_pct: 75.0,
        };
        let json = serde_json::to_value(&status).unwrap();
        assert_eq!(json["total_chunks"], 100);
        assert_eq!(json["embedded_chunks"], 75);
        assert_eq!(json["freshness_pct"], 75.0);
    }

    #[test]
    fn evidence_response_serializes_all_fields() {
        let resp = EvidenceResponse {
            results: vec![],
            query: "test query".to_string(),
            mode: "hybrid".to_string(),
            index_status: IndexStatusSummary {
                total_chunks: 0,
                embedded_chunks: 0,
                freshness_pct: 0.0,
            },
        };
        let json = serde_json::to_value(&resp).unwrap();
        assert_eq!(json["query"], "test query");
        assert_eq!(json["mode"], "hybrid");
        assert!(json["results"].as_array().unwrap().is_empty());
        assert!(json["index_status"].is_object());
    }

    // --- Scope parsing edge cases ---

    #[tokio::test]
    async fn non_selection_scope_prefix_ignored() {
        let state = test_state().await;
        let app = test_router(state);

        // "folder:xyz" is not a recognized scope prefix — should be ignored, not error
        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&mode=keyword&scope=folder:xyz")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn whitespace_only_query_returns_400() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=%20%20%20")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
    }

    #[tokio::test]
    async fn explicit_limit_5_returns_ok() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test&limit=5&mode=keyword")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
    }

    #[tokio::test]
    async fn default_mode_is_hybrid() {
        let state = test_state().await;
        let app = test_router(state);

        let resp = app
            .oneshot(
                Request::builder()
                    .uri("/vault/evidence?q=test")
                    .body(Body::empty())
                    .unwrap(),
            )
            .await
            .unwrap();

        assert_eq!(resp.status(), StatusCode::OK);
        let body: serde_json::Value = serde_json::from_slice(
            &axum::body::to_bytes(resp.into_body(), 1024 * 64)
                .await
                .unwrap(),
        )
        .unwrap();
        assert_eq!(body["mode"], "hybrid");
    }
}