v0.2.6-pre.003-fix.002

This commit is contained in:
2026-08-20 21:33:46 +02:00
parent 0e72914237
commit 3fa4ab251a
13 changed files with 652 additions and 81 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-config-lib/unit_tests/document.rs
// version: 4
// version: 5
#[test]
fn committed_logging_document_passes_registered_schema_and_semantic_validation() {
@@ -32,6 +32,63 @@ fn committed_logging_document_passes_registered_schema_and_semantic_validation()
}
}
#[test]
fn committed_logging_document_exposes_reusable_operational_profiles() {
let workspace = workspace_root();
let bootstrap = crate::ConfigBootstrapOptions::from_paths(workspace.join("config"), workspace.join("config/schemas"));
let registry = crate::ConfigFileRegistry::defaults();
let file_id = crate::ConfigFileId::new(crate::FILE_ID_STD_LOGGING);
assert!(bootstrap.is_ok(), "workspace Config paths should be valid: {bootstrap:?}");
assert!(registry.is_ok(), "default registry should be valid: {registry:?}");
assert!(file_id.is_ok(), "logging file_id should be valid: {file_id:?}");
if let (std::result::Result::Ok(bootstrap), std::result::Result::Ok(registry), std::result::Result::Ok(file_id)) = (bootstrap, registry, file_id) {
let engine = crate::ConfigDocumentEngine::new(bootstrap, registry);
let document = engine.load_validated_document(&file_id);
assert!(document.is_ok(), "committed std.logging.json should validate: {document:?}");
if let std::result::Result::Ok(document) = document {
let profiles = document.value().get("profiles").and_then(serde_json::Value::as_array);
assert!(profiles.is_some(), "validated Logging document should retain profiles");
if let std::option::Option::Some(profiles) = profiles {
for profile_id in
["console_error", "console_warn", "console_info", "console_debug", "console_trace", "file_info", "local_dev", "superdev", "supertrace"]
{
assert!(
profiles.iter().any(|profile| -> bool {
return profile.get("profile_id").and_then(serde_json::Value::as_str) == std::option::Option::Some(profile_id);
}),
"committed Logging document is missing profile {profile_id}"
);
}
assert_super_profile(profiles, "superdev", "debug");
assert_super_profile(profiles, "supertrace", "trace");
}
}
}
}
fn assert_super_profile(profiles: &[serde_json::Value], profile_id: &str, file_level: &str) {
let profile = profiles.iter().find(|profile| -> bool {
return profile.get("profile_id").and_then(serde_json::Value::as_str) == std::option::Option::Some(profile_id);
});
assert!(profile.is_some(), "missing super Logging profile {profile_id}");
if let std::option::Option::Some(profile) = profile {
let console_level =
profile.get("console").and_then(|value| value.get("filter")).and_then(|value| value.get("level")).and_then(serde_json::Value::as_str);
assert_eq!(console_level, std::option::Option::Some("debug"));
let files = profile.get("files").and_then(serde_json::Value::as_array);
assert_eq!(files.map(std::vec::Vec::len), std::option::Option::Some(7));
if let std::option::Option::Some(files) = files {
assert!(
files.iter().all(|file| -> bool {
return file.get("filter").and_then(|value| value.get("level")).and_then(serde_json::Value::as_str)
== std::option::Option::Some(file_level);
}),
"all {profile_id} file sinks should use level {file_level}"
);
}
}
}
#[test]
fn missing_document_is_reported_with_file_read_error() {
let fixture = fixture_roots("missing-document");