test: exercise compact parent projection

This commit is contained in:
Michael Snoyman committed 2026-09-24 19:11:31 +03:00
1 parent df35836b75
commit 89dbaec6f5
1 file changed
+6 -14
+6 -14
View File
@@ -599,20 +599,12 @@ def test_session_model_parent_session_id():
def test_session_compact_includes_parent():
"""Verify compact() includes parent_session_id."""
src = _read('api/models.py')
# Find the compact method and scan its full body for parent_session_id.
# PR #1591 (May 2026) added a has_pending_user_message recompute block at
# the top of compact() which pushed the parent_session_id field beyond a
# 1500-char window — widen the scan to 3000 chars to cover the full
# return-dict body without re-tightening every time compact() grows.
# compact() accepts optional projection flags on separate lines; match the
# method name and first parameter without pinning formatting.
compact_def_match = re.search(r"def compact\(\s*self", src)
assert compact_def_match, "Could not find compact() method"
snippet = src[compact_def_match.start():compact_def_match.start() + 3500]
assert "'parent_session_id'" in snippet, \
"compact() should include parent_session_id"
"""Verify compact() exposes a fork's parent and omits it for root sessions."""
fork = routes.Session(session_id="fork-1", parent_session_id="parent-1")
assert fork.compact()["parent_session_id"] == "parent-1"
root = routes.Session(session_id="root-1")
assert "parent_session_id" not in root.compact()
def test_session_metadata_fields_includes_parent():