1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
@@ -0,0 +1,74 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPECTED = (
|
||||
"uid, folder, message_id, in_reply_to, references_header, subject, "
|
||||
"from_address, from_name, to_addresses, cc_addresses, date, flags, "
|
||||
"size, has_attachments, snippet, reaction"
|
||||
)
|
||||
|
||||
|
||||
def read(rel: str) -> str:
|
||||
return (ROOT / rel).read_text()
|
||||
|
||||
|
||||
def test_cached_message_projection_is_stable_for_all_sql_dialects():
|
||||
for dialect in ("sqlite", "mysql", "pgsql"):
|
||||
text = read(f"src/queries/{dialect}/queries.rs")
|
||||
m = re.search(r'pub const MSG_SELECT_COLS: &str = "([^"]+)";', text)
|
||||
assert m, dialect
|
||||
assert m.group(1) == EXPECTED, dialect
|
||||
|
||||
|
||||
def test_cached_message_row_mapping_matches_projection():
|
||||
text = read("src/db/messages.rs")
|
||||
assert "let has_attachments_int: i32 = row.get(13)?;" in text
|
||||
assert "flags: row.get(11)?" in text
|
||||
assert "size: row.get(12)?" in text
|
||||
assert "snippet: row.get(14)?" in text
|
||||
assert "reaction: row.get(15)?" in text
|
||||
|
||||
|
||||
def test_cached_message_projection_does_not_include_body_cache_columns():
|
||||
sqlite = read("src/queries/sqlite/queries.rs")
|
||||
m = re.search(r'pub const MSG_SELECT_COLS: &str = "([^"]+)";', sqlite)
|
||||
projection = m.group(1)
|
||||
for unexpected in ("date_epoch", "body_cached", "body_html", "body_text", "attachments_json", "raw_headers", "email_theme"):
|
||||
assert unexpected not in projection
|
||||
|
||||
|
||||
def test_cached_message_projection_executes_on_fresh_sqlite_schema():
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect(":memory:")
|
||||
migration_dir = ROOT / "migrations/sqlite"
|
||||
for migration in sorted(migration_dir.glob("V*.sql")):
|
||||
if migration.name.startswith("V047__sessions"):
|
||||
continue
|
||||
conn.executescript(migration.read_text())
|
||||
|
||||
conn.execute("INSERT OR IGNORE INTO folders(name) VALUES ('INBOX')")
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO messages
|
||||
(uid, folder, message_id, in_reply_to, references_header, subject,
|
||||
from_address, from_name, to_addresses, cc_addresses, date, flags,
|
||||
size, has_attachments, snippet, date_epoch, reaction)
|
||||
VALUES (1, 'INBOX', 'm1', NULL, NULL, 'Subject',
|
||||
'a@example.com', 'Alice', '[]', '[]', '2026-10-30', '\\Seen',
|
||||
123, 1, 'snippet', 1761840000, 'ok')
|
||||
"""
|
||||
)
|
||||
|
||||
row = conn.execute(
|
||||
f"SELECT {EXPECTED} FROM messages WHERE folder = ? AND uid = ?",
|
||||
("INBOX", 1),
|
||||
).fetchone()
|
||||
|
||||
assert len(row) == 16
|
||||
assert row[11] == "\\Seen"
|
||||
assert row[12] == 123
|
||||
assert row[13] == 1
|
||||
assert row[14] == "snippet"
|
||||
assert row[15] == "ok"
|
||||
Reference in new issue
Block a user