mod local;
mod remote;
pub mod types;
#[cfg(any(test, feature = "dev-tools"))]
pub mod test_seams;
pub use local::LocalAuthority;
pub use remote::RemoteAuthority;
pub use types::*;
pub trait OrchestrationAuthority: Send + Sync {
fn apply_policy(&self, request: &PolicyRequest) -> AuthorityDecision<PolicyOutcome>;
fn resolve_target(&self, context: &StageContext) -> AuthorityDecision<ResolvedTarget>;
fn resolve_target_with_feedback(&self, context: &StageContext) -> TargetResolution {
TargetResolution::new(self.resolve_target(context), context.model_id.clone(), None)
}
fn select_model(&self, request: &ModelRequest) -> AuthorityDecision<ModelSelection>;
fn record_outcome(&self, _outcome: &ExecutionOutcome) {
}
fn invalidate_cache(&self) {
}
fn name(&self) -> &str;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context::DeviceMetrics;
use crate::device::ResourceMonitor;
use crate::ir::{Envelope, EnvelopeKind};
fn default_metrics() -> DeviceMetrics {
DeviceMetrics::default()
}
fn text_envelope(text: &str) -> Envelope {
Envelope::new(EnvelopeKind::Text(text.to_string()))
}
#[test]
fn test_local_authority_name() {
let authority = LocalAuthority::new();
assert_eq!(authority.name(), "local");
}
#[test]
fn test_remote_authority_name() {
let authority = RemoteAuthority::new("https://api.xybrid.dev");
assert_eq!(authority.name(), "remote");
}
#[test]
fn test_local_authority_allows_by_default() {
let authority = LocalAuthority::new();
let request = PolicyRequest {
stage_id: "test".to_string(),
envelope: text_envelope("hello"),
metrics: default_metrics(),
};
let decision = authority.apply_policy(&request);
assert!(decision.result.is_allowed());
assert_eq!(decision.source, DecisionSource::Local);
}
#[test]
fn test_local_authority_respects_explicit_target() {
let authority = LocalAuthority::new();
let context = StageContext {
stage_id: "test".to_string(),
model_id: "whisper-tiny".to_string(),
input_kind: EnvelopeKind::Audio(vec![]),
metrics: default_metrics(),
resource_monitor: ResourceMonitor::global(),
explicit_target: Some(crate::pipeline::ExecutionTarget::Device),
local_availability: None,
device_class: None,
device_class_schema_version: None,
};
let decision = authority.resolve_target(&context);
assert_eq!(decision.result, ResolvedTarget::Device);
assert!(decision.reason.to_lowercase().contains("explicit"));
}
#[test]
fn test_remote_authority_falls_back_to_local() {
let authority = RemoteAuthority::new("https://api.xybrid.dev");
let request = PolicyRequest {
stage_id: "test".to_string(),
envelope: text_envelope("hello"),
metrics: default_metrics(),
};
let decision = authority.apply_policy(&request);
assert!(decision.result.is_allowed());
assert_eq!(decision.source, DecisionSource::Default); }
}