142 lines
4.6 KiB
Python
142 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def run_command(command: list[str], cwd: Path) -> tuple[int, str]:
|
|
completed = subprocess.run(command, cwd=cwd, text=True, capture_output=True)
|
|
output = (completed.stdout or "") + (completed.stderr or "")
|
|
if output:
|
|
sys.stdout.write(output)
|
|
if not output.endswith("\n"):
|
|
sys.stdout.write("\n")
|
|
return completed.returncode, output
|
|
|
|
|
|
def command_name(name: str) -> str:
|
|
if os.name == "nt" and name == "npm":
|
|
return "npm.cmd"
|
|
return name
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", required=True)
|
|
args = parser.parse_args()
|
|
|
|
root = Path(args.root)
|
|
tauri_app = root / "tauri-app"
|
|
tauri_backend = tauri_app / "src-tauri"
|
|
|
|
unit_command = [
|
|
command_name("npm"),
|
|
"test",
|
|
"--",
|
|
"src/features/runtime/runtime-utils.test.ts",
|
|
"src/features/runtime/components/RuntimeSurface.test.tsx",
|
|
]
|
|
saved_startup_command = [
|
|
command_name("npm"),
|
|
"test",
|
|
"--",
|
|
"src/features/runtime/components/RuntimeSurface.test.tsx",
|
|
"-t",
|
|
"covers the saved local startup lifecycle from stopped to starting to ready",
|
|
]
|
|
local_onboarding_command = [
|
|
command_name("npm"),
|
|
"test",
|
|
"--",
|
|
"src/features/runtime/components/RuntimeSurface.test.tsx",
|
|
"-t",
|
|
"supports local onboarding from browsing a models folder through save and start",
|
|
]
|
|
local_mode_cta_command = [
|
|
command_name("npm"),
|
|
"test",
|
|
"--",
|
|
"src/features/runtime/components/RuntimeSurface.test.tsx",
|
|
"-t",
|
|
"keeps the local primary CTA visible while switching from remote to local mode",
|
|
]
|
|
health_revalidation_surface_command = [
|
|
command_name("npm"),
|
|
"test",
|
|
"--",
|
|
"src/features/runtime/components/RuntimeSurface.test.tsx",
|
|
"-t",
|
|
"surfaces degraded local runtime state after periodic health revalidation fails",
|
|
]
|
|
build_command = [command_name("npm"), "run", "build"]
|
|
cargo_check_command = [
|
|
command_name("cargo"),
|
|
"check",
|
|
"--manifest-path",
|
|
str(tauri_backend / "Cargo.toml"),
|
|
]
|
|
health_revalidation_backend_command = [
|
|
command_name("cargo"),
|
|
"test",
|
|
"--manifest-path",
|
|
str(tauri_backend / "Cargo.toml"),
|
|
"runtime::tests::runtime_revalidation_marks_unhealthy_local_process_as_degraded",
|
|
"--",
|
|
"--exact",
|
|
]
|
|
|
|
unit_code, _ = run_command(unit_command, tauri_app)
|
|
saved_startup_code, _ = run_command(saved_startup_command, tauri_app)
|
|
local_onboarding_code, _ = run_command(local_onboarding_command, tauri_app)
|
|
local_mode_cta_code, _ = run_command(local_mode_cta_command, tauri_app)
|
|
health_revalidation_surface_code, _ = run_command(
|
|
health_revalidation_surface_command, tauri_app
|
|
)
|
|
build_code, _ = run_command(build_command, tauri_app)
|
|
cargo_check_code, _ = run_command(cargo_check_command, root)
|
|
health_revalidation_backend_code, _ = run_command(
|
|
health_revalidation_backend_command, root
|
|
)
|
|
|
|
unit_passed = 1 if unit_code == 0 else 0
|
|
saved_startup_flow_passed = 1 if saved_startup_code == 0 else 0
|
|
local_onboarding_flow_passed = 1 if local_onboarding_code == 0 else 0
|
|
local_mode_cta_passed = 1 if local_mode_cta_code == 0 else 0
|
|
health_revalidation_passed = (
|
|
1
|
|
if health_revalidation_surface_code == 0
|
|
and health_revalidation_backend_code == 0
|
|
else 0
|
|
)
|
|
build_passed = 1 if build_code == 0 else 0
|
|
cargo_check_passed = 1 if cargo_check_code == 0 else 0
|
|
|
|
total_checks = 7
|
|
passed_checks = (
|
|
unit_passed
|
|
+ saved_startup_flow_passed
|
|
+ local_onboarding_flow_passed
|
|
+ local_mode_cta_passed
|
|
+ health_revalidation_passed
|
|
+ build_passed
|
|
+ cargo_check_passed
|
|
)
|
|
score = round((passed_checks / total_checks) * 100.0, 3)
|
|
|
|
print(f"METRIC runtime_lifecycle_score={score}")
|
|
print(f"METRIC unit_passed={unit_passed}")
|
|
print(f"METRIC local_mode_cta_passed={local_mode_cta_passed}")
|
|
print(f"METRIC saved_startup_flow_passed={saved_startup_flow_passed}")
|
|
print(f"METRIC local_onboarding_flow_passed={local_onboarding_flow_passed}")
|
|
print(f"METRIC health_revalidation_passed={health_revalidation_passed}")
|
|
print(f"METRIC build_passed={build_passed}")
|
|
print(f"METRIC cargo_check_passed={cargo_check_passed}")
|
|
|
|
return 0 if passed_checks == total_checks else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|