0.5.1-pre.005

This commit is contained in:
2026-08-10 01:36:42 +02:00
parent ec07ddbd80
commit b6a286a4df
54 changed files with 6236 additions and 5569 deletions

View File

@@ -1,11 +1,12 @@
// file: kb-app-demo-desktop/src/app_state.rs
// version: 12
// version: 13
//! Shared Tauri application state and startup initialization.
/// Shared state managed by Tauri for the desktop demo application.
pub(crate) struct AppState {
config_path: std::string::String,
logging_config_path: std::string::String,
app_config: ks_config::AppConfig,
active_profile: ks_config::ProfileConfig,
logging_guard: std::sync::Mutex<ks_logging::LoggingGuard>,
@@ -30,6 +31,7 @@ impl crate::AppState {
/// Initializes configuration, logging and shared runtime state.
pub(crate) fn initialize() -> ks_core::Result<crate::AppState> {
let config_path = resolve_config_path();
let logging_config_path = resolve_logging_config_path();
let workspace_root = crate::workspace_root_dir();
let app_config = match ks_config::read_config_json_file_with_environment(
&config_path,
@@ -42,7 +44,17 @@ impl crate::AppState {
std::result::Result::Ok(profile) => profile.clone(),
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let logging_config = convert_logging_config(&active_profile.logging);
let logging_document = match ks_logging::read_logging_json_file_with_environment(
&logging_config_path,
&workspace_root,
) {
std::result::Result::Ok(config) => config,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let logging_config = match ks_logging::active_logging_profile(&logging_document) {
std::result::Result::Ok(profile) => profile.clone(),
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let logging_guard = match ks_logging::init_logging(&logging_config) {
std::result::Result::Ok(guard) => guard,
std::result::Result::Err(error) => return std::result::Result::Err(error),
@@ -54,6 +66,7 @@ impl crate::AppState {
};
return std::result::Result::Ok(crate::AppState {
config_path: config_path.display().to_string(),
logging_config_path: logging_config_path.display().to_string(),
app_config,
active_profile,
logging_guard: std::sync::Mutex::new(logging_guard),
@@ -78,6 +91,11 @@ impl crate::AppState {
return self.config_path.as_str();
}
/// Returns the path used to load the logging configuration file.
pub(crate) fn logging_config_path(&self) -> &str {
return self.logging_config_path.as_str();
}
/// Returns the complete parsed application configuration.
pub(crate) fn app_config(&self) -> &ks_config::AppConfig {
return &self.app_config;
@@ -198,40 +216,26 @@ impl crate::AppState {
}
}
fn convert_logging_config(config: &ks_config::LoggingConfig) -> ks_logging::LoggingConfig {
let mut targets = std::vec::Vec::<ks_logging::LogTargetConfig>::new();
for target in &config.targets {
targets.push(ks_logging::LogTargetConfig {
name: target.name.clone(),
enabled: target.enabled,
sink: target.sink.clone(),
level: target.level.clone(),
path: target.path.clone(),
rotation: target.rotation.clone(),
format: target.format.clone(),
ansi: target.ansi,
targets: target.targets.clone(),
});
}
let mut target_filters = std::vec::Vec::<ks_logging::LogTargetFilterConfig>::new();
for filter in &config.target_filters {
target_filters.push(ks_logging::LogTargetFilterConfig {
target: filter.target.clone(),
level: filter.level.clone(),
});
}
return ks_logging::LoggingConfig {
default_level: config.default_level.clone(),
targets,
target_filters,
};
}
fn resolve_config_path() -> std::path::PathBuf {
let configured = std::env::var("KS_CONFIG_PATH").ok();
return resolve_config_path_from_value(configured.as_deref());
}
fn resolve_logging_config_path() -> std::path::PathBuf {
let configured = std::env::var("KS_LOGGING_CONFIG_PATH").ok();
return resolve_logging_config_path_from_value(configured.as_deref());
}
fn resolve_logging_config_path_from_value(value: std::option::Option<&str>) -> std::path::PathBuf {
if let std::option::Option::Some(configured) = value {
let trimmed = configured.trim();
if !trimmed.is_empty() {
return std::path::PathBuf::from(trimmed);
}
}
return crate::workspace_root_dir().join("config/logging.config.json");
}
fn resolve_config_path_from_value(value: std::option::Option<&str>) -> std::path::PathBuf {
if let std::option::Option::Some(configured) = value {
let trimmed = configured.trim();
@@ -239,17 +243,26 @@ fn resolve_config_path_from_value(value: std::option::Option<&str>) -> std::path
return std::path::PathBuf::from(trimmed);
}
}
return crate::workspace_root_dir().join("config/example.config.json");
return crate::workspace_root_dir().join("config/app.config.json");
}
#[cfg(test)]
mod tests {
#[test]
fn resolve_config_path_uses_workspace_example_by_default() {
fn resolve_config_path_uses_workspace_default_by_default() {
let path = super::resolve_config_path_from_value(std::option::Option::None);
assert_eq!(
path.file_name().and_then(std::ffi::OsStr::to_str),
std::option::Option::Some("example.config.json")
std::option::Option::Some("app.config.json")
);
}
#[test]
fn resolve_logging_config_path_uses_workspace_default_by_default() {
let path = super::resolve_logging_config_path_from_value(std::option::Option::None);
assert_eq!(
path.file_name().and_then(std::ffi::OsStr::to_str),
std::option::Option::Some("logging.config.json")
);
}
}

View File

@@ -1,5 +1,5 @@
// file: kb-app-demo-desktop/src/demo_execution_solana_core.rs
// version: 14
// version: 15
//! Tauri adapter for bounded Solana Core execution on Devnet.
@@ -851,7 +851,7 @@ mod tests {
#[test]
fn example_config_exposes_one_devnet_execution_profile() {
let config =
match ks_config::parse_config_json(include_str!("../../config/example.config.json")) {
match ks_config::parse_config_json(include_str!("../../config/app.config.json")) {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => panic!("example config parse failed: {error}"),
};
@@ -865,7 +865,7 @@ mod tests {
#[test]
fn profile_selection_rejects_mainnet_profiles() {
let config =
match ks_config::parse_config_json(include_str!("../../config/example.config.json")) {
match ks_config::parse_config_json(include_str!("../../config/app.config.json")) {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => panic!("example config parse failed: {error}"),
};

View File

@@ -1,5 +1,5 @@
// file: kb-app-demo-desktop/src/tauri.rs
// version: 35
// version: 36
//! Tauri runtime assembly and private command wrappers.
@@ -21,6 +21,7 @@ pub fn run() -> ks_core::Result<()> {
tracing::info!(
target: crate::TRACING_TARGET,
config_path = app_state.config_path(),
logging_config_path = app_state.logging_config_path(),
active_profile = app_state.active_profile().name.as_str(),
logging_routes = app_state.logging_route_count(),
configured_profiles = app_state.app_config().profiles.len(),