vecboost 0.3.0-rc.1

High-performance embedding vector service written in Rust
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
// Copyright (c) 2025-2026 Kirky.X🌠
// SPDX-License-Identifier: Apache-2.0

//! ModuleMeta + AsyncAutoBuilder trait 实现
//!
//! 基于 trait-kit 0.3 的 `AsyncKit`(`Send + Sync`,基于 `Arc<RwLock>`)。
//! 所有模块实现 `AsyncAutoBuilder`,`build` 返回 `Pin<Box<dyn Future>>`,
//! 在 `AsyncKit::build().await` 时按拓扑序异步构造。

use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use tokio::sync::RwLock;
use trait_kit::AsyncKit;
use trait_kit::prelude::*;

#[cfg(feature = "auth")]
use super::AuthModule;
#[cfg(feature = "auth")]
use super::CsrfConfigModule;
#[cfg(feature = "http")]
use super::PrometheusCollectorModule;
use super::RateLimitModule;
use super::{
    AuditModule, CacheConfig, CacheModule, ConfigWatcherModule, DbConfig, DbModule,
    EmbeddingModule, IpWhitelistModule, MetricsCollectorModule, PipelineQueueModule,
    PriorityCalculatorModule, RerankModule, ResponseChannelModule, WorkerManagerModule,
};
use crate::audit::AuditLogger;
#[cfg(feature = "auth")]
use crate::auth::GarrisonHandle;
#[cfg(feature = "http")]
use crate::metrics::PrometheusCollector;
use crate::rate_limit::LimiteronAdapter;
use crate::service::embedding::EmbeddingService;
use crate::service::rerank::RerankService;
use crate::{
    metrics::InferenceCollector,
    pipeline::{PriorityCalculator, PriorityRequestQueue, ResponseChannel, WorkerManager},
};

// ---------------------------------------------------------------------------
// EmbeddingModule
// ---------------------------------------------------------------------------

impl ModuleMeta for EmbeddingModule {
    const NAME: &'static str = "embedding";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for EmbeddingModule {
    type Capability = Arc<RwLock<EmbeddingService>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// EmbeddingModule — lifecycle + health
// ---------------------------------------------------------------------------

impl AsyncLifecycle for EmbeddingModule {
    fn on_ready<'a>(
        _kit: &'a AsyncKit<trait_kit::AsyncReady>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>> {
        Box::pin(async {
            log::info!("EmbeddingModule: model engine ready");
            Ok(())
        })
    }
}

impl AsyncHealthCheck for EmbeddingModule {
    fn check(_cap: &Self::Capability) -> HealthStatus {
        // EmbeddingService is always operational after successful build
        HealthStatus::Healthy
    }
}

// ---------------------------------------------------------------------------
// RerankModule
// ---------------------------------------------------------------------------

impl ModuleMeta for RerankModule {
    const NAME: &'static str = "rerank";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for RerankModule {
    type Capability = Arc<RwLock<RerankService>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

impl AsyncLifecycle for RerankModule {
    fn on_ready<'a>(
        _kit: &'a AsyncKit<trait_kit::AsyncReady>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>> {
        Box::pin(async {
            log::info!("RerankModule: rerank service ready");
            Ok(())
        })
    }
}

impl AsyncHealthCheck for RerankModule {
    fn check(_cap: &Self::Capability) -> HealthStatus {
        HealthStatus::Healthy
    }
}

// ---------------------------------------------------------------------------
// AuthModule (auth feature only)
// ---------------------------------------------------------------------------

#[cfg(feature = "auth")]
impl ModuleMeta for AuthModule {
    const NAME: &'static str = "auth";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

#[cfg(feature = "auth")]
impl AsyncAutoBuilder for AuthModule {
    type Capability = Option<Arc<GarrisonHandle>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// RateLimitModule
// ---------------------------------------------------------------------------

impl ModuleMeta for RateLimitModule {
    const NAME: &'static str = "rate_limit";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for RateLimitModule {
    type Capability = Arc<LimiteronAdapter>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// RateLimitModule — health + lifecycle
// ---------------------------------------------------------------------------

impl AsyncHealthCheck for RateLimitModule {
    fn check(cap: &Self::Capability) -> HealthStatus {
        // 读取 LimiteronAdapter 中缓存的健康状态(由 check_health() 异步更新)
        if cap.is_healthy() {
            HealthStatus::Healthy
        } else {
            HealthStatus::Unhealthy {
                detail: "rate limiter health check failed".into(),
            }
        }
    }
}

impl AsyncLifecycle for RateLimitModule {
    fn on_ready<'a>(
        _kit: &'a AsyncKit<trait_kit::AsyncReady>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>> {
        Box::pin(async {
            log::info!("RateLimitModule: on_ready — limiteron rate limiter active");
            Ok(())
        })
    }

    fn on_shutdown<'a>(
        _cap: &'a Self::Capability,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
        Box::pin(async {
            log::info!("RateLimitModule: on_shutdown — rate limiter shut down");
        })
    }
}

// ---------------------------------------------------------------------------
// CacheModule
// ---------------------------------------------------------------------------

impl ModuleMeta for CacheModule {
    const NAME: &'static str = "cache";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for CacheModule {
    type Capability = bool;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move {
            Ok(kit
                .config::<CacheConfig>()
                .map(|c| c.enabled)
                .unwrap_or(false))
        })
    }
}

// ---------------------------------------------------------------------------
// CacheModule — health
// ---------------------------------------------------------------------------

impl AsyncHealthCheck for CacheModule {
    fn check(cap: &Self::Capability) -> HealthStatus {
        if *cap {
            HealthStatus::Healthy
        } else {
            HealthStatus::Degraded {
                detail: "cache disabled".into(),
            }
        }
    }
}

// ---------------------------------------------------------------------------
// DbModule
// ---------------------------------------------------------------------------

impl ModuleMeta for DbModule {
    const NAME: &'static str = "db";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for DbModule {
    type Capability = bool;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { Ok(kit.config::<DbConfig>().map(|c| c.enabled).unwrap_or(false)) })
    }
}

// ---------------------------------------------------------------------------
// AuditModule
// ---------------------------------------------------------------------------

impl ModuleMeta for AuditModule {
    const NAME: &'static str = "audit";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for AuditModule {
    type Capability = Option<Arc<AuditLogger>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// AuditModule — lifecycle
// ---------------------------------------------------------------------------

impl AsyncLifecycle for AuditModule {
    fn on_shutdown<'a>(cap: &'a Self::Capability) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
        Box::pin(async move {
            if let Some(logger) = cap {
                log::info!("AuditModule: flushing audit log before shutdown");
                if let Err(e) = logger.flush().await {
                    log::error!("AuditModule: failed to flush audit log: {}", e);
                }
            }
        })
    }
}

// ===========================================================================
// 覆盖 VecboostState 剩余字段的 13 个 Module 实现
//
// 设计原则与现有 6 个 Module 保持一致:
//   - 复杂类型(Arc<T>、Option<Arc<T>>、Vec<String>)→ `kit.config::<Self::Capability>()`
//     严格模式:missing config = TraitKitError::MissingConfig
//   - bool 类型 → `kit.config::<Newtype>().map(|c| c.0).unwrap_or(false)`
//     宽松模式(与 CacheModule/DbModule 一致):missing config 默认 false
// ===========================================================================

// ---------------------------------------------------------------------------
// CsrfConfigModule (auth feature)
// ---------------------------------------------------------------------------

#[cfg(feature = "auth")]
impl ModuleMeta for CsrfConfigModule {
    const NAME: &'static str = "csrf_config";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

#[cfg(feature = "auth")]
impl AsyncAutoBuilder for CsrfConfigModule {
    type Capability = Option<Arc<crate::auth::GarrisonCsrfConfig>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// MetricsCollectorModule
// ---------------------------------------------------------------------------

impl ModuleMeta for MetricsCollectorModule {
    const NAME: &'static str = "metrics_collector";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for MetricsCollectorModule {
    type Capability = Option<Arc<InferenceCollector>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// PrometheusCollectorModule(仅 http feature)
// ---------------------------------------------------------------------------

#[cfg(feature = "http")]
impl ModuleMeta for PrometheusCollectorModule {
    const NAME: &'static str = "prometheus_collector";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

#[cfg(feature = "http")]
impl AsyncAutoBuilder for PrometheusCollectorModule {
    type Capability = Option<Arc<PrometheusCollector>>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// IpWhitelistModule
// ---------------------------------------------------------------------------

impl ModuleMeta for IpWhitelistModule {
    const NAME: &'static str = "ip_whitelist";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for IpWhitelistModule {
    type Capability = Vec<String>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// PipelineQueueModule
// ---------------------------------------------------------------------------

impl ModuleMeta for PipelineQueueModule {
    const NAME: &'static str = "pipeline_queue";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for PipelineQueueModule {
    type Capability = Arc<PriorityRequestQueue>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// ResponseChannelModule
// ---------------------------------------------------------------------------

impl ModuleMeta for ResponseChannelModule {
    const NAME: &'static str = "response_channel";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for ResponseChannelModule {
    type Capability = Arc<ResponseChannel>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// PriorityCalculatorModule
// ---------------------------------------------------------------------------

impl ModuleMeta for PriorityCalculatorModule {
    const NAME: &'static str = "priority_calculator";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for PriorityCalculatorModule {
    type Capability = Arc<PriorityCalculator>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// WorkerManagerModule
// ---------------------------------------------------------------------------

impl ModuleMeta for WorkerManagerModule {
    const NAME: &'static str = "worker_manager";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for WorkerManagerModule {
    type Capability = Arc<WorkerManager>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

// ---------------------------------------------------------------------------
// ConfigWatcherModule — confers watch 集成
// ---------------------------------------------------------------------------

impl ModuleMeta for ConfigWatcherModule {
    const NAME: &'static str = "config_watcher";
    const VERSION: &'static str = env!("CARGO_PKG_VERSION"); // negotiate:模块能力自声明

    fn dependencies() -> &'static [(&'static str, std::any::TypeId)] {
        &[]
    }
}

impl AsyncAutoBuilder for ConfigWatcherModule {
    type Capability = Arc<confers::watcher::WatcherGuard>;
    type Error = TraitKitError;

    fn build<'a>(
        kit: &'a AsyncKit,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Capability, Self::Error>> + Send + 'a>> {
        Box::pin(async move { kit.config::<Self::Capability>() })
    }
}

impl AsyncLifecycle for ConfigWatcherModule {
    fn on_ready<'a>(
        _kit: &'a AsyncKit<trait_kit::AsyncReady>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>> {
        Box::pin(async {
            log::info!("ConfigWatcherModule: config file watcher ready");
            Ok(())
        })
    }

    fn on_shutdown<'a>(cap: &'a Self::Capability) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
        Box::pin(async move {
            log::info!("ConfigWatcherModule: shutting down config watcher");
            if let Err(e) = cap.shutdown(std::time::Duration::from_secs(5)).await {
                log::error!("ConfigWatcherModule: error during watcher shutdown: {}", e);
            }
        })
    }
}

#[cfg(test)]
mod impl_tests {
    use super::*;
    use crate::config::model::Precision;
    use crate::engine::InferenceEngine;
    use crate::error::VecboostError;
    use async_trait::async_trait;

    struct TestMockEngine;

    #[async_trait]
    impl InferenceEngine for TestMockEngine {
        fn embed(&self, _text: &str) -> Result<Vec<f32>, VecboostError> {
            Ok(vec![0.0; 128])
        }
        fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>, VecboostError> {
            Ok(texts.iter().map(|_| vec![0.0; 128]).collect())
        }
        fn precision(&self) -> &Precision {
            &Precision::Fp32
        }
        fn supports_mixed_precision(&self) -> bool {
            false
        }
        async fn try_fallback_to_cpu(
            &mut self,
            _config: &crate::config::model::ModelConfig,
        ) -> Result<(), VecboostError> {
            Ok(())
        }
    }

    // -- ModuleMeta NAME constants --
    #[test]
    fn test_embedding_module_name() {
        assert_eq!(EmbeddingModule::NAME, "embedding");
    }

    #[test]
    fn test_rerank_module_name() {
        assert_eq!(RerankModule::NAME, "rerank");
    }

    #[test]
    fn test_rate_limit_module_name() {
        assert_eq!(RateLimitModule::NAME, "rate_limit");
    }

    #[test]
    fn test_cache_module_name() {
        assert_eq!(CacheModule::NAME, "cache");
    }

