Fix B2 foundation proof for Compose omitted false bind option

This commit is contained in:
Codex
2026-09-30 16:29:26 +03:00
parent 9dcd520503
commit 1e191868be
8 changed files with 328 additions and 4 deletions
@@ -26,7 +26,88 @@ def candidate():
return v
FIXTURE = Path(__file__).with_name('fixtures') / 'device-b2-foundation-compose220'
def compose_fixture():
return tuple(json.loads((FIXTURE / (name + '.json')).read_text()) for name in ('base', 'candidate'))
class Foundation(unittest.TestCase):
def test_source_yaml_and_new_identity_remain_exact(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
(root / 'deployment').mkdir()
(root / R.DEVICE_B2_DESCRIPTOR).write_text(json.dumps(R.device_b2_descriptor()))
yaml = root / R.DEVICE_B2_OVERRIDE
yaml.write_text(R.DEVICE_B2_YAML)
# Isolate the YAML/identity guard; no database or SQL execution.
with mock.patch.object(R, 'sha256_file', return_value=R.DEVICE_B2_SQL_SHA):
R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID)
with self.assertRaises(R.DeployError):
R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, 'device-b2-foundation-v1-20260930-001')
for replacement in ('true', 'null', '0'):
yaml.write_text(R.DEVICE_B2_YAML.replace('create_host_path: false', 'create_host_path: ' + replacement))
with self.subTest(replacement=replacement), self.assertRaises(R.DeployError):
R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID)
yaml.write_text(R.DEVICE_B2_YAML.replace(' create_host_path: false\n', ''))
with self.assertRaises(R.DeployError):
R.validate_device_b2_payload(root, R.DEVICE_B2_ENTRIES, R.DEVICE_B2_ID)
def test_real_compose_2201_output_preserves_raw_inputs_and_digest(self):
base, actual = compose_fixture()
saved = copy.deepcopy((base, actual))
mount = next(v for v in actual['services']['device-control-core']['volumes']
if v['target'] == R.DEVICE_B2_DESTINATION)
self.assertEqual(mount['bind'], {})
self.assertNotIn('read_only', mount)
self.assertEqual(R.device_b2_config_proof(base, actual), R.device_release_drift_digest(actual))
self.assertEqual((base, actual), saved)
self.assertEqual((FIXTURE / 'override.yml').read_text(), R.DEVICE_B2_YAML)
def test_real_compose_new_mount_accepts_only_false_or_omitted_booleans(self):
base, actual = compose_fixture()
for read_only in ('omitted', False):
for create in ('omitted', False):
v = copy.deepcopy(actual)
mount = next(m for m in v['services']['device-control-core']['volumes']
if m['target'] == R.DEVICE_B2_DESTINATION)
if read_only != 'omitted': mount['read_only'] = read_only
if create != 'omitted': mount['bind']['create_host_path'] = create
with self.subTest(read_only=read_only, create=create):
R.device_b2_config_proof(base, v)
for key in ('read_only', 'create_host_path'):
for value in (True, None, 0, 1, 0.0, 'false', {}, []):
v = copy.deepcopy(actual)
mount = next(m for m in v['services']['device-control-core']['volumes']
if m['target'] == R.DEVICE_B2_DESTINATION)
target = mount if key == 'read_only' else mount['bind']
target[key] = value
with self.subTest(key=key, value=value), self.assertRaises(R.DeployError):
R.device_b2_config_proof(base, v)
def test_real_compose_rejects_other_mount_options_and_unrelated_changes(self):
base, actual = compose_fixture()
for mutation in ('source', 'type', 'bind-null', 'bind-absent', 'propagation',
'existing-bind', 'existing-readonly', 'duplicate', 'env', 'network', 'database'):
v = copy.deepcopy(actual)
core = v['services']['device-control-core']
mount = next(m for m in core['volumes'] if m['target'] == R.DEVICE_B2_DESTINATION)
existing = next(m for m in core['volumes'] if m['target'] != R.DEVICE_B2_DESTINATION)
if mutation == 'source': mount['source'] = '/other'
if mutation == 'type': mount['type'] = 'volume'
if mutation == 'bind-null': mount['bind'] = None
if mutation == 'bind-absent': mount.pop('bind')
if mutation == 'propagation': mount['bind']['propagation'] = 'rshared'
if mutation == 'existing-bind': existing['bind']['create_host_path'] = False
if mutation == 'existing-readonly': existing['read_only'] = False
if mutation == 'duplicate': core['volumes'].append(copy.deepcopy(mount))
if mutation == 'env': core['environment']['EXISTING'] = 'changed'
if mutation == 'network': core['networks']['private']['priority'] = 0
if mutation == 'database': v['services']['device-postgres']['image'] = 'changed'
with self.subTest(mutation=mutation), self.assertRaises(R.DeployError):
R.device_b2_config_proof(base, v)
def test_scope_has_only_core_and_no_build(self):
self.assertEqual(R.component_services('device-b2-foundation',R.DEVICE_B2_ENTRIES),('device-control-core',))
self.assertFalse(R.component_builds('device-b2-foundation',R.DEVICE_B2_ENTRIES))