feat(deploy): finalize MVP deployment and file transfer approach
This commit is contained in:
parent
6369721876
commit
0f79494fbe
43 changed files with 3078 additions and 645 deletions
|
|
@ -4,29 +4,12 @@ from pathlib import Path
|
|||
from types import SimpleNamespace
|
||||
|
||||
from adapter.matrix.files import (
|
||||
build_agent_incoming_path,
|
||||
build_workspace_attachment_path,
|
||||
build_agent_workspace_path,
|
||||
download_matrix_attachment,
|
||||
)
|
||||
from core.protocol import Attachment
|
||||
|
||||
|
||||
def test_build_workspace_attachment_path_scopes_by_surface_user_and_room(tmp_path: Path):
|
||||
rel_path, abs_path = build_workspace_attachment_path(
|
||||
workspace_root=tmp_path,
|
||||
matrix_user_id="@alice:example.org",
|
||||
room_id="!room:example.org",
|
||||
filename="report.pdf",
|
||||
timestamp="20260420-153000",
|
||||
)
|
||||
|
||||
assert (
|
||||
rel_path
|
||||
== "surfaces/matrix/alice_example.org/room_example.org/inbox/20260420-153000-report.pdf"
|
||||
)
|
||||
assert abs_path == tmp_path / rel_path
|
||||
|
||||
|
||||
async def test_download_matrix_attachment_persists_file_and_returns_workspace_path(tmp_path: Path):
|
||||
async def download(url: str):
|
||||
assert url == "mxc://server/id"
|
||||
|
|
@ -49,40 +32,46 @@ async def test_download_matrix_attachment_persists_file_and_returns_workspace_pa
|
|||
timestamp="20260420-153000",
|
||||
)
|
||||
|
||||
assert saved.workspace_path is not None
|
||||
assert saved.workspace_path.endswith("20260420-153000-report.pdf")
|
||||
assert (tmp_path / saved.workspace_path).read_bytes() == b"%PDF-1.7"
|
||||
assert saved.workspace_path == "report.pdf"
|
||||
assert (tmp_path / "report.pdf").read_bytes() == b"%PDF-1.7"
|
||||
|
||||
|
||||
def test_build_workspace_attachment_path_keeps_room_safe_agents_relative_contract(tmp_path: Path):
|
||||
rel_path, abs_path = build_workspace_attachment_path(
|
||||
workspace_root=tmp_path / "agents" / "7",
|
||||
matrix_user_id="@alice+bob:example.org",
|
||||
room_id="!room/ops:example.org",
|
||||
filename="quarterly status (final).pdf",
|
||||
timestamp="20260420-153000",
|
||||
)
|
||||
|
||||
assert rel_path == (
|
||||
"surfaces/matrix/alice_bob_example.org/room_ops_example.org/inbox/"
|
||||
"20260420-153000-quarterly_status_final_.pdf"
|
||||
)
|
||||
assert not Path(rel_path).is_absolute()
|
||||
assert abs_path == tmp_path / "agents" / "7" / rel_path
|
||||
|
||||
|
||||
def test_build_agent_incoming_path_uses_agent_workspace_volume(tmp_path: Path):
|
||||
rel_path, abs_path = build_agent_incoming_path(
|
||||
def test_build_agent_workspace_path_uses_agent_workspace_volume(tmp_path: Path):
|
||||
rel_path, abs_path = build_agent_workspace_path(
|
||||
workspace_root=tmp_path / "agents" / "17",
|
||||
filename="quarterly status.pdf",
|
||||
timestamp="20260428-110000",
|
||||
)
|
||||
|
||||
assert rel_path == "incoming/20260428-110000-quarterly_status.pdf"
|
||||
assert rel_path == "quarterly status.pdf"
|
||||
assert abs_path == tmp_path / "agents" / "17" / rel_path
|
||||
|
||||
|
||||
async def test_download_matrix_attachment_uses_agent_workspace_incoming_dir(tmp_path: Path):
|
||||
def test_build_agent_workspace_path_uses_windows_style_copy_index(tmp_path: Path):
|
||||
workspace_root = tmp_path / "agents" / "17"
|
||||
workspace_root.mkdir(parents=True)
|
||||
(workspace_root / "report.pdf").write_bytes(b"old")
|
||||
(workspace_root / "report (1).pdf").write_bytes(b"older")
|
||||
|
||||
rel_path, abs_path = build_agent_workspace_path(
|
||||
workspace_root=workspace_root,
|
||||
filename="report.pdf",
|
||||
)
|
||||
|
||||
assert rel_path == "report (2).pdf"
|
||||
assert abs_path == workspace_root / "report (2).pdf"
|
||||
|
||||
|
||||
def test_build_agent_workspace_path_sanitizes_to_basename(tmp_path: Path):
|
||||
rel_path, abs_path = build_agent_workspace_path(
|
||||
workspace_root=tmp_path / "agents" / "17",
|
||||
filename="../../quarterly: status?.pdf",
|
||||
)
|
||||
|
||||
assert rel_path == "quarterly_ status_.pdf"
|
||||
assert abs_path == tmp_path / "agents" / "17" / "quarterly_ status_.pdf"
|
||||
|
||||
|
||||
async def test_download_matrix_attachment_uses_agent_workspace_root(tmp_path: Path):
|
||||
async def download(url: str):
|
||||
assert url == "mxc://server/id"
|
||||
return SimpleNamespace(body=b"%PDF-1.7")
|
||||
|
|
@ -101,5 +90,5 @@ async def test_download_matrix_attachment_uses_agent_workspace_incoming_dir(tmp_
|
|||
timestamp="20260428-110000",
|
||||
)
|
||||
|
||||
assert saved.workspace_path == "incoming/20260428-110000-report.pdf"
|
||||
assert saved.workspace_path == "report.pdf"
|
||||
assert (tmp_path / "agents" / "17" / saved.workspace_path).read_bytes() == b"%PDF-1.7"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue