Add unattended end-to-end self-test mode for the production webview
VOICED_SELFTEST_OUT runs the Diagnostics checks plus an issue, archive, export (searchable, flattened, re-render), cancel and archive-immutability flow through the real IPC, writes a JSON report and exits. Inert without the variable; doubles as the per-release gate on installed builds.
This commit is contained in:
@@ -2,6 +2,7 @@ mod commands;
|
||||
mod db;
|
||||
mod gst;
|
||||
mod models;
|
||||
mod selftest;
|
||||
|
||||
use rusqlite::Connection;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -135,6 +136,8 @@ pub fn run() {
|
||||
commands::files::get_last_export_dir,
|
||||
commands::files::reveal_in_folder,
|
||||
commands::files::open_file,
|
||||
selftest::selftest_config,
|
||||
selftest::selftest_report,
|
||||
])
|
||||
.run(tauri::generate_context!());
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//! Unattended end-to-end self-test hook. Inert unless `VOICED_SELFTEST_OUT` is set: the webview asks
|
||||
//! for the report path at startup, runs its checks and hands the JSON back, and the process exits with
|
||||
//! the verdict. This is the release gate that proves the real webview works, which Node tests cannot.
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const ENV_VAR: &str = "VOICED_SELFTEST_OUT";
|
||||
|
||||
fn configured_path() -> Option<PathBuf> {
|
||||
std::env::var_os(ENV_VAR).filter(|v| !v.is_empty()).map(PathBuf::from)
|
||||
}
|
||||
|
||||
fn write_report(path: &Path, json: &str) -> Result<(), String> {
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent).map_err(|e| format!("Could not create {}: {e}", parent.display()))?;
|
||||
}
|
||||
let mut file = std::fs::File::create(path).map_err(|e| format!("Could not write the report: {e}"))?;
|
||||
file.write_all(json.as_bytes())
|
||||
.and_then(|()| file.sync_all())
|
||||
.map_err(|e| format!("Could not write the report: {e}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn selftest_config() -> Option<String> {
|
||||
configured_path().map(|p| p.to_string_lossy().into_owned())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn selftest_report(json: String, ok: bool) -> Result<(), String> {
|
||||
let path = configured_path().ok_or_else(|| "The self-test is not enabled".to_string())?;
|
||||
write_report(&path, &json)?;
|
||||
std::process::exit(if ok { 0 } else { 1 });
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn writes_the_report_creating_folders() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("a/b/report.json");
|
||||
write_report(&path, "{\"ok\":true}").unwrap();
|
||||
assert_eq!(std::fs::read_to_string(&path).unwrap(), "{\"ok\":true}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user