tidaldb/tidal/tests/visibility_feature_flag.rs
jx12n b55ad70141 fix: M0-M10 third-pass remediation — durability, replication, and CLI hardening
Resolves the 142 findings from tidal/docs/reviews/CODE_REVIEW_m0-m10.md across
the engine, server, net, and CLI surfaces:

- WAL/session-journal durability, checkpoint format, and crash-recovery hardening
- Replication shipper/receiver, tenant isolation, and migration paths
- Cluster scatter-gather, router, standalone server + health/offload endpoints
- tidalctl refactored into command modules with JSON output and WAL-state tooling
- Cohort, governance, signal-ledger, and vector-registry correctness fixes
- Expanded UAT/integration/durability test coverage across all milestones
2026-06-08 10:28:34 -06:00

82 lines
2.7 KiB
Rust

//! Integration tests for M7P4 Operational Visibility — metrics feature flag.
//!
//! - Task 07: Metrics feature flag (zero-overhead base types)
#![allow(clippy::too_many_lines, clippy::unwrap_used)]
use std::time::Duration;
use tidaldb::{
TidalDb,
schema::{DecaySpec, EntityKind, Window},
};
// ── Shared test schema ───────────────────────────────────────────────────────
fn build_test_schema() -> tidaldb::schema::Schema {
use tidaldb::{AgentPolicy, schema::SchemaBuilder};
let mut builder = SchemaBuilder::new();
let _ = builder
.signal(
"view",
EntityKind::Item,
DecaySpec::Exponential {
half_life: Duration::from_secs(7 * 24 * 3600),
},
)
.windows(&[Window::OneHour])
.add();
let _ = builder
.signal(
"like",
EntityKind::Item,
DecaySpec::Exponential {
half_life: Duration::from_secs(30 * 24 * 3600),
},
)
.windows(&[Window::OneHour])
.add();
builder.session_policy(
"default",
AgentPolicy {
allowed_signals: vec!["view".to_string(), "like".to_string()],
denied_signals: vec![],
max_session_duration: Duration::from_secs(3600),
max_signals_per_session: 1000,
},
);
builder.build().unwrap()
}
// ── Task 07: Feature Flag ────────────────────────────────────────────────────
/// `QueryStats` is always available regardless of the `metrics` feature flag.
/// This test intentionally has NO `#[cfg(feature = "metrics")]` annotation.
#[test]
fn query_stats_available_without_metrics_feature() {
use tidaldb::query::stats::QueryStats;
let stats = QueryStats::new("my_profile".to_owned());
assert_eq!(stats.profile_name, "my_profile");
assert_eq!(stats.total_time_us, 0);
assert_eq!(stats.candidates_considered, 0);
assert_eq!(stats.filters_applied, 0);
assert_eq!(stats.degradation_level, 0);
}
/// `MetricsState` base fields (`uptime_seconds`, `health_ok_value`) work
/// unconditionally — they are NOT gated behind the `metrics` feature.
#[test]
fn metrics_state_base_fields_always_available() {
let schema = build_test_schema();
let db = TidalDb::builder()
.ephemeral()
.with_schema(schema)
.open()
.unwrap();
// These methods exist and compile even with --no-default-features.
assert!(db.metrics().uptime_seconds() >= 0.0);
assert!((db.metrics().health_ok_value() - 1.0).abs() < f64::EPSILON);
}