v0.1.4-pre.018
This commit is contained in:
72
crates/ksp-app-config-desk/tests/desktop_contract.rs
Normal file
72
crates/ksp-app-config-desk/tests/desktop_contract.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
// file: crates/ksp-app-config-desk/tests/desktop_contract.rs
|
||||
// version: 1
|
||||
|
||||
//! Desktop build/shell contract audits for Config Desk.
|
||||
|
||||
fn app_root() -> std::path::PathBuf {
|
||||
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
}
|
||||
|
||||
fn read_text(path: &std::path::Path) -> String {
|
||||
let source = std::fs::read_to_string(path);
|
||||
assert!(source.is_ok(), "unable to read {}", path.display());
|
||||
return match source {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => String::new(),
|
||||
};
|
||||
}
|
||||
|
||||
fn read_json(path: &std::path::Path) -> serde_json::Value {
|
||||
let source = read_text(path);
|
||||
let parsed = serde_json::from_str::<serde_json::Value>(source.as_str());
|
||||
assert!(parsed.is_ok(), "unable to parse {}", path.display());
|
||||
return match parsed {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => serde_json::Value::Null,
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tauri_and_frontend_build_contracts_remain_explicit() {
|
||||
let root = app_root();
|
||||
let tauri = read_json(root.join("tauri.conf.json").as_path());
|
||||
assert_eq!(tauri.pointer("/build/devUrl").and_then(serde_json::Value::as_str), std::option::Option::Some("http://localhost:1430"));
|
||||
assert_eq!(tauri.pointer("/build/beforeDevCommand").and_then(serde_json::Value::as_str), std::option::Option::Some("npm run dev"));
|
||||
assert_eq!(tauri.pointer("/build/beforeBuildCommand").and_then(serde_json::Value::as_str), std::option::Option::Some("npm run build"));
|
||||
let windows = tauri.pointer("/app/windows").and_then(serde_json::Value::as_array);
|
||||
assert!(windows.is_some());
|
||||
let windows = match windows {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
assert_eq!(windows.len(), 2);
|
||||
let labels = windows.iter().filter_map(|window| window.get("label").and_then(serde_json::Value::as_str)).collect::<std::vec::Vec<_>>();
|
||||
assert_eq!(labels, ["splash", "main"]);
|
||||
let main = windows.iter().find(|window| window.get("label").and_then(serde_json::Value::as_str) == std::option::Option::Some("main"));
|
||||
assert!(main.is_some());
|
||||
if let std::option::Option::Some(main) = main {
|
||||
assert_eq!(main.get("visible").and_then(serde_json::Value::as_bool), std::option::Option::Some(false));
|
||||
}
|
||||
let package = read_json(root.join("package.json").as_path());
|
||||
let build = package.pointer("/scripts/build").and_then(serde_json::Value::as_str);
|
||||
let check = package.pointer("/scripts/check").and_then(serde_json::Value::as_str);
|
||||
assert!(build.is_some_and(|value| value.contains("tsc") && value.contains("vite build")));
|
||||
assert!(check.is_some_and(|value| value.contains("tsc --noEmit") && value.contains("vite build")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shell_registry_owns_view_activation_and_specialized_editor_dispatch() {
|
||||
let root = app_root();
|
||||
let registry = read_text(root.join("frontend/ts/shell_registry.ts").as_path());
|
||||
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
||||
let documents = read_text(root.join("frontend/ts/documents.ts").as_path());
|
||||
let html = read_text(root.join("frontend/main.html").as_path());
|
||||
assert!(registry.contains("export const viewRegistry"));
|
||||
assert!(registry.contains("fileId: \"cfg.std.logging\""));
|
||||
assert!(registry.contains("viewId: \"logging\""));
|
||||
assert!(main.contains("registeredViewIds()"));
|
||||
assert!(main.contains("ksp:activate-view"));
|
||||
assert!(documents.contains("specializedEditorForFileId"));
|
||||
assert!(documents.contains("requestViewActivation"));
|
||||
assert!(html.contains("id=\"openSpecializedEditor\""));
|
||||
}
|
||||
80
crates/ksp-app-config-desk/tests/desktop_security.rs
Normal file
80
crates/ksp-app-config-desk/tests/desktop_security.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
// file: crates/ksp-app-config-desk/tests/desktop_security.rs
|
||||
// version: 1
|
||||
|
||||
//! Desktop security/ownership regression audits local to Config Desk.
|
||||
|
||||
fn app_root() -> std::path::PathBuf {
|
||||
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
}
|
||||
|
||||
fn collect_files(directory: &std::path::Path, extension: &str, files: &mut std::vec::Vec<std::path::PathBuf>) {
|
||||
let entries = std::fs::read_dir(directory);
|
||||
let entries = match entries {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
for entry in entries {
|
||||
let entry = match entry {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => continue,
|
||||
};
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_files(path.as_path(), extension, files);
|
||||
continue;
|
||||
}
|
||||
if path.extension().and_then(std::ffi::OsStr::to_str) == std::option::Option::Some(extension) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_text(path: &std::path::Path) -> String {
|
||||
let source = std::fs::read_to_string(path);
|
||||
assert!(source.is_ok(), "unable to read {}", path.display());
|
||||
return match source {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => String::new(),
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frontend_avoids_native_dialogs_and_persistent_secret_storage() {
|
||||
let root = app_root();
|
||||
let mut typescript = std::vec::Vec::new();
|
||||
collect_files(root.join("frontend/ts").as_path(), "ts", &mut typescript);
|
||||
assert!(!typescript.is_empty());
|
||||
for path in typescript {
|
||||
let source = read_text(path.as_path());
|
||||
for forbidden in ["window.alert(", "window.confirm(", "window.prompt("] {
|
||||
assert!(!source.contains(forbidden), "{} uses forbidden browser-native dialog {forbidden}", path.display());
|
||||
}
|
||||
}
|
||||
let secret_reveal = read_text(root.join("frontend/ts/secret_reveal.ts").as_path());
|
||||
assert!(!secret_reveal.contains("localStorage"));
|
||||
assert!(!secret_reveal.contains("sessionStorage"));
|
||||
assert!(secret_reveal.contains("clearTransientSecretReveal"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tauri_commands_and_logging_adapters_remain_on_owned_boundaries() {
|
||||
let root = app_root();
|
||||
let manifest = read_text(root.join("Cargo.toml").as_path());
|
||||
assert!(manifest.contains("ksp-logging-lib"));
|
||||
assert!(manifest.contains("tauri-plugin-tracing"));
|
||||
assert!(!manifest.contains("tauri-plugin-log"));
|
||||
let source_root = root.join("src");
|
||||
let mut rust_files = std::vec::Vec::new();
|
||||
collect_files(source_root.as_path(), "rs", &mut rust_files);
|
||||
let mut command_attribute_count = 0usize;
|
||||
for path in rust_files {
|
||||
let source = read_text(path.as_path());
|
||||
let count = source.matches("#[tauri::command]").count();
|
||||
if path.file_name().and_then(std::ffi::OsStr::to_str) == std::option::Option::Some("tauri.rs") {
|
||||
command_attribute_count += count;
|
||||
} else {
|
||||
assert_eq!(count, 0, "{} declares a Tauri command outside tauri.rs", path.display());
|
||||
}
|
||||
}
|
||||
assert!(command_attribute_count > 0);
|
||||
}
|
||||
Reference in New Issue
Block a user