Files
s41r4j-cybot/scripts/test_library_metadata.py
s41r4j 0f03d49514
CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
Initial commit
2026-11-01 09:14:18 +05:30

40 lines
2.2 KiB
Python

import hashlib
import json
from pathlib import Path
import tempfile
import unittest
import library_metadata as package
class LibraryMetadataTests(unittest.TestCase):
def fixture(self,root):
(root/'library.py').write_text('value = 1\n');(root/'adapter.py').write_text('pass\n');(root/'LICENSE').write_text('fixture notice')
digest=lambda path:hashlib.sha256(path.read_bytes()).hexdigest()
source={'url':'https://example.invalid/checked-source.tar.gz','sha256':'a'*64}
lock={'source':source,'files':{'library.py':digest(root/'library.py'),'LICENSE':digest(root/'LICENSE')}}
(root/'source.lock.json').write_text(json.dumps(lock))
package.install(root,'fixture','1.0.0',source,{'requests':'2.34.2'},root/'LICENSE')
return digest(root/'source.lock.json'),digest(root/'adapter.py')
def test_canonical_identity_requires_source_and_installed_record_integrity(self):
with tempfile.TemporaryDirectory() as temp:
root=Path(temp);lock,adapter=self.fixture(root)
self.assertEqual(package.verify(root,'fixture','1.0.0',lock,adapter),'1.0.0')
(root/'library.py').write_text('value = 2\n')
with self.assertRaisesRegex(RuntimeError,'checked source'):package.verify(root,'fixture','1.0.0',lock,adapter)
def test_unrecorded_files_and_metadata_changes_are_rejected(self):
with tempfile.TemporaryDirectory() as temp:
root=Path(temp);lock,adapter=self.fixture(root)
extra=root/'unexpected.py';extra.write_text('pass\n')
with self.assertRaisesRegex(RuntimeError,'Unrecorded'):package.verify(root,'fixture','1.0.0',lock,adapter)
extra.unlink();(root/'fixture-1.0.0.dist-info/INSTALLER').write_text('changed\n')
with self.assertRaisesRegex(RuntimeError,'file changed'):package.verify(root,'fixture','1.0.0',lock,adapter)
def test_source_symlinks_are_rejected_before_reading(self):
with tempfile.TemporaryDirectory() as temp:
root=Path(temp);lock,adapter=self.fixture(root)
(root/'library.py').unlink();(root/'library.py').symlink_to(root/'adapter.py')
with self.assertRaisesRegex(RuntimeError,'regular library source'):package.verify(root,'fixture','1.0.0',lock,adapter)