#!/usr/bin/env python3 """Repository layout contract: MRDIMM top plus isolated 6400 top.""" from __future__ import annotations import sys import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] TOOLS = ROOT / "tools" if str(TOOLS) not in sys.path: sys.path.insert(0, str(TOOLS)) import test_profiles # noqa: E402 class ProjectStructureTests(unittest.TestCase): def test_new_architecture_and_evidence_directories_exist(self) -> None: profile = test_profiles.detect_test_profile(ROOT) required = test_profiles.structure_required_paths(profile) for relative in required: with self.subTest(relative=relative, profile=profile): # Compact trees may nest under source/; accept either layout. candidates = ( ROOT / relative, ROOT / "source" / relative, ) self.assertTrue( any(path.is_file() for path in candidates), f"{relative} missing under profile={profile}", ) if not test_profiles.requires_reference_legacy_rtl(profile): for relative in test_profiles.REFERENCE_ONLY_PATHS: with self.subTest(relative=relative, profile=profile): # Detached compact must not require excluded legacy_rtl. self.assertFalse( test_profiles.requires_reference_legacy_rtl(profile), "review-compact-detached must not require legacy_rtl", ) def test_only_canonical_top_is_active(self) -> None: top_dirs = ( ROOT / "src" / "top", ROOT / "source" / "src" / "top", ) top_dir = next((path for path in top_dirs if path.is_dir()), None) self.assertIsNotNone(top_dir, "src/top missing") assert top_dir is not None tops = sorted(path.name for path in top_dir.glob("*.v")) self.assertEqual( tops, ["prod2u_6400_front_back_top.v", "prod2u_p4_normal_v3_top.v"], ) def test_active_td_and_build_inputs_exclude_retired_protocol(self) -> None: def _read(*parts: str) -> str: for base in (ROOT, ROOT / "source"): path = base.joinpath(*parts) if path.is_file(): return path.read_text(encoding="utf-8") self.fail(f"missing {'/'.join(parts)}") return "" active = "\n".join( [ _read("td", "syn", "prod2u_p4_normal_v3.tcl"), _read("td", "phy", "prod2u_p4_normal_v3.tcl"), _read("td", "prod2u_p4_normal_v3.prj"), _read("tools", "prod2u_p4_normal_v3_build.py"), ] ).casefold() for retired in ("binary921", "921600", "response_scheduler", "host_ack", "jog", "motor_compat", "solenoid"): self.assertNotIn(retired, active) def test_phase2_top_port_shape_has_three_axis_and_six_limits(self) -> None: top_path = None for base in (ROOT, ROOT / "source"): candidate = base / "src" / "top" / "prod2u_p4_normal_v3_top.v" if candidate.is_file(): top_path = candidate break self.assertIsNotNone(top_path) assert top_path is not None top = top_path.read_text(encoding="ascii") self.assertIn("output wire [7:0] ptc_pwm_out", top) self.assertIn("output wire [3:0] fan_pwm_out", top) for port in ("z_step", "z_dir", "x_limit_ls", "x_limit_hs", "z_limit_hs"): self.assertIn(port, top) self.assertNotIn("intake_solenoid_out", top) if __name__ == "__main__": unittest.main()