From 41cb341405312c80a0708ca5c26af29093875419 Mon Sep 17 00:00:00 2001 From: Joseph Magly <1159087+jmagly@users.noreply.github.com> Date: Sat, 15 Aug 2026 21:10:03 -0400 Subject: [PATCH] test: close runtime decision mutation gaps --- obliteratus/runtime_contracts.py | 2 +- tests/test_runtime_contracts.py | 33 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/obliteratus/runtime_contracts.py b/obliteratus/runtime_contracts.py index b97384d..d7c1db8 100644 --- a/obliteratus/runtime_contracts.py +++ b/obliteratus/runtime_contracts.py @@ -111,7 +111,7 @@ def attention_projection_names( all_names = outputs + tuple(input_names) if num_kv_shared_layers <= 0: return all_names - if num_layers <= 0 or not 0 <= layer_index < num_layers: + if not 0 <= layer_index < num_layers: raise ValueError("shared-KV projection requires a valid layer index and layer count") if num_kv_shared_layers > num_layers: raise ValueError("num_kv_shared_layers cannot exceed the model layer count") diff --git a/tests/test_runtime_contracts.py b/tests/test_runtime_contracts.py index 85dd390..3ff0e89 100644 --- a/tests/test_runtime_contracts.py +++ b/tests/test_runtime_contracts.py @@ -109,7 +109,7 @@ def test_model_load_policy_precedence_is_explicit(overrides, expected): def test_model_load_policy_rejects_unsupported_quantization_before_branching(): - with pytest.raises(ValueError, match="Unknown quantization '3bit'"): + with pytest.raises(ValueError) as error: resolve_model_load_policy( device="auto", resolved_device="cuda", @@ -119,6 +119,7 @@ def test_model_load_policy_rejects_unsupported_quantization_before_branching(): device_map_auto_supported=True, bitsandbytes_supported=True, ) + assert str(error.value) == "Unknown quantization '3bit'. Choose None, '4bit', or '8bit'" @pytest.mark.parametrize("quantization", ["4bit", "8bit"]) @@ -166,6 +167,17 @@ def test_output_only_projection_is_independent_of_shared_kv_layout(): ) == _OUTPUT_NAMES +def test_nonshared_projection_does_not_require_shared_storage_ownership_metadata(): + assert attention_projection_names( + projection_target="all", + layer_index=-1, + num_layers=0, + num_kv_shared_layers=0, + output_names=_OUTPUT_NAMES, + input_names=_INPUT_NAMES, + ) == _OUTPUT_NAMES + _INPUT_NAMES + + @pytest.mark.parametrize( ("layer_index", "expected"), [ @@ -186,6 +198,17 @@ def test_shared_kv_owner_projects_storage_once_and_borrowers_skip_it(layer_index ) == expected +def test_single_layer_can_own_kv_storage_shared_by_the_whole_model(): + assert attention_projection_names( + projection_target="all", + layer_index=0, + num_layers=1, + num_kv_shared_layers=1, + output_names=_OUTPUT_NAMES, + input_names=_INPUT_NAMES, + ) == _OUTPUT_NAMES + _INPUT_NAMES + + @pytest.mark.parametrize( ("layer_index", "num_layers", "shared_layers", "message"), [ @@ -201,7 +224,7 @@ def test_shared_kv_layout_rejects_impossible_ownership( shared_layers, message, ): - with pytest.raises(ValueError, match=message): + with pytest.raises(ValueError) as error: attention_projection_names( projection_target="all", layer_index=layer_index, @@ -210,6 +233,12 @@ def test_shared_kv_layout_rejects_impossible_ownership( output_names=_OUTPUT_NAMES, input_names=_INPUT_NAMES, ) + expected = ( + "num_kv_shared_layers cannot exceed the model layer count" + if message == "cannot exceed" + else "shared-KV projection requires a valid layer index and layer count" + ) + assert str(error.value) == expected @pytest.mark.parametrize(