43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
"""Regression of the zero-dispatch contract/schema integration failure."""
|
|
import copy
|
|
import json
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
from o1_partition import InputViolation
|
|
from run_o1_prepare_v2 import validate_runtime_contract,resource_reason
|
|
|
|
|
|
class EngineeringAcceptance(unittest.TestCase):
|
|
def setUp(self):
|
|
# Actual immutable metadata contract, not a differently named test fixture.
|
|
self.c=json.loads(Path('artifacts/o1-preparation-2026-11-17/contract.json').read_text())
|
|
|
|
def test_actual_frozen_contract_passes_startup_and_first_monitor(self):
|
|
self.assertTrue(validate_runtime_contract(self.c))
|
|
self.assertIsNone(resource_reason(self.c,self.c['initial_preparation_cpu_seconds'],0,100000000,0))
|
|
self.assertIn('total_tree_rss_bytes',self.c['limits'])
|
|
self.assertNotIn('total_rss_bytes',self.c['limits'])
|
|
|
|
def test_missing_or_legacy_memory_key_refused_before_dispatch(self):
|
|
self.c['limits']['total_rss_bytes']=self.c['limits'].pop('total_tree_rss_bytes')
|
|
with self.assertRaisesRegex(InputViolation,'total_tree_rss_bytes'):
|
|
validate_runtime_contract(self.c)
|
|
|
|
def test_actual_contract_all_resource_boundaries(self):
|
|
self.assertEqual(resource_reason(self.c,43200,1,0,0),'GLOBAL_PREPARATION_CPU_LIMIT')
|
|
self.assertEqual(resource_reason(self.c,0,0,36*2**30+1,0),'GLOBAL_RSS_LIMIT')
|
|
self.assertEqual(resource_reason(self.c,0,0,0,100*2**30),'GLOBAL_DISK_LIMIT')
|
|
self.assertIsNone(resource_reason(self.c,43200,0,36*2**30,100*2**30-1))
|
|
|
|
def test_budget_widening_rejected(self):
|
|
self.c['limits']['preparation_cpu_seconds']+=1
|
|
with self.assertRaises(InputViolation):validate_runtime_contract(self.c)
|
|
|
|
def test_duplicate_or_changed_first_ten_rejected(self):
|
|
self.c['dispatch'][11]=self.c['dispatch'][10]
|
|
with self.assertRaises(InputViolation):validate_runtime_contract(self.c)
|
|
|
|
|
|
if __name__=='__main__':unittest.main(verbosity=2)
|