refactor: remove legacy history and proxy migrations (#6518)
This commit is contained in:
1 parent
1c28b20c7e
commit
cb3ba45317
47 files changed
+207
-1925
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -12,40 +11,9 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from nanobot.config.loader import load_config
|
||||
from nanobot.session.jsonl_migration import WORKSPACE_BACKUP_DIR
|
||||
from nanobot.session.location import SessionLocation
|
||||
from nanobot.session.manager import SessionManager
|
||||
|
||||
|
||||
def _write_legacy_session(
|
||||
old_dir: Path,
|
||||
key: str,
|
||||
content: str,
|
||||
*,
|
||||
updated_at: str = "2026-01-01T00:00:00",
|
||||
) -> Path:
|
||||
"""Write a valid session file in the legacy in-workspace location."""
|
||||
old_dir.mkdir(parents=True, exist_ok=True)
|
||||
path = old_dir / f"{SessionLocation.storage_key(key)}.jsonl"
|
||||
path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"_type": "metadata",
|
||||
"key": key,
|
||||
"created_at": "2026-01-01T00:00:00",
|
||||
"updated_at": updated_at,
|
||||
"metadata": {},
|
||||
"last_consolidated": 0,
|
||||
}
|
||||
)
|
||||
+ "\n"
|
||||
+ json.dumps({"role": "user", "content": content})
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return path
|
||||
|
||||
|
||||
def test_sessions_are_stored_outside_workspace(tmp_path: Path) -> None:
|
||||
workspace = tmp_path / "workspace"
|
||||
manager = SessionManager(workspace=workspace)
|
||||
@@ -219,45 +187,3 @@ def test_equivalent_workspace_paths_share_one_store(tmp_path: Path) -> None:
|
||||
|
||||
via_link = SessionManager(workspace=link_workspace).get_or_create("telegram:1")
|
||||
assert via_link.messages[-1]["content"] == "via-real"
|
||||
|
||||
|
||||
def test_migration_rejects_symlinked_session_file(tmp_path, create_symlink):
|
||||
workspace = tmp_path / "workspace"
|
||||
path = _write_legacy_session(workspace / "sessions", "cli:test", "original")
|
||||
target = tmp_path / "outside.jsonl"
|
||||
path.rename(target)
|
||||
create_symlink(path, target)
|
||||
with pytest.raises(RuntimeError, match="migration failed"):
|
||||
SessionManager(workspace)
|
||||
assert "original" in target.read_text()
|
||||
|
||||
|
||||
def test_migration_rejects_symlinked_source_directory(tmp_path, create_symlink):
|
||||
workspace = tmp_path / "workspace"
|
||||
workspace.mkdir()
|
||||
outside = tmp_path / "outside"
|
||||
outside.mkdir()
|
||||
create_symlink(workspace / "sessions", outside, target_is_directory=True)
|
||||
with pytest.raises(ValueError, match="symlink"):
|
||||
SessionManager(workspace)
|
||||
|
||||
|
||||
def test_workspace_migration_rejects_symlinked_backup_directory(tmp_path, create_symlink):
|
||||
workspace = tmp_path / "workspace"
|
||||
root = tmp_path / "root"
|
||||
source = _write_legacy_session(workspace / "sessions", "cli:test", "original")
|
||||
original = source.read_bytes()
|
||||
location = SessionLocation(workspace, sessions_root=root)
|
||||
outside = tmp_path / "outside"
|
||||
outside.mkdir()
|
||||
backup = location.sessions_dir / WORKSPACE_BACKUP_DIR
|
||||
create_symlink(backup, outside, target_is_directory=True)
|
||||
|
||||
with pytest.raises(RuntimeError, match="Could not move legacy sessions"):
|
||||
SessionManager(workspace, sessions_root=root)
|
||||
assert source.read_bytes() == original
|
||||
assert list(outside.iterdir()) == []
|
||||
backup.unlink()
|
||||
manager = SessionManager(workspace, sessions_root=root)
|
||||
assert not source.exists()
|
||||
assert (manager.sessions_dir / WORKSPACE_BACKUP_DIR / source.name).read_bytes() == original
|
||||
Reference in new issue
Block a user