883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
104 lines
5.7 KiB
Python
104 lines
5.7 KiB
Python
"""Focused new publication boundary; consumes owning SDK2 metadata only."""
|
|
from copy import deepcopy
|
|
import hashlib
|
|
import json
|
|
import os
|
|
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 = Path(os.environ.get('GW_TEST_ORIGINAL_UI_PUBLICATION_SPEC',
|
|
ROOT / 'runtime/continuation-20261029/source-realm-UI-publication/two-UI-publication-input-spec.private.json'))
|
|
|
|
@unittest.skipUnless(SPEC.is_file(), 'Owning private two-UI publication fixture is not present')
|
|
class OriginalUIReplacementTest(unittest.TestCase):
|
|
def test_actual_candidate_and_changed_scope_boundaries(self):
|
|
spec = json.loads(SPEC.read_text())
|
|
receipt = spec['candidate_receipt_fields']
|
|
self.assertFalse(receipt['applied'])
|
|
self.assertTrue(spec['activation_disabled'])
|
|
documents = {}
|
|
hashes = {}
|
|
actual_read, actual_digest = publication.read, publication.digest
|
|
def record_read(path):
|
|
result = actual_read(path)
|
|
documents[str(path)] = result
|
|
return result
|
|
def record_digest(path):
|
|
result = actual_digest(path)
|
|
hashes[str(path)] = result
|
|
return result
|
|
# Actual saved candidate inputs and hashes are loaded once. No bodies,
|
|
# parent asset validation, Source export or SDK execution is repeated.
|
|
with patch.object(publication, 'read', side_effect=record_read), patch.object(publication, 'digest', side_effect=record_digest):
|
|
expected, validation = publication._reviewed_original_ui_replacement(receipt)
|
|
self.assertEqual(expected['replaced_native_UI_file_data_ids'], [5612385, 5613302])
|
|
self.assertEqual(expected['new_file_data_ids'], [])
|
|
self.assertEqual(expected['registered_assets'], 32337)
|
|
self.assertEqual(validation['staged_native_SDK_FileID_bodies_exact'], 2)
|
|
self.assertEqual(validation['parent_index_preimages'], 16)
|
|
self.assertFalse(validation['native_UI_runtime_acceptance_verified'])
|
|
self.assertEqual({k: receipt[k] for k in expected if k != 'applied'},
|
|
{k: v for k, v in expected.items() if k != 'applied'})
|
|
self.assertEqual({k: spec['candidate_changed_validation_fields'][k] for k in validation}, validation)
|
|
|
|
def reject_changed(label, mutate):
|
|
candidate = deepcopy(receipt)
|
|
docs = deepcopy(documents)
|
|
pins = dict(hashes)
|
|
mutate(candidate, docs, pins)
|
|
with self.subTest(label=label), patch.object(publication, 'read', side_effect=lambda p: docs[str(p)]), \
|
|
patch.object(publication, 'digest', side_effect=lambda p: pins[str(p)]):
|
|
with self.assertRaises(ValueError):
|
|
publication._reviewed_original_ui_replacement(candidate)
|
|
|
|
def edit_input(candidate, docs, pins, key, mutate):
|
|
ref = candidate['inputs'][key]
|
|
value = deepcopy(docs[ref['path']])
|
|
mutate(value)
|
|
path = 'private-unit-fixture-' + key + '.json'
|
|
value_sha = hashlib.sha256(json.dumps(value, sort_keys=True).encode()).hexdigest()
|
|
docs[path] = value
|
|
pins[path] = value_sha
|
|
candidate['inputs'][key] = {'path': path, 'sha256': value_sha}
|
|
|
|
reject_changed('off-scope SDK body', lambda c, d, h: edit_input(c, d, h, 'SDK',
|
|
lambda x: x['rows'][0].update(file_data_id=5612386)))
|
|
reject_changed('unreviewed candidate payload', lambda c, d, h: edit_input(c, d, h, 'SDK',
|
|
lambda x: x['rows'][0].update(sha256='0' * 64)))
|
|
reject_changed('missing Native-pruned parent preimage', lambda c, d, h: edit_input(c, d, h, 'rollback_plan',
|
|
lambda x: x['parent_index_files'].pop()))
|
|
reject_changed('wrong derived mapping namespace', lambda c, d, h: edit_input(c, d, h, 'rollback_plan',
|
|
lambda x: x.update(derived_mapping_relative_namespace='client')))
|
|
reject_changed('unexpected physical file', lambda c, d, h: edit_input(c, d, h, 'delta_plan',
|
|
lambda x: x['files'][0].update(relative='Data/data/data.000')))
|
|
|
|
# The dispatcher recognizes this proof kind but must still reject a
|
|
# PREPARED receipt. No fake applied receipt is written or published.
|
|
prepared_path = 'private-unit-prepared-UI-receipt.json'
|
|
documents[prepared_path] = deepcopy(receipt)
|
|
with patch.object(publication, 'read', side_effect=lambda p: documents[str(p)]), \
|
|
patch.object(publication, 'digest', side_effect=lambda p: hashes[str(p)]):
|
|
with self.assertRaisesRegex(ValueError, 'Unreviewed published client receipt'):
|
|
publication._publication_proof(ROOT / 'runtime/Octo-Run-1023',
|
|
{'receipt_path': prepared_path, 'composed_root': receipt['composed_root'], 'validation_sha256': ''},
|
|
historical=True)
|
|
output = os.environ.get('GW_TEST_ORIGINAL_UI_BOUNDARY_RESULT')
|
|
if output:
|
|
Path(output).write_text(json.dumps({
|
|
'kind': 'reviewed-original-UI-publication-owning-boundary-v1',
|
|
'status': 'PASS_PREPARED_EXACT_TWO_UI_PUBLICATION_PROOF',
|
|
'expected_receipt_fields': expected, 'required_post_copy_validation': validation,
|
|
'actual_candidate_metadata_loaded_once': True, 'wrong_scope_cases_rejected': 5,
|
|
'prepared_not_applied_dispatch_rejected': True, 'native_or_SDK_actions': 0,
|
|
'installed': False, 'native_UI_acceptance': False,
|
|
}, indent=2) + '\n')
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|