Files
games/scripts/audit_distribution_layout.py

129 lines
5.0 KiB
Python

#!/usr/bin/env python3
# file: scripts/audit_distribution_layout.py
# version: 5
"""Audit the static distribution layout expected by supported POCs."""
from __future__ import annotations
import argparse
import pathlib
import sys
FORBIDDEN_PATHS = (
"builds",
)
REQUIRED_PATHS = (
"crates/apps/game-reflex-poc-desktop/Cargo.toml",
"crates/apps/game-snake-poc-desktop/Cargo.toml",
"crates/apps/game-reflex-poc-tauri/Cargo.toml",
"crates/apps/game-reflex-poc-tauri/package.json",
"crates/apps/game-reflex-poc-tauri/tsconfig.json",
"crates/apps/game-reflex-poc-tauri/vite.config.ts",
"crates/apps/game-reflex-poc-tauri/tauri.conf.json",
"crates/apps/game-reflex-poc-tauri/capabilities/default.json",
"crates/apps/game-reflex-poc-tauri/icons/icon.png",
"crates/apps/game-reflex-poc-tauri/frontend/index.html",
"crates/apps/game-reflex-poc-tauri/frontend/ts/main.ts",
"crates/apps/game-reflex-poc-wasm/Cargo.toml",
"crates/apps/game-snake-poc-wasm/Cargo.toml",
"Web/game-snake-poc/package.json",
"Web/game-snake-poc/tsconfig.json",
"Web/game-snake-poc/vite.config.ts",
"Web/game-snake-poc/frontend/main.html",
"Web/game-snake-poc/frontend/sass/_simplebar.scss",
"Web/game-snake-poc/frontend/sass/main.scss",
"Web/game-snake-poc/frontend/ts/main.ts",
"Android/game-reflex-poc/build.gradle",
"Android/game-snake-poc/build.gradle",
"scripts/build_android_rust.py",
"scripts/build_reflex_tauri_wasm.py",
"assets/common",
"assets/game-reflex-poc",
"assets/game-snake-poc",
)
def audit_snake_web_shell(root: pathlib.Path) -> list[str]:
"""Validate the KSP-derived bounded SimpleBar shell contract."""
violations: list[str] = []
html_path = root / "Web/game-snake-poc/frontend/main.html"
app_scss_path = root / "Web/game-snake-poc/frontend/sass/_app.scss"
main_ts_path = root / "Web/game-snake-poc/frontend/ts/main.ts"
if not html_path.exists() or not app_scss_path.exists() or not main_ts_path.exists():
return violations
html = html_path.read_text(encoding="utf-8")
app_scss = app_scss_path.read_text(encoding="utf-8")
main_ts = main_ts_path.read_text(encoding="utf-8")
required_html = (
'<main class="app-main container-fluid p-0">',
'<div class="row g-0 h-100 flex-nowrap">',
'<section class="col app-content app-scrollable h-100" data-simplebar>',
)
for fragment in required_html:
if fragment not in html:
violations.append(f"DIST-LAYOUT-003: Snake Web shell missing required HTML contract: {fragment}")
if '<main class="app-main container-fluid p-0" data-simplebar>' in html:
violations.append("DIST-LAYOUT-004: data-simplebar must be attached to the bounded app-content zone, not app-main")
required_scss = (
".app-scrollable {",
"height: 100%;",
"max-height: 100%;",
)
for fragment in required_scss:
if fragment not in app_scss:
violations.append(f"DIST-LAYOUT-005: Snake Web shell missing required Sass contract: {fragment}")
required_ts = (
'import ResizeObserver from "resize-observer-polyfill";',
'import "simplebar";',
').ResizeObserver = ResizeObserver;',
)
for fragment in required_ts:
if fragment not in main_ts:
violations.append(f"DIST-LAYOUT-006: Snake Web shell missing SimpleBar bootstrap contract: {fragment}")
return violations
def main() -> int:
"""Validate that every static distribution boundary exists."""
parser = argparse.ArgumentParser()
parser.add_argument("--root", default=".", help="workspace root")
arguments = parser.parse_args()
root = pathlib.Path(arguments.root).resolve()
missing: list[str] = []
forbidden_present: list[str] = []
contract_violations: list[str] = []
for relative in REQUIRED_PATHS:
if not (root / relative).exists():
missing.append(relative)
for relative in FORBIDDEN_PATHS:
if (root / relative).exists():
forbidden_present.append(relative)
contract_violations.extend(audit_snake_web_shell(root))
if missing:
for relative in missing:
print(f"DIST-LAYOUT-001: missing required path: {relative}", file=sys.stderr)
print(f"Distribution layout audit: {len(missing)} violation(s)", file=sys.stderr)
return 1
if forbidden_present:
for relative in forbidden_present:
print(f"DIST-LAYOUT-002: generated path must stay outside repository: {relative}", file=sys.stderr)
print(f"Distribution layout audit: {len(forbidden_present)} violation(s)", file=sys.stderr)
return 1
if contract_violations:
for violation in contract_violations:
print(violation, file=sys.stderr)
print(f"Distribution layout audit: {len(contract_violations)} violation(s)", file=sys.stderr)
return 1
print(f"Distribution layout audit: clean ({len(REQUIRED_PATHS)} required path(s), {len(FORBIDDEN_PATHS)} forbidden path(s) absent)")
return 0
if __name__ == "__main__":
raise SystemExit(main())