883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
71 lines
3.8 KiB
Python
71 lines
3.8 KiB
Python
"""Focused changed-scope checks for the saved chained original UI candidate."""
|
|
from copy import deepcopy
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import published_client_assets as publication
|
|
|
|
SPEC = ROOT / 'runtime/continuation-20261029/rea-ui-races-base/chained-publication-candidate.private.json'
|
|
|
|
|
|
@unittest.skipUnless(SPEC.is_file(), 'Private chained UI candidate is unavailable')
|
|
class ChainedUIReplacementTest(unittest.TestCase):
|
|
def test_rejects_changed_sdk_and_rollback_evidence(self):
|
|
receipt = json.loads(SPEC.read_text())
|
|
refs = [receipt['parent_publication'], *receipt['inputs'].values()]
|
|
documents = {r['path']: json.loads(Path(r['path']).read_text()) for r in refs}
|
|
hashes = {r['path']: r['sha256'] for r in refs}
|
|
|
|
def check_changed(key, mutate, message):
|
|
changed = deepcopy(documents)
|
|
mutate(changed[receipt['inputs'][key]['path']])
|
|
with patch.object(publication, 'read', side_effect=lambda path: changed[str(path)]), \
|
|
patch.object(publication, 'digest', side_effect=lambda path: hashes[str(path)]):
|
|
with self.assertRaisesRegex(ValueError, message):
|
|
publication._reviewed_original_ui_replacement(receipt)
|
|
|
|
check_changed('SDK', lambda doc: doc.update(candidate_root='0' * 32),
|
|
'Exact chained UI SDK proof required')
|
|
check_changed('rollback_plan', lambda doc: doc.update(restore_parent_indices_before_candidate_deletion=False),
|
|
'Corrected original UI rollback contract required')
|
|
check_changed('delta_plan', lambda doc: doc['files'][0].update(relative='Data/data/data.000'),
|
|
'Off-scope original UI physical file')
|
|
|
|
def test_evidence_chain_rejects_changed_parent_and_child_scope(self):
|
|
fixture = SPEC.parent / 'generic-publication-reused-generation-test.private.json'
|
|
if not fixture.is_file():
|
|
self.skipTest('Private generic-chain fixture is unavailable')
|
|
receipt = json.loads(fixture.read_text())['candidate_receipt']
|
|
parent = json.loads(Path(receipt['parent_publication']['path']).read_text())
|
|
refs = [receipt['parent_publication'], parent['inputs']['COW'], *receipt['inputs'].values()]
|
|
documents = {r['path']: json.loads(Path(r['path']).read_text()) for r in refs}
|
|
hashes = {r['path']: r['sha256'] for r in refs}
|
|
|
|
def check_changed(key, mutate, message):
|
|
changed = deepcopy(documents)
|
|
mutate(changed[receipt['inputs'][key]['path']])
|
|
with patch.object(publication, 'read', side_effect=lambda path: changed[str(path)]), \
|
|
patch.object(publication, 'digest', side_effect=lambda path: hashes[str(path)]):
|
|
with self.assertRaisesRegex(ValueError, message):
|
|
publication._reviewed_original_ui_replacement(receipt)
|
|
|
|
check_changed('parent_validation', lambda doc: doc.update(composed_root='0' * 32),
|
|
'Accepted UI parent validation differs')
|
|
check_changed('native_UI_metadata', lambda doc: doc['rows'][0].update(file_data_id=42),
|
|
'Off-scope original UI identity')
|
|
check_changed('UI_owner', lambda doc: doc['candidates']['glue'].update(sha256='0' * 64),
|
|
'Chained UI body identity differs')
|
|
check_changed('COW', lambda doc: doc.update(original_build_config='0' * 32),
|
|
'Original UI COW relationship differs')
|
|
check_changed('COW', lambda doc: doc['new_index_generations'][0].update(new_file='../unsafe.idx'),
|
|
'Unsafe UI candidate generation path')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|