feat: drawer surgical delete with cascade preview (T98.4)
This commit is contained in:
@@ -383,3 +383,76 @@ def test_t98_3_hidden_turn_disappears_from_read_recent_dialogue(
|
||||
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
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# T98.4 — surgical delete with cascade preview.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_t98_4_delete_preview_returns_impact_report_html(client, tmp_path):
|
||||
db = tmp_path / "test.db"
|
||||
_seed_chat(db)
|
||||
user_id, bot_id = _seed_turns(db)
|
||||
|
||||
response = client.get(
|
||||
f"/chats/chat_bot_a/drawer/turn/delete-preview/{user_id}"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
body = response.text
|
||||
|
||||
# Modal markup with the event id and the cascade list.
|
||||
assert "delete-impact-modal" in body
|
||||
assert f"Delete event {user_id}?" in body
|
||||
assert "delete-impact-cascade" in body
|
||||
# Both turns ride along in the cascade — user_turn at user_id, then
|
||||
# the assistant_turn at bot_id (>= user_id).
|
||||
assert "user_turn" in body
|
||||
assert "assistant_turn" in body
|
||||
# Confirm-form posts to the delete route.
|
||||
assert f"/drawer/turn/delete/{user_id}" in body
|
||||
|
||||
|
||||
def test_t98_4_delete_invokes_rewind_and_drops_cascade(client, tmp_path):
|
||||
db = tmp_path / "test.db"
|
||||
_seed_chat(db)
|
||||
user_id, bot_id = _seed_turns(db)
|
||||
|
||||
# Append a third turn after the assistant_turn so we can verify the
|
||||
# cascade catches everything from user_id forward.
|
||||
with open_db(db) as conn:
|
||||
extra_id = append_and_apply(
|
||||
conn,
|
||||
kind="user_turn",
|
||||
payload={
|
||||
"chat_id": "chat_bot_a",
|
||||
"prose": "follow-up",
|
||||
"segments": [],
|
||||
},
|
||||
)
|
||||
|
||||
# Sanity: all three turn rows exist.
|
||||
with open_db(db) as conn:
|
||||
turn_count = conn.execute(
|
||||
"SELECT COUNT(*) FROM event_log "
|
||||
"WHERE kind IN ('user_turn', 'assistant_turn')"
|
||||
).fetchone()[0]
|
||||
assert turn_count == 3
|
||||
|
||||
# Delete from user_id forward.
|
||||
response = client.post(f"/chats/chat_bot_a/drawer/turn/delete/{user_id}")
|
||||
assert response.status_code == 200
|
||||
|
||||
# All three turns are gone — the rewind truncated the log past
|
||||
# user_id - 1, removing user_id, bot_id, and extra_id.
|
||||
with open_db(db) as conn:
|
||||
turn_count = conn.execute(
|
||||
"SELECT COUNT(*) FROM event_log "
|
||||
"WHERE kind IN ('user_turn', 'assistant_turn')"
|
||||
).fetchone()[0]
|
||||
assert turn_count == 0
|
||||
for ev_id in (user_id, bot_id, extra_id):
|
||||
row = conn.execute(
|
||||
"SELECT 1 FROM event_log WHERE id = ?", (ev_id,)
|
||||
).fetchone()
|
||||
assert row is None, f"event {ev_id} should have been deleted"
|
||||
|
||||
Reference in New Issue
Block a user