#![cfg(test)]
use super::{
OTLP_TAIL_SAMPLING_E2E_BEAD_ID, OTLP_TAIL_SAMPLING_SCOPE_BEAD_ID,
OTLP_TAIL_SAMPLING_SCOPE_CONTRACT_VERSION, OtlpSpan, OtlpTailSamplingSupportClass,
otlp_tail_based_sampling_scope,
};
#[test]
fn tail_based_sampling_scope_is_explicitly_unsupported() {
let scope = otlp_tail_based_sampling_scope();
assert_eq!(
scope.contract_version,
OTLP_TAIL_SAMPLING_SCOPE_CONTRACT_VERSION
);
assert_eq!(scope.bead_id, OTLP_TAIL_SAMPLING_SCOPE_BEAD_ID);
assert_eq!(scope.feeds_bead_id, OTLP_TAIL_SAMPLING_E2E_BEAD_ID);
assert_eq!(
scope.support_class,
OtlpTailSamplingSupportClass::ExplicitlyUnsupported
);
assert_eq!(scope.support_class_str(), "explicitly_unsupported");
assert_eq!(scope.evidence_quality, "unsupported");
assert_eq!(scope.verdict, "unsupported");
assert!(!scope.production_supported);
}
#[test]
fn tail_based_sampling_scope_names_missing_production_surfaces() {
let scope = otlp_tail_based_sampling_scope();
for required_surface in [
"trace-completion detector",
"bounded span buffer for deferred decisions",
"late sampling policy API",
"flush/shutdown behavior for undecided traces",
] {
assert!(
scope.missing_surfaces.contains(&required_surface),
"missing tail-sampling surface not recorded: {required_surface}"
);
}
for required_semantic in [
"policy match after trace completion",
"consistent decision across every span in a trace",
"bounded memory and trace-expiry behavior",
"no trace leaks on cancellation, flush, or shutdown",
] {
assert!(
scope.desired_semantics.contains(&required_semantic),
"future tail-sampling semantic not recorded: {required_semantic}"
);
}
}
#[test]
fn head_based_sampling_remains_the_live_export_boundary() {
let sampled = OtlpSpan {
span_id: "span-sampled".to_string(),
name: "sampled-operation".to_string(),
start_time_unix_nano: 1,
end_time_unix_nano: 2,
attributes: Vec::new(),
trace_flags: Some(0x01),
};
let unsampled = OtlpSpan {
span_id: "span-unsampled".to_string(),
name: "unsampled-operation".to_string(),
start_time_unix_nano: 1,
end_time_unix_nano: 2,
attributes: Vec::new(),
trace_flags: Some(0x00),
};
let legacy_unspecified = OtlpSpan {
span_id: "span-legacy".to_string(),
name: "legacy-operation".to_string(),
start_time_unix_nano: 1,
end_time_unix_nano: 2,
attributes: Vec::new(),
trace_flags: None,
};
assert!(sampled.is_sampled());
assert!(!unsampled.is_sampled());
assert!(
legacy_unspecified.is_sampled(),
"spans without W3C flags remain sampled for backward-compatible head-based export"
);
}
#[test]
fn tail_sampling_scope_matches_mock_code_finder_evidence_fields() {
let scope = otlp_tail_based_sampling_scope();
assert_eq!(scope.support_class_str(), "explicitly_unsupported");
assert_eq!(scope.verdict, "unsupported");
assert_eq!(scope.evidence_quality, "unsupported");
assert_eq!(scope.feeds_bead_id, "asupersync-uw9zg9");
assert!(
!scope.missing_surfaces.is_empty(),
"unsupported evidence must carry blocker context"
);
assert!(
!scope.desired_semantics.is_empty(),
"unsupported evidence must state what production support would require"
);
}