50 lines
2.8 KiB
Python
50 lines
2.8 KiB
Python
"""Focused source-only guards for the new passive feature-upgrade namespace."""
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
import uuid
|
|
|
|
import runtime_feature_upgrade as feature
|
|
|
|
|
|
class FeatureUpgradeGuards(unittest.TestCase):
|
|
def test_historical_source_derivation_is_exact_and_owns_new_namespace(self):
|
|
source=feature.UPGRADE
|
|
self.assertIn("$p.old_sha256 -cne '"+feature.OLD+"'",source)
|
|
self.assertNotIn("$p.old_sha256 -cne '"+feature.ORIGINAL+"'",source)
|
|
self.assertIn("\\runtime-feature-active-intent.json'",source)
|
|
self.assertNotIn("\\runtime-active-intent.json'",source)
|
|
self.assertIn("\\runtime-feature-'+$p.id",source)
|
|
self.assertIn('Complete passive feature upgrade before any helper/pin installation',source)
|
|
self.assertIn('Original six-field passive configuration',source)
|
|
with self.assertRaises(Exception):feature.replace_once('same same','same','changed')
|
|
|
|
def test_old_default_profile_cannot_claim_new_feature_qualification(self):
|
|
with self.assertRaises(Exception):
|
|
feature.stable(dict(schema_version=1,architecture=feature.TARGET,default_features=True,system_helper_feature=False,system_helper_client_feature=False),current_sources=False)
|
|
|
|
def test_restore_then_finish_cannot_publish_historical_new_runtime(self):
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
folder=Path(temporary);ident=str(uuid.uuid4())
|
|
feature.write(folder,'rollback-intent.json',{'started_at':'2026-11-14T00:00:00+00:00'})
|
|
feature.write(folder,'before.json',{'fixture':True})
|
|
manifest={'artifacts':{'agent':{'sha256':'11'*32}}}
|
|
native={'completed':True,'read_only':True,'restored':False,'native':{'binary_sha256':'11'*32}}
|
|
with patch.object(feature,'load_case',return_value=(folder,{},manifest)),patch.object(feature,'remote',return_value=native),patch.object(feature,'publish') as publish:
|
|
with self.assertRaises(Exception):feature.finish(ident)
|
|
publish.assert_not_called()
|
|
|
|
def test_current_runtime_cas_rejects_another_transition(self):
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
folder=Path(temporary);current=folder/'index.json'
|
|
feature.write(folder,'index.json',{'case_id':str(uuid.uuid4())})
|
|
feature.write(folder,'result.json',{'verified':True})
|
|
with patch.object(feature,'CURRENT',current):
|
|
with self.assertRaises(Exception):
|
|
feature.publish(folder,'result.json',{'previous_runtime_index_sha256':'00'*32},'11'*32,False)
|
|
self.assertEqual(set(path.name for path in folder.iterdir()),{'index.json','result.json'})
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|