[Tests] Cover get_unhashed_block_ids_all_groups (#55928)
Signed-off-by: Aditya Ganesh Kumar <adty910@gmail.com>
Aditya Ganesh Kumar committed
Sep 19, 2026 at 17:13 UTC
a5a30471ff2bb7f0824f2da10e358af98d304472
1 file changed
+26
tests/v1/core/test_prefix_caching.py
+26
@@ -5937,3 +5937,29 @@ def test_device_eviction_keeps_host_prefix():
5937
assert host_block.block_hash is not None, (
5938
"Device eviction invalidated unrelated host KV"
5939
)
5940
+
5941
+
5942
+def test_get_unhashed_block_ids_all_groups():
5943
+ """Unhashed, non-null block ids are reported per KV cache group.
5944
+ A group with no unhashed blocks reports an empty list, not a missing entry.
5945
+ """
5946
+
5947
+ def hashed(block_id: int, group_id: int) -> KVCacheBlock:
5948
+ block = KVCacheBlock(block_id=block_id)
5949
+ block.set_block_hash(make_block_hash_with_group_id(BlockHash(b"h"), group_id))
5950
+ return block
5951
+
5952
+ blocks = KVCacheBlocks(
5953
+ (
5954
+ [
5955
+ KVCacheBlock(block_id=1), # unhashed
5956
+ hashed(2, group_id=0), # cached
5957
+ KVCacheBlock(block_id=3, is_null=True), # null padding
5958
+ KVCacheBlock(block_id=4), # unhashed
5959
+ ],
5960
+ # No unhashed blocks in this group.
5961
+ [hashed(5, group_id=1), KVCacheBlock(block_id=6, is_null=True)],
5962
+ )
5963
+ )
5964
+
5965
+ assert blocks.get_unhashed_block_ids_all_groups() == [[1, 4], []]