tidaldb/tidal/tests/visibility_feature_flag.rs
jordan cdbe9cb453 Merge remote-tracking branch 'origin/main' (m11/m12 cluster) into m9/m10
Reconciles two independently-developed lines from base 006d3d0:
  ours   — M9/M10 community layers, retroactive purge + re-materialization,
           signal revocation, agent capability boundaries, P1 feedback loop,
           reason labels, instrumented metrics
  theirs — M11/M12 cluster mode (tidal-net gRPC transport, tidal-server
           cluster/scatter-gather, tidal-stress), multi-vector preference,
           ANN candidate-gen, warm-tier day buckets, keyed signal snapshots

Notable semantic resolutions:

* storage::keys::Tag — both sides allocated 0x0E..0x11 for different
  records. Kept theirs' 0x0E..0x1A (shipped on-disk format) and renumbered
  ours to 0x1B..0x1E (CommunityMembership/Revocation/PurgeManifest/
  CommunityLeave); Tag::ALL grown to 30 so the contiguity drift guard holds.

* ranking executor — took theirs' rewrite (SignalReadPlan pre-pass, keyed
  SignalKey snapshots, Result-returning reads, finalize()) and re-applied
  ours' M10 read suppression at the chokepoints it introduced:
  single_signal_score, score_hot/trending/controversial,
  CreatorEngagementRate, and the Stage-4 boost loop.

* signals::warm — theirs' day-bucket/read-time-rotation rewrite, with ours'
  subtract_bucket and Clone extended to the new day tier; ours' test split
  kept (warm/tests.rs, warm/proptests.rs) carrying theirs' updated bodies.

* db::signals — kept ours' contribution-logging try_cohort_attribution in
  signal_dispatch.rs and theirs' event-time try_update_preference_vector;
  dropped the superseded duplicates.

* db::mod / from_parts — theirs' constructors, with ours' purge/
  re-materialization/revocation/community/skip-counter fields and restart
  rebuilds; from_parts kept in its own file per the 600-line guideline.

* schema::validation::builders — ours' module split with theirs' expanded
  tests; policy validation runs both sides' checks (read-signal lists +
  profile overrides, then the zero-duration limit guard).

* feedback Unhide no longer writes a -1.0 "hide" signal: theirs' engine
  rejects negative weights (spec §8). Reverses index state only, matching
  every other undo action.

* SessionState::new is now the single construction path (gains
  overrides_rejected/default_profile); AuditEntry gains kind on the
  deserialize path, inferred from the accepted flag as before.

* Removed tidal/src/replication/tcp_transport.rs and its test: never
  declared in replication/mod.rs on either branch, so it had never
  compiled and nothing referenced it. Superseded by tidal-net's
  GrpcTransport.

Verified: cargo clippy -p tidaldb (lib) clean; --all-targets compiles for
tidaldb/tidal-net/tidal-server/tidal-stress; 2094/2094 lib tests and the
integration suite pass except m8p3_reconcile_production's two CRDT-count
assertions, which fail identically on MERGE_HEAD (pre-existing).
tidalctl cannot build locally: its aws-sdk deps need rustc 1.91.1, local
toolchain is 1.91.0.
2026-08-03 02:16:04 -06:00

83 lines
2.8 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,
..AgentPolicy::default()
},
);
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);
}