Add missing pathing information to frontend

This commit is contained in:
Jack Kingsman
2026-01-18 14:17:49 -08:00
parent b13af6433d
commit 13220c4a8f
19 changed files with 281 additions and 40 deletions
+75 -7
View File
@@ -78,13 +78,30 @@ class TestMigration001:
)
""")
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
# Messages table with old schema (for migrations 6 and 7)
await conn.execute("""
CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT NOT NULL,
conversation_key TEXT NOT NULL,
text TEXT NOT NULL,
sender_timestamp INTEGER,
received_at INTEGER NOT NULL,
path_len INTEGER,
txt_type INTEGER DEFAULT 0,
signature TEXT,
outgoing INTEGER DEFAULT 0,
acked INTEGER DEFAULT 0,
UNIQUE(type, conversation_key, text, sender_timestamp)
)
""")
await conn.commit()
# Run migrations
applied = await run_migrations(conn)
assert applied == 5 # All 5 migrations run
assert await get_version(conn) == 5
assert applied == 7 # All 7 migrations run
assert await get_version(conn) == 7
# Verify columns exist by inserting and selecting
await conn.execute(
@@ -143,15 +160,32 @@ class TestMigration001:
)
""")
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
# Messages table with old schema (for migrations 6 and 7)
await conn.execute("""
CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT NOT NULL,
conversation_key TEXT NOT NULL,
text TEXT NOT NULL,
sender_timestamp INTEGER,
received_at INTEGER NOT NULL,
path_len INTEGER,
txt_type INTEGER DEFAULT 0,
signature TEXT,
outgoing INTEGER DEFAULT 0,
acked INTEGER DEFAULT 0,
UNIQUE(type, conversation_key, text, sender_timestamp)
)
""")
await conn.commit()
# Run migrations twice
applied1 = await run_migrations(conn)
applied2 = await run_migrations(conn)
assert applied1 == 5 # All 5 migrations run
assert applied1 == 7 # All 7 migrations run
assert applied2 == 0 # No migrations on second run
assert await get_version(conn) == 5
assert await get_version(conn) == 7
finally:
await conn.close()
@@ -189,14 +223,31 @@ class TestMigration001:
)
""")
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
# Messages table with old schema (for migrations 6 and 7)
await conn.execute("""
CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT NOT NULL,
conversation_key TEXT NOT NULL,
text TEXT NOT NULL,
sender_timestamp INTEGER,
received_at INTEGER NOT NULL,
path_len INTEGER,
txt_type INTEGER DEFAULT 0,
signature TEXT,
outgoing INTEGER DEFAULT 0,
acked INTEGER DEFAULT 0,
UNIQUE(type, conversation_key, text, sender_timestamp)
)
""")
await conn.commit()
# Run migrations - should not fail
applied = await run_migrations(conn)
# All 5 migrations applied (version incremented) but no error
assert applied == 5
assert await get_version(conn) == 5
# All 7 migrations applied (version incremented) but no error
assert applied == 7
assert await get_version(conn) == 7
finally:
await conn.close()
@@ -234,6 +285,23 @@ class TestMigration001:
)
""")
await conn.execute("CREATE INDEX idx_raw_packets_decrypted ON raw_packets(decrypted)")
# Messages table with old schema (for migrations 6 and 7)
await conn.execute("""
CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT NOT NULL,
conversation_key TEXT NOT NULL,
text TEXT NOT NULL,
sender_timestamp INTEGER,
received_at INTEGER NOT NULL,
path_len INTEGER,
txt_type INTEGER DEFAULT 0,
signature TEXT,
outgoing INTEGER DEFAULT 0,
acked INTEGER DEFAULT 0,
UNIQUE(type, conversation_key, text, sender_timestamp)
)
""")
await conn.execute(
"INSERT INTO contacts (public_key, name, type) VALUES (?, ?, ?)",
("existingkey", "ExistingContact", 1),
+6 -6
View File
@@ -430,7 +430,7 @@ class TestCreateMessageFromDecrypted:
assert broadcast["text"] == "TestSender: Hello world"
assert broadcast["sender_timestamp"] == 1700000000
assert broadcast["received_at"] == 1700000001
assert broadcast["path_len"] is None # Historical decryption has no path info
assert broadcast["path"] is None # Historical decryption has no path info
assert broadcast["outgoing"] is False
assert broadcast["acked"] == 0
@@ -529,8 +529,8 @@ class TestMessageBroadcastStructure:
"""Test that message broadcasts have the correct structure for frontend."""
@pytest.mark.asyncio
async def test_realtime_broadcast_includes_path_len(self, test_db, captured_broadcasts):
"""Real-time packet processing includes path_len in broadcast."""
async def test_realtime_broadcast_includes_path(self, test_db, captured_broadcasts):
"""Real-time packet processing includes path in broadcast."""
from app.packet_processor import process_raw_packet
fixture = FIXTURES["channel_message"]
@@ -550,9 +550,9 @@ class TestMessageBroadcastStructure:
assert len(message_broadcasts) == 1
broadcast = message_broadcasts[0]["data"]
# Real-time processing extracts path_len from packet (flood packets have path_len=0)
assert "path_len" in broadcast
# The test packet is a flood packet, so path_len should be 0 or None depending on packet structure
# Real-time processing extracts path from packet (flood packets have empty path)
assert "path" in broadcast
# The test packet is a flood packet, so path should be empty string ""
class TestRawPacketStorage: