Files
IdeA/crates/application/src/health.rs
Blomios 785e9935fd feat(memory): config embedders (LOT C2) + suggestion contextuelle (LOT C3) + contexte projet partagé
- LOT C2 (§14.5.3) : use cases de configuration des embedders déclaratifs
  (List/Save/Delete + DescribeEmbedderEngines : modèles ONNX recommandés,
  environnement local détecté, stratégies compilées). UI EmbedderSettings.
- LOT C3 (§14.5.5) : suggestion contextuelle best-effort à l'activation quand la
  mémoire dépasse le budget de recall sans embedder configuré (event
  EmbedderSuggested, anti-spam 1×/session, « ne plus demander »).
- Contexte projet partagé .ideai/CONTEXT.md (model-agnostic) injecté à tous les
  agents/profils au lancement, avant la persona. UI ProjectContextPanel.

Tests : backend workspace vert (0 échec) ; frontend 306/306.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 09:24:51 +02:00

85 lines
2.9 KiB
Rust

//! [`HealthUseCase`] — a trivial, in-memory use case used to validate the
//! end-to-end wiring (composition root → Tauri command → use case → ports →
//! frontend gateway). It carries its ports as `Arc<dyn Port>`, exactly like
//! every real use case will (ARCHITECTURE §6).
//!
//! It depends only on the utility ports [`Clock`] and [`IdGenerator`], so it
//! exercises dependency injection without needing any I/O adapter.
use std::sync::Arc;
use domain::ports::{Clock, EventBus, IdGenerator};
use domain::DomainEvent;
use domain::ProjectId;
use crate::error::AppError;
/// Input for [`HealthUseCase::execute`].
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct HealthInput {
/// Optional caller-supplied note echoed back in the report (used by tests
/// and the frontend smoke check).
pub note: Option<String>,
}
/// Output of [`HealthUseCase::execute`]: a small health report.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HealthReport {
/// Application/crate version (`CARGO_PKG_VERSION`).
pub version: String,
/// Liveness flag — always `true` if the use case ran.
pub alive: bool,
/// Server "now" in epoch milliseconds (from the injected [`Clock`]).
pub time_millis: i64,
/// A fresh correlation id (from the injected [`IdGenerator`]).
pub correlation_id: String,
/// Echoed caller note, if any.
pub note: Option<String>,
}
/// Trivial health/ping use case validating the DI + IPC pipeline.
pub struct HealthUseCase {
clock: Arc<dyn Clock>,
ids: Arc<dyn IdGenerator>,
events: Arc<dyn EventBus>,
}
impl HealthUseCase {
/// Builds the use case from its injected ports.
#[must_use]
pub fn new(
clock: Arc<dyn Clock>,
ids: Arc<dyn IdGenerator>,
events: Arc<dyn EventBus>,
) -> Self {
Self { clock, ids, events }
}
/// Executes the health check.
///
/// As a side effect it publishes a [`DomainEvent`] on the [`EventBus`] so
/// the event-relay path is exercised end to end (the relay forwards it to a
/// Tauri event). A `ProjectCreated`-shaped event is reused here purely as a
/// no-op smoke signal; no project is actually created.
///
/// # Errors
/// Returns [`AppError`] — never, in this trivial implementation, but the
/// signature matches the real use-case contract.
pub fn execute(&self, input: HealthInput) -> Result<HealthReport, AppError> {
let correlation = self.ids.new_uuid();
// Exercise the event-bus relay path with a harmless smoke event.
self.events.publish(DomainEvent::ProjectCreated {
project_id: ProjectId::from_uuid(correlation),
});
Ok(HealthReport {
version: env!("CARGO_PKG_VERSION").to_owned(),
alive: true,
time_millis: self.clock.now_millis(),
correlation_id: correlation.to_string(),
note: input.note,
})
}
}