merge: T90 phase 3.6 carry-overs trio
This commit is contained in:
@@ -22,7 +22,7 @@ from chat.db.migrate import apply_migrations
|
||||
from chat.eventlog.log import append_event
|
||||
from chat.eventlog.projector import project
|
||||
from chat.llm.mock import MockLLMClient
|
||||
from chat.services.memory_write import record_turn_memory, record_turn_memory_for_present
|
||||
from chat.services.memory_write import record_turn_memory_for_present
|
||||
import chat.state.entities # noqa: F401 - register handlers
|
||||
import chat.state.memory # noqa: F401
|
||||
import chat.state.world # noqa: F401
|
||||
@@ -64,14 +64,19 @@ def test_record_turn_memory_writes_event_and_projects(tmp_path):
|
||||
apply_migrations(db)
|
||||
_seed_minimal(db)
|
||||
with open_db(db) as conn:
|
||||
eid, mid = record_turn_memory(
|
||||
# T90.3: legacy ``record_turn_memory`` was removed; the unified
|
||||
# ``record_turn_memory_for_present`` with ``guest_bot_id=None``
|
||||
# produces the same single-bot witness mask [1,1,0].
|
||||
result = record_turn_memory_for_present(
|
||||
conn,
|
||||
chat_id="chat_bot_a",
|
||||
host_bot_id="bot_a",
|
||||
guest_bot_id=None,
|
||||
narrative_text="BotA looks up. 'You're back late.'",
|
||||
scene_id=None,
|
||||
chat_clock_at="2026-04-26T20:00:00+00:00",
|
||||
)
|
||||
eid, mid = result["bot_a"]
|
||||
assert eid > 0
|
||||
assert mid is not None and mid > 0
|
||||
|
||||
@@ -111,12 +116,15 @@ def test_record_turn_memory_omits_optional_fields(tmp_path):
|
||||
_seed_minimal(db)
|
||||
with open_db(db) as conn:
|
||||
# Call without scene_id/chat_clock_at — should default to None.
|
||||
eid, mid = record_turn_memory(
|
||||
# T90.3: migrated from legacy ``record_turn_memory``.
|
||||
result = record_turn_memory_for_present(
|
||||
conn,
|
||||
chat_id="chat_bot_a",
|
||||
host_bot_id="bot_a",
|
||||
guest_bot_id=None,
|
||||
narrative_text="A simple memory.",
|
||||
)
|
||||
eid, mid = result["bot_a"]
|
||||
assert eid > 0
|
||||
assert mid is not None and mid > 0
|
||||
|
||||
|
||||
@@ -757,6 +757,13 @@ def test_regenerate_with_prior_lifecycle_logs_warning(tmp_path, monkeypatch, cap
|
||||
# row's id.
|
||||
assert str(at_id) in msg
|
||||
assert str(completed_id) in msg
|
||||
# T90.2: wording was tightened from "from superseded turn" to
|
||||
# "at-or-after turn <id>" — when regenerating an OLDER turn, the
|
||||
# listed transitions may include legitimate intervening-turn ones
|
||||
# that stand on their own. The new phrasing avoids implying the
|
||||
# warning's target turn directly authored every listed transition.
|
||||
assert "at-or-after turn" in msg
|
||||
assert "from superseded turn" not in msg
|
||||
|
||||
|
||||
def test_regenerate_sibling_lookup_scoped_to_chat(tmp_path, monkeypatch):
|
||||
|
||||
@@ -186,6 +186,82 @@ def test_read_recent_dialogue_filters_superseded_and_other_chats(tmp_path):
|
||||
assert ut_id is not None
|
||||
|
||||
|
||||
def test_read_recent_dialogue_limit_respects_chat_scope(tmp_path):
|
||||
"""T90.1: ``read_recent_dialogue`` must push the chat_id filter into
|
||||
SQL so that ``LIMIT N`` returns N rows scoped to the requested chat —
|
||||
not N globally-recent rows that may then be filtered down to fewer in
|
||||
Python.
|
||||
|
||||
Setup: two chats with 60 turns each, interleaved. With the old
|
||||
post-fetch filter, ``LIMIT 50`` would pull 50 globally-recent rows
|
||||
(most or all from chat_b — the most recent inserts) and then drop
|
||||
chat_b ones via the Python check, yielding far fewer than 50 chat_a
|
||||
rows. After the SQL pushdown, ``LIMIT 50`` should return exactly 50
|
||||
chat_a rows.
|
||||
"""
|
||||
db = tmp_path / "test.db"
|
||||
apply_migrations(db)
|
||||
with open_db(db) as conn:
|
||||
for chat_id, host_bot in (("chat_a", "bot_a"), ("chat_b", "bot_b")):
|
||||
append_event(
|
||||
conn,
|
||||
kind="bot_authored",
|
||||
payload={
|
||||
"id": host_bot,
|
||||
"name": host_bot,
|
||||
"persona": "...",
|
||||
"voice_samples": [],
|
||||
"traits": [],
|
||||
"backstory": "",
|
||||
"initial_relationship_to_you": "",
|
||||
"kickoff_prose": "",
|
||||
},
|
||||
)
|
||||
append_event(
|
||||
conn,
|
||||
kind="chat_created",
|
||||
payload={
|
||||
"id": chat_id,
|
||||
"host_bot_id": host_bot,
|
||||
"initial_time": "2026-04-26T20:00:00+00:00",
|
||||
"narrative_anchor": "Day 1",
|
||||
"weather": "",
|
||||
},
|
||||
)
|
||||
# Interleave 60 user_turn rows in each chat — chat_b's go in last
|
||||
# so they dominate the global tail.
|
||||
for i in range(60):
|
||||
append_event(
|
||||
conn,
|
||||
kind="user_turn",
|
||||
payload={
|
||||
"chat_id": "chat_a",
|
||||
"prose": f"a-{i}",
|
||||
"segments": [],
|
||||
},
|
||||
)
|
||||
for i in range(60):
|
||||
append_event(
|
||||
conn,
|
||||
kind="user_turn",
|
||||
payload={
|
||||
"chat_id": "chat_b",
|
||||
"prose": f"b-{i}",
|
||||
"segments": [],
|
||||
},
|
||||
)
|
||||
project(conn)
|
||||
|
||||
out = read_recent_dialogue(conn, "chat_a", limit=50)
|
||||
|
||||
# All returned rows should belong to chat_a (texts a-* only).
|
||||
assert len(out) == 50
|
||||
for entry in out:
|
||||
assert entry["text"].startswith("a-"), (
|
||||
f"foreign chat row leaked: {entry!r}"
|
||||
)
|
||||
|
||||
|
||||
def test_gather_prior_edges_fills_missing_with_default(tmp_path):
|
||||
"""``gather_prior_edges`` returns one entry per directed pair across
|
||||
``present_ids``. Missing rows fall back to the schema default
|
||||
|
||||
Reference in New Issue
Block a user