tidaldb/tidal/tests/visibility_errors.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

57 lines
1.9 KiB
Rust

//! Integration tests for M7P4 Operational Visibility — structured error context.
//!
//! - Task 06: Structured error context
#![allow(clippy::too_many_lines, clippy::unwrap_used)]
use tidaldb::schema::EntityKind;
// ── Task 06: Structured Error Context ────────────────────────────────────────
/// `TidalError::Internal` wraps `ErrorContext` with operation + detail fields.
#[test]
fn tidal_error_internal_wraps_error_context() {
use tidaldb::TidalError;
let err = TidalError::internal("test_operation", "something went wrong");
if let TidalError::Internal(ctx) = &err {
assert_eq!(ctx.operation, "test_operation");
assert_eq!(ctx.detail, "something went wrong");
assert!(ctx.entity_id.is_none(), "entity_id should default to None");
assert!(
ctx.entity_kind.is_none(),
"entity_kind should default to None"
);
assert!(
ctx.signal_type.is_none(),
"signal_type should default to None"
);
} else {
panic!("expected TidalError::Internal, got {err:?}");
}
// Display must include the operation name.
let display = format!("{err}");
assert!(
display.contains("test_operation"),
"Display must include the operation name: {display}"
);
}
/// `ErrorContext` builder pattern sets optional fields correctly.
#[test]
fn error_context_builder_sets_optional_fields() {
use tidaldb::ErrorContext;
let ctx = ErrorContext::new("write_signal", "WAL append failed")
.with_entity(42)
.with_kind(EntityKind::Item)
.with_signal("view");
assert_eq!(ctx.operation, "write_signal");
assert_eq!(ctx.detail, "WAL append failed");
assert_eq!(ctx.entity_id, Some(42));
assert_eq!(ctx.entity_kind, Some(EntityKind::Item));
assert_eq!(ctx.signal_type, Some("view".to_string()));
}