diff --git a/changelog.d/tsk-nfivhi-cap-context-snapshot-marker-overhead.md b/changelog.d/tsk-nfivhi-cap-context-snapshot-marker-overhead.md new file mode 100644 index 000000000..5dfaab07f --- /dev/null +++ b/changelog.d/tsk-nfivhi-cap-context-snapshot-marker-overhead.md @@ -0,0 +1,3 @@ +### Fixed + +- Added regression coverage for `_cap_context_snapshot()` on many-small-fields snapshots (long field names and short values, and many short-named fields) staying within the 32768-byte limit. The marker-overhead accounting fix this card targeted was independently landed with a more thorough byte-precise budget in tsk-kkxn6f's `_build_truncated_marker()`; this fold pass kept that implementation and this card's added tests. diff --git a/tests/test_restart_orchestrator_resume.py b/tests/test_restart_orchestrator_resume.py index d72ab57e7..14ee35a6a 100644 --- a/tests/test_restart_orchestrator_resume.py +++ b/tests/test_restart_orchestrator_resume.py @@ -315,6 +315,24 @@ def test_missing_snapshot_is_noop(self): ro._cap_context_snapshot(note) assert "context_snapshot" not in note + def test_many_long_keys_small_values_stays_under_limit(self): + big = {f"k{i:04d}_" + "x" * 53: "v" for i in range(600)} + note = {"context_snapshot": big} + ro._cap_context_snapshot(note) + capped_size = len(json.dumps(note["context_snapshot"], separators=(",", ":"))) + assert capped_size <= ro._MAX_CONTEXT_SNAPSHOT_BYTES, ( + f"cap returned {capped_size} bytes" + ) + + def test_many_short_keys_small_values_stays_under_limit(self): + big = {f"k{i}": i for i in range(4000)} + note = {"context_snapshot": big} + ro._cap_context_snapshot(note) + capped_size = len(json.dumps(note["context_snapshot"], separators=(",", ":"))) + assert capped_size <= ro._MAX_CONTEXT_SNAPSHOT_BYTES, ( + f"cap returned {capped_size} bytes" + ) + class TestResumeRetryLoopCapsSnapshot: @pytest.mark.asyncio