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,7 +1,7 @@
{
"name": "ksp-app-wallet-desk",
"private": true,
"version": "0.2.6-pre.3.fix.1",
"version": "0.2.6-pre.3.fix.2",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "KSP Wallet Desk",
"version": "0.2.6-pre.3.fix.1",
"version": "0.2.6-pre.3.fix.2",
"identifier": "com.sasedev.ksp-app-wallet-desk",
"build": {
"beforeDevCommand": "npm run dev",

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-wallet-desk/tests/config_composition.rs
// version: 2
// version: 3
//! Config composition contracts introduced for Wallet Desk pre.003.
@@ -29,8 +29,8 @@ fn wallet_desk_composite_selects_logging_transport_and_wallet_by_file_id() {
assert!(composite.is_ok(), "committed Wallet Desk composite should resolve: {composite:?}");
if let std::result::Result::Ok(composite) = composite {
assert_eq!(composite.profile_id(), "devnet");
assert_component(&composite, "logging", ksp_config_lib::FILE_ID_STD_LOGGING, "wallet_desk_dev");
assert_wallet_desk_logging_trace_profile(&composite);
assert_component(&composite, "logging", ksp_config_lib::FILE_ID_STD_LOGGING, "supertrace");
assert_wallet_desk_supertrace_profile(&composite);
assert_component(&composite, "transport", ksp_config_lib::FILE_ID_STD_TRANSPORT, "devnet_public");
assert_component(&composite, "wallet", ksp_config_lib::FILE_ID_STD_WALLET, "default");
}
@@ -38,12 +38,12 @@ fn wallet_desk_composite_selects_logging_transport_and_wallet_by_file_id() {
}
}
fn assert_wallet_desk_logging_trace_profile(composite: &ksp_config_lib::ResolvedConfigComposite) {
fn assert_wallet_desk_supertrace_profile(composite: &ksp_config_lib::ResolvedConfigComposite) {
let component = composite.component("logging");
assert!(component.is_some(), "missing logging component");
if let std::option::Option::Some(component) = component {
let profile = component.resolved().profile();
assert_eq!(profile.get("default_filter").and_then(serde_json::Value::as_str), std::option::Option::Some("info"));
assert_eq!(profile.get("default_filter").and_then(serde_json::Value::as_str), std::option::Option::Some("trace"));
let console = profile.get("console").and_then(serde_json::Value::as_object);
let console_filter = console
.and_then(|value| {
@@ -55,26 +55,39 @@ fn assert_wallet_desk_logging_trace_profile(composite: &ksp_config_lib::Resolved
return value.get("level");
})
.and_then(serde_json::Value::as_str);
assert_eq!(console_level, std::option::Option::Some("trace"));
let targets = console_filter
assert_eq!(console_level, std::option::Option::Some("debug"));
let console_targets = console_filter
.and_then(|value| {
return value.get("targets");
})
.and_then(serde_json::Value::as_array);
assert!(targets.is_some(), "Wallet Desk console targets should exist");
if let std::option::Option::Some(targets) = targets {
assert!(targets.iter().any(|target| -> bool {
return target.as_str() == std::option::Option::Some("ksp-app-wallet-desk");
}));
assert_eq!(console_targets.and_then(|value| value.first()).and_then(serde_json::Value::as_str), std::option::Option::Some("*"));
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 {
for target in [
"ksp-app-config-desk",
"ksp-app-wallet-desk",
"ksp-config-lib",
"ksp-core-lib",
"ksp-logging-lib",
"ksp-onchain-transport-lib",
"ksp-wallet-lib",
] {
assert!(
files.iter().any(|file| -> bool {
let filter = file.get("filter");
let level = filter.and_then(|value| value.get("level")).and_then(serde_json::Value::as_str);
let targets = filter.and_then(|value| value.get("targets")).and_then(serde_json::Value::as_array);
return level == std::option::Option::Some("trace")
&& targets.is_some_and(|targets| targets.iter().any(|value| value.as_str() == std::option::Option::Some(target)));
}),
"supertrace should contain one trace file sink for target {target}"
);
}
}
let target_filters = profile.get("target_filters").and_then(serde_json::Value::as_array);
assert!(target_filters.is_some(), "Wallet Desk target filters should exist");
if let std::option::Option::Some(target_filters) = target_filters {
assert!(target_filters.iter().any(|filter| -> bool {
return filter.get("target_prefix").and_then(serde_json::Value::as_str) == std::option::Option::Some("ksp-app-wallet-desk")
&& filter.get("level").and_then(serde_json::Value::as_str) == std::option::Option::Some("trace");
}));
}
assert!(target_filters.is_some_and(std::vec::Vec::is_empty), "supertrace should rely on the global trace takeover instead of per-target overrides");
}
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-config-lib/tests/ownership.rs
// version: 4
// version: 5
//! Workspace ownership audits for KSP application configuration boundaries.
@@ -81,6 +81,10 @@ fn collect_environment_names(source: &str, names: &mut std::collections::BTreeSe
index += 1;
continue;
};
if !environment_name_start_boundary(bytes, index) {
index += 1;
continue;
}
let mut end = index + prefix_length;
while end < bytes.len() {
let byte = bytes[end];
@@ -94,6 +98,7 @@ fn collect_environment_names(source: &str, names: &mut std::collections::BTreeSe
if let std::result::Result::Ok(candidate) = candidate
&& candidate.len() > prefix_length
&& !candidate.ends_with('_')
&& environment_name_end_boundary(bytes, end)
&& !is_environment_namespace_label(candidate)
{
names.insert(candidate.to_owned());
@@ -106,6 +111,22 @@ fn is_environment_namespace_label(candidate: &str) -> bool {
return matches!(candidate, "KSP_PUBLIC" | "KSP_SECRET" | "KSPB_PUBLIC" | "KSPB_SECRET");
}
fn environment_name_end_boundary(bytes: &[u8], end: usize) -> bool {
if end >= bytes.len() {
return true;
}
let next = bytes[end];
return !next.is_ascii_alphanumeric() && next != b'_';
}
fn environment_name_start_boundary(bytes: &[u8], index: usize) -> bool {
if index == 0 {
return true;
}
let previous = bytes[index - 1];
return !previous.is_ascii_alphanumeric() && previous != b'_';
}
fn dotenv_example_assignments(source: &str) -> std::collections::BTreeMap<String, usize> {
let mut assignments = std::collections::BTreeMap::<String, usize>::new();
for (line_index, line) in source.lines().enumerate() {
@@ -267,6 +288,8 @@ fn environment_name_scanner_ignores_namespace_labels_but_keeps_concrete_names()
const KSP_SECRET_API_KEY: &str = "KSP_SECRET_API_KEY";
const KSPB_PUBLIC_ENDPOINT: &str = "KSPB_PUBLIC_ENDPOINT";
const KSPB_SECRET_TOKEN: &str = "KSPB_SECRET_TOKEN";
const FILE_ID_COMPOSITE_KSP_APP_WALLET_DESK: &str = "cfg.composite.ksp-app-wallet-desk";
const KSP_PUBLIC_RPC_URL_SUFFIXED: &str = "not-an-env";
"#;
let mut names = std::collections::BTreeSet::<String>::new();
collect_environment_names(source, &mut names);
@@ -278,6 +301,8 @@ fn environment_name_scanner_ignores_namespace_labels_but_keeps_concrete_names()
assert!(names.contains("KSP_SECRET_API_KEY"));
assert!(names.contains("KSPB_PUBLIC_ENDPOINT"));
assert!(names.contains("KSPB_SECRET_TOKEN"));
assert!(!names.contains("KSP_APP_WALLET_DESK"));
assert!(!names.contains("KSP_PUBLIC_RPC_URL_SUFFIXED"));
}
#[test]

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");