v0.1.3-pre.005

This commit is contained in:
2026-08-15 20:22:02 +02:00
parent 29660fd9f0
commit 063b24ee1c
17 changed files with 957 additions and 244 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/unit_tests/runtime.rs
// version: 6
// version: 8
#[test]
fn level_mapping_covers_all_ksp_levels() {
@@ -56,7 +56,7 @@ fn disabled_runtime_has_no_layers_or_outputs() {
};
assert!(prepared.layers.is_empty());
assert!(prepared.outputs.console.is_none());
assert!(prepared.outputs.file.is_none());
assert!(prepared.outputs.files.is_empty());
}
#[test]
@@ -75,7 +75,7 @@ fn console_runtime_composes_takeover_filter_before_formatter_and_owns_guard() {
};
assert_eq!(prepared.layers.len(), 1);
assert!(prepared.outputs.console.is_some());
assert!(prepared.outputs.file.is_none());
assert!(prepared.outputs.files.is_empty());
assert_eq!(prepared.outputs.dropped_lines(), crate::DroppedLines::zero());
}
@@ -103,40 +103,74 @@ fn takeover_filter_prefers_more_specific_ksp_prefixes_and_supports_off() {
}
#[test]
fn pre_multi_sink_runtime_rejects_new_capabilities_instead_of_ignoring_them() {
let routed_console = crate::ConsoleSettings::new(
fn multi_sink_runtime_accepts_metadata_routing_formats_and_console_ansi() {
let root = std::env::temp_dir().join(format!("ksp-pre005-unit-{}", std::process::id()));
let _cleanup_before = std::fs::remove_dir_all(root.as_path());
let console = crate::ConsoleSettings::new(
true,
crate::ConsoleOutput::Stdout,
true,
crate::LogFormat::Compact,
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["ksp-logging-lib".to_string()], std::vec!["logging".to_string()]),
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["ksp-logging-lib".to_string()], std::vec!["*".to_string()]),
);
let routed_settings =
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::Some(routed_console), std::vec::Vec::new());
assert!(routed_settings.validate().is_ok());
assert!(super::prepare_runtime(&routed_settings).is_err());
let first_file = crate::FileSettings::new(
"file.first",
true,
"logs",
root.join("first"),
"first.log",
crate::FileRotation::Never,
crate::LogFormat::Human,
crate::OutputFilter::unrestricted(),
crate::LogFormat::Pretty,
crate::OutputFilter::new(crate::LogFilterLevel::Info, std::vec!["ksp-logging-lib".to_string()], std::vec!["*".to_string()]),
);
let second_file = crate::FileSettings::new(
"file.second",
true,
"logs",
"second.log",
root.join("second"),
"second.jsonl",
crate::FileRotation::Never,
crate::LogFormat::Human,
crate::OutputFilter::unrestricted(),
crate::LogFormat::Json,
crate::OutputFilter::new(crate::LogFilterLevel::Error, std::vec!["*".to_string()], std::vec!["*".to_string()]),
);
let multi_file_settings =
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![first_file, second_file]);
assert!(multi_file_settings.validate().is_ok());
assert!(super::prepare_runtime(&multi_file_settings).is_err());
let settings = crate::LoggingSettings::new(
crate::LogFilterLevel::Trace,
crate::SpanEvents::Off,
std::option::Option::Some(console),
std::vec![first_file, second_file],
);
let result = super::prepare_runtime(&settings);
assert!(result.is_ok());
let prepared = match result {
std::result::Result::Ok(prepared) => prepared,
std::result::Result::Err(_) => return,
};
assert_eq!(prepared.layers.len(), 1);
assert!(prepared.outputs.console.is_some());
assert_eq!(prepared.outputs.files.len(), 2);
assert_eq!(prepared.outputs.file_dropped_lines("file.first"), std::option::Option::Some(0));
assert_eq!(prepared.outputs.file_dropped_lines("file.second"), std::option::Option::Some(0));
drop(prepared);
let cleanup_after = std::fs::remove_dir_all(root.as_path());
assert!(cleanup_after.is_ok());
}
#[test]
fn domain_routing_is_explicitly_deferred_instead_of_ignored() {
let console = crate::ConsoleSettings::new(
true,
crate::ConsoleOutput::Stdout,
false,
crate::LogFormat::Human,
crate::OutputFilter::new(crate::LogFilterLevel::Debug, std::vec!["*".to_string()], std::vec!["logging".to_string()]),
);
let settings = crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::Some(console), std::vec::Vec::new());
assert!(settings.validate().is_ok());
let result = super::prepare_runtime(&settings);
assert!(result.is_err());
let error = match result {
std::result::Result::Ok(_) => return,
std::result::Result::Err(error) => error,
};
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_SETTINGS);
}
struct BlockingWriter {

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/unit_tests/settings.rs
// version: 2
// version: 3
fn unrestricted_file(output_id: &str) -> crate::FileSettings {
return crate::FileSettings::new(
@@ -50,8 +50,10 @@ fn output_filter_preserves_level_targets_and_domains() {
assert_eq!(filter.domains().len(), 2);
assert_eq!(filter.domains()[0], "config");
assert_eq!(filter.domains()[1], "logging.runtime");
assert!(!filter.is_unrestricted());
assert!(crate::OutputFilter::unrestricted().is_unrestricted());
let unrestricted = crate::OutputFilter::unrestricted();
assert_eq!(unrestricted.level(), crate::LogFilterLevel::Trace);
assert_eq!(unrestricted.targets(), &["*".to_string()]);
assert_eq!(unrestricted.domains(), &["*".to_string()]);
}
#[test]
@@ -74,7 +76,7 @@ fn compatibility_console_constructors_are_unrestricted_human_and_non_ansi() {
assert!(stdout.enabled());
assert!(!stdout.ansi());
assert_eq!(stdout.format(), crate::LogFormat::Human);
assert!(stdout.filter().is_unrestricted());
assert_eq!(stdout.filter(), &crate::OutputFilter::unrestricted());
}
#[test]
@@ -175,21 +177,21 @@ fn validation_rejects_empty_file_paths_and_persistent_ansi() {
crate::OutputFilter::unrestricted(),
)
.with_ansi(true);
assert!(
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![empty_directory])
.validate()
.is_err()
);
assert!(
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![empty_prefix])
.validate()
.is_err()
);
assert!(
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![ansi_file])
.validate()
.is_err()
);
let empty_directory_settings =
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![empty_directory]);
let empty_prefix_settings =
crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![empty_prefix]);
let ansi_file_settings = crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::None, std::vec![ansi_file]);
assert!(empty_directory_settings.validate().is_err());
assert!(empty_prefix_settings.validate().is_err());
assert!(ansi_file_settings.validate().is_err());
}
#[test]
fn validation_rejects_ansi_json_console() {
let console = crate::ConsoleSettings::new(true, crate::ConsoleOutput::Stdout, true, crate::LogFormat::Json, crate::OutputFilter::unrestricted());
let settings = crate::LoggingSettings::new(crate::LogFilterLevel::Info, crate::SpanEvents::Off, std::option::Option::Some(console), std::vec::Vec::new());
assert!(settings.validate().is_err());
}
#[test]

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/unit_tests/writer.rs
// version: 1
// version: 2
#[test]
fn ansi_writer_strips_csi_sequences() {
@@ -28,3 +28,24 @@ fn ansi_writer_strips_osc_sequences_terminated_by_bell_or_st() {
assert!(second.is_ok());
assert_eq!(writer.into_inner(), b"abcd");
}
#[test]
fn output_level_routing_covers_all_filter_levels() {
assert!(!super::level_is_enabled(&tracing::Level::ERROR, crate::LogFilterLevel::Off));
assert!(super::level_is_enabled(&tracing::Level::ERROR, crate::LogFilterLevel::Error));
assert!(!super::level_is_enabled(&tracing::Level::WARN, crate::LogFilterLevel::Error));
assert!(super::level_is_enabled(&tracing::Level::WARN, crate::LogFilterLevel::Warn));
assert!(!super::level_is_enabled(&tracing::Level::INFO, crate::LogFilterLevel::Warn));
assert!(super::level_is_enabled(&tracing::Level::INFO, crate::LogFilterLevel::Info));
assert!(super::level_is_enabled(&tracing::Level::DEBUG, crate::LogFilterLevel::Debug));
assert!(super::level_is_enabled(&tracing::Level::TRACE, crate::LogFilterLevel::Trace));
}
#[test]
fn disabled_routed_writer_discards_bytes_without_error() {
let mut writer = super::RoutedWriter::<std::vec::Vec<u8>>::Disabled;
let write_result = std::io::Write::write_all(&mut writer, b"discarded");
let flush_result = std::io::Write::flush(&mut writer);
assert!(write_result.is_ok());
assert!(flush_result.is_ok());
}