    #[test]
    fn test_db_module_name() {
        assert_eq!(DbModule::NAME, "db");
    }

    #[test]
    fn test_audit_module_name() {
        assert_eq!(AuditModule::NAME, "audit");
    }

    #[test]
    fn test_metrics_collector_module_name() {
        assert_eq!(MetricsCollectorModule::NAME, "metrics_collector");
    }

    #[test]
    fn test_ip_whitelist_module_name() {
        assert_eq!(IpWhitelistModule::NAME, "ip_whitelist");
    }

    #[test]
    fn test_pipeline_queue_module_name() {
        assert_eq!(PipelineQueueModule::NAME, "pipeline_queue");
    }

    #[test]
    fn test_response_channel_module_name() {
        assert_eq!(ResponseChannelModule::NAME, "response_channel");
    }

    #[test]
    fn test_priority_calculator_module_name() {
        assert_eq!(PriorityCalculatorModule::NAME, "priority_calculator");
    }

    #[test]
    fn test_worker_manager_module_name() {
        assert_eq!(WorkerManagerModule::NAME, "worker_manager");
    }

    #[test]
    fn test_config_watcher_module_name() {
        assert_eq!(ConfigWatcherModule::NAME, "config_watcher");
    }

    #[cfg(feature = "auth")]
    #[test]
    fn test_auth_module_name() {
        assert_eq!(AuthModule::NAME, "auth");
    }

    #[cfg(feature = "auth")]
    #[test]
    fn test_csrf_config_module_name() {
        assert_eq!(CsrfConfigModule::NAME, "csrf_config");
    }

    #[cfg(feature = "http")]
    #[test]
    fn test_prometheus_collector_module_name() {
        assert_eq!(PrometheusCollectorModule::NAME, "prometheus_collector");
    }

    // -- ModuleMeta dependencies (all should be empty) --
    #[test]
    fn test_all_modules_have_no_dependencies() {
        assert!(EmbeddingModule::dependencies().is_empty());
        assert!(RerankModule::dependencies().is_empty());
        assert!(RateLimitModule::dependencies().is_empty());
        assert!(CacheModule::dependencies().is_empty());
        assert!(DbModule::dependencies().is_empty());
        assert!(AuditModule::dependencies().is_empty());
        assert!(MetricsCollectorModule::dependencies().is_empty());
        assert!(IpWhitelistModule::dependencies().is_empty());
        assert!(PipelineQueueModule::dependencies().is_empty());
        assert!(ResponseChannelModule::dependencies().is_empty());
        assert!(PriorityCalculatorModule::dependencies().is_empty());
        assert!(WorkerManagerModule::dependencies().is_empty());
        assert!(ConfigWatcherModule::dependencies().is_empty());
    }

    // -- AsyncHealthCheck implementations --
    #[test]
    fn test_embedding_health_check_always_healthy() {
        let engine: Arc<RwLock<dyn InferenceEngine + Send + Sync>> =
            Arc::new(RwLock::new(TestMockEngine));
        let service = crate::service::embedding::EmbeddingService::new(engine, None);
        let cap: <EmbeddingModule as AsyncAutoBuilder>::Capability = Arc::new(RwLock::new(service));
        let status = <EmbeddingModule as AsyncHealthCheck>::check(&cap);
        assert!(matches!(status, HealthStatus::Healthy));
    }

    #[test]
    fn test_rerank_health_check_always_healthy() {
        let engine: Arc<RwLock<dyn InferenceEngine + Send + Sync>> =
            Arc::new(RwLock::new(TestMockEngine));
        let service = crate::service::rerank::RerankService::new(engine, None);
        let cap: <RerankModule as AsyncAutoBuilder>::Capability = Arc::new(RwLock::new(service));
        let status = <RerankModule as AsyncHealthCheck>::check(&cap);
        assert!(matches!(status, HealthStatus::Healthy));
    }

    #[test]
    fn test_cache_health_check_enabled() {
        let status = <CacheModule as AsyncHealthCheck>::check(&true);
        assert!(matches!(status, HealthStatus::Healthy));
    }

    #[test]
    fn test_cache_health_check_disabled() {
        let status = <CacheModule as AsyncHealthCheck>::check(&false);
        assert!(matches!(status, HealthStatus::Degraded { .. }));
    }
}