Files
WoW-Hybrid-gateway/tests/archived_fixture_guard_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

34 lines
2.5 KiB
Python

"""Static/unit-only safeguards: never import or execute the fixture entrypoints."""
import ast,re,unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
FLAG='--allow-archived-praxiscopy-4518-fixture'
class ArchivedFixtureGuard(unittest.TestCase):
def test_python_opt_in_dominates_every_operational_statement(self):
for name in ('ops/local_fixture_recovery.py','ops/native_corpse_release_test.py'):
with self.subTest(name=name):
text=(ROOT/name).read_text();tree=ast.parse(text)
main=next(n for n in tree.body if isinstance(n,ast.FunctionDef)and n.name=='main')
flags=[n for n in ast.walk(main)if isinstance(n,ast.Call)and isinstance(n.func,ast.Attribute)and n.func.attr=='add_argument'and any(isinstance(a,ast.Constant)and a.value==FLAG for a in n.args)]
self.assertEqual(len(flags),1)
self.assertTrue(any(k.arg=='action'and isinstance(k.value,ast.Constant)and k.value.value=='store_true'for k in flags[0].keywords))
guard=next(n for n in main.body if isinstance(n,ast.If)and ast.dump(n.test)==ast.dump(ast.parse('not args.allow_archived_praxiscopy_4518_fixture',mode='eval').body))
self.assertTrue(any(isinstance(n,ast.Call)and isinstance(n.func,ast.Attribute)and n.func.attr=='error'for n in ast.walk(guard)))
# DB/session/UI/controller/tool calls must all occur after the fail-closed gate.
operations={'db','Controller','local_listeners','WorldTrace','Session'}
for node in ast.walk(main):
if isinstance(node,ast.Call)and(isinstance(node.func,ast.Name)and node.func.id in operations or isinstance(node.func,ast.Attribute)and node.func.attr in('run','macro','click_at','send','receive_for')):
self.assertGreater(node.lineno,guard.end_lineno)
self.assertIn(FLAG,text[text.index('subprocess.run'):])
def test_cpp_explicit_guard_precedes_input_and_authentication(self):
source=(ROOT/'tools/local_fixture_recovery.cpp').read_text();main=source[source.index('int main('):]
gate=re.search(r'if\(argc!=4 \|\| std::string\(argv\[3\]\)!=\"'+re.escape(FLAG)+r'\".*?return 2;',main,re.S)
self.assertIsNotNone(gate)
for operation in ('std::getline','LegacySession session','command(session,','session.send('):
self.assertLess(gate.end(),main.index(operation))
def test_live_mutation_entrypoints_not_registered_as_ctest(self):
text=(ROOT/'CMakeLists.txt').read_text()
for match in re.finditer(r'add_test\([^\n]+',text):
self.assertNotIn('local_fixture_recovery',match.group());self.assertNotIn('native_corpse_release_test.py',match.group())
if __name__=='__main__':unittest.main()