refactor: implement governed Delivery program contracts
This commit is contained in:
1 parent
c306ea4794
commit
65e546c448
18 files changed
+575
-99
No files matched your search
@@ -0,0 +1,47 @@
|
||||
"""Canonical bindings preserve owners and original checksum sensitivity."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
from canonical_identity import IDENTITIES, canonicalize, original_identity
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
class CanonicalIdentity(unittest.TestCase):
|
||||
def test_exact_identity_and_dependency_count(self):
|
||||
current = (ROOT / 'SKILL.md').read_text()
|
||||
baseline = subprocess.check_output(['git', 'show', 'HEAD:SKILL.md'], cwd=ROOT, text=True)
|
||||
def deps(text):
|
||||
return re.search(r'related_skills: \[(.*?)\]', text)[1].split(', ')
|
||||
expected = [IDENTITIES.get(v, v) for v in deps(baseline)]
|
||||
self.assertEqual(deps(current), expected)
|
||||
self.assertEqual(len(expected), 18 if ROOT.name.endswith('aerosim') else 12)
|
||||
self.assertEqual(len(set(expected)), len(expected))
|
||||
self.assertIn('corp-v1-glossary', expected)
|
||||
self.assertFalse(set(expected) & set(IDENTITIES))
|
||||
|
||||
def test_mapping_is_reversible_and_not_a_general_rewrite(self):
|
||||
self.assertEqual(len(IDENTITIES), len(set(IDENTITIES.values())))
|
||||
for old, new in IDENTITIES.items():
|
||||
text = f'Load `{old}`; skill_view(name="{old}"); https://example/{old}; /opt/data/{old}/'
|
||||
mapped = canonicalize(text)
|
||||
self.assertIn(f'`{new}`', mapped)
|
||||
self.assertEqual(original_identity(mapped), text)
|
||||
text = 'tags: [corp-v1, discord, channel] /opt/data/corp-v1-aerosim-delivery/ gondor-v1-aerosim-dev'
|
||||
self.assertEqual(original_identity(text), text)
|
||||
|
||||
def test_golden_normalization_still_detects_policy_mutation(self):
|
||||
for old in IDENTITIES:
|
||||
baseline = f'Load `{old}` before mutation; stop if unavailable.'
|
||||
canonical = canonicalize(baseline)
|
||||
digest = lambda t: hashlib.sha256(original_identity(t).encode()).hexdigest()
|
||||
self.assertEqual(digest(canonical), digest(baseline))
|
||||
self.assertNotEqual(digest(canonical.replace('stop', 'continue')), digest(baseline))
|
||||
|
||||
def test_no_legacy_operational_loads(self):
|
||||
for path in [ROOT / 'SKILL.md', *ROOT.glob('references/*.md')]:
|
||||
text = path.read_text()
|
||||
self.assertEqual(canonicalize(text), text, str(path))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user