Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exercise exact dependency closure, resource ownership and isolated profile inputs."""
|
||||
import ast
|
||||
import importlib.util
|
||||
import os
|
||||
import re
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
@@ -9,8 +13,11 @@ import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'tools'))
|
||||
TOOLS=Path(os.environ.get('ERR_OPTIONAL_IDENTITY_TOOLS',Path(__file__).resolve().parents[1]/'tools'))
|
||||
sys.path.insert(0,str(TOOLS))
|
||||
import resource_references as refs
|
||||
import external_addons as ext
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
ROOT=Path(os.environ.get('ERR_REPO',Path(__file__).resolve().parents[1]))
|
||||
|
||||
class ExternalAddonsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -69,4 +76,68 @@ class ExternalAddonsTests(unittest.TestCase):
|
||||
pak=self.source/ext.DIRECT[0]/'data.pak';pak.unlink();pak.symlink_to(self.source/ext.DIRECT[1]/'data.pak')
|
||||
with self.assertRaisesRegex(ValueError,'regular file'):ext.installed(self.source,self.value)
|
||||
|
||||
|
||||
class OptionalIdentityTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.name=refs.OPTIONAL_FILE
|
||||
self.text=(ROOT/self.name).read_text()
|
||||
self.guid='574AA64002B8E308';self.resource='Prefabs/Characters/REAPER_SpectatorCameraHelper.et'
|
||||
def rejected_reference(self,name,text):
|
||||
self.assertIn((self.guid,self.resource),list(refs.hard_resource_references(name,text)))
|
||||
def test_exact_comparison_only_and_every_other_reference_retained(self):
|
||||
all_refs=re.findall(r'\{([A-F0-9]{16})\}([^"\n]+)',self.text)
|
||||
expected=[pair for pair in all_refs if pair!=(self.guid,self.resource)]
|
||||
self.assertEqual(list(refs.hard_resource_references(self.name,self.text)),expected)
|
||||
self.assertIn(('37578B1666981FCE','Prefabs/Characters/Core/Character_Base.et'),expected)
|
||||
self.rejected_reference('addons/core/Scripts/Game/Other.c',self.text)
|
||||
for changed in [
|
||||
self.text+'\n', # even a benign source edit needs renewed audit
|
||||
self.text.replace('return prefab ==', 'Resource.Load(prefab); return prefab =='),
|
||||
self.text.replace('return prefab ==', 'return Resource.Load(').replace(refs.OPTIONAL_RESOURCE+'";',refs.OPTIONAL_RESOURCE+'");'),
|
||||
self.text+'\nResource.Load("'+refs.OPTIONAL_RESOURCE+'");',
|
||||
self.text+'\nSpawn("'+refs.OPTIONAL_RESOURCE+'");',
|
||||
self.text+'\nResourceName extra = "'+refs.OPTIONAL_RESOURCE+'";',
|
||||
self.text.replace(refs.OPTIONAL_METHOD,'/*'+refs.OPTIONAL_METHOD+'*/'),
|
||||
self.text.replace('CameraSlot(BaseContainer slot)','DifferentMethod(BaseContainer slot)'),
|
||||
self.text.replace('if (!ModsPresent()) return false;',''),
|
||||
]: self.rejected_reference(self.name,changed)
|
||||
unknown=self.text.replace(self.guid,'574AA64002B8E309')
|
||||
self.assertIn(('574AA64002B8E309',self.resource),list(refs.hard_resource_references(self.name,unknown)))
|
||||
# The optional addon never enters either resource policy or dependency closure.
|
||||
value=ext.policy(ROOT)
|
||||
self.assertNotIn('5EB139459EBF5C16',ext.ALLOWED)
|
||||
self.assertFalse(ext.resource_allowed(value,set(ext.ALLOWED),self.guid,self.resource))
|
||||
def repository_resource_loop(self,name,text):
|
||||
# Execute the actual dependency-scanner loop without running the full suite.
|
||||
source=Path(os.environ.get('ERR_OPTIONAL_CHECK_SOURCE',TOOLS/'check.py')).read_text()
|
||||
tree=ast.parse(source)
|
||||
loops=[node for node in ast.walk(tree) if isinstance(node,ast.For) and isinstance(node.target,ast.Tuple)
|
||||
and [getattr(n,'id',None) for n in node.target.elts]==['g','path']]
|
||||
self.assertEqual(len(loops),1)
|
||||
code=compile(ast.fix_missing_locations(ast.Module(body=loops,type_ignores=[])),'actual_repository_resource_loop','exec')
|
||||
env=dict(re=re,hard_resource_references=refs.hard_resource_references,p=ROOT/name,ROOT=ROOT,s=text,
|
||||
resources={},owners={},vanilla=json.loads((ROOT/'docs/vanilla-resources.json').read_text()),
|
||||
external=ext.policy(ROOT),visibility={'core':{'core',*ext.ALLOWED}},resource_allowed=ext.resource_allowed)
|
||||
exec(code,env)
|
||||
def test_actual_repository_resource_loop(self):
|
||||
self.repository_resource_loop(self.name,self.text)
|
||||
for name,text in [(self.name,self.text+'\nResource.Load("'+refs.OPTIONAL_RESOURCE+'");'),
|
||||
('addons/core/Scripts/Game/Other.c',self.text),
|
||||
(self.name,self.text.replace('return prefab ==','return Resource.Load(').replace(refs.OPTIONAL_RESOURCE+'";',refs.OPTIONAL_RESOURCE+'");'))]:
|
||||
with self.assertRaisesRegex(AssertionError,'Unresolved/mismatched'):
|
||||
self.repository_resource_loop(name,text)
|
||||
def test_actual_bundle_validator(self):
|
||||
path=Path(os.environ.get('ERR_OPTIONAL_BUNDLE_SOURCE',TOOLS/'source_bundle.py'))
|
||||
spec=importlib.util.spec_from_file_location('optional_test_source_bundle',path)
|
||||
bundle=importlib.util.module_from_spec(spec);spec.loader.exec_module(bundle)
|
||||
payload={name:(ROOT/name).read_bytes() for name in bundle.inventory(ROOT)}
|
||||
before=ext.policy(ROOT)
|
||||
bundle.validate(payload,ROOT)
|
||||
self.assertEqual(before,ext.policy(ROOT))
|
||||
for changed in [self.text+'\nResource.Load("'+refs.OPTIONAL_RESOURCE+'");',
|
||||
self.text+'\nSpawn("'+refs.OPTIONAL_RESOURCE+'");']:
|
||||
altered=dict(payload);altered[self.name]=changed.encode()
|
||||
with self.assertRaisesRegex(ValueError,'unresolved or nonvanilla'):
|
||||
bundle.validate(altered,ROOT)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user