OR-1 dataflow CPU sketch
1"""Regression tests: deleted types must not be re-introduced."""
2
3import ast
4from pathlib import Path
5
6import cm_inst
7import tokens
8
9PROJECT_ROOT = Path(__file__).resolve().parent.parent
10DELETED_NAMES = frozenset({
11 "SysToken", "CfgToken", "IOToken", "LoadInstToken", "RouteSetToken", "CfgOp",
12})
13
14
15class TestAC1_DeletedTypesAbsent:
16 """AC1: Old token types and CfgOp must not exist."""
17
18 def test_no_sys_token(self):
19 """SysToken must not exist in tokens module."""
20 assert not hasattr(tokens, 'SysToken')
21
22 def test_no_cfg_token(self):
23 """CfgToken must not exist in tokens module."""
24 assert not hasattr(tokens, 'CfgToken')
25
26 def test_no_io_token(self):
27 """IOToken must not exist in tokens module."""
28 assert not hasattr(tokens, 'IOToken')
29
30 def test_no_load_inst_token(self):
31 """LoadInstToken must not exist in tokens module."""
32 assert not hasattr(tokens, 'LoadInstToken')
33
34 def test_no_route_set_token(self):
35 """RouteSetToken must not exist in tokens module."""
36 assert not hasattr(tokens, 'RouteSetToken')
37
38 def test_no_cfg_op(self):
39 """CfgOp must not exist in cm_inst module."""
40 assert not hasattr(cm_inst, 'CfgOp')
41
42
43class TestAC1_3NoStaleImports:
44 """AC1.3: No module in the codebase imports any deleted type."""
45
46 def test_no_production_code_imports_deleted_types(self):
47 """Scan all production .py files for import statements referencing deleted names."""
48 violations = []
49 for py_file in PROJECT_ROOT.rglob("*.py"):
50 if "test" in py_file.name or py_file.is_relative_to(PROJECT_ROOT / "tests"):
51 continue
52 try:
53 tree = ast.parse(py_file.read_text(), filename=str(py_file))
54 except SyntaxError:
55 continue
56 for node in ast.walk(tree):
57 if isinstance(node, ast.ImportFrom):
58 for alias in node.names:
59 if alias.name in DELETED_NAMES:
60 violations.append(f"{py_file}:{node.lineno} imports {alias.name}")
61 assert violations == [], f"Stale imports found:\n" + "\n".join(violations)
62
63
64class TestAC7_3_FrameRedesignMigration:
65 """AC7.3: Verify frame-based redesign types are correct; legacy types are gone."""
66
67 def test_aluinst_not_in_cm_inst(self):
68 """ALUInst should NOT be importable from cm_inst (replaced by Instruction)."""
69 assert not hasattr(cm_inst, 'ALUInst'), \
70 "ALUInst should not exist in cm_inst (use Instruction instead)"
71
72 def test_sminst_not_in_cm_inst(self):
73 """SMInst should NOT be importable from cm_inst (replaced by Instruction)."""
74 assert not hasattr(cm_inst, 'SMInst'), \
75 "SMInst should not exist in cm_inst (use Instruction instead)"
76
77 def test_addr_not_in_cm_inst(self):
78 """Addr should NOT be importable from cm_inst (replaced by FrameDest)."""
79 assert not hasattr(cm_inst, 'Addr'), \
80 "Addr should not exist in cm_inst (use FrameDest instead)"
81
82 def test_iramwritetoken_not_in_tokens(self):
83 """IRAMWriteToken should NOT be importable from tokens (replaced by PELocalWriteToken)."""
84 assert not hasattr(tokens, 'IRAMWriteToken'), \
85 "IRAMWriteToken should not exist in tokens (use PELocalWriteToken instead)"
86
87 def test_matchentry_not_in_emu_types(self):
88 """MatchEntry should NOT be importable from emu.types (frame-based PE doesn't use it)."""
89 from emu import types as emu_types
90 assert not hasattr(emu_types, 'MatchEntry'), \
91 "MatchEntry should not exist in emu.types (frame-based matching doesn't use it)"
92
93 def test_instruction_importable_from_cm_inst(self):
94 """Instruction should be importable from cm_inst."""
95 from cm_inst import Instruction
96 assert Instruction is not None
97
98 def test_outputstyle_importable_from_cm_inst(self):
99 """OutputStyle should be importable from cm_inst."""
100 from cm_inst import OutputStyle
101 assert OutputStyle is not None
102
103 def test_framedest_importable_from_cm_inst(self):
104 """FrameDest should be importable from cm_inst."""
105 from cm_inst import FrameDest
106 assert FrameDest is not None
107
108 def test_petoken_importable_from_tokens(self):
109 """PEToken should be importable from tokens."""
110 from tokens import PEToken
111 assert PEToken is not None
112
113 def test_perlocalwritetoken_importable_from_tokens(self):
114 """PELocalWriteToken should be importable from tokens."""
115 from tokens import PELocalWriteToken
116 assert PELocalWriteToken is not None
117
118 def test_framecontroltoken_importable_from_tokens(self):
119 """FrameControlToken should be importable from tokens."""
120 from tokens import FrameControlToken
121 assert FrameControlToken is not None