Polish mobile UI and editor workflows

This commit is contained in:
pewdiepie-archdaemon
2026-06-27 13:05:44 +00:00
parent 87e46e576a
commit 45ee5a71f4
48 changed files with 6455 additions and 1177 deletions
+13
View File
@@ -0,0 +1,13 @@
from pathlib import Path
def test_active_email_reader_blocks_immediate_reply_tools():
source = Path("routes/chat_routes.py").read_text(encoding="utf-8")
guard_start = source.index("if active_email_ctx and active_email_ctx.get(\"uid\"):")
guard_block = source[guard_start:source.index("# Enforce per-user privileges", guard_start)]
assert '"reply_to_email"' in guard_block
assert '"mcp__email__reply_to_email"' in guard_block
assert '"send_email"' in guard_block
assert '"mcp__email__send_email"' in guard_block
assert '"create_document"' in guard_block
+87 -2
View File
@@ -184,6 +184,87 @@ def test_sender_signature_cache_is_owner_scoped_and_migrates_legacy_rows(tmp_pat
conn.close()
def test_email_message_index_is_owner_account_folder_scoped(tmp_path, monkeypatch):
import routes.email_helpers as email_helpers
db_path = tmp_path / "scheduled_emails.db"
monkeypatch.setattr(email_helpers, "SCHEDULED_DB", db_path)
email_helpers._init_scheduled_db()
conn = sqlite3.connect(db_path)
try:
info = conn.execute("PRAGMA table_info(email_message_index)").fetchall()
pk_cols = [r[1] for r in sorted((r for r in info if r[5]), key=lambda r: r[5])]
assert pk_cols == ["owner", "account_key", "folder", "uid"]
conn.execute(
"""
INSERT INTO email_message_index
(owner, account_key, folder, uid, message_id, subject, updated_at)
VALUES ('alice', 'acct-a', 'INBOX', '7', '<same@example.com>', 'Alice', '2026-01-01')
"""
)
conn.execute(
"""
INSERT INTO email_message_index
(owner, account_key, folder, uid, message_id, subject, updated_at)
VALUES ('bob', 'acct-a', 'INBOX', '7', '<same@example.com>', 'Bob', '2026-01-01')
"""
)
rows = conn.execute(
"SELECT owner, subject FROM email_message_index WHERE account_key='acct-a' AND folder='INBOX' AND uid='7' ORDER BY owner"
).fetchall()
assert rows == [("alice", "Alice"), ("bob", "Bob")]
finally:
conn.close()
def test_email_index_helpers_roundtrip_and_update_flags(tmp_path, monkeypatch):
import routes.email_helpers as email_helpers
import routes.email_routes as email_routes
db_path = tmp_path / "scheduled_emails.db"
monkeypatch.setattr(email_helpers, "SCHEDULED_DB", db_path)
monkeypatch.setattr(email_routes, "SCHEDULED_DB", db_path)
email_helpers._init_scheduled_db()
email_routes._email_index_upsert(
"alice",
"acct-a",
"INBOX",
[{
"uid": "11",
"message_id": "<m@example.com>",
"subject": "Cached",
"from_name": "Sender",
"from_address": "sender@example.com",
"to": "alice@example.com",
"cc": "",
"date": "2026-01-01T00:00:00+00:00",
"date_display": "Thu, 1 Jan 2026 00:00:00 +0000",
"date_epoch": 1767225600,
"size": 123,
"flags": "\\Seen",
"has_attachments": True,
}],
)
rows = email_routes._email_index_rows("alice", "acct-a", "INBOX", ["11", "12"])
assert rows["11"]["subject"] == "Cached"
assert rows["11"]["is_read"] is True
assert rows["11"]["has_attachments"] is True
email_routes._email_index_update_flags("alice", "acct-a", "INBOX", "11", "\\Seen", False)
email_routes._email_index_update_flags("alice", "acct-a", "INBOX", "11", "\\Flagged", True)
rows = email_routes._email_index_rows("alice", "acct-a", "INBOX", ["11"])
assert rows["11"]["is_read"] is False
assert rows["11"]["is_flagged"] is True
email_routes._email_index_delete("alice", "acct-a", "INBOX", "11")
assert email_routes._email_index_rows("alice", "acct-a", "INBOX", ["11"]) == {}
@pytest.mark.asyncio
async def test_ai_reply_cache_lookup_is_owner_scoped(tmp_path, monkeypatch):
import routes.email_helpers as email_helpers
@@ -280,8 +361,12 @@ async def test_sender_signature_read_lookup_is_owner_scoped(tmp_path, monkeypatc
def uid(self, command, _uid, query):
assert command == "FETCH"
assert query == "(BODY.PEEK[])"
return "OK", [(b"1 (UID 1 BODY[])", raw)]
assert query.startswith("(BODY.PEEK[HEADER] BODY.PEEK[TEXT]<0.")
header, body = raw.split(b"\r\n\r\n", 1)
return "OK", [
(b"1 (UID 1 BODY[HEADER])", header + b"\r\n\r\n"),
(b"1 (UID 1 BODY[TEXT]<0>)", body),
]
@contextmanager
def fake_imap(_account_id=None, owner=""):
@@ -82,3 +82,14 @@ def test_suggest_document_skips_non_object_suggestion_items():
assert block.content == (
"<<<FIND>>>\nold\n<<<SUGGEST>>>\nnew\n<<<REASON>>>\nclearer\n<<<END>>>"
)
def test_ui_control_open_email_reply_preserves_structured_body():
block = function_call_to_tool_block(
"ui_control",
'{"action":"open_email_reply","uid":"3228","folder":"INBOX","mode":"reply","body":"Hi Andy,\\n\\nNo thank you.\\n\\nBest,"}',
)
assert block is not None
assert block.tool_type == "ui_control"
assert block.content == "open_email_reply 3228 INBOX reply Hi Andy,\n\nNo thank you.\n\nBest,"
+22
View File
@@ -0,0 +1,22 @@
from src.agent_tools.document_tools import _strip_pdf_editor_markers
def test_pdf_ai_edit_derivative_strips_pdf_plumbing():
raw = """<!-- pdf_source upload_id="0123456789abcdef0123456789abcdef.pdf" -->
# Contract
- **Name:** Felix <!-- field=Name type=text -->
- Hello world <!-- annotation id=a1 page=1 x=1 y=2 w=3 h=4 kind=text -->
"""
assert _strip_pdf_editor_markers(raw) == "# Contract\n\n- **Name:** Felix\n- Hello world"
def test_pdf_ai_edit_derivative_strips_form_source_marker():
raw = """<!-- pdf_form_source upload_id="0123456789abcdef0123456789abcdef.pdf" fields="12" -->
# Form
"""
assert _strip_pdf_editor_markers(raw) == "# Form"