feat: drawer hide-from-view toggle + turn_hidden manual_edit branch (T98.3)
This commit is contained in:
@@ -280,3 +280,106 @@ def test_t98_2_edit_significance_via_existing_route_lands_manual_edit(
|
||||
assert int(payload["target_id"]) == target_id
|
||||
assert payload["prior_value"] == 0
|
||||
assert payload["new_value"] == 3
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# T98.3 — hide-from-view toggle.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _seed_turns(db: Path) -> tuple[int, int]:
|
||||
"""Append one user_turn + one assistant_turn; return their event ids."""
|
||||
with open_db(db) as conn:
|
||||
user_id = append_and_apply(
|
||||
conn,
|
||||
kind="user_turn",
|
||||
payload={
|
||||
"chat_id": "chat_bot_a",
|
||||
"prose": "How are you doing today?",
|
||||
"segments": [],
|
||||
},
|
||||
)
|
||||
bot_id = append_and_apply(
|
||||
conn,
|
||||
kind="assistant_turn",
|
||||
payload={
|
||||
"chat_id": "chat_bot_a",
|
||||
"speaker_id": "bot_a",
|
||||
"text": "Quite well, thanks for asking!",
|
||||
"truncated": False,
|
||||
"user_turn_id": user_id,
|
||||
},
|
||||
)
|
||||
return user_id, bot_id
|
||||
|
||||
|
||||
def test_t98_3_hide_turn_flips_event_log_hidden_via_manual_edit(
|
||||
client, tmp_path
|
||||
):
|
||||
db = tmp_path / "test.db"
|
||||
_seed_chat(db)
|
||||
user_id, bot_id = _seed_turns(db)
|
||||
|
||||
response = client.post(
|
||||
f"/chats/chat_bot_a/drawer/turn/hide/{user_id}",
|
||||
data={"hidden": "1"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
with open_db(db) as conn:
|
||||
# event_log.hidden flipped to 1.
|
||||
row = conn.execute(
|
||||
"SELECT hidden FROM event_log WHERE id = ?", (user_id,)
|
||||
).fetchone()
|
||||
assert int(row[0]) == 1
|
||||
|
||||
# manual_edit landed with the prior snapshot.
|
||||
import json as _json
|
||||
|
||||
log = conn.execute(
|
||||
"SELECT payload_json FROM event_log "
|
||||
"WHERE kind = 'manual_edit' ORDER BY id DESC LIMIT 1"
|
||||
).fetchone()
|
||||
payload = _json.loads(log[0])
|
||||
assert payload["target_kind"] == "turn_hidden"
|
||||
assert int(payload["target_id"]) == user_id
|
||||
assert payload["prior_value"] == {"hidden": 0}
|
||||
assert payload["new_value"] == {"hidden": 1}
|
||||
|
||||
|
||||
def test_t98_3_hidden_turn_disappears_from_read_recent_dialogue(
|
||||
client, tmp_path
|
||||
):
|
||||
"""Hiding a turn must drop it from the prompt-window read.
|
||||
|
||||
``read_recent_dialogue`` (chat.services.turn_common) filters
|
||||
``hidden = 0`` server-side, so flipping the flag via the drawer
|
||||
route must surface immediately.
|
||||
"""
|
||||
db = tmp_path / "test.db"
|
||||
_seed_chat(db)
|
||||
user_id, bot_id = _seed_turns(db)
|
||||
|
||||
# Sanity baseline — both turns visible before the hide.
|
||||
with open_db(db) as conn:
|
||||
from chat.services.turn_common import read_recent_dialogue
|
||||
|
||||
before = read_recent_dialogue(conn, "chat_bot_a", limit=10)
|
||||
before_ids = [t["event_id"] for t in before]
|
||||
assert user_id in before_ids
|
||||
assert bot_id in before_ids
|
||||
|
||||
# Hide the user turn via the drawer route.
|
||||
response = client.post(
|
||||
f"/chats/chat_bot_a/drawer/turn/hide/{user_id}",
|
||||
data={"hidden": "1"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
with open_db(db) as conn:
|
||||
from chat.services.turn_common import read_recent_dialogue
|
||||
|
||||
after = read_recent_dialogue(conn, "chat_bot_a", limit=10)
|
||||
after_ids = [t["event_id"] for t in after]
|
||||
assert user_id not in after_ids
|
||||
assert bot_id in after_ids # the unhidden bot turn still surfaces
|
||||
|
||||
Reference in New Issue
Block a user