1- """
1+ """
22Unit and integration tests for UP-21: message edit/versioning.
33
44Unit tests use an in-memory SQLite DB via aiosqlite + init_schema.
5- Integration tests use httpx against the test server (port 39769 ).
5+ Integration tests use httpx against the test server (TEST_BASE_URL from _constants ).
66"""
77import pytest
88import aiosqlite
1111from src .db .database import init_schema
1212from src .db import crud
1313from src .db .crud import MessageEditNoChangeError , MessageNotFoundError
14-
15- # ── Integration server base URL (from shared _constants) ─────────────────────
16- try :
17- from tests ._constants import TEST_BASE_URL as BASE_URL
18- except ImportError :
19- BASE_URL = "http://127.0.0.1:39769"
14+ from tests ._constants import TEST_BASE_URL as BASE_URL
2015
2116
2217# ── Helpers ───────────────────────────────────────────────────────────────────
@@ -45,7 +40,6 @@ async def _post(db, thread_id, author, content):
4540# ═══════════════════════════════════════════════════════════════════════════════
4641
4742
48- @pytest .mark .asyncio
4943async def test_msg_edit_updates_content ():
5044 """msg_edit replaces messages.content with the new value."""
5145 db = await _make_db ()
@@ -59,7 +53,6 @@ async def test_msg_edit_updates_content():
5953 await db .close ()
6054
6155
62- @pytest .mark .asyncio
6356async def test_msg_edit_creates_history_entry ():
6457 """msg_edit inserts a record in message_edits with old_content."""
6558 db = await _make_db ()
@@ -76,7 +69,6 @@ async def test_msg_edit_creates_history_entry():
7669 await db .close ()
7770
7871
79- @pytest .mark .asyncio
8072async def test_msg_edit_increments_version ():
8173 """Each successive edit increments version by 1."""
8274 db = await _make_db ()
@@ -95,7 +87,6 @@ async def test_msg_edit_increments_version():
9587 await db .close ()
9688
9789
98- @pytest .mark .asyncio
9990async def test_msg_edit_sets_edited_at ():
10091 """msg_edit sets messages.edited_at to a non-null datetime."""
10192 db = await _make_db ()
@@ -112,7 +103,6 @@ async def test_msg_edit_sets_edited_at():
112103 await db .close ()
113104
114105
115- @pytest .mark .asyncio
116106async def test_msg_edit_preserves_old_content ():
117107 """old_content in message_edits matches the pre-edit content exactly."""
118108 db = await _make_db ()
@@ -127,7 +117,6 @@ async def test_msg_edit_preserves_old_content():
127117 await db .close ()
128118
129119
130- @pytest .mark .asyncio
131120async def test_msg_edit_author_only_permission ():
132121 """PermissionError when edited_by does not match the original author."""
133122 db = await _make_db ()
@@ -139,7 +128,6 @@ async def test_msg_edit_author_only_permission():
139128 await db .close ()
140129
141130
142- @pytest .mark .asyncio
143131async def test_msg_edit_system_can_edit_any_message ():
144132 """'system' is allowed to edit any message regardless of author."""
145133 db = await _make_db ()
@@ -154,7 +142,6 @@ async def test_msg_edit_system_can_edit_any_message():
154142 await db .close ()
155143
156144
157- @pytest .mark .asyncio
158145async def test_msg_edit_system_role_cannot_be_edited ():
159146 """Messages with role='system' cannot be edited (PermissionError)."""
160147 db = await _make_db ()
@@ -175,7 +162,6 @@ async def test_msg_edit_system_role_cannot_be_edited():
175162 await db .close ()
176163
177164
178- @pytest .mark .asyncio
179165async def test_msg_edit_same_content_raises_noop ():
180166 """MessageEditNoChangeError is raised when new_content equals current content."""
181167 db = await _make_db ()
@@ -189,7 +175,6 @@ async def test_msg_edit_same_content_raises_noop():
189175 await db .close ()
190176
191177
192- @pytest .mark .asyncio
193178async def test_msg_edit_noop_carries_current_version ():
194179 """MessageEditNoChangeError.current_version reflects post-edit state."""
195180 db = await _make_db ()
@@ -205,7 +190,6 @@ async def test_msg_edit_noop_carries_current_version():
205190 await db .close ()
206191
207192
208- @pytest .mark .asyncio
209193async def test_msg_edit_nonexistent_message ():
210194 """MessageNotFoundError is raised when message_id does not exist."""
211195 db = await _make_db ()
@@ -216,7 +200,6 @@ async def test_msg_edit_nonexistent_message():
216200 await db .close ()
217201
218202
219- @pytest .mark .asyncio
220203async def test_msg_edit_updates_fts_index ():
221204 """After edit, msg_search returns results for the new content, not the old."""
222205 db = await _make_db ()
@@ -235,7 +218,6 @@ async def test_msg_edit_updates_fts_index():
235218 await db .close ()
236219
237220
238- @pytest .mark .asyncio
239221async def test_msg_edit_history_returns_all_versions ():
240222 """msg_edit_history returns one entry per edit performed."""
241223 db = await _make_db ()
@@ -252,7 +234,6 @@ async def test_msg_edit_history_returns_all_versions():
252234 await db .close ()
253235
254236
255- @pytest .mark .asyncio
256237async def test_msg_edit_history_empty_for_unedited_message ():
257238 """msg_edit_history returns [] when no edits have been applied."""
258239 db = await _make_db ()
@@ -264,7 +245,6 @@ async def test_msg_edit_history_empty_for_unedited_message():
264245 await db .close ()
265246
266247
267- @pytest .mark .asyncio
268248async def test_msg_edit_history_ordered_by_version ():
269249 """msg_edit_history entries are ordered by version ascending."""
270250 db = await _make_db ()
@@ -281,7 +261,6 @@ async def test_msg_edit_history_ordered_by_version():
281261 await db .close ()
282262
283263
284- @pytest .mark .asyncio
285264async def test_msg_list_includes_edit_fields ():
286265 """msg_list response includes edited_at (None) and edit_version (0) for new messages."""
287266 db = await _make_db ()
@@ -298,7 +277,6 @@ async def test_msg_list_includes_edit_fields():
298277 await db .close ()
299278
300279
301- @pytest .mark .asyncio
302280async def test_msg_list_reflects_edit_fields_after_edit ():
303281 """msg_list shows non-null edited_at and incremented edit_version after an edit."""
304282 db = await _make_db ()
0 commit comments