mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
test_inventory: ignore pycache, mirror semantic discovery, distinguish optional retail hints
This commit is contained in:
@ -4,7 +4,7 @@ This document provides the authoritative subsystem test map and prerequisite cat
|
||||
|
||||
## Overview
|
||||
|
||||
The repository contains **1,177** test files, of which **1,168 (99.2%)** are fully synthetic and can be run without retail game packages, executables, or proprietary assets.
|
||||
`tools/test_inventory.py` dynamically discovers source test modules across `tests/` and `runtime/test/` (skipping bytecode caches like `__pycache__` and matching `scripts/run_semantic_tests.py` package discovery rules inside `tests/semantic/`). Over 99% of test files are synthetic and run without retail game packages, executables, or proprietary assets.
|
||||
|
||||
```bash
|
||||
# Generate the full subsystem breakdown and metrics
|
||||
@ -16,26 +16,26 @@ python -I tools/test_inventory.py --json
|
||||
# Filter tests by subsystem (runtime, shader, tools, viewer)
|
||||
python -I tools/test_inventory.py --subsystem shader
|
||||
|
||||
# Display tests requiring retail package prerequisites
|
||||
# Display tests mentioning retail package environment variables (tagged optional vs required)
|
||||
python -I tools/test_inventory.py --gaps
|
||||
```
|
||||
|
||||
## Subsystem Breakdown
|
||||
## Subsystems
|
||||
|
||||
| Subsystem | Total Files | Synthetic | Retail Gated | Primary Runners | Key Coverage Areas |
|
||||
| :--- | :--- | :--- | :--- | :--- | :--- |
|
||||
| **Shader** | 600 | 600 (100%) | 0 | `python_unittest` | RDNA2 -> SPIR-V translator, float ALU rounding, vector compares, atomics, mesh/wave64 dispatch. |
|
||||
| **Tools** | 315 | 314 (99.7%) | 1 | `python_unittest`, `pytest` | Asset exporters, PE inspection, manifest checkers, BCPack/texture swizzlers, developer scripts. |
|
||||
| **Runtime** | 228 | 220 (96.5%) | 8 | `ctest_cpp` | D3D12/Vulkan shims, PE loader, root signature parser, XMA2 audio shims, memory and descriptor heaps. |
|
||||
| **Viewer** | 34 | 34 (100%) | 0 | `python_unittest`, `node_test` | Map viewer HTTP streaming, LOD residency handoffs, camera positioning, world grid chunking. |
|
||||
- **`shader`**: RDNA2 -> SPIR-V translator, float ALU rounding, vector compares, atomics, mesh/wave64 dispatch (`python_unittest`).
|
||||
- **`tools`**: Asset exporters, PE inspection, manifest checkers, BCPack/texture swizzlers, developer scripts (`python_unittest`, `pytest`).
|
||||
- **`runtime`**: D3D12/Vulkan shims, PE loader, root signature parser, XMA2 audio shims, memory and descriptor heaps (`ctest_cpp`).
|
||||
- **`viewer`**: Map viewer HTTP streaming, LOD residency handoffs, camera positioning, world grid chunking (`python_unittest`, `node_test`).
|
||||
|
||||
## Runner Distribution
|
||||
## Runners
|
||||
|
||||
- **`python_unittest` (918 files)**: Pure standard-library Python test suites runnable with `python -I`.
|
||||
- **`ctest_cpp` (226 files)**: Native C++20 tests built with CMake/Ninja under `runtime/build/`.
|
||||
- **`pytest` (31 files)**: Tests requiring the virtual environment dependencies pinned in `tests/requirements.txt`.
|
||||
- **`node_test` (2 files)**: Viewer streaming protocol tests running under Node.js (`node --test`).
|
||||
- **`python_unittest`**: Pure standard-library Python test suites runnable with `python -I`.
|
||||
- **`ctest_cpp`**: Native C++20 tests built with CMake/Ninja under `runtime/build/`.
|
||||
- **`pytest`**: Tests requiring the virtual environment dependencies pinned in `tests/requirements.txt`.
|
||||
- **`node_test`**: Viewer streaming protocol tests running under Node.js (`node --test`).
|
||||
|
||||
## Retail-Gated Tests (Gaps)
|
||||
## Retail-Gated & Optional Retail Checks (`--gaps`)
|
||||
|
||||
Only 9 tests require the retail package (`LEONIDA_GAME_DIR` / `LEONIDA_MOVIE`), located primarily in `runtime/test/` for end-to-end boot and loader verification against the retail package manifest. All other 1,168 tests execute strictly against hand-authored synthetic fixtures.
|
||||
`--gaps` surfaces files mentioning `LEONIDA_GAME_DIR`, `LEONIDA_MOVIE`, or `requires_retail_package`, labelling them with `retail_requirement`:
|
||||
- **`optional`**: Tests whose primary suite runs synthetically and only execute an optional retail leg when `LEONIDA_GAME_DIR`/`LEONIDA_MOVIE` is set (printing `SKIP` otherwise, such as `pe_loader_test.cpp`). These still count toward `synthetic` coverage.
|
||||
- **`required`**: Tests strictly gated on retail package prerequisites.
|
||||
|
||||
@ -5,10 +5,16 @@ import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
INVENTORY_TOOL = ROOT / "tools" / "test_inventory.py"
|
||||
TOOLS = ROOT / "tools"
|
||||
INVENTORY_TOOL = TOOLS / "test_inventory.py"
|
||||
if str(TOOLS) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
|
||||
import test_inventory # noqa: E402
|
||||
|
||||
|
||||
class TestInventoryTests(unittest.TestCase):
|
||||
@ -64,6 +70,47 @@ class TestInventoryTests(unittest.TestCase):
|
||||
data = json.loads(proc.stdout)
|
||||
for t in data["tests"]:
|
||||
self.assertTrue(t["needs_retail_game_data"])
|
||||
self.assertIn(t["retail_requirement"], ("optional", "required"))
|
||||
|
||||
def test_ignores_pycache_and_matches_semantic_discovery_rules(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_root = Path(tmp)
|
||||
sem = tmp_root / "tests" / "semantic"
|
||||
cache = sem / "__pycache__"
|
||||
pkg = sem / "pkg"
|
||||
rt = tmp_root / "runtime" / "test"
|
||||
cache.mkdir(parents=True)
|
||||
pkg.mkdir(parents=True)
|
||||
rt.mkdir(parents=True)
|
||||
|
||||
(sem / "test_sample.py").write_text("import unittest\n", encoding="utf-8", newline="\n")
|
||||
(sem / "testCase.py").write_text("import unittest\n", encoding="utf-8", newline="\n")
|
||||
(pkg / "__init__.py").write_text("import unittest\n", encoding="utf-8", newline="\n")
|
||||
(cache / "test_sample.cpython-314.pyc").write_bytes(b"\x00" * 16)
|
||||
(rt / "optional_retail_test.cpp").write_text(
|
||||
'// optional retail leg\nif (!getenv("LEONIDA_GAME_DIR")) printf("SKIP\\n");\n',
|
||||
encoding="utf-8",
|
||||
newline="\n",
|
||||
)
|
||||
(rt / "required_retail_test.py").write_text(
|
||||
"requires_retail_package = True\n", encoding="utf-8", newline="\n"
|
||||
)
|
||||
|
||||
items = {i["path"]: i for i in test_inventory.scan_tests(tmp_root)}
|
||||
self.assertEqual(
|
||||
sorted(items),
|
||||
[
|
||||
"runtime/test/optional_retail_test.cpp",
|
||||
"runtime/test/required_retail_test.py",
|
||||
"tests/semantic/pkg/__init__.py",
|
||||
"tests/semantic/testCase.py",
|
||||
"tests/semantic/test_sample.py",
|
||||
],
|
||||
)
|
||||
self.assertEqual(items["runtime/test/optional_retail_test.cpp"]["retail_requirement"], "optional")
|
||||
self.assertTrue(items["runtime/test/optional_retail_test.cpp"]["is_synthetic"])
|
||||
self.assertEqual(items["runtime/test/required_retail_test.py"]["retail_requirement"], "required")
|
||||
self.assertFalse(items["runtime/test/required_retail_test.py"]["is_synthetic"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -8,6 +8,7 @@ subsystems, tagging execution prerequisites and synthetic coverage gaps.
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@ -17,6 +18,8 @@ import sys
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
SUBSYSTEMS = ("runtime", "shader", "tools", "viewer")
|
||||
SOURCE_EXTENSIONS = (".py", ".cpp", ".c", ".cjs", ".js", ".mjs")
|
||||
SKIP_DIRS = {"__pycache__", ".git", ".pytest_cache", "build", "build_vs"}
|
||||
|
||||
|
||||
def classify_subsystem(rel_path: str, content: str) -> str:
|
||||
@ -79,53 +82,96 @@ def detect_prerequisites(runner: str, content: str) -> list[str]:
|
||||
return sorted(set(prereqs))
|
||||
|
||||
|
||||
def _discover_semantic_files(semantic_dir: Path) -> list[Path]:
|
||||
"""Mirror scripts/run_semantic_tests.py discovery rules for tests/semantic/."""
|
||||
found: list[Path] = []
|
||||
if not semantic_dir.is_dir():
|
||||
return found
|
||||
for base, dirs, files in os.walk(semantic_dir):
|
||||
dirs[:] = sorted(
|
||||
d for d in dirs
|
||||
if d not in SKIP_DIRS and os.path.isfile(os.path.join(base, d, "__init__.py"))
|
||||
)
|
||||
prefix = os.path.relpath(base, semantic_dir).replace(os.sep, ".")
|
||||
if prefix != "." and "__init__.py" in files:
|
||||
found.append(Path(base) / "__init__.py")
|
||||
for name in sorted(files):
|
||||
if re.fullmatch(r"[_a-z]\w*\.py", name, re.IGNORECASE) and fnmatch.fnmatch(name, "test*.py"):
|
||||
found.append(Path(base) / name)
|
||||
return found
|
||||
|
||||
|
||||
def _classify_retail_requirement(content: str) -> str:
|
||||
"""Classify retail package reliance as 'none', 'optional', or 'required'."""
|
||||
if "requires_retail_package" in content:
|
||||
return "required"
|
||||
has_env = "LEONIDA_GAME_DIR" in content or "LEONIDA_MOVIE" in content
|
||||
if not has_env:
|
||||
return "none"
|
||||
content_lower = content.lower()
|
||||
if "skip" in content_lower or "optional" in content_lower or "when unset" in content_lower:
|
||||
return "optional"
|
||||
return "required"
|
||||
|
||||
|
||||
def scan_tests(root: Path) -> list[dict]:
|
||||
"""Scan and catalog all test files in the repository."""
|
||||
inventory = []
|
||||
semantic_dir = root / "tests" / "semantic"
|
||||
candidates: set[Path] = set(_discover_semantic_files(semantic_dir))
|
||||
|
||||
search_dirs = [
|
||||
root / "tests",
|
||||
root / "runtime" / "test",
|
||||
]
|
||||
|
||||
for search_dir in search_dirs:
|
||||
if not search_dir.is_dir():
|
||||
continue
|
||||
for p in search_dir.rglob("*"):
|
||||
if not p.is_file():
|
||||
for base, dirs, files in os.walk(search_dir):
|
||||
base_path = Path(base)
|
||||
if base_path == semantic_dir:
|
||||
dirs[:] = []
|
||||
continue
|
||||
name_lower = p.name.lower()
|
||||
if not (
|
||||
name_lower.startswith("test_")
|
||||
or name_lower.endswith("_test.py")
|
||||
or name_lower.endswith("_test.cpp")
|
||||
or name_lower.endswith("_test.cjs")
|
||||
):
|
||||
continue
|
||||
|
||||
rel_path = p.relative_to(root).as_posix()
|
||||
try:
|
||||
content = p.read_text(encoding="utf-8", errors="ignore")
|
||||
except OSError:
|
||||
content = ""
|
||||
|
||||
subsystem = classify_subsystem(rel_path, content)
|
||||
runner = classify_runner(p, content)
|
||||
prereqs = detect_prerequisites(runner, content)
|
||||
|
||||
needs_retail = any(
|
||||
marker in content
|
||||
for marker in ("LEONIDA_GAME_DIR", "LEONIDA_MOVIE", "requires_retail_package")
|
||||
dirs[:] = sorted(
|
||||
d for d in dirs
|
||||
if d not in SKIP_DIRS and (base_path / d) != semantic_dir
|
||||
)
|
||||
for name in files:
|
||||
p = base_path / name
|
||||
if p.suffix.lower() not in SOURCE_EXTENSIONS:
|
||||
continue
|
||||
name_lower = name.lower()
|
||||
if (
|
||||
name_lower.startswith("test_")
|
||||
or name_lower.endswith("_test.py")
|
||||
or name_lower.endswith("_test.cpp")
|
||||
or name_lower.endswith("_test.cjs")
|
||||
):
|
||||
candidates.add(p)
|
||||
|
||||
inventory.append({
|
||||
"path": rel_path,
|
||||
"name": p.name,
|
||||
"subsystem": subsystem,
|
||||
"runner": runner,
|
||||
"prerequisites": prereqs,
|
||||
"is_synthetic": not needs_retail,
|
||||
"needs_retail_game_data": needs_retail,
|
||||
})
|
||||
for p in candidates:
|
||||
rel_path = p.relative_to(root).as_posix()
|
||||
try:
|
||||
content = p.read_text(encoding="utf-8", errors="ignore")
|
||||
except OSError:
|
||||
content = ""
|
||||
|
||||
subsystem = classify_subsystem(rel_path, content)
|
||||
runner = classify_runner(p, content)
|
||||
prereqs = detect_prerequisites(runner, content)
|
||||
retail_req = _classify_retail_requirement(content)
|
||||
needs_retail = retail_req != "none"
|
||||
|
||||
inventory.append({
|
||||
"path": rel_path,
|
||||
"name": p.name,
|
||||
"subsystem": subsystem,
|
||||
"runner": runner,
|
||||
"prerequisites": prereqs,
|
||||
"is_synthetic": retail_req != "required",
|
||||
"needs_retail_game_data": needs_retail,
|
||||
"retail_requirement": retail_req,
|
||||
})
|
||||
|
||||
return sorted(inventory, key=lambda x: x["path"])
|
||||
|
||||
@ -212,7 +258,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
print("\nFiltered Tests:")
|
||||
for item in inventory:
|
||||
prereq_str = ", ".join(item["prerequisites"]) if item["prerequisites"] else "none"
|
||||
print(f" [{item['subsystem']}] {item['path']} ({item['runner']}) — prereqs: {prereq_str}")
|
||||
retail_tag = f" [retail:{item['retail_requirement']}]" if item["retail_requirement"] != "none" else ""
|
||||
print(f" [{item['subsystem']}] {item['path']} ({item['runner']}){retail_tag} — prereqs: {prereq_str}")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user