Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
refactor: remove unused and deprecated APIs (#3272)
Qin Haojied47f2106ee69
diff --git a/bot/tests/test_agent_loop_outcome.py b/bot/tests/test_agent_loop_outcome.pyindex 6fc373db6..f2be2b363 100644--- a/bot/tests/test_agent_loop_outcome.py+++ b/bot/tests/test_agent_loop_outcome.py@@ -1,4 +1,3 @@-import jsonimport sysfrom datetime import datetimefrom pathlib import Path@@ -13,7 +12,6 @@ from vikingbot.agent.loop import AgentLoopfrom vikingbot.bus.events import InboundMessage, OutboundEventTypefrom vikingbot.bus.queue import MessageBusfrom vikingbot.config.schema import AgentsConfig, Config, SessionKey-from vikingbot.heartbeat.service import HEARTBEAT_METADATA_KEYfrom vikingbot.providers.base import LLMProvider, LLMResponse, ToolCallRequest@@ -317,58 +315,6 @@ async def test_agent_loop_makes_final_no_tool_call_when_iteration_limit_reached(assert token_usage == {"prompt_tokens": 17, "completion_tokens": 7, "total_tokens": 24}-async def test_agent_loop_evaluates_previous_response_outcome_before_new_user_turn(- temp_dir: Path, monkeypatch-):- monkeypatch.setattr(AgentLoop, "_register_builtin_hooks", lambda self: None)- monkeypatch.setattr(AgentLoop, "_register_default_tools", lambda self: None)- monkeypatch.setattr("vikingbot.agent.loop.SubagentManager", _FakeSubagentManager)-- bus = MessageBus()- config = Config(storage_workspace=str(temp_dir))- loop = AgentLoop(- bus=bus,- provider=_FakeProvider(),- workspace=temp_dir / "workspace",- config=config,- )-- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- session = loop.sessions.get_or_create(session_key, skip_heartbeat=True)- session.add_message(- "assistant",- "hello",- sender_id="user-1",- response_id="resp-123",- timestamp="2026-04-30T00:00:00",- )- await loop.sessions.save(session)-- response = await loop._process_message(- InboundMessage(- session_key=session_key,- sender_id="user-1",- content="that did not help",- need_reply=False,- timestamp=datetime.fromisoformat("2026-04-30T00:05:00"),- )- )-- assert response is not None- assert response.event_type == OutboundEventType.NO_REPLY- assert bus.outbound_size == 1-- outcome_event = await bus.consume_outbound()- assert outcome_event.event_type == OutboundEventType.RESPONSE_OUTCOME_EVALUATED- assert outcome_event.response_id == "resp-123"- assert outcome_event.metadata["response_outcome_evaluated"]["outcome_label"] == "reasked"- assert outcome_event.metadata["response_outcome_evaluated"]["reask_within_10m"] is True-- persisted_session = loop.sessions.get_or_create(session_key, skip_heartbeat=True)- assert persisted_session.metadata["response_outcomes"]["resp-123"]["outcome_label"] == "reasked"--@pytest.mark.asyncioasync def test_agent_loop_evaluates_previous_response_outcome_before_openviking_precommit_clear(temp_dir: Path, monkeypatch@@ -436,53 +382,6 @@ async def test_agent_loop_evaluates_previous_response_outcome_before_openviking_assert persisted_session.metadata["response_outcomes"]["resp-123"]["outcome_label"] == "reasked"-async def test_agent_loop_ignores_heartbeat_when_evaluating_previous_response_outcome(- temp_dir: Path, monkeypatch-):- monkeypatch.setattr(AgentLoop, "_register_builtin_hooks", lambda self: None)- monkeypatch.setattr(AgentLoop, "_register_default_tools", lambda self: None)- monkeypatch.setattr("vikingbot.agent.loop.SubagentManager", _FakeSubagentManager)-- bus = MessageBus()- config = Config(storage_workspace=str(temp_dir))- loop = AgentLoop(- bus=bus,- provider=_FakeProvider(),- workspace=temp_dir / "workspace",- config=config,- )-- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- session = loop.sessions.get_or_create(session_key, skip_heartbeat=False)- session.add_message(- "assistant",- "hello",- sender_id="user-1",- response_id="resp-123",- timestamp="2026-04-30T00:00:00",- )- await loop.sessions.save(session)-- response = await loop._process_message(- InboundMessage(- session_key=session_key,- sender_id="user-1",- content="Read HEARTBEAT.md if needed",- need_reply=False,- timestamp=datetime.fromisoformat("2026-04-30T00:05:00"),- metadata={HEARTBEAT_METADATA_KEY: True},- )- )-- assert response is not None- assert response.event_type == OutboundEventType.NO_REPLY- assert bus.outbound_size == 0-- persisted_session = loop.sessions.get_or_create(session_key, skip_heartbeat=False)- assert "response_outcomes" not in persisted_session.metadata--@pytest.mark.asyncioasync def test_agent_loop_build_prompt_history_uses_ov_context_plus_unsynced_tail(temp_dir: Path, monkeypatch@@ -1077,199 +976,3 @@ async def test_agent_loop_post_turn_clears_local_session_after_openviking_commitassert persisted_session.metadata["openviking"]["session_id"] == session_key.safe_name()assert persisted_session.metadata["openviking"]["last_synced_local_index"] == -1assert persisted_session.metadata["openviking"]["last_commit_local_index"] == -1---async def test_agent_loop_emits_normalized_response_completed_payload(temp_dir: Path, monkeypatch):- monkeypatch.setattr(AgentLoop, "_register_builtin_hooks", lambda self: None)- monkeypatch.setattr(AgentLoop, "_register_default_tools", lambda self: None)- monkeypatch.setattr("vikingbot.agent.loop.SubagentManager", _FakeSubagentManager)-- fake_langfuse = _FakeLangfuseClient()- monkeypatch.setattr(- "vikingbot.agent.loop.LangfuseClient.get_instance",- staticmethod(lambda: fake_langfuse),- )-- async def fake_run_agent_loop(self, **kwargs):- turn_tools = [- {- "tool_call_id": "call-search",- "tool_name": "search_docs",- "args": '{"query": "docs"}',- "result": "search result",- },- {- "tool_call_id": "call-fetch",- "tool_name": "fetch_page",- "args": '{"url": "https://example.com"}',- "result": "page result",- },- ]- kwargs["captured_turns"].append(- {- "role": "assistant",- "content": "I will check the docs.",- "tool_calls": turn_tools,- "timestamp": "2026-04-30T00:05:01",- }- )- return (- "final answer",- None,- turn_tools,- {"prompt_tokens": 12, "completion_tokens": 8},- 3,- )-- class FakeContextBuilder:- def __init__(self, *args, **kwargs):- self.latest_relevant_memories = None-- async def build_messages(self, **kwargs):- return [{"role": "user", "content": kwargs["current_message"]}]-- monkeypatch.setattr("vikingbot.agent.context.ContextBuilder", FakeContextBuilder)- monkeypatch.setattr(AgentLoop, "_run_agent_loop", fake_run_agent_loop)-- bus = MessageBus()- config = Config(- storage_workspace=str(temp_dir),- ov_server={"server_url": "http://127.0.0.1:1933"},- )- loop = AgentLoop(- bus=bus,- provider=_FakeProvider(),- workspace=temp_dir / "workspace",- config=config,- )-- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- response = await loop._process_message(- InboundMessage(- session_key=session_key,- sender_id="user-1",- content="please help",- timestamp=datetime.fromisoformat("2026-04-30T00:05:00"),- )- )-- assert response is not None- assert response.content == "final answer"- assert response.response_id is not None- assert bus.outbound_size == 1-- completed_event = await bus.consume_outbound()- assert completed_event.event_type == OutboundEventType.RESPONSE_COMPLETED- payload = completed_event.metadata["response_completed"]- assert payload["response_id"] == response.response_id- assert payload["session_id"] == "cli__default__session-1"- assert payload["channel"] == "cli__default"- assert payload["session_type"] == "cli"- assert payload["user_id"] == "user-1"- assert payload["prompt_tokens"] == 12- assert payload["completion_tokens"] == 8- assert payload["total_tokens"] == 20- assert payload["iteration_count"] == 3- assert payload["tool_count"] == 2- assert payload["tools_used_names"] == ["search_docs", "fetch_page"]- assert payload["response_length"] == len("final answer")- assert payload["has_reasoning"] is False- assert payload["time_cost_ms"] >= 0- assert payload["created_at"]- assert fake_langfuse.calls == [(response.response_id, payload)]-- session_path = temp_dir / "bot" / "sessions" / "cli__default__session-1.jsonl"- session_lines = session_path.read_text().splitlines()- metadata = json.loads(session_lines[0])- assert metadata["metadata"]["response_facts"][response.response_id] == payload- persisted_assistant = json.loads(session_lines[-1])- assert persisted_assistant["content"] == "final answer"- assert persisted_assistant["agent_turns"] == [- {- "role": "assistant",- "content": "I will check the docs.",- "tool_calls": [- {- "tool_call_id": "call-search",- "tool_name": "search_docs",- "args": '{"query": "docs"}',- "result": "search result",- },- {- "tool_call_id": "call-fetch",- "tool_name": "fetch_page",- "args": '{"url": "https://example.com"}',- "result": "page result",- },- ],- "timestamp": "2026-04-30T00:05:01",- }- ]---async def test_auto_openviking_memory_uses_distinct_tool_name(temp_dir: Path, monkeypatch):- monkeypatch.setattr(AgentLoop, "_register_builtin_hooks", lambda self: None)- monkeypatch.setattr(AgentLoop, "_register_default_tools", lambda self: None)- monkeypatch.setattr("vikingbot.agent.loop.SubagentManager", _FakeSubagentManager)-- fake_langfuse = _FakeLangfuseClient()- monkeypatch.setattr(- "vikingbot.agent.loop.LangfuseClient.get_instance",- staticmethod(lambda: fake_langfuse),- )-- class FakeContextBuilder:- def __init__(self, *args, **kwargs):- self.latest_relevant_memories = "remembered fact"-- async def build_messages(self, **kwargs):- return [{"role": "user", "content": kwargs["current_message"]}]-- async def fake_run_agent_loop(self, **kwargs):- return (- "final answer",- None,- [],- {"prompt_tokens": 12, "completion_tokens": 8},- 1,- )-- monkeypatch.setattr("vikingbot.agent.context.ContextBuilder", FakeContextBuilder)- monkeypatch.setattr(AgentLoop, "_run_agent_loop", fake_run_agent_loop)-- bus = MessageBus()- config = Config(- storage_workspace=str(temp_dir),- ov_server={"server_url": "http://127.0.0.1:1933"},- )- loop = AgentLoop(- bus=bus,- provider=_FakeProvider(),- workspace=temp_dir / "workspace",- config=config,- )-- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- response = await loop._process_message(- InboundMessage(- session_key=session_key,- sender_id="user-1",- content="please help",- timestamp=datetime.fromisoformat("2026-04-30T00:05:00"),- )- )-- assert response is not None- assert response.tools_used_names == ["auto_memory_search"]-- completed_payload = None- while bus.outbound_size:- event = await bus.consume_outbound()- if event.event_type == OutboundEventType.RESPONSE_COMPLETED:- completed_payload = event.metadata["response_completed"]-- assert completed_payload is not None- assert completed_payload["tool_count"] == 1- assert completed_payload["tools_used_names"] == ["auto_memory_search"]diff --git a/bot/tests/test_openapi_auth.py b/bot/tests/test_openapi_auth.pyindex cc43e225f..a90e4d6f6 100644--- a/bot/tests/test_openapi_auth.py+++ b/bot/tests/test_openapi_auth.py@@ -1116,67 +1116,6 @@ class TestOpenAPIAuth:assert pending.events[0]["type"] == "response"assert pending.events[0]["data"] == {"content": "hello", "response_id": "resp-123"}- def test_feedback_persists_event_and_emits_feedback_submitted(- self, message_bus, temp_workspace- ):- channel = OpenAPIChannel(- OpenAPIChannelConfig(),- message_bus,- workspace_path=temp_workspace,- )- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- session = channel._session_manager.get_or_create(session_key)- session.add_message(- "assistant",- "hello",- sender_id="user-1",- response_id="resp-123",- timestamp="2026-04-30T00:00:00",- )- asyncio.run(channel._session_manager.save(session))-- client = _make_client(channel)- response = client.post(- "/bot/v1/feedback",- json={- "session_id": "session-1",- "response_id": "resp-123",- "feedback_type": "thumb_up",- "feedback_text": "helpful",- },- )-- assert response.status_code == 200- body = response.json()- assert body["accepted"] is True- assert body["response_id"] == "resp-123"- assert body["session_id"] == "session-1"- assert body["feedback_type"] == "thumb_up"- assert message_bus.outbound_size == 2-- first_outbound = asyncio.run(message_bus.consume_outbound())- second_outbound = asyncio.run(message_bus.consume_outbound())- assert first_outbound.event_type == OutboundEventType.RESPONSE_OUTCOME_EVALUATED- assert first_outbound.response_id == "resp-123"- assert (- first_outbound.metadata["response_outcome_evaluated"]["outcome_label"]- == "positive_feedback"- )- assert second_outbound.event_type == OutboundEventType.FEEDBACK_SUBMITTED- assert second_outbound.response_id == "resp-123"- assert second_outbound.metadata["feedback_submitted"]["feedback_type"] == "thumb_up"- assert second_outbound.metadata["feedback_submitted"]["feedback_text"] == "helpful"-- session_path = temp_workspace / "sessions" / "cli__default__session-1.jsonl"- lines = session_path.read_text(encoding="utf-8").splitlines()- metadata = json.loads(lines[0])- assert metadata["metadata"]["feedback_events"][0]["response_id"] == "resp-123"- assert metadata["metadata"]["feedback_events"][0]["feedback_type"] == "thumb_up"- assert (- metadata["metadata"]["response_outcomes"]["resp-123"]["outcome_label"]- == "positive_feedback"- )-def test_feedback_requires_existing_response(self, message_bus, temp_workspace):channel = OpenAPIChannel(OpenAPIChannelConfig(),@@ -1217,66 +1156,6 @@ class TestOpenAPIAuth:assert response.status_code == 422assert "feedback_score is required when feedback_type is rating" in response.text- def test_rating_feedback_persists_score_and_emits_outcome(self, message_bus, temp_workspace):- channel = OpenAPIChannel(- OpenAPIChannelConfig(),- message_bus,- workspace_path=temp_workspace,- )- session_key = SessionKey(type="cli", channel_id="default", chat_id="session-1")- session = channel._session_manager.get_or_create(session_key)- session.add_message(- "assistant",- "hello",- sender_id="user-1",- response_id="resp-123",- timestamp="2026-04-30T00:00:00",- )- asyncio.run(channel._session_manager.save(session))-- client = _make_client(channel)- response = client.post(- "/bot/v1/feedback",- json={- "session_id": "session-1",- "response_id": "resp-123",- "feedback_type": "rating",- "feedback_score": -1,- "feedback_text": "bad answer",- },- )-- assert response.status_code == 200- body = response.json()- assert body["accepted"] is True- assert body["feedback_type"] == "rating"- assert message_bus.outbound_size == 2-- first_outbound = asyncio.run(message_bus.consume_outbound())- second_outbound = asyncio.run(message_bus.consume_outbound())- assert first_outbound.event_type == OutboundEventType.RESPONSE_OUTCOME_EVALUATED- assert (- first_outbound.metadata["response_outcome_evaluated"]["outcome_label"]- == "negative_feedback"- )- assert (- first_outbound.metadata["response_outcome_evaluated"]["evidence"]["feedback_score"]- == -1.0- )- assert second_outbound.event_type == OutboundEventType.FEEDBACK_SUBMITTED- assert second_outbound.metadata["feedback_submitted"]["feedback_type"] == "rating"- assert second_outbound.metadata["feedback_submitted"]["feedback_score"] == -1-- session_path = temp_workspace / "sessions" / "cli__default__session-1.jsonl"- lines = session_path.read_text(encoding="utf-8").splitlines()- metadata = json.loads(lines[0])- assert metadata["metadata"]["feedback_events"][0]["feedback_type"] == "rating"- assert metadata["metadata"]["feedback_events"][0]["feedback_score"] == -1- assert (- metadata["metadata"]["response_outcomes"]["resp-123"]["outcome_label"]- == "negative_feedback"- )-def test_feedback_reloads_session_after_stale_cached_miss(self, message_bus, temp_workspace):channel = OpenAPIChannel(OpenAPIChannelConfig(),diff --git a/bot/tests/test_openviking_api_key_type.py b/bot/tests/test_openviking_api_key_type.pyindex 581923212..947f57dd0 100644--- a/bot/tests/test_openviking_api_key_type.py+++ b/bot/tests/test_openviking_api_key_type.py@@ -881,20 +881,6 @@ def test_validate_openviking_auth_allows_trusted_root(monkeypatch, capsys):assert captured.err == ""-def test_warn_openviking_auth_config_uses_complete_validation(monkeypatch):- config = SimpleNamespace(ov_server=SimpleNamespace(server_url="http://ov.local"))- called = []- monkeypatch.setattr(- config_loader_module,- "validate_openviking_auth",- lambda value: called.append(value),- )-- config_loader_module.warn_openviking_auth_config(config)-- assert called == [config]--def test_memory_user_cli_option_warns_at_runtime(capsys):commands_module._warn_deprecated_memory_user(["legacy-user"])diff --git a/bot/vikingbot/agent/loop.py b/bot/vikingbot/agent/loop.pyindex a94c8c107..19d47e2b1 100644--- a/bot/vikingbot/agent/loop.py+++ b/bot/vikingbot/agent/loop.py@@ -235,45 +235,6 @@ class AgentLoop:self._mcp_stack = Noneself._mcp_connected = False- async def _publish_thinking_event(- self, session_key: SessionKey, event_type: OutboundEventType, content: str- ) -> None:- """- Publish a thinking event to the message bus.-- Thinking events are used to communicate the agent's internal processing- state to the user, such as when the agent is executing a tool or- processing a complex request.-- Args:- session_key: The session key identifying the conversation.- event_type: The type of thinking event (e.g., THINKING, TOOL_START).- content: The message content to display to the user.-- Note:- This is an internal method used by the agent loop to communicate- progress to users during long-running operations.-- Example:- async def notify_tool_call() -> None:- await self._publish_thinking_event(- session_key=SessionKey(- type="telegram",- channel_id="default",- chat_id="123",- ),- event_type=OutboundEventType.TOOL_CALL,- content="Executing web search...",- )- """- await self.bus.publish_outbound(- OutboundMessage(- session_key=session_key,- content=content,- event_type=event_type,- )- )-async def _publish_auto_memory_context(self,session_key: SessionKey,diff --git a/bot/vikingbot/agent/memory.py b/bot/vikingbot/agent/memory.pyindex ad3bcd54a..1e4486dc4 100644--- a/bot/vikingbot/agent/memory.py+++ b/bot/vikingbot/agent/memory.py@@ -97,18 +97,6 @@ class MemoryStore:else getattr(memory, "_recall_type", ""))- @staticmethod- def _get_recall_rank(memory: Any) -> int:- raw_rank = (- memory.get("_recall_rank", 0)- if isinstance(memory, dict)- else getattr(memory, "_recall_rank", 0)- )- try:- return int(raw_rank)- except (TypeError, ValueError):- return 0-@classmethoddef _infer_memory_type(cls, memory: Any) -> str:recall_type = cls._get_recall_type(memory)diff --git a/bot/vikingbot/bus/queue.py b/bot/vikingbot/bus/queue.pyindex 1e4067a6e..7d3f17829 100644--- a/bot/vikingbot/bus/queue.py+++ b/bot/vikingbot/bus/queue.py@@ -1,7 +1,7 @@"""Async message queue for decoupled channel-agent communication."""import asyncio-from typing import Callable, Awaitable, Any+from typing import Awaitable, Callablefrom loguru import logger@@ -79,8 +79,3 @@ class MessageBus:def inbound_size(self) -> int:"""Number of pending inbound messages."""return self.inbound.qsize()-- @property- def outbound_size(self) -> int:- """Number of pending outbound messages."""- return self.outbound.qsize()diff --git a/bot/vikingbot/channels/base.py b/bot/vikingbot/channels/base.pyindex 6ad8cbb7d..0051ae6ad 100644--- a/bot/vikingbot/channels/base.py+++ b/bot/vikingbot/channels/base.py@@ -1,7 +1,6 @@"""Base channel interface for chat platforms."""import base64-import refrom abc import ABC, abstractmethodfrom pathlib import Pathfrom typing import Any, Tuple@@ -243,43 +242,6 @@ class BaseChannel(ABC):return False, path_obj.read_bytes()- def _extract_images(self, content: str) -> tuple[list[str], str]:- """Extract image data URIs, URLs and local paths from content (support Markdown image syntax)."""- images = []- # 新增 Markdown 图片语法匹配 + 原有 Data URI/网络URL 匹配- # 匹配规则:- # 1.  中的路径- # 2. data: 开头的 Data URI- # 3. http/https 开头的网络链接- pattern = r"!\[.*?\]\(([^)]+)\)|(data:[^,]+,[^\s]+|https?://[^\s]+)"- parts = []- last_end = 0- trailing_punctuation = ")].,!?:;'\">}`"-- for m in re.finditer(pattern, content):- before = content[last_end : m.start()]- if before.strip():- parts.append(before)-- # 优先取 Markdown 图片里的路径(第一个分组),再取 Data URI/URL(第二个分组)- uri = m.group(1) if m.group(1) else m.group(2)- if not uri:- last_end = m.end()- continue-- # 清理末尾标点- while uri and uri[-1] in trailing_punctuation:- uri = uri[:-1]-- images.append(uri)- last_end = m.end()-- remaining = content[last_end:]- if remaining.strip():- parts.append(remaining)-- return images, "\n".join(parts)-def _is_image_data(self, data: bytes) -> bool:"""Check if bytes represent a valid image by magic numbers."""# Common image magic numbersdiff --git a/bot/vikingbot/channels/feishu.py b/bot/vikingbot/channels/feishu.pyindex 741381b29..84656f068 100644--- a/bot/vikingbot/channels/feishu.py+++ b/bot/vikingbot/channels/feishu.py@@ -4,7 +4,6 @@ import asyncioimport ioimport jsonimport re-import tempfileimport threadingimport timefrom collections import OrderedDict@@ -37,8 +36,6 @@ from vikingbot.config.schema import BotMode, FeishuChannelConfigtry:import lark_oapi as larkfrom lark_oapi.api.contact.v3 import (- BatchGetIdUserRequest,- BatchGetIdUserRequestBody,GetUserRequest,)from lark_oapi.api.im.v1 import (@@ -64,8 +61,6 @@ except ImportError:GetImageRequest = NoneGetUserRequest = NoneGetChatMembersRequest = None- BatchGetIdUserRequest = None- BatchGetIdUserRequestBody = None# Message type display mappingMSG_TYPE_MAP = {@@ -115,7 +110,6 @@ class FeishuChannel(BaseChannel):self._token_expire_time: float = 0self._chat_mode_cache: dict[str, str] = {} # 缓存群类型:group(普通群)/thread(话题群)self._user_name_cache: OrderedDict[str, str] = OrderedDict() # LRU缓存用户ID到姓名的映射- self._bot_name_cache: dict[str, str] = {} # 缓存机器人open_id到名称的映射self._chat_member_cache: OrderedDict[str, dict[str, Any]] = (OrderedDict()) # chat_id -> {members, expires_at, last_error_at}@@ -266,16 +260,6 @@ class FeishuChannel(BaseChannel):# Read the image bytes from the response filereturn response.file.read()- async def _save_image_to_temp(self, image_bytes: bytes) -> str:- """- Save image bytes to a temporary file and return the path.- """- with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f:- f.write(image_bytes)- temp_path = f.name-- return temp_path-async def _get_chat_mode(self, chat_id: str) -> str:"""获取群类型:group(普通群)/thread(话题群)"""if chat_id in self._chat_mode_cache:@@ -535,69 +519,6 @@ class FeishuChannel(BaseChannel):return elements or [{"tag": "markdown", "content": content}]- async def _process_content_with_images(- self, content: str, receive_id_type: str, chat_id: str- ) -> list[dict]:- """- Process content, extract and upload Markdown images, return card elements.-- Returns: list of card elements (markdown + img elements)- """- # Extract images from Markdown- images = []- markdown_pattern = r"!\[([^\]]*)\]\((send://[^)\s]+\.(png|jpeg|jpg|gif|bmp|webp))\)"- # Find all images and upload them- for m in re.finditer(markdown_pattern, content):- alt_text = m.group(1) or ""- img_url = m.group(2)- try:- is_content, result = await self._parse_data_uri(img_url)-- if not is_content and isinstance(result, bytes):- # It's an image - upload- image_key = await self._upload_image_to_feishu(result)- images.append({"alt": alt_text, "img_key": image_key})- except Exception as e:- logger.exception(f"Failed to upload Markdown image {img_url[:100]}: {e}")- content = re.sub(markdown_pattern, "", content)-- # Pattern: - send_pattern = r"(send://[^)\s]+\.(png|jpeg|jpg|gif|bmp|webp))\)?"- # Find all images and upload them- for m in re.finditer(send_pattern, content):- img_url = m.group(1) or ""- try:- is_content, result = await self._parse_data_uri(img_url)-- if not is_content and isinstance(result, bytes):- # It's an image - upload- image_key = await self._upload_image_to_feishu(result)- images.append({"img_key": image_key})- except Exception as e:- logger.exception(f"Failed to upload Markdown image {img_url[:100]}: {e}")-- # Remove all  from content- content_no_images = re.sub(send_pattern, "", content)-- elements = []- if content_no_images.strip():- elements = self._build_card_elements(content_no_images)-- # Add image elements- for img in images:- elements.append(- {- "tag": "img",- "img_key": img["img_key"],- "alt": {"tag": "plain_text", "content": ""},- }- )-- if not elements:- elements = [{"tag": "markdown", "content": content_no_images}]-- return elements-async def send(self, msg: OutboundMessage) -> None:"""Send a message through Feishu."""# 先调用基类处理通用动作@@ -1022,92 +943,6 @@ class FeishuChannel(BaseChannel):return None- async def _get_bot_name(self, open_id: str) -> str | None:- """- Get bot name by open_id.- First tries to get from cache, then uses config bot_name or "Bot".- Returns bot name if found, None otherwise.- """- # Check cache first- if open_id in self._bot_name_cache:- return self._bot_name_cache[open_id]-- # Use config bot_name if available, otherwise "Bot"- bot_name = self.config.bot_name or "Bot"- self._bot_name_cache[open_id] = bot_name- return bot_name-- async def _batch_get_user_names(- self, open_ids: list[str], chat_id: str | None = None- ) -> dict[str, str]:- """- Get user names from Feishu API by open_ids (fetches individually with LRU cache).- Returns a dict mapping open_id to user name.- """- if not open_ids:- return {}-- result = {}- missing_ids = []- for open_id in open_ids:- cached_name = self._get_cached_user_name(open_id)- if cached_name:- result[open_id] = cached_name- else:- missing_ids.append(open_id)-- if not missing_ids:- return result-- try:- for open_id in missing_ids:- try:- name = await self._get_user_name(open_id, chat_id=chat_id)- if name:- result[open_id] = name- except Exception as e:- logger.warning(f"Failed to get user name for {open_id}: {e}")- except Exception as e:- logger.warning(f"Failed to get user names: {e}")-- return result-- async def _process_group_message_content(- self, content: str, sender_id: str, chat_id: str | None = None- ) -> tuple[str, str]:- """- Process group message content:- 1. Get sender name and prepend to content- 2. Replace @open_id mentions with @name mentions-- Returns:- tuple of (processed_content, sender_name)- """- mentioned_open_ids = OPEN_ID_MENTION_PATTERN.findall(content)- mentioned_open_ids = [mid[1:] for mid in mentioned_open_ids] if mentioned_open_ids else []-- all_ids_to_fetch = list({sender_id} | set(mentioned_open_ids))- user_name_map = await self._batch_get_user_names(all_ids_to_fetch, chat_id=chat_id)-- processed_content = content- if mentioned_open_ids:- for open_id in mentioned_open_ids:- name = user_name_map.get(open_id)- if not name:- # If user name not found, try to get bot name- name = await self._get_bot_name(open_id)- if name:- processed_content = processed_content.replace(f"@{open_id}", f"@{name}")-- sender_name = user_name_map.get(sender_id, "")- if not sender_name:- # If sender name not found, try to get bot name- sender_name = await self._get_bot_name(sender_id) or ""- if sender_name:- processed_content = f"[{sender_name}]: {processed_content}"-- return processed_content, sender_name-async def _on_message(self, data: "P2ImMessageReceiveV1") -> None:"""Handle incoming message from Feishu."""try:diff --git a/bot/vikingbot/channels/manager.py b/bot/vikingbot/channels/manager.pyindex 323d8d7ed..ac83bba2d 100644--- a/bot/vikingbot/channels/manager.py+++ b/bot/vikingbot/channels/manager.py@@ -191,26 +191,6 @@ class ChannelManager:# Wait for all to complete (they should run forever)await asyncio.gather(*tasks, return_exceptions=True)- async def stop_all(self) -> None:- """Stop all channels and the dispatcher."""- logger.info("Stopping all channels...")-- # Stop dispatcher- if self._dispatch_task:- self._dispatch_task.cancel()- try:- await self._dispatch_task- except asyncio.CancelledError:- pass-- # Stop all channels- for name, channel in self.channels.items():- try:- await channel.stop()- logger.info(f"Stopped {name} channel")- except Exception as e:- logger.exception(f"Error stopping {name}: {e}")-async def _dispatch_outbound(self) -> None:"""Dispatch outbound messages to the appropriate channel."""logger.info("Outbound dispatcher started")diff --git a/bot/vikingbot/channels/utils.py b/bot/vikingbot/channels/utils.pyindex d67404979..a9b8fe456 100644--- a/bot/vikingbot/channels/utils.py+++ b/bot/vikingbot/channels/utils.py@@ -1,11 +1,8 @@"""Shared utilities for channel implementations - image path handling, etc."""-import base64import refrom pathlib import Path-from loguru import logger-from typing import Tuple, List-+from typing import List, Tuple# Common image file extensionsIMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".svg", ".tiff"}@@ -103,18 +100,3 @@ def read_image_file(path_str: str) -> bytes:raise IOError(f"Path is not a file: {path_str}")return path.read_bytes()---def image_to_data_uri(image_bytes: bytes, mime_type: str = "image/png") -> str:- """- Convert image bytes to a data URI.-- Args:- image_bytes: Image data- mime_type: MIME type of the image-- Returns:- Data URI string- """- b64 = base64.b64encode(image_bytes).decode("utf-8")- return f"data:{mime_type};base64,{b64}"diff --git a/bot/vikingbot/cli/commands.py b/bot/vikingbot/cli/commands.pyindex 7b41658ea..c82dd52d9 100644--- a/bot/vikingbot/cli/commands.py+++ b/bot/vikingbot/cli/commands.py@@ -19,9 +19,7 @@ from prompt_toolkit.history import FileHistoryfrom prompt_toolkit.patch_stdout import patch_stdoutfrom prompt_toolkit.styles import Style as PromptStylefrom rich.console import Console-from rich.markdown import Markdownfrom rich.table import Table-from rich.text import Textfrom vikingbot import __logo__, __version__from vikingbot.agent.loop import AgentLoop@@ -266,15 +264,6 @@ def _init_prompt_session() -> None:)-def _print_agent_response(response: str, render_markdown: bool) -> None:- """Render assistant response with consistent terminal styling."""- content = response or ""- body = Markdown(content) if render_markdown else Text(content)- console.print()- console.print(f"[cyan]{__logo__} vikingbot[/cyan]")- console.print(body)- console.print()-def _is_exit_command(command: str) -> bool:"""Return True when input should end interactive chat."""@@ -463,9 +452,6 @@ def gateway(agent_loop.run(),server.serve(),]- # if enable_console:- # tasks.append(start_console(console_port))-try:await asyncio.gather(*tasks)finally:@@ -657,25 +643,6 @@ def prepare_heartbeat(config, agent_loop, session_manager) -> HeartbeatService:return heartbeat-async def start_console(console_port):- """Start the console web UI in a separate thread within the same process."""- try:- import threading-- from vikingbot.console.console_gradio_simple import run_console_server-- def run_in_thread():- try:- run_console_server(console_port)- except Exception as e:- console.print(f"[yellow]Console server error: {e}[/yellow]")-- thread = threading.Thread(target=run_in_thread, daemon=True)- thread.start()- console.print(f"[green]✓[/green] Console: http://localhost:{console_port}")- except Exception as e:- console.print(f"[yellow]Warning: Console not available ({e})[/yellow]")-# ============================================================================# Agent Commands@@ -683,14 +650,6 @@ async def start_console(console_port):# Helper for thinking spinner context-def _thinking_ctx(logs: bool):- """Return a context manager for showing thinking spinner."""- if logs:- from contextlib import nullcontext-- return nullcontext()- return console.status("[dim]vikingbot is thinking...[/dim]", spinner="dots")-def prepare_agent_channel(config,diff --git a/bot/vikingbot/config/loader.py b/bot/vikingbot/config/loader.pyindex 0456a8e5b..083828f49 100644--- a/bot/vikingbot/config/loader.py+++ b/bot/vikingbot/config/loader.py@@ -711,16 +711,6 @@ def validate_openviking_auth(config: Config) -> None:return-def warn_openviking_auth_config(config: Config) -> None:- """Backward-compatible wrapper for the complete OpenViking auth validation."""- validate_openviking_auth(config)---def warn_missing_openviking_user_api_key(config: Config) -> None:- """Backward-compatible wrapper for the complete OpenViking auth validation."""- warn_openviking_auth_config(config)--def save_config(config: Config, config_path: Path | None = None, include_defaults: bool = False) -> None:diff --git a/bot/vikingbot/config/schema.py b/bot/vikingbot/config/schema.pyindex f46a04b2c..657319629 100644--- a/bot/vikingbot/config/schema.py+++ b/bot/vikingbot/config/schema.py@@ -190,10 +190,6 @@ class MochatChannelConfig(BaseChannelConfig):reply_delay_mode: str = "non-mention"reply_delay_ms: int = 120000- def _generate_default_id(self) -> str:- # Use agent_user_id as the ID- return self.agent_user_id if self.agent_user_id else "mochat"-class DingTalkChannelConfig(BaseChannelConfig):"""DingTalk channel configuration (multi-channel support)."""diff --git a/bot/vikingbot/openviking_mount/mount.py b/bot/vikingbot/openviking_mount/mount.pyindex 79b353d5a..653050b91 100644--- a/bot/vikingbot/openviking_mount/mount.py+++ b/bot/vikingbot/openviking_mount/mount.py@@ -298,48 +298,6 @@ class OpenVikingMount:logger.error(f"Failed to delete {uri}: {e}")raise- def get_abstract(self, path: Union[str, Path]) -> Optional[str]:- """- 获取文件/目录的L0摘要-- Args:- path: 本地文件路径-- Returns:- 摘要内容- """- self._ensure_client()-- uri = self._path_to_uri(path)- logger.debug(f"Getting abstract for: {uri}")-- try:- return self._client.abstract(uri)- except Exception as e:- logger.warning(f"Failed to get abstract for {uri}: {e}")- return None-- def get_overview(self, path: Union[str, Path]) -> Optional[str]:- """- 获取文件/目录的L1概览-- Args:- path: 本地文件路径-- Returns:- 概览内容- """- self._ensure_client()-- uri = self._path_to_uri(path)- logger.debug(f"Getting overview for: {uri}")-- try:- return self._client.overview(uri)- except Exception as e:- logger.warning(f"Failed to get overview for {uri}: {e}")- return None-def search(self, query: str, target_path: Optional[Union[str, Path]] = None) -> List[FileInfo]:"""语义搜索diff --git a/crates/ragfs/src/core/multibackend_wrapper.rs b/crates/ragfs/src/core/multibackend_wrapper.rsindex 4dbb600c0..0d204dba1 100644--- a/crates/ragfs/src/core/multibackend_wrapper.rs+++ b/crates/ragfs/src/core/multibackend_wrapper.rs@@ -495,11 +495,6 @@ impl MultiWriteWrappedFSBuilder {self}- /// Accept the legacy read-route cache TTL option as a no-op.- pub fn read_route_cache_ttl(self, _read_route_cache_ttl: Duration) -> Self {- self- }-/// Configure the context resolver used by retry and admin background paths.pub fn ctx_resolver(mut self, ctx_resolver: Arc<dyn FsContextResolver>) -> Self {self.ctx_resolver = ctx_resolver;diff --git a/docs/design/parser-two-layer-refactor-plan.md b/docs/design/parser-two-layer-refactor-plan.mdindex 07d5fab1f..0c9433156 100644--- a/docs/design/parser-two-layer-refactor-plan.md+++ b/docs/design/parser-two-layer-refactor-plan.md@@ -232,6 +232,9 @@ async with await registry.access("https://github.com/user/repo") as resource:### 自定义 Accessor```python+import tempfile+from pathlib import Path+from openviking.parse.accessors import DataAccessor, LocalResourceclass MyAccessor(DataAccessor):@@ -244,7 +247,7 @@ class MyAccessor(DataAccessor):async def access(self, source: str, **kwargs) -> LocalResource:# 获取数据到本地...- temp_path = self._create_temp_dir()+ temp_path = Path(tempfile.mkdtemp(prefix="openviking_"))# ... 下载逻辑 ...return LocalResource(path=temp_path,diff --git a/openviking/core/context.py b/openviking/core/context.pyindex 9ffb16b78..7fce512e7 100644--- a/openviking/core/context.py+++ b/openviking/core/context.py@@ -159,11 +159,6 @@ class Context:"""Get image references (data URIs or URLs) for multimodal vectorization."""return self.vectorize.images- def update_activity(self):- """Update activity statistics."""- self.active_count += 1- self.updated_at = datetime.now(timezone.utc)-def to_dict(self) -> Dict[str, Any]:"""Convert context to dictionary format for storage."""created_at_str = format_iso8601(self.created_at) if self.created_at else Nonediff --git a/openviking/core/directories.py b/openviking/core/directories.pyindex 5ab1c3999..faa132ba2 100644--- a/openviking/core/directories.py+++ b/openviking/core/directories.py@@ -224,22 +224,6 @@ class DirectoryInitializer:return count- async def initialize_agent_directories(self, ctx: RequestContext) -> int:- """Deprecated compatibility hook; agent directories are no longer initialized."""- return 0-- async def _ensure_container_directory(- self,- uri: str,- parent_uri: Optional[str],- ctx: RequestContext,- ) -> None:- """Ensure an intermediate namespace container exists without seeding vectors."""- try:- await self._get_viking_fs().mkdir(uri, exist_ok=True, ctx=ctx)- except Exception:- pass-async def _ensure_directory(self,uri: str,diff --git a/openviking/core/namespace.py b/openviking/core/namespace.pyindex fa62f3119..4c99372a9 100644--- a/openviking/core/namespace.py+++ b/openviking/core/namespace.py@@ -173,15 +173,6 @@ def canonical_session_uri(ctx: RequestContext, session_id: Optional[str] = None)return f"{root}/{session_id}"-def canonical_user_content_root(ctx: RequestContext, kind: str) -> str:- segment = _CONTENT_SEGMENT_BY_KIND[kind]- return f"{canonical_user_root(ctx)}/{segment}"---def legacy_session_uri(session_id: Optional[str] = None) -> str:- if not session_id:- return "viking://session"- return f"viking://session/{session_id}"def is_session_uri(uri: str) -> bool:@@ -312,19 +303,6 @@ def is_content_root_uri()-def is_content_namespace_root_uri(uri: str, ctx: RequestContext) -> bool:- try:- canonical_uri = canonicalize_uri(uri, ctx)- except (ValueError, NamespaceShapeError):- return False- parts = uri_parts(canonical_uri)- if parts == ["resources"]:- return True- classification = classify_uri(canonical_uri)- return (- classification.content_index is not None and len(parts) == classification.content_index + 1- )-def _validate_peer_id_segments(parts: list[str]) -> None:if len(parts) >= 3 and parts[0] == "user" and parts[1] == "peers":diff --git a/openviking/core/retrieval_targets.py b/openviking/core/retrieval_targets.pyindex 5b699b45d..410bc5a88 100644--- a/openviking/core/retrieval_targets.py+++ b/openviking/core/retrieval_targets.py@@ -162,11 +162,6 @@ def _is_agent_scope_uri(target_uri: str) -> bool:return parts and parts[0] == "agent" and len(parts) >= 2 and parts[1] in {"skills", "endpoints", "tools", "payments"}-def _with_suffix(root: str, suffix: List[str]) -> str:- if not suffix:- return root- return f"{root}/{'/'.join(suffix)}"-def _resolve_peer_target(target_uri: str,diff --git a/openviking/eval/recorder/playback.py b/openviking/eval/recorder/playback.pydeleted file mode 100644index 00a849bb9..000000000--- a/openviking/eval/recorder/playback.py+++ /dev/null@@ -1,27 +0,0 @@-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.-# SPDX-License-Identifier: AGPL-3.0-"""-Deprecated: Playback module for IORecorder.--This module has been moved to openviking.eval.playback.-This file provides backward compatibility.-"""--import warnings---def get_record_stats(record_file: str) -> dict:- """- Deprecated: Get statistics from a record file without playback.-- Use openviking.eval.record_analysis.analyze_records instead.- """- warnings.warn(- "get_record_stats is deprecated. Use openviking.eval.record_analysis.analyze_records instead.",- DeprecationWarning,- stacklevel=2,- )- from openviking.eval.record_analysis import analyze_records-- stats = analyze_records(record_file)- return stats.to_dict()diff --git a/openviking/message/message.py b/openviking/message/message.pyindex 80d968b9e..7d119e1ad 100644--- a/openviking/message/message.py+++ b/openviking/message/message.py@@ -182,17 +182,6 @@ class Message:created_at=data.get("created_at"),)- def get_tool_parts(self) -> List[ToolPart]:- """Get all ToolParts."""- return [p for p in self.parts if isinstance(p, ToolPart)]-- def find_tool_part(self, tool_id: str) -> Optional[ToolPart]:- """Find ToolPart by tool_id."""- for p in self.parts:- if isinstance(p, ToolPart) and p.tool_id == tool_id:- return p- return None-def to_jsonl(self) -> str:"""Serialize to JSONL string."""return json.dumps(self.to_dict(), ensure_ascii=False)diff --git a/openviking/metrics/core/registry.py b/openviking/metrics/core/registry.pyindex 0c96a9ec5..2bd969d64 100644--- a/openviking/metrics/core/registry.py+++ b/openviking/metrics/core/registry.py@@ -636,11 +636,6 @@ class _Gauge:"""Increase one series in the bound gauge family by a positive delta."""self._family.add(labels=labels, delta=amount)- def dec(self, amount: float = 1.0, *, labels: Mapping[str, str] | None = None) -> None:- """Decrease one series in the bound gauge family by a positive amount."""- self._family.add(labels=labels, delta=-amount)--class _Histogram:"""Public lightweight handle used by callers to mutate one histogram family."""diff --git a/openviking/models/embedder/base.py b/openviking/models/embedder/base.pyindex 8138c1548..9f2e79496 100644--- a/openviking/models/embedder/base.py+++ b/openviking/models/embedder/base.py@@ -803,11 +803,6 @@ class FailoverEmbedder(EmbedderBase):)return first.get_dimension()- @property- def active_credential_index(self) -> int:- """Get the index of the currently active credential."""- return self._switcher.get_active_index()-@propertydef active_credential_id(self) -> str:"""Get the ID of the currently active credential."""diff --git a/openviking/models/vlm/backends/codex_auth.py b/openviking/models/vlm/backends/codex_auth.pyindex 49e4c3b6a..fdeb37e63 100644--- a/openviking/models/vlm/backends/codex_auth.py+++ b/openviking/models/vlm/backends/codex_auth.py@@ -552,30 +552,6 @@ def has_codex_auth_available() -> bool:)-def _sync_external_codex_auth(- external_path: Path,- ov_auth_path: Path,- *,- fallback_payload: Optional[Dict[str, Any]] = None,-) -> Dict[str, Any]:- external_payload = _load_tokens_from_source("codex-cli", external_path)- if external_payload is not None:- _write_tokens_to_ov_store(- ov_auth_path,- external_payload["access_token"],- external_payload["refresh_token"],- last_refresh=external_payload.get("last_refresh"),- imported_from=str(external_path),- client_id=external_payload.get("client_id"),- auth_owner=CODEX_AUTH_OWNER_EXTERNAL,- )- return external_payload- if fallback_payload is not None:- return fallback_payload- raise CodexAuthError(- f"Externally managed Codex auth is unavailable at {external_path}. Re-run Codex CLI login or openviking-server init."- )-def resolve_codex_runtime_credentials(*,diff --git a/openviking/models/vlm/base.py b/openviking/models/vlm/base.pyindex 04762de16..d17ce0b2a 100644--- a/openviking/models/vlm/base.py+++ b/openviking/models/vlm/base.py@@ -331,14 +331,6 @@ class VLMFactory:return LiteLLMVLMProvider(config)- @staticmethod- def get_available_providers() -> List[str]:- """Get list of available providers"""- from .registry import get_all_provider_names-- return get_all_provider_names()--def _annotate_vlm_error(exc: Exception, vlm_instance: "VLMBase") -> None:"""Attach model and api_base info to an exception for better error diagnostics.@@ -825,11 +817,6 @@ class MultiCredentialVLM(VLMBase):messages=messages,)- @property- def active_credential_index(self) -> int:- """Get the index of the currently active credential."""- return self._switcher.get_active_index()-@propertydef active_credential_id(self) -> str:"""Get the ID of the currently active credential."""diff --git a/openviking/observability/context.py b/openviking/observability/context.pyindex 553fa4027..ae0b22c4f 100644--- a/openviking/observability/context.py+++ b/openviking/observability/context.py@@ -193,21 +193,6 @@ class ObservabilityContext:self.execution_span_id = span_id or self.execution_trace_id[:16]return self- def set_extra(self, key: str, value: Any) -> "ObservabilityContext":- """- Set an extra attribute.-- Args:- key: The attribute key.- value: The attribute value.-- Returns:- Self for method chaining.- """- self.extra[key] = value- return self--# Global context variable_OBSERVABILITY_CONTEXT: contextvars.ContextVar[Optional[ObservabilityContext]] = (contextvars.ContextVar(diff --git a/openviking/observability/events.py b/openviking/observability/events.pyindex 690d93eb1..3db4604df 100644--- a/openviking/observability/events.py+++ b/openviking/observability/events.py@@ -99,11 +99,6 @@ def unregister_event_subscriber(name: str) -> None:_GLOBAL_EVENT_BUS.unregister(name)-def reset_event_bus_for_tests() -> None:- """Clear all subscribers from the process-global bus."""- _GLOBAL_EVENT_BUS.clear()--def _metadata_from_context(payload: dict[str, Any]) -> dict[str, str | None]:"""Build event metadata from payload first, then current root context."""root = get_observability_context().rootdiff --git a/openviking/parse/accessors/base.py b/openviking/parse/accessors/base.pyindex e9a424558..dbf30f640 100644--- a/openviking/parse/accessors/base.py+++ b/openviking/parse/accessors/base.py@@ -7,7 +7,6 @@ Data Accessors are responsible for fetching data from remote sourcesor special paths and making them available as local files/directories."""-import osimport shutilfrom abc import ABC, abstractmethodfrom dataclasses import dataclass, field@@ -163,35 +162,3 @@ class DataAccessor(ABC):resource: The LocalResource to clean up"""resource.cleanup()-- def _create_temp_dir(self, prefix: str = "ov_accessor_") -> Path:- """- Create a temporary directory for this accessor.-- Args:- prefix: Prefix for the temporary directory name-- Returns:- Path to the created temporary directory- """- import tempfile-- temp_dir = tempfile.mkdtemp(prefix=prefix)- return Path(temp_dir)-- def _create_temp_file(self, suffix: str = "", prefix: str = "ov_accessor_") -> Path:- """- Create a temporary file for this accessor.-- Args:- suffix: Suffix for the temporary file name- prefix: Prefix for the temporary file name-- Returns:- Path to the created temporary file- """- import tempfile-- fd, temp_path = tempfile.mkstemp(suffix=suffix, prefix=prefix)- os.close(fd)- return Path(temp_path)diff --git a/openviking/parse/accessors/registry.py b/openviking/parse/accessors/registry.pyindex f37d79e73..7d3ec2003 100644--- a/openviking/parse/accessors/registry.py+++ b/openviking/parse/accessors/registry.py@@ -153,20 +153,6 @@ class AccessorRegistry:return accessorreturn None- def list_accessors(self, source: Optional[Union[str, Path]] = None) -> List[DataAccessor]:- """- List registered accessors.-- Args:- source: Optional source to filter by (only returns accessors that can handle it)-- Returns:- List of DataAccessor instances- """- if source is None:- return list(self._accessors)- return [a for a in self._accessors if a.can_handle(source)]-async def access(self, source: Union[str, Path], **kwargs) -> LocalResource:"""Access a source by routing to the appropriate accessor.diff --git a/openviking/parse/base.py b/openviking/parse/base.pyindex 2d63c66b4..54f065686 100644--- a/openviking/parse/base.py+++ b/openviking/parse/base.py@@ -254,69 +254,6 @@ class ResourceNode:texts.append(child.get_text(include_children=True))return "\n".join(texts)- def get_abstract(self, max_length: int = 256) -> str:- """- Generate L0 abstract for this node.-- Args:- max_length: Maximum character length-- Returns:- Abstract text- """- if "abstract" in self.meta:- return self.meta["abstract"]- if self.title:- abstract = self.title- else:- content = self.get_content()- abstract = content[:max_length] if content else ""-- if len(abstract) > max_length:- abstract = abstract[: max_length - 3] + "..."-- return abstract-- def get_overview(self, max_length: int = 4000) -> str:- """- Generate L1 overview for this node.-- Args:- max_length: Maximum character length-- Returns:- Overview text including structure summary- """- if "overview" in self.meta:- return self.meta["overview"]- # Default overview generation- parts = []- if self.title:- parts.append(f"**{self.title}**")-- # Add content preview- content = self.get_content()- if content:- content_preview = content[:1000]- if len(content) > 1000:- content_preview += "..."- parts.append(content_preview)-- # Add children summary- if self.children:- parts.append(f"\n[Contains {len(self.children)} sub-sections]")- for child in self.children[:5]: # First 5 children- child_abstract = child.get_abstract(max_length=100)- parts.append(f" - {child_abstract}")- if len(self.children) > 5:- parts.append(f" ... and {len(self.children) - 5} more")-- overview = "\n".join(parts)- if len(overview) > max_length:- overview = overview[: max_length - 3] + "..."-- return overview-def to_dict(self) -> Dict[str, Any]:"""Convert node to dictionary."""return {diff --git a/openviking/parse/parsers/media/audio.py b/openviking/parse/parsers/media/audio.pyindex 29b760383..de0b75a82 100644--- a/openviking/parse/parsers/media/audio.py+++ b/openviking/parse/parsers/media/audio.py@@ -24,15 +24,12 @@ Example workflow:Supported formats: MP3, WAV, OGG, FLAC, AAC, M4A, OPUS, AC3"""-import asyncioimport base64import osimport tempfilefrom pathlib import Pathfrom typing import List, Optional, Union-import openai-from openviking.parse.base import NodeType, ParseResult, ResourceNodefrom openviking.parse.parsers.base_parser import BaseParserfrom openviking.parse.parsers.media.constants import AUDIO_EXTENSIONS@@ -170,223 +167,6 @@ class AudioParser(BaseParser):meta={"content_type": "audio", "format": format_str.lower()},)- async def _asr_transcribe(self, audio_bytes: bytes, model: Optional[str]) -> str:- """- Generate audio transcription using ASR.-- Args:- audio_bytes: Audio binary data- model: ASR model name-- Returns:- Audio transcription in markdown format-- TODO: Integrate with actual ASR API (Whisper, etc.)- """- model_name = model or self.config.transcription_model- api_key = os.getenv("OPENAI_API_KEY")- if not api_key:- logger.error("OPENAI_API_KEY not found, skip audio transcription")- return "Audio transcription unavailable: OPENAI_API_KEY is not set."-- temp_file_path = None-- def _sync_transcribe() -> str:- nonlocal temp_file_path- client_kwargs = {"api_key": api_key}- base_url = os.getenv("OPENAI_BASE_URL")- if base_url:- client_kwargs["base_url"] = base_url-- client = openai.OpenAI(**client_kwargs)- with tempfile.NamedTemporaryFile(mode="wb", suffix=".wav", delete=False) as temp_file:- temp_file.write(audio_bytes)- temp_file_path = temp_file.name-- with open(temp_file_path, "rb") as f:- response = client.audio.transcriptions.create(- model=model_name,- file=f,- language=self.config.language,- )-- if isinstance(response, dict):- return str(response.get("text", "")).strip()- return str(getattr(response, "text", "")).strip()-- try:- text = await asyncio.get_event_loop().run_in_executor(None, _sync_transcribe)- return text or "Audio transcription returned empty result."- except Exception as e:- logger.exception("Audio transcription failed: %s", e)- return f"Audio transcription failed: {str(e)}"- finally:- if temp_file_path and os.path.exists(temp_file_path):- try:- os.remove(temp_file_path)- except Exception as cleanup_error:- logger.warning(- "Failed to cleanup temporary audio file %s: %s",- temp_file_path,- cleanup_error,- )-- async def _asr_transcribe_with_timestamps(- self, audio_bytes: bytes, model: Optional[str]- ) -> Optional[str]:- """- Extract transcription with timestamps from audio using ASR.-- Args:- audio_bytes: Audio binary data- model: ASR model name-- Returns:- Transcript with timestamps in markdown format, or None if not available-- TODO: Integrate with ASR API- """- model_name = model or self.config.transcription_model- api_key = os.getenv("OPENAI_API_KEY")- if not api_key:- logger.error("OPENAI_API_KEY not found, skip timestamp transcription")- return None-- temp_file_path = None-- def _format_timestamp(seconds: float) -> str:- total_seconds = max(0, int(float(seconds)))- minutes, secs = divmod(total_seconds, 60)- return f"{minutes:02d}:{secs:02d}"-- def _sync_transcribe_with_timestamps() -> Optional[str]:- nonlocal temp_file_path- client_kwargs = {"api_key": api_key}- base_url = os.getenv("OPENAI_BASE_URL")- if base_url:- client_kwargs["base_url"] = base_url-- client = openai.OpenAI(**client_kwargs)- with tempfile.NamedTemporaryFile(mode="wb", suffix=".wav", delete=False) as temp_file:- temp_file.write(audio_bytes)- temp_file_path = temp_file.name-- with open(temp_file_path, "rb") as f:- response = client.audio.transcriptions.create(- model=model_name,- file=f,- language=self.config.language,- response_format="verbose_json",- timestamp_granularities=["segment"],- )-- segments = None- if isinstance(response, dict):- segments = response.get("segments")- else:- segments = getattr(response, "segments", None)-- if not segments:- return None-- lines = []- for segment in segments:- if isinstance(segment, dict):- start = segment.get("start")- end = segment.get("end")- text = str(segment.get("text", "")).strip()- else:- start = getattr(segment, "start", None)- end = getattr(segment, "end", None)- text = str(getattr(segment, "text", "")).strip()-- if start is None or end is None or not text:- continue-- lines.append(f"**[{_format_timestamp(start)} - {_format_timestamp(end)}]** {text}")-- return "\n\n".join(lines) if lines else None-- try:- return await asyncio.get_event_loop().run_in_executor(- None, _sync_transcribe_with_timestamps- )- except Exception as e:- logger.exception("Timestamp transcription failed: %s", e)- return None- finally:- if temp_file_path and os.path.exists(temp_file_path):- try:- os.remove(temp_file_path)- except Exception as cleanup_error:- logger.warning(- "Failed to cleanup temporary audio file %s: %s",- temp_file_path,- cleanup_error,- )-- async def _generate_semantic_info(- self, node: ResourceNode, description: str, viking_fs, has_transcript: bool- ):- """- Phase 2: Generate abstract and overview.-- Args:- node: ResourceNode to update- description: Audio description- viking_fs: VikingFS instance- has_transcript: Whether transcript file exists- """- # Generate abstract (short summary, < 100 tokens)- abstract = description[:200] if len(description) > 200 else description-- # Generate overview (content summary + file list + usage instructions)- overview_parts = [- "## Content Summary\n",- description,- "\n\n## Available Files\n",- f"- {node.meta['original_filename']}: Original audio file ({node.meta['duration']}s, {node.meta['sample_rate']}Hz, {node.meta['channels']}ch, {node.meta['format'].upper()} format)\n",- ]-- if has_transcript:- overview_parts.append("- transcript.md: Transcript with timestamps from the audio\n")-- overview_parts.append("\n## Usage\n")- overview_parts.append("### Play Audio\n")- overview_parts.append("```python\n")- overview_parts.append("audio_bytes = await audio_resource.play()\n")- overview_parts.append("# Returns: Audio file binary data\n")- overview_parts.append("# Purpose: Play or save the audio\n")- overview_parts.append("```\n\n")-- if has_transcript:- overview_parts.append("### Get Timestamps Transcript\n")- overview_parts.append("```python\n")- overview_parts.append("timestamps = await audio_resource.timestamps()\n")- overview_parts.append("# Returns: FileContent object or None\n")- overview_parts.append("# Purpose: Extract timestamped transcript from the audio\n")- overview_parts.append("```\n\n")-- overview_parts.append("### Get Audio Metadata\n")- overview_parts.append("```python\n")- overview_parts.append(- f"duration = audio_resource.get_duration() # {node.meta['duration']}s\n"- )- overview_parts.append(- f"sample_rate = audio_resource.get_sample_rate() # {node.meta['sample_rate']}Hz\n"- )- overview_parts.append(- f"channels = audio_resource.get_channels() # {node.meta['channels']}\n"- )- overview_parts.append(f'format = audio_resource.get_format() # "{node.meta["format"]}"\n')- overview_parts.append("```\n")-- overview = "".join(overview_parts)-- # Store in node meta- node.meta["abstract"] = abstract- node.meta["overview"] = overview-async def parse_content(self, content: str, source_path: Optional[str] = None, instruction: str = "", **kwargs) -> ParseResult:diff --git a/openviking/parse/parsers/media/image.py b/openviking/parse/parsers/media/image.pyindex e6338d87f..668d848ee 100644--- a/openviking/parse/parsers/media/image.py+++ b/openviking/parse/parsers/media/image.py@@ -10,8 +10,6 @@ They serve as a design reference for future media parsing capabilities.For current document parsing (PDF, Markdown, HTML, Text), see other parser modules."""-import asyncio-import iofrom pathlib import Pathfrom typing import List, Optional, Union@@ -21,9 +19,7 @@ from openviking.parse.base import NodeType, ParseResult, ResourceNodefrom openviking.parse.parsers.base_parser import BaseParserfrom openviking.parse.parsers.media.constants import IMAGE_EXTENSIONSfrom openviking.parse.parsers.media.naming import resolve_media_names-from openviking.prompts import render_promptfrom openviking.storage.viking_fs import get_viking_fs-from openviking_cli.utils.config import get_openviking_configfrom openviking_cli.utils.config.parser_config import ImageConfigfrom openviking_cli.utils.logger import get_loggerfrom openviking_cli.utils.uri import VikingURI@@ -155,129 +151,6 @@ class ImageParser(BaseParser):meta={"content_type": "image", "format": format_str.lower()},)- async def _vlm_describe(self, image_bytes: bytes, model: Optional[str]) -> str:- """- Generate image description using VLM.-- Args:- image_bytes: Image binary data- model: VLM model name-- Returns:- Image description in markdown format- """- try:- vlm = get_openviking_config().vlm-- # Render prompt- prompt = render_prompt(- "parsing.image_summary",- {- "context": "No additional context",- },- )- response = await vlm.get_vision_completion_async(- prompt=prompt,- images=[image_bytes],- )- logger.info(- f"[ImageParser._vlm_describe] VLM response received, length: {len(response)}, content: {response[:256]}"- )-- return response.strip()-- except Exception as e:- logger.error(- f"[ImageParser._vlm_describe] Error in VLM image description: {e}", exc_info=True- )- # Fallback to basic description- return "Image description (VLM integration failed)\n\nThis is an image file."-- async def _ocr_extract(self, image_bytes: bytes, lang: str) -> Optional[str]:- """- Extract text from image using OCR via Tesseract.-- Args:- image_bytes: Image binary data- lang: OCR language code (e.g., "eng", "chi_sim")-- Returns:- Extracted text as a string, or None if no text found- """- try:- import pytesseract- except ImportError:- logger.warning("pytesseract not installed. Install with: pip install openviking[ocr]")- return None-- def _sync_ocr() -> Optional[str]:- img = Image.open(io.BytesIO(image_bytes))- text = pytesseract.image_to_string(img, lang=lang).strip()- return text if text else None-- try:- return await asyncio.get_event_loop().run_in_executor(None, _sync_ocr)- except Exception as e:- logger.error(f"[ImageParser._ocr_extract] OCR extraction failed: {e}", exc_info=True)- return None-- async def _generate_semantic_info(- self, node: ResourceNode, description: str, viking_fs, has_ocr: bool, root_dir_uri: str- ):- """- Phase 2: Generate abstract and overview and write to .abstract.md and .overview.md.-- Args:- node: ResourceNode to update- description: Image description- viking_fs: VikingFS instance- has_ocr: Whether OCR file exists- root_dir_uri: Root directory URI to write semantic files- """- # Generate abstract (short summary, < 100 tokens)- abstract = description[:253] + "..." if len(description) > 256 else description-- # Generate overview (content summary + file list + usage instructions)- overview_parts = [- "## Content Summary\n",- description,- "\n\n## Available Files\n",- f"- {node.meta['original_filename']}: Original image file ({node.meta['width']}x{node.meta['height']}, {node.meta['format'].upper()} format)\n",- ]-- if has_ocr:- overview_parts.append("- ocr.md: OCR text recognition result from the image\n")-- overview_parts.append("\n## Usage\n")- overview_parts.append("### View Image\n")- overview_parts.append("```python\n")- overview_parts.append("image_bytes = await image_resource.view()\n")- overview_parts.append("# Returns: PNG/JPG format image binary data\n")- overview_parts.append("# Purpose: Display or save the image\n")- overview_parts.append("```\n\n")-- if has_ocr:- overview_parts.append("### Get OCR-recognized Text\n")- overview_parts.append("```python\n")- overview_parts.append("ocr_text = await image_resource.ocr()\n")- overview_parts.append("# Returns: FileContent object or None\n")- overview_parts.append("# Purpose: Extract text information from the image\n")- overview_parts.append("```\n\n")-- overview_parts.append("### Get Image Metadata\n")- overview_parts.append("```python\n")- overview_parts.append(- f"size = image_resource.get_size() # ({node.meta['width']}, {node.meta['height']})\n"- )- overview_parts.append(f'format = image_resource.get_format() # "{node.meta["format"]}"\n')- overview_parts.append("```\n")-- overview = "".join(overview_parts)-- # Store in node meta- node.meta["abstract"] = abstract- node.meta["overview"] = overview-# Write to files in temp directory# await viking_fs.write_file(f"{root_dir_uri}/.abstract.md", abstract)# await viking_fs.write_file(f"{root_dir_uri}/.overview.md", overview)diff --git a/openviking/parse/parsers/media/video.py b/openviking/parse/parsers/media/video.pyindex 3d9d8b429..26105155e 100644--- a/openviking/parse/parsers/media/video.py+++ b/openviking/parse/parsers/media/video.py@@ -162,82 +162,6 @@ class VideoParser(BaseParser):meta={"content_type": "video", "format": format_str.lower()},)- async def _generate_video_description(self, file_path: Path, config: VideoConfig) -> str:- """- Generate video description using key frames and audio transcription.-- Args:- file_path: Video file path- config: Video parsing configuration-- Returns:- Video description in markdown format-- TODO: Integrate with actual video processing libraries- """- # Fallback implementation - returns basic placeholder- return "Video description (video processing integration pending)\n\nThis is a video. Video processing feature has not yet integrated external libraries."-- async def _generate_semantic_info(- self, node: ResourceNode, description: str, viking_fs, has_key_frames: bool- ):- """- Phase 2: Generate abstract and overview.-- Args:- node: ResourceNode to update- description: Video description- viking_fs: VikingFS instance- has_key_frames: Whether key frames directory exists- """- # Generate abstract (short summary, < 100 tokens)- abstract = description[:200] if len(description) > 200 else description-- # Generate overview (content summary + file list + usage instructions)- overview_parts = [- "## Content Summary\n",- description,- "\n\n## Available Files\n",- f"- {node.meta['original_filename']}: Original video file ({node.meta['duration']}s, {node.meta['width']}x{node.meta['height']}, {node.meta['fps']}fps, {node.meta['format'].upper()} format)\n",- ]-- if has_key_frames:- overview_parts.append("- keyframes/: Directory containing extracted key frames\n")-- overview_parts.append("\n## Usage\n")- overview_parts.append("### Play Video\n")- overview_parts.append("```python\n")- overview_parts.append("video_bytes = await video_resource.play()\n")- overview_parts.append("# Returns: Video file binary data\n")- overview_parts.append("# Purpose: Play or save the video\n")- overview_parts.append("```\n\n")-- if has_key_frames:- overview_parts.append("### Get Key Frames\n")- overview_parts.append("```python\n")- overview_parts.append("keyframes = await video_resource.keyframes()\n")- overview_parts.append("# Returns: List of key frame resources\n")- overview_parts.append("# Purpose: Analyze video scenes\n")- overview_parts.append("```\n\n")-- overview_parts.append("### Get Video Metadata\n")- overview_parts.append("```python\n")- overview_parts.append(- f"duration = video_resource.get_duration() # {node.meta['duration']}s\n"- )- overview_parts.append(- f"resolution = video_resource.get_resolution() # ({node.meta['width']}, {node.meta['height']})\n"- )- overview_parts.append(f"fps = video_resource.get_fps() # {node.meta['fps']}\n")- overview_parts.append(f'format = video_resource.get_format() # "{node.meta["format"]}"\n')- overview_parts.append("```\n")-- overview = "".join(overview_parts)-- # Store in node meta- node.meta["abstract"] = abstract- node.meta["overview"] = overview-async def parse_content(self, content: str, source_path: Optional[str] = None, instruction: str = "", **kwargs) -> ParseResult:diff --git a/openviking/parse/parsers/upload_utils.py b/openviking/parse/parsers/upload_utils.pyindex e33de87c9..fdf43ad87 100644--- a/openviking/parse/parsers/upload_utils.py+++ b/openviking/parse/parsers/upload_utils.py@@ -12,11 +12,10 @@ from openviking.parse.parsers.constants import (ADDITIONAL_TEXT_EXTENSIONS,CODE_EXTENSIONS,DOCUMENTATION_EXTENSIONS,- IGNORE_DIRS,IGNORE_EXTENSIONS,)from openviking.parse.parsers.text_encoding import normalize_text_bytes-from openviking.utils.path_safety import safe_join_viking_uri, sanitize_relative_viking_path+from openviking.utils.path_safety import safe_join_viking_urifrom openviking_cli.utils.logger import get_loggerlogger = get_logger(__name__)@@ -97,44 +96,6 @@ def should_skip_file(return False, ""-def should_skip_directory(- dir_name: str,- ignore_dirs: Optional[Set[str]] = None,-) -> bool:- """Return True when a directory should be skipped during traversal."""- effective_ignore_dirs = ignore_dirs if ignore_dirs is not None else IGNORE_DIRS- return dir_name in effective_ignore_dirs or dir_name.startswith(".")---def _sanitize_rel_path(rel_path: str) -> str:- """Compatibility wrapper for existing upload utility callers/tests."""- return sanitize_relative_viking_path(rel_path)---async def upload_text_files(- file_paths: List[Tuple[Path, str]],- viking_uri_base: str,- viking_fs: Any,-) -> Tuple[int, List[str]]:- """Upload text files to VikingFS and return uploaded count with warnings."""- uploaded_count = 0- warnings: List[str] = []-- for file_path, rel_path in file_paths:- try:- target_uri = safe_join_viking_uri(viking_uri_base, rel_path)- content = file_path.read_bytes()- content = detect_and_convert_encoding(content, file_path)- await viking_fs.write_file_bytes(target_uri, content)- uploaded_count += 1- except Exception as exc:- warning = f"Failed to upload {file_path}: {exc}"- warnings.append(warning)- logger.warning(warning)-- return uploaded_count, warnings--_UPLOAD_CONCURRENCY = 8diff --git a/openviking/parse/registry.py b/openviking/parse/registry.pyindex 3dc1b9298..a907936a2 100644--- a/openviking/parse/registry.py+++ b/openviking/parse/registry.py@@ -184,10 +184,6 @@ class ParserRegistry:del self._extension_map[ext.lower()]del self._parsers[name]- def get_parser(self, name: str) -> Optional[BaseParser]:- """Get parser by name."""- return self._parsers.get(name)-def get_parser_for_file(self, path: Union[str, Path]) -> Optional[BaseParser]:"""Get appropriate parser for a file.diff --git a/openviking/pyagfs/async_client.py b/openviking/pyagfs/async_client.pyindex 931479951..3e1fd7457 100644--- a/openviking/pyagfs/async_client.py+++ b/openviking/pyagfs/async_client.py@@ -66,10 +66,6 @@ class AsyncAGFSClient:def __init__(self, client: AGFSSyncClientProtocol):self._client = client- @property- def sync_client(self) -> AGFSSyncClientProtocol:- return self._client-async def run(self, method_name: str, /, *args: Any, **kwargs: Any) -> Any:"""Run a sync client method in a worker thread, preserving ctx when supported."""try:diff --git a/openviking/resource/watch_manager.py b/openviking/resource/watch_manager.pyindex 1a0e88063..34c964789 100644--- a/openviking/resource/watch_manager.py+++ b/openviking/resource/watch_manager.py@@ -598,52 +598,6 @@ class WatchManager:)return plan- async def plan_move_tasks_under_uri_internal(- self,- old_uri: str,- new_uri: str,- ) -> Dict[str, str]:- """Return the watch-task URI rewrite plan for a resource move.-- This is an internal lifecycle hook used before moving resources so URI- conflicts can fail the move before any resource state is changed.- """- async with self._lock:- return self._plan_move_tasks_under_uri_unlocked(old_uri, new_uri)-- async def move_tasks_under_uri_internal(- self,- old_uri: str,- new_uri: str,- ) -> List[WatchTask]:- """Rewrite watch-task target URIs after a resource move."""- async with self._lock:- plan = self._plan_move_tasks_under_uri_unlocked(old_uri, new_uri)- if not plan:- return []-- for task_id in plan:- task = self._tasks[task_id]- if task.to_uri:- self._uri_to_task.pop(task.to_uri, None)-- updated: List[WatchTask] = []- for task_id, target_uri in plan.items():- task = self._tasks[task_id]- old_parent = _parent_uri(task.to_uri or "")- task.to_uri = target_uri- if task.parent_uri is not None and task.parent_uri == old_parent:- task.parent_uri = _parent_uri(target_uri)- self._uri_to_task[target_uri] = task_id- updated.append(task)-- await self._save_tasks()- logger.info(- f"[WatchManager] Rewrote {len(updated)} watch task target URI(s) "- f"under {old_uri} to {new_uri}"- )- return updated-async def sync_tasks_with_resource_move_internal(self,old_uri: str,@@ -907,19 +861,3 @@ class WatchManager:continuenext_times.append(task.next_execution_time)return min(next_times) if next_times else None-- async def clear_all_tasks(self) -> int:- """Clear all tasks (for testing purposes).-- Returns:- Number of tasks cleared- """- async with self._lock:- count = len(self._tasks)- self._tasks.clear()- self._uri_to_task.clear()-- await self._save_tasks()-- logger.info(f"[WatchManager] Cleared {count} tasks")- return countdiff --git a/openviking/server/app.py b/openviking/server/app.pyindex 992bc736c..c50e500a9 100644--- a/openviking/server/app.py+++ b/openviking/server/app.py@@ -62,21 +62,6 @@ from openviking_cli.utils.logger import init_otel_log_handler_from_server_configlogger = get_logger(__name__)-def _on_deferred_init_done(task):- if task.cancelled():- logger.warning("Deferred initialization cancelled")- return-- exc = task.exception()- if exc is None:- return-- logger.error(- "Deferred initialization failed, exiting",- exc_info=(type(exc), exc, exc.__traceback__),- )- os._exit(1)-async def _initialize_auth_plugin(app: FastAPI,@@ -226,10 +211,6 @@ def create_app(if service is not None:_configure_session_tool_outputs(service)- async def _deferred_init(service, app, config):- """Retained for tests that validate deferred-init callback behavior."""- await _initialize_runtime_state(app, service, config)-@asynccontextmanagerasync def lifespan(app: FastAPI):"""Application lifespan handler."""diff --git a/openviking/server/oauth/storage.py b/openviking/server/oauth/storage.pyindex 5de1830b3..2ad7c20bd 100644--- a/openviking/server/oauth/storage.py+++ b/openviking/server/oauth/storage.py@@ -26,7 +26,7 @@ import secretsimport sqlite3import timefrom pathlib import Path-from typing import Any, Iterable, Optional+from typing import Any, Optionalfrom openviking.server.oauth.otp import hash_secretfrom openviking_cli.utils import get_logger@@ -490,21 +490,6 @@ class OAuthStore:async with self._lock:return await asyncio.to_thread(_q)- async def revoke_chain(self, *, client_id: str, account_id: str, user_id: str) -> int:- """Revoke every refresh token for (client, account, user). Returns count."""-- def _revoke() -> int:- assert self._conn is not None- cur = self._conn.execute(- "UPDATE oauth_refresh_tokens SET consumed = 1 "- "WHERE client_id = ? AND account_id = ? AND user_id = ? AND consumed = 0",- (client_id, account_id, user_id),- )- return cur.rowcount-- async with self._lock:- return await asyncio.to_thread(_revoke)-# ---- Access tokens ----async def insert_access(@@ -803,12 +788,3 @@ class OAuthStore:return await asyncio.to_thread(_gc)# ---- Test helpers (no-op in production paths) ------ async def _all_codes_for_test(self) -> Iterable[dict[str, Any]]:- def _q() -> list[dict[str, Any]]:- assert self._conn is not None- cur = self._conn.execute("SELECT * FROM oauth_codes")- return [_row_to_dict(cur, r) for r in cur.fetchall()]-- async with self._lock:- return await asyncio.to_thread(_q)diff --git a/openviking/server/routers/sessions.py b/openviking/server/routers/sessions.pyindex a7ba11628..37afab144 100644--- a/openviking/server/routers/sessions.py+++ b/openviking/server/routers/sessions.py@@ -4,7 +4,7 @@from typing import Any, Dict, List, Literal, Optional-from fastapi import APIRouter, Body, Depends, HTTPException, Path, Query, Request+from fastapi import APIRouter, Body, Depends, HTTPException, Path, Queryfrom pydantic import BaseModel, Field, field_validator, model_validatorfrom openviking.core.path_variables import resolve_path_variables@@ -180,12 +180,6 @@ def _to_jsonable(value: Any) -> Any:return value-def _request_auth_mode(request: Request) -> str:- config = getattr(request.app.state, "config", None)- if config is not None and hasattr(config, "get_effective_auth_mode"):- return config.get_effective_auth_mode()- return "api_key"-@router.post("")async def create_session(diff --git a/openviking/server/routers/skills.py b/openviking/server/routers/skills.pyindex 34d3fbfbb..ffe005b1f 100644--- a/openviking/server/routers/skills.py+++ b/openviking/server/routers/skills.py@@ -7,7 +7,7 @@ import reimport shutilimport uuidfrom pathlib import Path-from typing import Any, Dict, Optional, Union+from typing import Any, Dict, Optionalimport yamlfrom fastapi import APIRouter, Depends, Request@@ -159,18 +159,6 @@ async def _entry_looks_like_skill(return True-def _merge_skills(skills_list: list[list[Dict[str, Any]]]) -> list[Dict[str, Any]]:- """Merge skills from multiple sources, user skills take precedence."""- seen_names = set()- result = []- for skills in skills_list:- for skill in skills:- name = skill.get("name")- if name not in seen_names:- seen_names.add(name)- result.append(skill)- return result-def _validate_skill_name(skill_name: str) -> str:return validate_skill_name(skill_name)@@ -486,47 +474,6 @@ async def _list_skill_files(return entries-def _parse_skill_data(- service,- data: Any,- *,- allow_local_path_resolution: bool,- source_path_hint: Optional[str] = None,-) -> Dict[str, Any]:- skill_processor = getattr(service.resources, "_skill_processor", None)- if skill_processor is None:- raise RuntimeError("SkillProcessor is required for skill validation")- skill_dict, _, _, _ = skill_processor._parse_skill( # noqa: SLF001 - keep parser authority centralized.- data,- allow_local_path_resolution=allow_local_path_resolution,- source_path_hint=source_path_hint,- )- return skill_dict---def _validate_data_matches_name(- service,- data: Any,- skill_name: str,- *,- allow_local_path_resolution: bool,- source_path_hint: Optional[str] = None,-) -> Dict[str, Any]:- parsed = _parse_skill_data(- service,- data,- allow_local_path_resolution=allow_local_path_resolution,- source_path_hint=source_path_hint,- )- expected_name = _validate_skill_name(skill_name)- if parsed.get("name") != expected_name:- raise InvalidArgumentError(- f"Skill name mismatch: path name is '{expected_name}', content name is '{parsed.get('name')}'",- details={"expected": expected_name, "actual": parsed.get("name")},- )- return parsed--async def _restore_skill_privacy(service,ctx: RequestContext,diff --git a/openviking/service/core.py b/openviking/service/core.pyindex 7a35a14b8..d78ced348 100644--- a/openviking/service/core.py+++ b/openviking/service/core.py@@ -564,10 +564,3 @@ class OpenVikingService:if not self._directory_initializer:return 0return await self._directory_initializer.initialize_user_directories(ctx)-- async def initialize_agent_directories(self, ctx: RequestContext) -> int:- """Initialize current user's current-agent directory tree."""- self._ensure_initialized()- if not self._directory_initializer:- return 0- return await self._directory_initializer.initialize_agent_directories(ctx)diff --git a/openviking/service/fs_service.py b/openviking/service/fs_service.pyindex 3ef2b667c..3573eaa77 100644--- a/openviking/service/fs_service.py+++ b/openviking/service/fs_service.py@@ -412,37 +412,6 @@ class FSService:rollback_resource=lambda: viking_fs.mv(to_uri, from_uri, ctx=ctx),)- async def _plan_watch_before_mv(self, from_uri: str, to_uri: str) -> None:- if context_type_for_uri(from_uri) != "resource":- return- if context_type_for_uri(to_uri) != "resource":- return- if is_watch_task_control_uri(from_uri) or is_watch_task_control_uri(to_uri):- return- watch_manager = self._get_watch_manager()- if not watch_manager:- return- await watch_manager.plan_move_tasks_under_uri_internal(from_uri, to_uri)-- async def _sync_watch_after_mv(self, from_uri: str, to_uri: str) -> None:- if context_type_for_uri(from_uri) != "resource":- return- if context_type_for_uri(to_uri) != "resource":- return- if is_watch_task_control_uri(from_uri) or is_watch_task_control_uri(to_uri):- return- watch_manager = self._get_watch_manager()- if not watch_manager:- return- updated = await watch_manager.move_tasks_under_uri_internal(from_uri, to_uri)- if updated:- logger.info(- "Updated %d watch task target URI(s) after moving %s to %s",- len(updated),- from_uri,- to_uri,- )-async def _sync_watch_after_rm(self, uri: str, *, context_type: str) -> None:if context_type != "resource":returndiff --git a/openviking/service/reindex_executor.py b/openviking/service/reindex_executor.pyindex ca6d96249..57a261024 100644--- a/openviking/service/reindex_executor.py+++ b/openviking/service/reindex_executor.py@@ -1388,55 +1388,6 @@ class ReindexExecutor:counters.failed_records += 1counters.warnings.append(f"Failed to reindex {skill_file_uri} vector: {exc}")- async def _reindex_memory_directory_vectors(- self,- *,- uri: str,- counters: _ReindexCounters,- ctx: RequestContext,- ) -> None:- counters.scanned_records += 1- abstract = await self._read_directory_abstract(uri, ctx=ctx)- overview = await self._read_directory_overview(uri, ctx=ctx)- if not abstract and not overview:- counters.unsupported_records += 1- counters.warnings.append(f"No semantic source found for {uri}")- return-- parent_uri = VikingURI(uri).parent.uri- if abstract:- try:- await self._upsert_context(- uri=uri,- parent_uri=parent_uri,- abstract=abstract,- vector_text=abstract,- is_leaf=False,- context_type=ContextType.MEMORY.value,- level=ContextLevel.ABSTRACT,- ctx=ctx,- )- counters.rebuilt_records += 1- except Exception as exc:- counters.failed_records += 1- counters.warnings.append(f"Failed to reindex {uri} L0 vector: {exc}")- if overview:- try:- await self._upsert_context(- uri=uri,- parent_uri=parent_uri,- abstract=abstract,- vector_text=overview,- is_leaf=False,- context_type=ContextType.MEMORY.value,- level=ContextLevel.OVERVIEW,- ctx=ctx,- )- counters.rebuilt_records += 1- except Exception as exc:- counters.failed_records += 1- counters.warnings.append(f"Failed to reindex {uri} L1 vector: {exc}")-async def _reindex_memory_vectors(self,*,diff --git a/openviking/service/task_tracker.py b/openviking/service/task_tracker.pyindex 8e235184e..c020497b4 100644--- a/openviking/service/task_tracker.py+++ b/openviking/service/task_tracker.py@@ -97,12 +97,6 @@ def set_task_tracker(tracker: "TaskTracker") -> None:_instance = tracker-def reset_task_tracker() -> None:- """Reset singleton (for testing)."""- global _instance- _instance = None--# ── Sanitization ──_SENSITIVE_PATTERNS = re.compile(diff --git a/openviking/session/compressor_v3.py b/openviking/session/compressor_v3.pyindex 6a648c173..7ddd0d702 100644--- a/openviking/session/compressor_v3.py+++ b/openviking/session/compressor_v3.py@@ -1127,16 +1127,6 @@ def _case_evidence(case: Case) -> str:return "Structured batch training CaseSpec supplied by the training pipeline."-def _operations_to_cases(operations: ResolvedOperations) -> list[Case]:- cases: list[Case] = []- for op in getattr(operations, "upsert_operations", []) or []:- if getattr(op, "memory_type", None) != _CASES_MEMORY_TYPE:- continue- case = _operation_to_case(op)- if case is not None:- cases.append(case)- return cases-async def _canonical_cases_from_update_result(*,diff --git a/openviking/session/memory/__init__.py b/openviking/session/memory/__init__.pyindex 5090571ab..719d3b33f 100644--- a/openviking/session/memory/__init__.py+++ b/openviking/session/memory/__init__.py@@ -86,8 +86,6 @@ __all__ = ["MemoryLsTool","register_tool","get_tool",- "get_tool_schemas",- "list_tools","add_tool_call_pair_to_messages",# Language utilities and helpers"detect_language_from_conversation",diff --git a/openviking/session/memory/memory_type_registry.py b/openviking/session/memory/memory_type_registry.pyindex 97f38a823..0c5f1df7b 100644--- a/openviking/session/memory/memory_type_registry.py+++ b/openviking/session/memory/memory_type_registry.py@@ -132,25 +132,6 @@ class MemoryTypeRegistry:return list(self._types.keys())return [mt.memory_type for mt in self._types.values() if mt.enabled]- def list_search_uris(self, user_space: str) -> List[str]:- """List all directory URIs for search scope.-- Args:- user_space: User space name-- Returns:- List of directory URIs from enabled schemas- """- uris = []- for schema in self.list_all(include_disabled=False):- if schema.directory:- dir_path = TemplateUtils.render(- schema.directory,- {"user_space": user_space},- )- uris.append(dir_path)- return uris-def load_from_yaml(self, yaml_path: str, replace: bool = False) -> None:"""Load memory type from a YAML file.diff --git a/openviking/session/memory/memory_updater.py b/openviking/session/memory/memory_updater.pyindex 9051e46a7..a34fbb741 100644--- a/openviking/session/memory/memory_updater.py+++ b/openviking/session/memory/memory_updater.py@@ -10,7 +10,6 @@ to the storage system.from __future__ import annotationsimport re-from dataclasses import dataclassfrom typing import TYPE_CHECKING, Any, Dict, List, Optional, Tupleif TYPE_CHECKING:@@ -52,25 +51,6 @@ logger = get_logger(__name__)_MEMORY_ABSTRACT_MAX_BYTES = 50_000_EXTRACTION_CHUNK_MIN_CHARS = 100_EXTRACTION_CHUNK_BOUNDARY_RE = re.compile(r"(\n+|[。!?;!?;]+|(?<!\d)\.(?!\d))")-_RESOURCE_ADDITION_FIELD_RE = re.compile(- r"^(Resource URI|Source name|Added at|Resource abstract|User reason):\s*(.*)$",- re.MULTILINE,-)-_RESOURCE_URI_MARKER_RE = re.compile(- r"[,,;;::\s]*(?:资源\s*URI\s*为|资源\s*URI|Resource\s+URI)\s*[::为]?\s*",- re.IGNORECASE,-)---@dataclass(frozen=True)-class ChunkMeta:- """Metadata for a derived extraction chunk message."""-- source_message_id: str- chunk_index: int- chunk_count: int--async def write_stored_links(links: List[StoredLink],ctx: RequestContext,@@ -163,24 +143,17 @@ class ExtractContext:def __init__(self,messages: List[Message],- chunk_meta: Optional[Dict[int, ChunkMeta]] = None,*,split_long_text_messages: bool = True,):- if chunk_meta is None:- if split_long_text_messages:- self.messages, self.chunk_meta = self._build_extraction_messages(messages)- else:- self.messages, self.chunk_meta = list(messages or []), {}+ if split_long_text_messages:+ self.messages = self._build_extraction_messages(messages)else:- self.messages = messages- self.chunk_meta = chunk_meta+ self.messages = list(messages or [])self.page_id_map = PageIdMap()@classmethod- def _build_extraction_messages(- cls, messages: List[Message]- ) -> Tuple[List[Message], Dict[int, ChunkMeta]]:+ def _build_extraction_messages(cls, messages: List[Message]) -> List[Message]:"""Build messages used by memory extraction.Long text-only messages are split into derived chunks so event `ranges`@@ -188,26 +161,20 @@ class ExtractContext:matching. The original session messages are not modified."""extraction_messages: List[Message] = []- chunk_meta: Dict[int, ChunkMeta] = {}for message in messages:- for extraction_message, meta in cls._split_message_for_extraction(message):- extraction_messages.append(extraction_message)- if meta is not None:- chunk_meta[id(extraction_message)] = meta- return extraction_messages, chunk_meta+ extraction_messages.extend(cls._split_message_for_extraction(message))+ return extraction_messages@classmethod- def _split_message_for_extraction(- cls, message: Message- ) -> List[Tuple[Message, Optional[ChunkMeta]]]:+ def _split_message_for_extraction(cls, message: Message) -> List[Message]:parts = getattr(message, "parts", [])if not parts or not all(isinstance(part, TextPart) for part in parts):- return [(message, None)]+ return [message]text = "".join(part.text for part in parts)chunks = cls._split_text_for_extraction(text)if len(chunks) <= 1:- return [(message, None)]+ return [message]chunk_messages = []for idx, chunk in enumerate(chunks):@@ -218,16 +185,7 @@ class ExtractContext:parts=[TextPart(chunk)],created_at=message.created_at,)- chunk_messages.append(- (- chunk_message,- ChunkMeta(- source_message_id=message.id,- chunk_index=idx,- chunk_count=len(chunks),- ),- )- )+ chunk_messages.append(chunk_message)return chunk_messages@classmethod@@ -351,138 +309,6 @@ class ExtractContext:continuereturn datetime.now().strftime("%Y%m%d%H%M%S")- def get_event_content(- self, ranges_str: str, summary: str | None, ratio_threshold: float = 0.2- ) -> str:- """根据原始消息与 summary 的字符数比例,决定返回原始消息还是摘要。"""- if not ranges_str:- return summary or ""- msg_range = self.read_message_ranges(ranges_str)- original = msg_range.pretty_print()- if not summary or not summary.strip():- return original or ""- if not original:- return summary- if len(summary) / len(original) >= ratio_threshold:- return original- return summary-- def get_resource_event_content(self, ranges_str: str, summary: str) -> str:- """Return a user-readable event body for add-resource derived events."""- if not ranges_str:- return ""- additions = self._resource_additions_from_ranges(ranges_str)- if not additions:- return ""- addition = additions[0]- resource_uri = addition.get("Resource URI", "")- if not resource_uri:- return ""- return self._link_resource_summary(summary or "", resource_uri, addition).strip()-- def _resource_additions_from_ranges(self, ranges_str: str) -> List[Dict[str, str]]:- msg_range = self.read_message_ranges(ranges_str)- additions: List[Dict[str, str]] = []- for msg_group in msg_range.elements:- for msg in msg_group:- text = self._message_text(msg)- if "## Resource Addition" not in text:- continue- fields = {- match.group(1): match.group(2).strip()- for match in _RESOURCE_ADDITION_FIELD_RE.finditer(text)- }- if fields.get("Resource URI"):- additions.append(fields)- return additions-- @staticmethod- def _message_text(message: Message) -> str:- parts = getattr(message, "parts", [])- texts = [part.text for part in parts if isinstance(part, TextPart) and part.text]- if texts:- return "\n".join(texts)- return message.content or ""-- @classmethod- def _link_resource_summary(- cls,- summary: str,- resource_uri: str,- addition: Dict[str, str],- ) -> str:- text = (summary or "").strip()- if not text:- return cls._resource_addition_fallback_sentence(resource_uri, addition)- if f"]({resource_uri})" in text:- return text- if resource_uri in text:- return cls._replace_bare_resource_uri(text, resource_uri, addition)- label = cls._resource_label_from_addition(addition)- return cls._finish_sentence(f"{text.rstrip('。.!')},关联资源为[{label}]({resource_uri})")-- @classmethod- def _replace_bare_resource_uri(- cls,- text: str,- resource_uri: str,- addition: Dict[str, str],- ) -> str:- uri_start = text.find(resource_uri)- if uri_start < 0:- return text- prefix = text[:uri_start]- suffix = text[uri_start + len(resource_uri) :]- marker = _RESOURCE_URI_MARKER_RE.search(prefix)- if marker:- visible_prefix = prefix[: marker.start()].rstrip(",,;;:: ")- label = cls._resource_clause_from_summary_prefix(visible_prefix)- if not label:- label = cls._resource_label_from_addition(addition)- if label and visible_prefix.endswith(label):- visible_prefix = visible_prefix[: -len(label)] + f"[{label}]({resource_uri})"- else:- visible_prefix = f"{visible_prefix}[{label}]({resource_uri})"- return cls._finish_sentence(visible_prefix)-- label = cls._resource_label_from_addition(addition)- return cls._finish_sentence(f"{prefix.rstrip()}[{label}]({resource_uri}){suffix.strip()}")-- @staticmethod- def _resource_clause_from_summary_prefix(prefix: str) -> str:- text = prefix.strip(",,;;:: ")- tail = re.split(r"[,,;;。.!??]", text)[-1].strip()- return tail if 0 < len(tail) <= 120 else ""-- @classmethod- def _resource_label_from_addition(cls, addition: Dict[str, str]) -> str:- reason = addition.get("User reason", "").strip()- for prefix in ("这是一张", "这是一个", "该资源是", "这个是", "这是"):- if reason.startswith(prefix):- reason = reason[len(prefix) :].strip()- break- reason = reason.strip("。.!! ")- if reason:- return reason[:80]- source_name = addition.get("Source name", "").strip()- return source_name or "相关资源"-- @classmethod- def _resource_addition_fallback_sentence(- cls,- resource_uri: str,- addition: Dict[str, str],- ) -> str:- label = cls._resource_label_from_addition(addition)- return f"用户保存了[{label}]({resource_uri})。"-- @staticmethod- def _finish_sentence(text: str) -> str:- text = text.strip(",,;;:: ")- if text.endswith(("。", ".", "!", "!", "?", "?")):- return text- return text + "。"-def read_message_ranges(self, ranges_str: str) -> "MessageRange":"""Parse ranges string like "0-10,50-60" or "7,9,11,13" and return combined MessageRange.@@ -537,93 +363,14 @@ class ExtractContext:range_msgs = self.messages[start : end + 1]elements.append(range_msgs)- return MessageRange(elements, chunk_meta=self.chunk_meta)+ return MessageRange(elements)class MessageRange:"""Represents a range of messages for formatting."""- def __init__(- self,- elements: List[List[Message]],- chunk_meta: Optional[Dict[int, ChunkMeta]] = None,- ):+ def __init__(self, elements: List[List[Message]]):self.elements = elements- self.chunk_meta = chunk_meta or {}-- def pretty_print(self) -> str:- """Pretty print the message range with '...' separator between non-contiguous ranges."""- result = []- for i, msg_group in enumerate(self.elements):- result.extend(self._format_contiguous_group(msg_group))- # Add "..." separator between non-contiguous message groups- if i < len(self.elements) - 1:- result.append("...")- return "\n".join(result)-- def _format_contiguous_group(self, msg_group: List[Message]) -> List[str]:- formatted = []- current_messages: List[Message] = []-- def flush_current() -> None:- nonlocal current_messages- if not current_messages:- return- content = self._format_merged_content(current_messages)- formatted.append(f"**{self._speaker_for(current_messages[0])}**: {content}")- current_messages = []-- for msg in msg_group:- if current_messages and not self._can_merge_messages(current_messages[-1], msg):- flush_current()- current_messages.append(msg)-- flush_current()- return formatted-- @staticmethod- def _speaker_for(message: Message) -> str:- return getattr(message, "peer_id", None) or message.role-- def _can_merge_messages(self, previous: Message, current: Message) -> bool:- previous_meta = self._chunk_meta_for(previous)- current_meta = self._chunk_meta_for(current)- if previous_meta is None or current_meta is None:- return False- if self._speaker_for(previous) != self._speaker_for(current):- return False- return (- previous_meta.source_message_id == current_meta.source_message_id- and current_meta.chunk_index == previous_meta.chunk_index + 1- )-- def _format_merged_content(self, messages: List[Message]) -> str:- content = "".join((self._message_content(msg) or "") for msg in messages)- if not messages or not self._contains_chunk_message(messages):- return content-- first_chunk = self._chunk_meta_for(messages[0])- if first_chunk is not None and first_chunk.chunk_index > 0:- content = "..." + content.lstrip()- last_chunk = self._chunk_meta_for(messages[-1])- if last_chunk is not None and last_chunk.chunk_index < last_chunk.chunk_count - 1:- content = content.rstrip() + "..."- return content-- def _message_content(self, message: Message) -> str:- texts: List[str] = []- for part in getattr(message, "parts", []) or []:- if isinstance(part, TextPart):- texts.append(part.text or "")- if texts:- return "".join(texts)- return getattr(message, "content", "") or ""-- def _contains_chunk_message(self, messages: List[Message]) -> bool:- return any(self._chunk_meta_for(msg) is not None for msg in messages)-- def _chunk_meta_for(self, message: Message) -> Optional[ChunkMeta]:- return self.chunk_meta.get(id(message))def _first_message_time(self) -> str | None:"""获取第一条消息的时间(内部方法)"""@@ -675,9 +422,6 @@ class MemoryUpdateResult:def add_error(self, uri: str, error: Exception) -> None:self.errors.append((uri, error))- def has_changes(self) -> bool:- return len(self.written_uris) > 0 or len(self.edited_uris) > 0 or len(self.deleted_uris) > 0-def summary(self) -> str:return (f"Written: {len(self.written_uris)}, "@@ -714,10 +458,6 @@ class MemoryUpdater:self._vikingdb = vikingdbself._transaction_handle = transaction_handle- def set_registry(self, registry: MemoryTypeRegistry) -> None:- """Set the memory type registry for URI resolution."""- self._registry = registry-def _get_viking_fs(self):"""Get or create VikingFS instance."""if self._viking_fs is None:diff --git a/openviking/session/memory/page_id_map.py b/openviking/session/memory/page_id_map.pyindex 691579b41..4624e2b49 100644--- a/openviking/session/memory/page_id_map.py+++ b/openviking/session/memory/page_id_map.py@@ -47,8 +47,3 @@ class PageIdMap:def resolve(self, page_id: int) -> Optional[str]:"""Resolve page_id to URI."""return self._id_to_uri.get(page_id)-- @property- def has_links_enabled(self) -> bool:- """Whether any pages have been registered (links feature is active)."""- return len(self._id_to_uri) > 0diff --git a/openviking/session/memory/schema_model_generator.py b/openviking/session/memory/schema_model_generator.pyindex 1b2e1cea2..c78bc392c 100644--- a/openviking/session/memory/schema_model_generator.py+++ b/openviking/session/memory/schema_model_generator.py@@ -13,7 +13,12 @@ from typing import Annotated, Any, Dict, List, Optional, Tuple, Type, Unionfrom pydantic import BaseModel, Field, WithJsonSchema, create_modelfrom pydantic.config import ConfigDict-from openviking.session.memory.dataclass import DeleteId, FaultTolerantBaseModel, MemoryTypeSchema, WikiLink+from openviking.session.memory.dataclass import (+ DeleteId,+ FaultTolerantBaseModel,+ MemoryTypeSchema,+ WikiLink,+)from openviking.session.memory.memory_isolation_handler import RoleScopefrom openviking.session.memory.merge_op import MergeOp, MergeOpFactoryfrom openviking.session.memory.merge_op.base import FieldType, get_python_type_for_field@@ -51,7 +56,6 @@ class SchemaModelGenerator:self._template_context = dict(template_context or {})self._model_cache: Dict[str, Type[BaseModel]] = {}self._flat_data_models: Dict[str, Type[BaseModel]] = {}- self._union_model: Optional[Type[BaseModel]] = Noneself._operations_model: Optional[Type[BaseModel]] = Nonedef _render_description(self, description: str) -> str:@@ -172,54 +176,6 @@ class SchemaModelGenerator:models[memory_type.memory_type] = self.create_flat_data_model(memory_type)return models- def create_discriminated_union_model(self) -> Type[BaseModel]:- """- Create a unified MemoryData model with discriminator support.-- The model uses 'memory_type' as the discriminator field to- determine which fields model to use.-- Returns:- Unified Pydantic model with discriminator (a wrapper model containing the union)- """- if self._union_model is not None:- return self._union_model-- # Generate all flat data models first (including disabled for completeness)- self.generate_all_models(include_disabled=True)-- # Build the annotated union with discriminator - only use enabled types- if not self.schemas:- raise ValueError("No memory types in schemas")-- # Create union of flat data models- enabled_memory_types = self.schemas- flat_model_union_types = tuple(- self._flat_data_models[mt.memory_type] for mt in enabled_memory_types- )-- if flat_model_union_types:- FlatDataUnion = Union[tuple(flat_model_union_types)] # type: ignore- else:- # Fallback if no types are enabled- class GenericMemoryData(BaseModel):- """Generic memory data (fallback)."""-- memory_type: str = Field(..., description="Memory type identifier")-- FlatDataUnion = GenericMemoryData # type: ignore-- # Wrap the union in a BaseModel for JSON schema generation- class MemoryDataWrapper(BaseModel):- """Wrapper model for memory data union."""-- data: FlatDataUnion = Field(..., description="Memory data") # type: ignore-- model_config = ConfigDict(extra="forbid")-- self._union_model = MemoryDataWrapper- return self._union_model-def create_structured_operations_model(self, role_scope: Optional[RoleScope] = None) -> Type[BaseModel]:"""Create a structured MemoryOperations model with type-safe write operations.@@ -357,21 +313,6 @@ class SchemaModelGenerator:self._operations_model = StructuredMemoryOperationsreturn self._operations_model- def get_llm_json_schema(self, role_scope: Optional[RoleScope] = None) -> Dict[str, Any]:- """Get the JSON schema for the structured LLM operations model."""- return self.create_structured_operations_model(role_scope).model_json_schema()-- def get_memory_data_json_schema(self) -> Dict[str, Any]:- """- Get the JSON schema just for the flat memory data union.-- Returns:- JSON schema for MemoryData- """- memory_model = self.create_discriminated_union_model()- return memory_model.model_json_schema()--class SchemaPromptGenerator:"""Prompt generator that incorporates schema information into LLM prompts.diff --git a/openviking/session/memory/session_extract_context_provider.py b/openviking/session/memory/session_extract_context_provider.pyindex 0a142f44f..a7990234d 100644--- a/openviking/session/memory/session_extract_context_provider.py+++ b/openviking/session/memory/session_extract_context_provider.py@@ -6,12 +6,10 @@ Session Extract Context Provider - 会话提取 Provider 实现从会话消息中提取记忆的实现。"""-import osimport refrom typing import TYPE_CHECKING, Any, Dict, List, Optionalfrom openviking.message.part import TextPart, ToolPart-from openviking.prompts.manager import PromptManagerfrom openviking.server.identity import RequestContext, ToolContextfrom openviking.session.memory.core import ExtractContextProviderfrom openviking.session.memory.dataclass import MemoryFile@@ -22,7 +20,6 @@ from openviking.session.memory.memory_isolation_handler import ()from openviking.session.memory.memory_type_registry import (MemoryTypeRegistry,- resolve_memory_templates_dir,)from openviking.session.memory.tools import (add_tool_call_pair_to_messages,@@ -303,7 +300,6 @@ After exploring, analyze the conversation and output ALL memory write/edit/deletuser utterances and can leak environment/database state into usermemories. Agent-scope providers enable tool evidence explicitly."""- from openviking.message.part import ToolPartparts = getattr(msg, "parts", [])formatted_parts: List[str] = []@@ -620,29 +616,6 @@ After exploring, analyze the conversation and output ALL memory write/edit/deletschemas = [s for s in schemas if self._isolation_handler.allows_schema(s)]return schemas- def get_schema_directories(self) -> List[str]:- """返回需要加载的 schema 目录"""- if self._schema_directories is None:- memory_templates_dir = str(PromptManager._get_bundled_templates_dir() / "memory")- config = get_openviking_config()- custom_dir = config.memory.custom_templates_dir- self._schema_directories = [memory_templates_dir]- if getattr(config.memory, "experimental_memory_switch", False):- experimental_memory_dir = os.path.join(memory_templates_dir, "experimental_memory")- if os.path.exists(experimental_memory_dir):- self._schema_directories.append(experimental_memory_dir)- if custom_dir:- custom_dir_expanded = os.path.expanduser(custom_dir)- if os.path.exists(custom_dir_expanded):- self._schema_directories.append(custom_dir_expanded)- else:- memory_templates_dir = str(resolve_memory_templates_dir())- if memory_templates_dir != str(- PromptManager._get_bundled_templates_dir() / "memory"- ) and os.path.exists(memory_templates_dir):- self._schema_directories.append(memory_templates_dir)- return self._schema_directories-def _get_registry(self) -> MemoryTypeRegistry:"""内部获取 registry(自动在初始化时加载)"""if self._registry is None:diff --git a/openviking/session/memory/streaming_memory_updater.py b/openviking/session/memory/streaming_memory_updater.pyindex f554aab86..73ec93463 100644--- a/openviking/session/memory/streaming_memory_updater.py+++ b/openviking/session/memory/streaming_memory_updater.py@@ -144,10 +144,6 @@ class StreamingMemoryUpdater:def closed(self) -> bool:return self._closed- @property- def last_result(self) -> StreamingMemoryUpdateResult | None:- return self._last_result-async def get_buffered_operation_count(self) -> int:async with self._group_batchers_lock:batchers = list(self._group_batchers.values())diff --git a/openviking/session/memory/tools.py b/openviking/session/memory/tools.pyindex 550bbcc11..76dee7e9e 100644--- a/openviking/session/memory/tools.py+++ b/openviking/session/memory/tools.py@@ -363,15 +363,6 @@ def get_tool(name: str) -> Optional[MemoryTool]:return MEMORY_TOOLS_REGISTRY.get(name)-# Tools exposed to LLM (not all registered tools are exposed)-LLM_TOOLS = ["read"]---def get_tool_schemas() -> List[Dict[str, Any]]:- """Get tools exposed to LLM in OpenAI function schema format."""- return [tool.to_schema() for tool in MEMORY_TOOLS_REGISTRY.values() if tool.name in LLM_TOOLS]--# Register default toolsregister_tool(MemoryReadTool())register_tool(MemorySearchTool())diff --git a/openviking/session/memory/utils/__init__.py b/openviking/session/memory/utils/__init__.pyindex cd031e114..e7289612d 100644--- a/openviking/session/memory/utils/__init__.py+++ b/openviking/session/memory/utils/__init__.py@@ -12,7 +12,6 @@ from openviking.session.memory.utils.json_parser import (extract_json_content,parse_json_with_stability,parse_value_with_tolerance,- remove_json_trailing_content,value_fault_tolerance,)from openviking.session.memory.utils.language import (@@ -67,7 +66,6 @@ __all__ = ["is_uri_allowed",# JSON Parser"extract_json_content",- "remove_json_trailing_content","parse_json_with_stability","value_fault_tolerance","parse_value_with_tolerance",diff --git a/openviking/session/memory/utils/json_parser.py b/openviking/session/memory/utils/json_parser.pyindex 1f51cd262..380a4f093 100644--- a/openviking/session/memory/utils/json_parser.py+++ b/openviking/session/memory/utils/json_parser.py@@ -37,7 +37,6 @@ logger = get_logger(__name__)# Exported for testing__all__ = ["extract_json_content",- "remove_json_trailing_content","parse_json_with_stability","value_fault_tolerance","parse_value_with_tolerance",@@ -138,21 +137,6 @@ def extract_json_content(s: str) -> str:return result-def remove_json_trailing_content(s: str) -> str:- """- Layer 1: Remove extra content after JSON closing brace.-- DEPRECATED: Use extract_json_content() instead which handles both leading and trailing content.-- Args:- s: Raw LLM response string-- Returns:- String with only the JSON part- """- return extract_json_content(s)--def _get_origin_type(annotation) -> Type:"""Extract base type from Optional or Union types.diff --git a/openviking/session/memory/utils/streaming_batcher.py b/openviking/session/memory/utils/streaming_batcher.pyindex d91966d3e..272426708 100644--- a/openviking/session/memory/utils/streaming_batcher.py+++ b/openviking/session/memory/utils/streaming_batcher.py@@ -73,10 +73,6 @@ class StreamingBatcher(Generic[T, R]):def closed(self) -> bool:return self._closed- @property- def last_result(self) -> R | None:- return self._last_result-async def get_buffered_size(self) -> int:async with self._buffer_lock:return sum(self._item_size(item.payload) for item in self._buffer)diff --git a/openviking/session/session.py b/openviking/session/session.pyindex 61fbadc2d..e058d190c 100644--- a/openviking/session/session.py+++ b/openviking/session/session.py@@ -983,41 +983,6 @@ class Session:)return msgs[0]- def update_tool_part(- self,- message_id: str,- tool_id: str,- output: str,- status: str = "completed",- ) -> None:- """Update tool status."""- msg = next((m for m in self._messages if m.id == message_id), None)- if not msg:- return-- tool_part = msg.find_tool_part(tool_id)- if not tool_part:- return-- tool_part.tool_output = output- tool_part.tool_status = status- tool_part.tool_output_ref = ""- tool_part.tool_output_truncated = False- tool_part.tool_output_original_chars = None- tool_part.tool_output_preview_chars = None- tool_part.tool_output_sha256 = ""- tool_part.tool_output_storage_uri = ""- tool_part.tool_output_source_ref = ""- tool_part.tool_output_source_offset = None- tool_part.tool_output_source_limit = None- tool_part.tool_output_externalization_error = ""- tool_part.tool_output_externalized_reason = ""- self._externalize_large_tool_outputs(msg)-- self._save_tool_result(tool_id, msg, tool_part.tool_output, status)- self._update_message_in_jsonl()- self._rebuild_pending_tokens()-async def read_tool_result(self,tool_result_id: str,@@ -1761,38 +1726,6 @@ class Session:ctx=self.ctx,)- def _update_active_counts(self) -> int:- """Update active_count for used contexts/skills."""- if not self._vikingdb_manager:- return 0-- uris = [usage.uri for usage in self._usage_records if usage.uri]- try:- updated = run_async(self._vikingdb_manager.increment_active_count(self.ctx, uris))- except Exception as e:- logger.debug(f"Could not update active_count for usage URIs: {e}")- updated = 0-- if updated > 0:- logger.info(f"Updated active_count for {updated} contexts/skills")- return updated-- async def _update_active_counts_async(self) -> int:- """Async update active_count for used contexts/skills."""- if not self._vikingdb_manager:- return 0-- uris = [usage.uri for usage in self._usage_records if usage.uri]- try:- updated = await self._vikingdb_manager.increment_active_count(self.ctx, uris)- except Exception as e:- logger.debug(f"Could not update active_count for usage URIs: {e}")- updated = 0-- if updated > 0:- logger.info(f"Updated active_count for {updated} contexts/skills")- return updated-async def get_session_context(self, token_budget: int = 128_000) -> Dict[str, Any]:"""Get assembled session context with the latest summary archive and merged messages."""if token_budget < 0:@@ -1864,10 +1797,6 @@ class Session:"current_messages": current_messages,}- async def get_context_for_assemble(self, token_budget: int = 128_000) -> Dict[str, Any]:- """Backward-compatible alias for the assembled session context."""- return await self.get_session_context(token_budget=token_budget)-async def get_session_archive(self, archive_id: str) -> Dict[str, Any]:"""Get one completed archive by archive ID."""from openviking_cli.exceptions import NotFoundError@@ -2218,36 +2147,6 @@ class Session:body = "\n".join(lines) if lines else "(no content)"return f"[{m.role}]: {body}"- def _generate_archive_summary(- self,- messages: List[Message],- latest_archive_overview: str = "",- ) -> str:- """Generate structured summary for archive."""- if not messages:- return ""-- formatted = "\n".join(self._format_message_for_wm(m) for m in messages)-- vlm = get_openviking_config().vlm- if vlm and vlm.is_available():- try:- from openviking.prompts import render_prompt-- prompt = render_prompt(- "compression.structured_summary",- {- "messages": formatted,- "latest_archive_overview": latest_archive_overview,- },- )- return run_async(vlm.get_completion_async(prompt))- except Exception as e:- logger.warning(f"LLM summary failed: {e}")-- turn_count = len([m for m in messages if m.role == "user"])- return f"# Session Summary\n\n**Overview**: {turn_count} turns, {len(messages)} messages"-async def _generate_archive_summary_async(self,messages: List[Message],@@ -3242,85 +3141,6 @@ class Session:return "\n".join(parts).rstrip() + "\n"- def _write_archive(- self,- index: int,- messages: List[Message],- abstract: str,- overview: str,- ) -> None:- """Write archive to history/archive_N/."""- if not self._viking_fs:- return-- viking_fs = self._viking_fs- archive_uri = f"{self._session_uri}/history/archive_{index:03d}"-- # Write messages.jsonl- lines = [m.to_jsonl() for m in messages]- run_async(- viking_fs.write_file(- uri=f"{archive_uri}/messages.jsonl",- content="\n".join(lines) + "\n",- ctx=self.ctx,- )- )-- run_async(- viking_fs.write_file(- uri=f"{archive_uri}/.abstract.md",- content=abstract,- ctx=self.ctx,- )- )- run_async(- viking_fs.write_file(- uri=f"{archive_uri}/.overview.md",- content=overview,- ctx=self.ctx,- )- )-- logger.debug(f"Written archive: {archive_uri}")-- def _write_to_agfs(self, messages: List[Message]) -> None:- """Write messages.jsonl to AGFS."""- if not self._viking_fs:- return-- viking_fs = self._viking_fs- turn_count = len([m for m in messages if m.role == "user"])-- abstract = self._generate_abstract()- overview = self._generate_overview(turn_count)-- lines = [m.to_jsonl() for m in messages]- content = "\n".join(lines) + "\n" if lines else ""-- run_async(- viking_fs.write_file(- uri=f"{self._session_uri}/messages.jsonl",- content=content,- ctx=self.ctx,- )- )-- # Update L0/L1- run_async(- viking_fs.write_file(- uri=f"{self._session_uri}/.abstract.md",- content=abstract,- ctx=self.ctx,- )- )- run_async(- viking_fs.write_file(- uri=f"{self._session_uri}/.overview.md",- content=overview,- ctx=self.ctx,- )- )-async def _write_to_agfs_async(self, messages: List[Message]) -> None:"""Write messages.jsonl to AGFS (async)."""if not self._viking_fs:@@ -3364,56 +3184,6 @@ class Session:))- def _update_message_in_jsonl(self) -> None:- """Update message in messages.jsonl."""- if not self._viking_fs:- return-- lines = [m.to_jsonl() for m in self._messages]- content = "\n".join(lines) + "\n"- run_async(- self._viking_fs.write_file(- f"{self._session_uri}/messages.jsonl",- content,- ctx=self.ctx,- )- )-- def _save_tool_result(- self,- tool_id: str,- msg: Message,- output: str,- status: str,- ) -> None:- """Save tool result to tools/{tool_id}/tool.json."""- if not self._viking_fs:- return-- tool_part = msg.find_tool_part(tool_id)- if not tool_part:- return-- tool_data = {- "tool_id": tool_id,- "tool_name": tool_part.tool_name,- "session_id": self.session_id,- "input": tool_part.tool_input,- "output": output,- "status": status,- "time": {"created": get_current_timestamp()},- "duration_ms": tool_part.duration_ms,- "prompt_tokens": tool_part.prompt_tokens,- "completion_tokens": tool_part.completion_tokens,- }- run_async(- self._viking_fs.write_file(- f"{self._session_uri}/tools/{tool_id}/tool.json",- json.dumps(tool_data, ensure_ascii=False),- ctx=self.ctx,- )- )-def _generate_abstract(self) -> str:"""Generate one-sentence summary for session."""if not self._messages:@@ -3446,32 +3216,6 @@ class Session:parts.append(f"- Historical archives: `{self._session_uri}/history/`")return "\n".join(parts)- def _write_relations(self) -> None:- """Create relations to used contexts/tools."""- if not self._viking_fs:- return-- viking_fs = self._viking_fs- for usage in self._usage_records:- try:- run_async(viking_fs.link(self._session_uri, usage.uri, ctx=self.ctx))- logger.debug(f"Created relation: {self._session_uri} -> {usage.uri}")- except Exception as e:- logger.warning(f"Failed to create relation to {usage.uri}: {e}")-- async def _write_relations_async(self) -> None:- """Create relations to used contexts/tools (async)."""- if not self._viking_fs:- return-- viking_fs = self._viking_fs- for usage in self._usage_records:- try:- await viking_fs.link(self._session_uri, usage.uri, ctx=self.ctx)- logger.debug(f"Created relation: {self._session_uri} -> {usage.uri}")- except Exception as e:- logger.warning(f"Failed to create relation to {usage.uri}: {e}")-# ============= Properties =============@propertydiff --git a/openviking/session/skill/session_skill_context_provider.py b/openviking/session/skill/session_skill_context_provider.pyindex 3870fa941..b437e5df4 100644--- a/openviking/session/skill/session_skill_context_provider.py+++ b/openviking/session/skill/session_skill_context_provider.py@@ -186,9 +186,6 @@ class SessionSkillContextProvider(SessionExtractContextProvider):def get_tools(self) -> List[str]:return ["read"]- def get_schema_directories(self) -> List[str]:- return [str(resolve_skill_extract_templates_dir())]-def _get_registry(self) -> MemoryTypeRegistry:if self._registry is None:self._registry = load_skill_extract_registry()diff --git a/openviking/session/tool_skill_utils.py b/openviking/session/tool_skill_utils.pydeleted file mode 100644index bdaab66e0..000000000--- a/openviking/session/tool_skill_utils.py+++ /dev/null@@ -1,127 +0,0 @@-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.-# SPDX-License-Identifier: AGPL-3.0--from __future__ import annotations--from difflib import SequenceMatcher-from typing import Any, Callable, Dict, Iterable, Tuple, Union--Number = Union[int, float]---def normalize_name(name: str) -> str:- return (name or "").lower().strip().replace("_", "").replace("-", "").replace(" ", "")---def extract_skill_name_from_uri(uri: str) -> str:- uri = (uri or "").strip()- if not uri:- return ""- return uri.rstrip("/").split("/")[-1]---def _calibrate_name(- candidate_name: str,- parts: Iterable[Any],- name_getter: Callable[[Any], str],- threshold: float,-) -> Tuple[str, str]:- candidate_name = (candidate_name or "").strip()- if not candidate_name:- return ("", "completed")-- candidate_norm = normalize_name(candidate_name)- best_ratio = -1.0- best_name = ""- best_status = "completed"-- for part in parts:- part_name = (name_getter(part) or "").strip()- if not part_name:- continue-- part_norm = normalize_name(part_name)- if part_name == candidate_name or (candidate_norm and part_norm == candidate_norm):- return (part_name, getattr(part, "tool_status", None) or "completed")-- ratio = SequenceMatcher(None, candidate_norm, part_norm).ratio()- # tie-break: prefer the last occurrence when multiple parts have the same similarity- if ratio > best_ratio or (ratio == best_ratio and ratio >= 0):- best_ratio = ratio- best_name = part_name- best_status = getattr(part, "tool_status", None) or "completed"-- if best_ratio >= threshold and best_name:- return (best_name, best_status)- return ("", "completed")---def calibrate_tool_name(candidate_tool_name: str, tool_parts: Iterable[Any]) -> Tuple[str, str]:- return _calibrate_name(- candidate_name=candidate_tool_name,- parts=tool_parts,- name_getter=lambda p: getattr(p, "tool_name", "") or "",- threshold=0.8,- )---def calibrate_skill_name(candidate_skill_name: str, tool_parts: Iterable[Any]) -> Tuple[str, str]:- return _calibrate_name(- candidate_name=candidate_skill_name,- parts=tool_parts,- name_getter=lambda p: extract_skill_name_from_uri(getattr(p, "skill_uri", "") or ""),- threshold=0.8,- )---def collect_tool_stats(tool_parts: Iterable[Any]) -> Dict[str, Dict[str, Number]]:- stats_map: Dict[str, Dict[str, Number]] = {}- for part in tool_parts:- name = (getattr(part, "tool_name", "") or "").strip()- if not name:- continue-- if name not in stats_map:- stats_map[name] = {- "duration_ms": 0,- "prompt_tokens": 0,- "completion_tokens": 0,- "success_time": 0,- "call_count": 0,- }-- stats_map[name]["call_count"] += 1- duration_ms = getattr(part, "duration_ms", None)- if duration_ms is not None:- stats_map[name]["duration_ms"] += duration_ms- prompt_tokens = getattr(part, "prompt_tokens", None)- if prompt_tokens is not None:- stats_map[name]["prompt_tokens"] += int(prompt_tokens)- completion_tokens = getattr(part, "completion_tokens", None)- if completion_tokens is not None:- stats_map[name]["completion_tokens"] += int(completion_tokens)- if (getattr(part, "tool_status", None) or "") == "completed":- stats_map[name]["success_time"] += 1-- return stats_map---def collect_skill_stats(tool_parts: Iterable[Any]) -> Dict[str, Dict[str, Number]]:- stats_map: Dict[str, Dict[str, Number]] = {}- for part in tool_parts:- skill_uri = getattr(part, "skill_uri", "") or ""- skill_name = extract_skill_name_from_uri(skill_uri)- if not skill_name:- continue-- if skill_name not in stats_map:- stats_map[skill_name] = {- "success_time": 0,- "call_count": 0,- }-- stats_map[skill_name]["call_count"] += 1- if (getattr(part, "tool_status", None) or "") == "completed":- stats_map[skill_name]["success_time"] += 1-- return stats_mapdiff --git a/openviking/session/train/components/policy_trainer.py b/openviking/session/train/components/policy_trainer.pyindex 06c33e7b7..e75e2011e 100644--- a/openviking/session/train/components/policy_trainer.py+++ b/openviking/session/train/components/policy_trainer.py@@ -178,11 +178,6 @@ class StreamingPolicyTrainer:def last_apply_result(self) -> PolicyApplyResult | None:return self._last_apply_result- async def get_buffered_gradient_count(self) -> int:- """Return the current buffered gradient count under the buffer lock."""-- return await self._batcher.get_buffered_size()-@propertydef closed(self) -> bool:return self._closeddiff --git a/openviking/session/train/components/progress.py b/openviking/session/train/components/progress.pyindex fafb98fa9..d2fc780a6 100644--- a/openviking/session/train/components/progress.py+++ b/openviking/session/train/components/progress.py@@ -203,11 +203,6 @@ class ProgressPrinter:sys.stdout.write(f"[{self.label}] {self.description}\n")sys.stdout.flush()- def _elapsed_seconds(self) -> float:- if self._started_at is None:- return 0.0- return max(0.0, time.monotonic() - self._started_at)-def _ensure_rich_started(self) -> None:if self._progress is not None:returndiff --git a/openviking/storage/queuefs/semantic_processor.py b/openviking/storage/queuefs/semantic_processor.pyindex 82e68af5d..e26c51d91 100644--- a/openviking/storage/queuefs/semantic_processor.py+++ b/openviking/storage/queuefs/semantic_processor.py@@ -1027,19 +1027,6 @@ class SemanticProcessor(DequeueHandlerBase):except Exception as e:logger.error(f"[SyncDiff] Failed to rewrite image URIs for {target_uri}: {e}")- async def _collect_children_abstracts(- self, children_uris: List[str], ctx: Optional[RequestContext] = None- ) -> List[Dict[str, str]]:- """Collect .abstract.md from subdirectories."""- viking_fs = get_viking_fs()- results = []-- for child_uri in children_uris:- abstract = await viking_fs.abstract(child_uri, ctx=ctx)- dir_name = child_uri.split("/")[-1]- results.append({"name": dir_name, "abstract": abstract})- return results-async def _generate_text_summary(self,file_path: str,diff --git a/openviking/storage/transaction/lock_manager.py b/openviking/storage/transaction/lock_manager.pyindex 3ef5e937f..d31efc612 100644--- a/openviking/storage/transaction/lock_manager.py+++ b/openviking/storage/transaction/lock_manager.py@@ -53,10 +53,6 @@ class LockManager:self._redo_task: Optional[asyncio.Task] = Noneself._running = False- @property- def redo_log(self) -> RedoLog:- return self._redo_log-@propertydef redo_recovery_enabled(self) -> bool:return self._redo_recovery_enableddiff --git a/openviking/storage/transaction/redo_log.py b/openviking/storage/transaction/redo_log.pyindex d51de8360..7631919c1 100644--- a/openviking/storage/transaction/redo_log.py+++ b/openviking/storage/transaction/redo_log.py@@ -26,23 +26,6 @@ class RedoLog:def _task_path(self, task_id: str) -> str:return f"{_REDO_ROOT}/{task_id}/redo.json"- async def _ensure_dirs_async(self, dir_path: str) -> None:- parts = dir_path.strip("/").split("/")- current = ""- for part in parts:- current = f"{current}/{part}"- try:- await self._async_agfs.mkdir(current)- except Exception:- pass-- async def write_pending_async(self, task_id: str, info: Dict[str, Any]) -> None:- """Write a redo marker before the operation starts."""- dir_path = f"{_REDO_ROOT}/{task_id}"- await self._ensure_dirs_async(dir_path)- data = json.dumps(info, default=str).encode("utf-8")- await self._async_agfs.write(self._task_path(task_id), data)-async def mark_done_async(self, task_id: str) -> None:"""Delete the redo marker after a successful operation."""try:diff --git a/openviking/storage/vectordb/collection/volcengine_collection.py b/openviking/storage/vectordb/collection/volcengine_collection.pyindex 5a44306b3..39e2afe60 100644--- a/openviking/storage/vectordb/collection/volcengine_collection.py+++ b/openviking/storage/vectordb/collection/volcengine_collection.py@@ -121,18 +121,6 @@ class VolcengineCollection(ICollection):f"Request to {action} failed: {response.status_code} {code} {message}")- @staticmethod- def _is_collection_not_found(response: Any, action: str) -> bool:- if action != "GetVikingdbCollection" or response.status_code != 404:- return False- try:- result = response.json()- except json.JSONDecodeError:- return False- metadata = result.get("ResponseMetadata", {}) if isinstance(result, dict) else {}- error = metadata.get("Error", {}) if isinstance(metadata, dict) else {}- return error.get("Code") == "NotFound.VikingdbCollection"-def _console_post(self, data: Dict[str, Any], action: str):params = {"Action": action, "Version": VIKING_DB_VERSION}response = self.console_client.do_req("POST", req_params=params, req_body=data)diff --git a/openviking/storage/vectordb/engine/_python_api.py b/openviking/storage/vectordb/engine/_python_api.pyindex 427944ab7..92a951368 100644--- a/openviking/storage/vectordb/engine/_python_api.py+++ b/openviking/storage/vectordb/engine/_python_api.py@@ -126,10 +126,6 @@ class Schema:def get_field_order(self) -> list[FieldMeta]:return self.field_orders- def get_total_byte_length(self) -> int:- return self.total_byte_length--def _get_row_value(row_data: Any, field_name: str, default_value: Any) -> Any:if isinstance(row_data, dict):return row_data.get(field_name, default_value)@@ -411,9 +407,6 @@ def _build_native_bytes_row_exports(backend: Any):except RuntimeError as exc:raise ValueError(str(exc)) from exc- def get_total_byte_length(self) -> int:- return int(backend._schema_get_total_byte_length(self._handle))-class BytesRow:def __init__(self, schema: Schema):self.schema = schemadiff --git a/openviking/storage/vectordb/index/local_index.py b/openviking/storage/vectordb/index/local_index.pyindex f5e443d03..b2241ba59 100644--- a/openviking/storage/vectordb/index/local_index.py+++ b/openviking/storage/vectordb/index/local_index.py@@ -555,20 +555,6 @@ class LocalIndex(IIndex):thread.join()self._dense_rebuild_thread = None- def wait_for_background_rebuild(self, timeout: float = 5.0) -> bool:- if not self._auto_background_rebuild:- return False- deadline = time.monotonic() + max(0.0, timeout)- while self.dense_search is not None and self.dense_search.needs_rebuild:- self._raise_dense_rebuild_failure()- if not self._retry_memory_blocked_rebuild():- self._wake_dense_rebuild_worker()- remaining = deadline - time.monotonic()- if remaining <= 0 or not self._dense_rebuild_completed.wait(remaining):- return False- self._raise_dense_rebuild_failure()- return self.dense_search is not None-def search(self,query_vector: Optional[List[float]],diff --git a/openviking/storage/vectordb/project/http_project.py b/openviking/storage/vectordb/project/http_project.pyindex 703e59a3f..5be3043f6 100644--- a/openviking/storage/vectordb/project/http_project.py+++ b/openviking/storage/vectordb/project/http_project.py@@ -205,29 +205,3 @@ class HttpProject:if collection:collection.drop()logger.info(f"Dropped remote collection: {collection_name}")-- def get_or_create_collection(- self, collection_name: str, meta_data: Optional[Dict[str, Any]] = None- ) -> Collection:- """- Get or create collection-- Args:- collection_name: Collection name- meta_data: Collection metadata (required only when creating)-- Returns:- Collection instance-- Raises:- ValueError: If collection does not exist and no meta_data provided- """- if self.has_collection(collection_name):- return self.get_collection(collection_name)-- if meta_data is None:- raise ValueError(- f"Collection {collection_name} does not exist and no meta_data provided"- )-- return self.create_collection(collection_name, meta_data)diff --git a/openviking/storage/vectordb/project/local_project.py b/openviking/storage/vectordb/project/local_project.pyindex e4e0d1a08..23b4de414 100644--- a/openviking/storage/vectordb/project/local_project.py+++ b/openviking/storage/vectordb/project/local_project.py@@ -218,29 +218,3 @@ class LocalProject:if collection:collection.drop()logger.info(f"Dropped collection: {collection_name}")-- def get_or_create_collection(- self, collection_name: str, meta_data: Optional[Dict[str, Any]] = None- ) -> Collection:- """Get or create collection.-- Args:- collection_name: Collection name- meta_data: Collection metadata (only required when creating)-- Returns:- Collection instance-- Raises:- ValueError: If collection does not exist and no meta_data provided- """- collection = self.get_collection(collection_name)- if collection:- return collection-- if meta_data is None:- raise ValueError(- f"Collection {collection_name} does not exist and no meta_data provided"- )-- return self.create_collection(collection_name, meta_data)diff --git a/openviking/storage/vectordb/project/project_group.py b/openviking/storage/vectordb/project/project_group.pyindex 1576185bc..e037bfa6c 100644--- a/openviking/storage/vectordb/project/project_group.py+++ b/openviking/storage/vectordb/project/project_group.py@@ -157,15 +157,6 @@ class ProjectGroup:"""return self.projects.get(project_name)- def list_projects(self):- """- List all project names-- Returns:- Project name list- """- return self.projects.list_names()-def get_projects(self) -> Dict[str, LocalProject]:"""Get all projectsdiff --git a/openviking/storage/vectordb/project/vikingdb_project.py b/openviking/storage/vectordb/project/vikingdb_project.pyindex 18be7f106..b295b06c1 100644--- a/openviking/storage/vectordb/project/vikingdb_project.py+++ b/openviking/storage/vectordb/project/vikingdb_project.py@@ -13,47 +13,6 @@ from openviking.storage.vectordb.collection.vikingdb_clients import (from openviking_cli.utils.logger import default_logger as logger-def get_or_create_vikingdb_project(- project_name: str = "default", config: Optional[Dict[str, Any]] = None-):- """- Get or create a VikingDB project for private deployment.-- Args:- project_name: Project name- config: Configuration dict with keys:- - Host: VikingDB service host- - Headers: Custom headers for authentication/context- - CollectionClass: Class path for collection implementation- - CollectionArgs: Optional dictionary of arguments to pass to collection constructor-- Returns:- VikingDBProject instance- """- if config is None:- raise ValueError("config is required")-- host = config.get("Host")- headers = config.get("Headers")- collection_class_path = config.get(- "CollectionClass",- "openviking.storage.vectordb.collection.vikingdb_collection.VikingDBCollection",- )- # Extract any other arguments that might be needed for collection initialization- collection_args = config.get("CollectionArgs", {})-- if not host:- raise ValueError("config must contain 'Host'")-- return VikingDBProject(- host=host,- headers=headers,- project_name=project_name,- collection_class_path=collection_class_path,- collection_args=collection_args,- )--class VikingDBProject:"""VikingDB project class for private deployment.@@ -175,28 +134,6 @@ class VikingDBProject:"""collection should be pre-created"""raise NotImplementedError("collection should be pre-created")- def get_or_create_collection(- self, collection_name: str, meta_data: Optional[Dict[str, Any]] = None- ) -> Collection:- """- Get or create collection.-- Args:- collection_name: Collection name- meta_data: Collection metadata (required if not exists)-- Returns:- Collection instance- """- collection = self.get_collection(collection_name)- if collection:- return collection-- if meta_data is None:- raise ValueError(f"meta_data is required to create collection {collection_name}")-- return self.create_collection(collection_name, meta_data)-def drop_collection(self, collection_name: str):"""Drop specified collection"""collection = self.get_collection(collection_name)diff --git a/openviking/storage/vectordb/project/volcengine_project.py b/openviking/storage/vectordb/project/volcengine_project.pyindex 8c7e74860..182b3903a 100644--- a/openviking/storage/vectordb/project/volcengine_project.py+++ b/openviking/storage/vectordb/project/volcengine_project.py@@ -188,24 +188,3 @@ class VolcengineProject:self.collections.remove(collection_name)logger.info(f"Dropped Volcengine collection: {collection_name}")-- def get_or_create_collection(- self, collection_name: str, meta_data: Optional[Dict[str, Any]] = None- ) -> Collection:- """- Get an existing collection or create a new one if it doesn't exist-- Args:- collection_name: Collection name- meta_data: Collection metadata (required if collection doesn't exist)-- Returns:- Collection instance- """- if self.has_collection(collection_name):- return self.get_collection(collection_name)-- if meta_data is None:- raise ValueError(f"meta_data is required to create collection {collection_name}")-- return self.create_collection(collection_name, meta_data)diff --git a/openviking/storage/vectordb/utils/validation.py b/openviking/storage/vectordb/utils/validation.pyindex 33175fe38..366eaa528 100644--- a/openviking/storage/vectordb/utils/validation.py+++ b/openviking/storage/vectordb/utils/validation.py@@ -340,34 +340,6 @@ def is_valid_index_meta_data_for_update(meta_data: dict, field_meta_dict: dict)return False-def fix_collection_meta(meta_data: dict) -> dict:- fields = meta_data.get("Fields", [])- has_pk = False- for item in fields:- if item.get("IsPrimaryKey", False):- has_pk = True- break-- if not has_pk:- fields.append(- {- "FieldName": "AUTO_ID",- "FieldType": "int64",- "IsPrimaryKey": True,- }- )-- field_count = meta_data.get("_FieldsCount", 0)- for item in fields:- if "_FieldID" not in item:- item["_FieldID"] = field_count- field_count += 1-- meta_data["_FieldsCount"] = field_count- meta_data["Fields"] = fields- return meta_data--# Data validation logicREQUIRED_COLLECTION_FIELD_TYPE_CHECK = {"int64": ([int], None, 0),diff --git a/openviking/storage/vectordb_adapters/base.py b/openviking/storage/vectordb_adapters/base.pyindex 326c30480..9d2287f34 100644--- a/openviking/storage/vectordb_adapters/base.py+++ b/openviking/storage/vectordb_adapters/base.py@@ -391,39 +391,6 @@ class CollectionAdapter(ABC):raise TypeError(f"Unsupported filter expr type: {type(expr)!r}")# Backward-compatible aliases: keep old non-underscore names callable.- def sanitize_scalar_index_fields(- self,- scalar_index_fields: list[str],- fields_meta: list[dict[str, Any]],- ) -> list[str]:- return self._sanitize_scalar_index_fields(- scalar_index_fields=scalar_index_fields,- fields_meta=fields_meta,- )-- def build_default_index_meta(- self,- *,- index_name: str,- distance: str,- use_sparse: bool,- sparse_weight: float,- scalar_index_fields: list[str],- ) -> Dict[str, Any]:- return self._build_default_index_meta(- index_name=index_name,- distance=distance,- use_sparse=use_sparse,- sparse_weight=sparse_weight,- scalar_index_fields=scalar_index_fields,- )-- def normalize_record_for_read(self, record: Dict[str, Any]) -> Dict[str, Any]:- return self._normalize_record_for_read(record)-- def compile_filter(self, expr: FilterExpr | Dict[str, Any] | None) -> Dict[str, Any]:- return self._compile_filter(expr)-def upsert(self, data: Dict[str, Any] | list[Dict[str, Any]]) -> list[str]:coll = self.get_collection()records = [data] if isinstance(data, dict) else datadiff --git a/openviking/storage/viking_fs.py b/openviking/storage/viking_fs.pyindex d3af8aa61..662dae765 100644--- a/openviking/storage/viking_fs.py+++ b/openviking/storage/viking_fs.py@@ -1474,12 +1474,6 @@ class VikingFS:return base_pathreturn f"{base_path.rstrip('/')}/{match_file.lstrip('/')}"- def _calculate_grep_match_depth(self, match_file: str) -> int:- """Calculate relative depth from a grep result path relative to the query root."""- if not match_file or match_file == ".":- return 0- return len([part for part in match_file.split("/") if part])-async def stat(self, uri: str, ctx: Optional[RequestContext] = None, skip_count: bool = False) -> Dict[str, Any]:@@ -2885,21 +2879,6 @@ class VikingFS:except UnicodeDecodeError:return data.decode("utf-8", errors="replace")- def _handle_agfs_content(self, result: Union[bytes, Any, None]) -> str:- """Handle AGFSClient content return types consistently."""- if isinstance(result, bytes):- return self._decode_bytes(result)- elif hasattr(result, "content") and result.content is not None:- return self._decode_bytes(result.content)- elif result is None:- return ""- else:- # Try to convert to string- try:- return str(result)- except Exception:- return ""-# ========== Vector Sync Helper Methods ==========async def _collect_uris(diff --git a/openviking/storage/viking_vector_index_backend.py b/openviking/storage/viking_vector_index_backend.pyindex 1295009ff..7b1096356 100644--- a/openviking/storage/viking_vector_index_backend.py+++ b/openviking/storage/viking_vector_index_backend.py@@ -136,9 +136,6 @@ class _SingleAccountBackend:self._meta_data_cache = coll.get_meta_data() or {}return self._meta_data_cache- def _refresh_meta_data(self, coll: Collection) -> None:- self._meta_data_cache = coll.get_meta_data() or {}-def _filter_known_fields(self, data: Dict[str, Any]) -> Dict[str, Any]:try:coll = self._get_collection()diff --git a/openviking/telemetry/execution.py b/openviking/telemetry/execution.pyindex 688fbacc5..d533e04fd 100644--- a/openviking/telemetry/execution.py+++ b/openviking/telemetry/execution.py@@ -119,38 +119,6 @@ def _fill_telemetry_summary_to_span(snapshot, span):logger.debug("failed to fill telemetry summary into span", exc_info=True)-def _fill_operation_context_from_snapshot(- operation_attrs: OperationSpanAttributes,- snapshot: Optional[TelemetrySnapshot],-) -> OperationSpanAttributes:- """- Update the bound operation context from a finished telemetry snapshot.-- Returns a new OperationSpanAttributes instance with the updated fields,- rather than modifying the input object in place. This avoids unintended- side effects when the same object is referenced elsewhere.-- Args:- operation_attrs: The original operation attributes.- snapshot: The telemetry snapshot (optional).-- Returns:- A new OperationSpanAttributes instance with updated fields, or the original- instance if snapshot is None.- """- if snapshot is None:- return operation_attrs-- # Create a new instance from the snapshot- updated = OperationSpanAttributes.from_telemetry_snapshot(- operation=operation_attrs.operation,- telemetry_id=snapshot.telemetry_id,- status=snapshot.summary.get("status"),- summary=snapshot.summary,- )-- return updated-async def run_with_telemetry(*,diff --git a/openviking/telemetry/operation.py b/openviking/telemetry/operation.pyindex c8aa649df..a15b444d8 100644--- a/openviking/telemetry/operation.py+++ b/openviking/telemetry/operation.py@@ -46,12 +46,6 @@ class TelemetrySnapshot:telemetry_id: strsummary: Dict[str, Any]- def to_usage_dict(self) -> Dict[str, Any]:- return {- "duration_ms": self.summary.get("duration_ms", 0),- "token_total": self.summary.get("tokens", {}).get("total", 0),- }-def to_dict(self,*,diff --git a/openviking/telemetry/runtime.py b/openviking/telemetry/runtime.pyindex d88e7ec3f..f01cfca36 100644--- a/openviking/telemetry/runtime.py+++ b/openviking/telemetry/runtime.py@@ -55,10 +55,6 @@ class MemoryTelemetryMeter:class TelemetryRuntime:meter_instance: MemoryTelemetryMeter = field(default_factory=MemoryTelemetryMeter)- def meter(self) -> MemoryTelemetryMeter:- return self.meter_instance--_RUNTIME = TelemetryRuntime()diff --git a/openviking/telemetry/tracer.py b/openviking/telemetry/tracer.pyindex 74ac439c2..537058977 100644--- a/openviking/telemetry/tracer.py+++ b/openviking/telemetry/tracer.py@@ -218,41 +218,6 @@ def _setup_logging():_log_trace_internal_failure("[TRACER] failed to attach standard logging trace_id filter")-def init_tracer_from_config() -> Any:- """Initialize tracer from the legacy ov.conf telemetry.tracer config."""- try:- from openviking_cli.utils.config import get_openviking_config-- config = get_openviking_config()- tracer_cfg = config.telemetry.tracer-- if not tracer_cfg.enabled:- logger.info("[TRACER] disabled in config")- return None-- if not tracer_cfg.endpoint:- logger.warning("[TRACER] endpoint not configured")- return None-- headers = {- "x-tls-otel-tracetopic": tracer_cfg.topic,- "x-tls-otel-ak": tracer_cfg.ak,- "x-tls-otel-sk": tracer_cfg.sk,- "x-tls-otel-region": "cn-beijing",- }-- return init_tracer(- endpoint=tracer_cfg.endpoint,- service_name=tracer_cfg.service_name or "openviking",- protocol="grpc",- headers=headers,- enabled=tracer_cfg.enabled,- )- except Exception as e:- logger.warning(f"[TRACER] init from config failed: {e}")- return None--def init_tracer_from_server_config(server_config: Any) -> Any:"""Initialize tracer from server.observability.traces config.diff --git a/openviking/utils/media_processor.py b/openviking/utils/media_processor.pyindex 6d235ed11..ae13783c4 100644--- a/openviking/utils/media_processor.py+++ b/openviking/utils/media_processor.py@@ -5,7 +5,7 @@from pathlib import Pathfrom typing import TYPE_CHECKING, Optional-from openviking.parse import DocumentConverter, parse+from openviking.parse import parsefrom openviking.parse.accessors.base import SourceTypefrom openviking.parse.accessors.mime_types import IANA_MEDIA_TYPE_TO_EXTENSIONfrom openviking.parse.base import ParseResult@@ -87,11 +87,6 @@ class UnifiedResourceProcessor:self._vlm_processor = VLMProcessor()return self._vlm_processor- def _get_document_converter(self) -> DocumentConverter:- if self._document_converter is None:- self._document_converter = DocumentConverter()- return self._document_converter-def _get_accessor_registry(self):"""Lazy initialize AccessorRegistry for two-layer mode."""if self._accessor_registry is None:@@ -207,13 +202,3 @@ class UnifiedResourceProcessor:def _is_url(self, source: str) -> bool:"""Check if source is a URL."""return is_remote_resource_source(source)-- @staticmethod- def _is_feishu_url(source: str) -> bool:- """Backward-compatible Feishu URL detector used by legacy tests/callers."""- try:- from openviking.parse.accessors.feishu_accessor import FeishuAccessor-- return FeishuAccessor._is_feishu_url(source)- except Exception:- return Falsediff --git a/openviking/utils/model_retry.py b/openviking/utils/model_retry.pyindex 5361f5a4d..eac035643 100644--- a/openviking/utils/model_retry.py+++ b/openviking/utils/model_retry.py@@ -633,74 +633,3 @@ class OrderedCredentialSwitcher:self._active_idx = idxself._last_switch_time = time.monotonic()self._active_request_count = 0-- def on_failure(self, idx: int, error_class: str) -> bool:- """Record a failure and decide whether to advance to the next credential.-- Args:- idx: The credential index that failed- error_class: One of ERROR_CLASS_* constants-- Returns:- True if the caller should advance to the next credential (idx += 1)- False if fail-fast (caller should re-raise the original exception)- """- # Transient errors that have exhausted retries are treated as quota_exceeded- if error_class == ERROR_CLASS_TRANSIENT:- error_class = ERROR_CLASS_QUOTA_EXCEEDED-- with self._lock:- # Request-level errors fail fast: the same request fails on every- # credential of the same model, so switching credentials is useless.- if error_class in (- ERROR_CLASS_PERMANENT,- ERROR_CLASS_INPUT_TOO_LARGE,- ERROR_CLASS_CONTENT_SAFETY,- ):- logger.warning(- f"Credential {idx} failed with {error_class} (request-level), fail-fast"- )- return False-- if error_class == ERROR_CLASS_AUTH:- # Credential-level error (key invalid / no permission / overdue).- # In multi-credential mode, advance to the next credential since- # another credential may have a valid key / permission / balance.- # The last credential (or single-credential mode) fails fast.- if idx == self._active_idx and self._active_idx + 1 < self._n:- self._active_idx += 1- self._last_switch_time = time.monotonic()- self._active_request_count = 0- logger.warning(- f"Credential {idx} failed with auth error; "- f"advancing to {self._active_idx} (multi-credential mode)"- )- return True- logger.warning(f"Credential {idx} failed with auth error, fail-fast")- return False-- if error_class == ERROR_CLASS_QUOTA_EXCEEDED:- if idx == self._active_idx:- self._active_idx = min(self._active_idx + 1, self._n)- self._last_switch_time = time.monotonic()- self._active_request_count = 0- logger.warning(- f"Credential {idx} failed with quota_exceeded, advancing to {self._active_idx}"- )- return True-- # Unknown error class: default to advancing (be conservative)- if idx == self._active_idx:- self._active_idx = min(self._active_idx + 1, self._n)- self._last_switch_time = time.monotonic()- self._active_request_count = 0- logger.warning(- f"Credential {idx} failed with unknown error class: {error_class}, advancing to {self._active_idx}"- )- return True-- @property- def is_exhausted(self) -> bool:- """Check if all credentials are exhausted."""- with self._lock:- return self._active_idx >= self._ndiff --git a/openviking/utils/time_utils.py b/openviking/utils/time_utils.pyindex 037969c06..34b0b5b9e 100644--- a/openviking/utils/time_utils.py+++ b/openviking/utils/time_utils.py@@ -33,19 +33,6 @@ def format_iso8601(dt: datetime) -> str:return dt.isoformat(timespec="milliseconds").replace("+00:00", "Z")-def format_simplified(dt: datetime, now: datetime) -> str:- """- Format datetime in UTC: HH:MM:SS if same UTC date as *now*, else YYYY-MM-DD.- """- if dt.tzinfo is not None:- dt = dt.astimezone(timezone.utc)- if now.tzinfo is not None:- now = now.astimezone(timezone.utc)- if dt.date() == now.date():- return dt.strftime("%H:%M:%S")- return dt.strftime("%Y-%m-%d")--def get_current_timestamp() -> str:"""Get current timestamp in ISO 8601 format compatible with VikingDB.diff --git a/openviking_cli/session/user_id.py b/openviking_cli/session/user_id.pyindex 11c3d42d8..891d89a30 100644--- a/openviking_cli/session/user_id.py+++ b/openviking_cli/session/user_id.py@@ -55,9 +55,6 @@ class UserIdentifier(object):"""User-level space name."""return self._user_id- def memory_space_uri(self) -> str:- return f"viking://user/{self.user_space_name()}/memories"-def to_dict(self):return {"account_id": self._account_id,diff --git a/openviking_cli/setup_wizard.py b/openviking_cli/setup_wizard.pyindex 197f91a8b..3c579e9f2 100644--- a/openviking_cli/setup_wizard.py+++ b/openviking_cli/setup_wizard.py@@ -399,10 +399,6 @@ def _prompt_confirm(prompt: str, default: bool = True) -> bool:return raw in ("y", "yes")-def _configured_hint(enabled: bool) -> str:- """Return a non-sensitive summary label for setup output."""- return "configured" if enabled else _dim("(not configured)")-def _rule(title: str) -> None:"""Print a section rule (rich when available, plain bold header otherwise)."""@@ -883,71 +879,6 @@ def _ollama_vlm_config(vlm: VLMPreset) -> dict[str, Any]:}-def _build_local_config(- model_name: str,- dimension: int,- workspace: str,- model_path: str | None = None,- cache_dir: str | None = None,- vlm_config: dict[str, Any] | None = None,-) -> dict[str, Any]:- """Build ov.conf dict for llama.cpp local embedding setup."""- embedding_dense: dict[str, Any] = {- "provider": "local",- "model": model_name,- "dimension": dimension,- }- if model_path:- embedding_dense["model_path"] = model_path- if cache_dir:- embedding_dense["cache_dir"] = cache_dir-- config: dict[str, Any] = {- "storage": {"workspace": workspace},- "embedding": {"dense": embedding_dense},- }- if vlm_config:- config["vlm"] = vlm_config- return config---def _build_cloud_config(- provider: CloudProvider,- embedding_api_key: str,- embedding_model: str,- embedding_dim: int,- vlm_model: str,- workspace: str,- embedding_api_base: str | None = None,- vlm_provider: str | None = None,- vlm_api_key: str | None = None,- vlm_api_base: str | None = None,-) -> dict[str, Any]:- resolved_vlm_provider = vlm_provider or provider.provider- resolved_vlm_api_base = vlm_api_base or provider.default_api_base- vlm_config: dict[str, Any] = {- "provider": resolved_vlm_provider,- "model": vlm_model,- "api_base": resolved_vlm_api_base,- "temperature": 0.0,- "max_retries": 2,- }- if vlm_api_key:- vlm_config["api_key"] = vlm_api_key-- return {- "storage": {"workspace": workspace},- "embedding": {- "dense": {- "provider": provider.provider,- "model": embedding_model,- "api_key": embedding_api_key,- "api_base": embedding_api_base or provider.default_api_base,- "dimension": embedding_dim,- },- },- "vlm": vlm_config,- }def _build_query_planner_config(preset: QueryPlannerPreset) -> dict[str, Any]:@@ -1597,32 +1528,6 @@ def _wizard_two_step() -> tuple[dict[str, Any] | None | object, bool | None]:return config, ollama_running-def _wizard_cloud() -> tuple[dict[str, Any] | None | object, bool | None]:- """Cloud API model setup flow: embedding first, then VLM.-- Returns ``(config, ollama_running)``. ``config`` may also be the- ``_CUSTOM_SETUP`` sentinel when the user was routed to manual editing.- """- dense = _prompt_cloud_embedding()- if dense is _CUSTOM_SETUP:- return _CUSTOM_SETUP, None- if dense is None:- return None, None-- reuse_key = None- if isinstance(dense, dict) and dense.get("api_key"):- reuse_key = (dense["provider"], dense["api_key"])- vlm_config, ollama_running = _prompt_cloud_vlm(reuse_key=reuse_key)- if vlm_config is None:- return None, ollama_running-- config: dict[str, Any] = {- "storage": {"workspace": _workspace_path()},- "embedding": {"dense": dense},- "vlm": vlm_config,- }- return config, ollama_running-def _wizard_server(current: dict[str, Any] | None = None) -> dict[str, Any] | None:"""Prompt for server binding, port, and auth (root API key when remote).diff --git a/openviking_cli/utils/downloader.py b/openviking_cli/utils/downloader.pydeleted file mode 100644index b654f37e7..000000000--- a/openviking_cli/utils/downloader.py+++ /dev/null@@ -1,120 +0,0 @@-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.-# SPDX-License-Identifier: AGPL-3.0-"""-URL downloader for OpenViking.--Provides basic file download functionality.-For URL content parsing, use HTMLParser instead.-"""--import hashlib-import re-from pathlib import Path-from typing import Optional, Tuple--from openviking_cli.utils.logger import get_logger-from openviking_cli.utils.storage import StoragePath, get_storage--logger = get_logger(__name__)---def is_url(data: str) -> bool:- """Check if string is a URL."""- if not isinstance(data, str):- return False- return data.startswith(("http://", "https://"))---async def download_file(- url: str,- storage: Optional[StoragePath] = None,- timeout: float = 30.0,-) -> Tuple[Optional[Path], Optional[str]]:- """- Download a file from URL.-- Args:- url: URL to download- storage: Storage path manager- timeout: Request timeout-- Returns:- Tuple of (file_path, error_message)- """- try:- import httpx- except ImportError:- return None, "httpx is required. Install with: pip install httpx"-- storage = storage or get_storage()- storage.ensure_dirs()-- try:- headers = {- "User-Agent": (- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "- "AppleWebKit/537.36 (KHTML, like Gecko) "- "Chrome/120.0.0.0 Safari/537.36"- )- }-- async with httpx.AsyncClient(- timeout=timeout,- follow_redirects=True,- headers=headers,- ) as client:- response = await client.get(url)- response.raise_for_status()-- # Determine filename- content_type = response.headers.get("content-type", "").lower()- filename = _generate_filename(url)-- # Determine extension from content type- if "pdf" in content_type:- ext = ".pdf"- elif "html" in content_type:- ext = ".html"- elif "json" in content_type:- ext = ".json"- elif "text" in content_type:- ext = ".txt"- else:- ext = ".bin"-- file_path = storage.get_download_path(filename, ext)- file_path.write_bytes(response.content)-- logger.info(f"Downloaded: {url} -> {file_path}")- return file_path, None-- except Exception as e:- logger.error(f"Download failed for {url}: {e}")- return None, str(e)---def _generate_filename(url: str, max_length: int = 50) -> str:- """Generate filename from URL, hash & shorten if too long."""- from urllib.parse import urlparse-- parsed = urlparse(url)- path = parsed.path-- if path and path != "/":- name = Path(path).stem- name = re.sub(r"[^a-zA-Z0-9_\-\u4e00-\u9fff]", "_", name)- name = re.sub(r"_+", "_", name)- if not name:- return "download"- if len(name) > max_length:- hash_suffix = hashlib.sha256(url.encode()).hexdigest()[:8]- return f"{name[: max_length - 9]}_{hash_suffix}"- return name-- host = parsed.netloc.replace(".", "_")- if not host:- return "download"- if len(host) > max_length:- hash_suffix = hashlib.sha256(url.encode()).hexdigest()[:8]- return f"{host[: max_length - 9]}_{hash_suffix}"- return hostdiff --git a/openviking_cli/utils/storage.py b/openviking_cli/utils/storage.pyindex f7ea728d7..a242746c7 100644--- a/openviking_cli/utils/storage.py+++ b/openviking_cli/utils/storage.py@@ -9,7 +9,6 @@ Manages file storage in .openviking/ directory for media files (images, tables,import shutilfrom pathlib import Pathfrom typing import Optional-from uuid import uuid4from openviking_cli.utils.logger import get_logger@@ -52,11 +51,6 @@ class StoragePath:self.media_dir = self.openviking_dir / self.MEDIA_DIRself.downloads_dir = self.openviking_dir / self.DOWNLOADS_DIR- def ensure_dirs(self) -> None:- """Create necessary directories if they don't exist."""- self.media_dir.mkdir(parents=True, exist_ok=True)- self.downloads_dir.mkdir(parents=True, exist_ok=True)-def get_resource_media_dir(self, resource_name: str, media_type: str = "images") -> Path:"""Get directory for storing resource media files.@@ -135,24 +129,6 @@ class StoragePath:logger.debug(f"Saved table image: {file_path}")return file_path- def get_download_path(self, filename: Optional[str] = None, extension: str = ".pdf") -> Path:- """- Get path for downloading a file.-- Args:- filename: Optional filename- extension: File extension-- Returns:- Path for the download- """- self.ensure_dirs()-- if filename is None:- filename = str(uuid4())-- return self.downloads_dir / f"{filename}{extension}"-def cleanup_resource_media(self, resource_name: str) -> None:"""Remove all media files for a resource.diff --git a/tests/README.md b/tests/README.mdindex b1e2ff977..2098b953d 100644--- a/tests/README.md+++ b/tests/README.md@@ -149,7 +149,7 @@ Tests for session management (`Session` class).| File | Description | Key Test Cases ||------|-------------|----------------|| `test_session_lifecycle.py` | Session creation and persistence | Create new session, create with custom ID, multiple sessions; `load()` existing session, load nonexistent |-| `test_session_messages.py` | Message management | `add_message()` user/assistant roles, TextPart/ContextPart/ToolPart; `update_tool_part()` status transitions (running→completed/failed) |+| `test_session_messages.py` | Message management | `add_message()` user/assistant roles, TextPart/ContextPart/ToolPart || `test_session_usage.py` | Usage tracking | `used()` record context URIs, record skill usage, record both; multiple usage records per session || `test_session_commit.py` | Session commit | `commit()` success status, memory extraction trigger, message archiving, empty session handling, multiple commits, usage record persistence || `test_session_context.py` | Context for search | `get_context_for_search()` with `current_messages` + `latest_archive_overview`; latest completed archive only |diff --git a/tests/agfs/test_async_client.py b/tests/agfs/test_async_client.pyindex f5746903e..efcce6889 100644--- a/tests/agfs/test_async_client.py+++ b/tests/agfs/test_async_client.py@@ -31,7 +31,7 @@ async def test_async_agfs_client_hides_threadpool(monkeypatch):sync_agfs = _SyncAGFS()agfs = AsyncAGFSClient(sync_agfs)- assert agfs.sync_client is sync_agfs+ assert agfs._client is sync_agfsassert await agfs.write("/tasks/1", b"data") == ("write","/tasks/1",diff --git a/tests/agfs/test_viking_fs_git.py b/tests/agfs/test_viking_fs_git.pyindex 63ebf8c0c..c1307713e 100644--- a/tests/agfs/test_viking_fs_git.py+++ b/tests/agfs/test_viking_fs_git.py@@ -797,7 +797,6 @@ async def test_restore_returns_pollable_task_id(vfs, monkeypatch):from openviking.service.task_tracker import (TaskTracker,- reset_task_tracker,set_task_tracker,)@@ -847,7 +846,7 @@ async def test_restore_returns_pollable_task_id(vfs, monkeypatch):assert task.status.value == "completed"assert ("reindex_file", "viking://resources/proj/x.md") in spy.callsfinally:- reset_task_tracker()+ set_task_tracker(None)# =========================================================================diff --git a/tests/cli/test_setup_wizard.py b/tests/cli/test_setup_wizard.pyindex 8ac0cf07f..8b199ec1c 100644--- a/tests/cli/test_setup_wizard.py+++ b/tests/cli/test_setup_wizard.py@@ -8,8 +8,6 @@ from unittest.mock import MagicMock, patchfrom openviking_cli.setup_wizard import (_CUSTOM_SETUP,- _DEFAULT_CODEX_MODEL,- _DEFAULT_GLM_MODEL,_DEFAULT_KIMI_MODEL,_GO_BACK,_SKIP_VLM,@@ -18,8 +16,6 @@ from openviking_cli.setup_wizard import (LOCAL_GGUF_PRESETS,QUERY_PLANNER_PRESETS,VLM_PRESETS,- _build_cloud_config,- _build_local_config,_build_ollama_config,_build_query_planner_config,_config_path,@@ -34,7 +30,6 @@ from openviking_cli.setup_wizard import (_prompt_required_input,_prompt_required_int,_update_existing_config,- _wizard_cloud,_wizard_ollama,_wizard_query_planner,_wizard_server,@@ -154,210 +149,6 @@ class TestConfigBuilding:# ~5k-token extraction prompt) and thinking disabled.assert vlm_cfg["extra_request_body"] == {"num_ctx": 16384, "think": False}- def test_cloud_config_structure(self):- provider = CLOUD_PROVIDERS[2] # OpenAI-- config = _build_cloud_config(- provider,- embedding_api_key="sk-test",- embedding_model="text-embedding-3-small",- embedding_dim=1536,- vlm_model="gpt-4o-mini",- workspace="/tmp/ov_test",- vlm_api_key="sk-test",- )-- assert config["embedding"]["dense"]["api_key"] == "sk-test"- assert config["vlm"]["api_key"] == "sk-test"- assert config["vlm"]["provider"] == "openai"-- def test_cloud_config_supports_codex_vlm(self):- provider = CLOUD_PROVIDERS[0] # VolcEngine-- config = _build_cloud_config(- provider,- embedding_api_key="ve-test",- embedding_model="doubao-embedding-vision-250615",- embedding_dim=1024,- vlm_model="gpt-5.3-codex",- workspace="/tmp/ov_test",- vlm_provider="openai-codex",- vlm_api_base="https://chatgpt.com/backend-api/codex",- )-- assert config["embedding"]["dense"]["provider"] == "volcengine"- assert config["embedding"]["dense"]["api_key"] == "ve-test"- assert config["vlm"]["provider"] == "openai-codex"- assert config["vlm"]["model"] == "gpt-5.3-codex"- assert config["vlm"]["api_base"] == "https://chatgpt.com/backend-api/codex"- assert "api_key" not in config["vlm"]-- def test_cloud_wizard_codex_uses_default_base_and_workspace(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 4],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- "doubao-embedding-vision-250615",- "gpt-5.3-codex",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1024,- ):- with patch("openviking_cli.setup_wizard._ensure_codex_auth", return_value=True):- config, _ = _wizard_cloud()-- assert config is not None- assert config["storage"]["workspace"] == _workspace_path()- assert config["vlm"]["provider"] == "openai-codex"- assert config["vlm"]["api_base"] == "https://chatgpt.com/backend-api/codex"- assert "api_key" not in config["vlm"]-- def test_cloud_wizard_supports_openai_vlm_option(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[3, 3],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "embed-test",- "text-embedding-3-small",- "openai-vlm-test",- "gpt-5.4",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1536,- ):- # Same provider on both sides → decline the key-reuse offer- # so the VLM key comes from the prompt sequence.- with patch(- "openviking_cli.setup_wizard._prompt_confirm",- return_value=False,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["storage"]["workspace"] == _workspace_path()- assert config["vlm"]["provider"] == "openai"- assert config["vlm"]["api_key"] == "openai-vlm-test"- assert config["vlm"]["api_base"] == CLOUD_PROVIDERS[2].default_api_base-- def test_cloud_wizard_supports_volcengine_vlm_option(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[3, 1],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "embed-test",- "text-embedding-3-small",- "ve-vlm-test",- "doubao-seed-2-0-code-preview-260215",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1536,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["storage"]["workspace"] == _workspace_path()- assert config["vlm"]["provider"] == "volcengine"- assert config["vlm"]["api_key"] == "ve-vlm-test"- assert config["vlm"]["api_base"] == CLOUD_PROVIDERS[0].default_api_base- assert config["vlm"]["model"] == "doubao-seed-2-0-code-preview-260215"-- def test_cloud_wizard_supports_byteplus_vlm_option(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[3, 2],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "embed-test",- "text-embedding-3-small",- "bp-vlm-test",- "doubao-seed-2-0-code-preview-260215",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1536,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["storage"]["workspace"] == _workspace_path()- assert config["vlm"]["provider"] == "volcengine"- assert config["vlm"]["api_key"] == "bp-vlm-test"- assert config["vlm"]["api_base"] == CLOUD_PROVIDERS[1].default_api_base- assert config["vlm"]["api_base"] == "https://ark.ap-southeast.bytepluses.com/api/v3"-- def test_cloud_wizard_supports_kimi_vlm(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 5],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- "doubao-embedding-vision-250615",- "kimi-test",- "kimi-code",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1024,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["vlm"]["provider"] == "kimi"- assert config["vlm"]["api_key"] == "kimi-test"- assert config["vlm"]["model"] == "kimi-code"- assert config["vlm"]["api_base"] == "https://api.kimi.com/coding"- assert config["storage"]["workspace"] == _workspace_path()-- def test_cloud_wizard_supports_glm_vlm(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 6],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- "doubao-embedding-vision-250615",- "glm-test",- "glm-4.6v",- ],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=1024,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["vlm"]["provider"] == "glm"- assert config["vlm"]["api_key"] == "glm-test"- assert config["vlm"]["model"] == "glm-4.6v"- assert config["vlm"]["api_base"] == "https://api.z.ai/api/coding/paas/v4"- assert config["storage"]["workspace"] == _workspace_path()-def test_prompt_required_input_uses_default_on_empty(self):with patch("builtins.input", return_value=""):value = _prompt_required_input("Model", default=_DEFAULT_KIMI_MODEL)@@ -370,109 +161,6 @@ class TestConfigBuilding:assert value == 1024- def test_cloud_wizard_uses_requested_defaults_when_inputs_are_empty(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 4],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- CLOUD_PROVIDERS[0].default_embedding_model,- _DEFAULT_CODEX_MODEL,- ],- ) as prompt_input:- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=CLOUD_PROVIDERS[0].default_embedding_dim,- ) as prompt_int:- with patch("openviking_cli.setup_wizard._ensure_codex_auth", return_value=True):- config, _ = _wizard_cloud()-- assert config is not None- assert config["embedding"]["dense"]["model"] == CLOUD_PROVIDERS[0].default_embedding_model- assert config["embedding"]["dense"]["dimension"] == CLOUD_PROVIDERS[0].default_embedding_dim- assert config["vlm"]["model"] == _DEFAULT_CODEX_MODEL- prompt_input.assert_any_call("Model", default=CLOUD_PROVIDERS[0].default_embedding_model)- prompt_input.assert_any_call("Model", default=_DEFAULT_CODEX_MODEL)- # Known default model → dimension auto-filled without prompting.- prompt_int.assert_not_called()-- def test_cloud_wizard_kimi_uses_requested_default_model(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 5],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- CLOUD_PROVIDERS[0].default_embedding_model,- "kimi-test",- _DEFAULT_KIMI_MODEL,- ],- ) as prompt_input:- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=CLOUD_PROVIDERS[0].default_embedding_dim,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["vlm"]["model"] == _DEFAULT_KIMI_MODEL- prompt_input.assert_any_call("Model", default=_DEFAULT_KIMI_MODEL)-- def test_cloud_wizard_glm_uses_requested_default_model(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[1, 6],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "ve-test",- CLOUD_PROVIDERS[0].default_embedding_model,- "glm-test",- _DEFAULT_GLM_MODEL,- ],- ) as prompt_input:- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=CLOUD_PROVIDERS[0].default_embedding_dim,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["vlm"]["model"] == _DEFAULT_GLM_MODEL- prompt_input.assert_any_call("Model", default=_DEFAULT_GLM_MODEL)-- def test_cloud_wizard_volcengine_uses_requested_default_model(self):- with patch(- "openviking_cli.setup_wizard._prompt_choice",- side_effect=[3, 1],- ):- with patch(- "openviking_cli.setup_wizard._prompt_required_input",- side_effect=[- "embed-test",- CLOUD_PROVIDERS[2].default_embedding_model,- "ve-vlm-test",- CLOUD_PROVIDERS[0].default_vlm_model,- ],- ) as prompt_input:- with patch(- "openviking_cli.setup_wizard._prompt_required_int",- return_value=CLOUD_PROVIDERS[2].default_embedding_dim,- ):- config, _ = _wizard_cloud()-- assert config is not None- assert config["vlm"]["provider"] == "volcengine"- assert config["vlm"]["api_key"] == "ve-vlm-test"- assert config["vlm"]["model"] == CLOUD_PROVIDERS[0].default_vlm_model- prompt_input.assert_any_call("Model", default=CLOUD_PROVIDERS[0].default_vlm_model)-def test_all_presets_valid(self):"""Every preset should produce a config with required fields."""for emb in EMBEDDING_PRESETS:@@ -747,78 +435,6 @@ class TestConfigWriting:# ----------------------------------------------------------------------------class TestLocalConfigBuilding:- def test_local_config_with_builtin_model(self):- preset = LOCAL_GGUF_PRESETS[0]- config = _build_local_config(- model_name=preset.model_name,- dimension=preset.dimension,- workspace="/tmp/ov_test",- )-- assert config["storage"]["workspace"] == "/tmp/ov_test"-- dense = config["embedding"]["dense"]- assert dense["provider"] == "local"- assert dense["model"] == "bge-small-zh-v1.5-f16"- assert dense["dimension"] == 512- assert "model_path" not in dense- assert "vlm" not in config-- def test_local_config_with_ollama_vlm(self):- config = _build_local_config(- model_name="bge-small-zh-v1.5-f16",- dimension=512,- workspace="/tmp/ov_test",- vlm_config={- "provider": "litellm",- "model": "ollama/qwen3.5:4b",- "api_key": "no-key",- "api_base": "http://localhost:11434",- },- )-- assert config["embedding"]["dense"]["provider"] == "local"- assert config["vlm"]["provider"] == "litellm"- assert config["vlm"]["model"] == "ollama/qwen3.5:4b"-- def test_local_config_with_cloud_vlm(self):- config = _build_local_config(- model_name="bge-small-zh-v1.5-f16",- dimension=512,- workspace="/tmp/ov_test",- vlm_config={- "provider": "openai",- "model": "gpt-4o-mini",- "api_key": "sk-test",- "api_base": "https://api.openai.com/v1",- },- )-- assert config["embedding"]["dense"]["provider"] == "local"- assert config["vlm"]["provider"] == "openai"- assert config["vlm"]["model"] == "gpt-4o-mini"-- def test_local_config_without_vlm(self):- config = _build_local_config(- model_name="bge-small-zh-v1.5-f16",- dimension=512,- workspace="/tmp/ov_test",- )-- assert "vlm" not in config-- def test_local_config_with_cache_dir(self):- config = _build_local_config(- model_name="bge-small-zh-v1.5-f16",- dimension=512,- workspace="/tmp/ov_test",- cache_dir="/custom/cache",- )-- assert config["embedding"]["dense"]["cache_dir"] == "/custom/cache"--class TestLlamaCppDetection:def test_llamacpp_installed(self):with patch.dict("sys.modules", {"llama_cpp": MagicMock()}):@@ -1243,20 +859,6 @@ class TestQueryPlannerAlreadyConfigured:class TestCloudOtherRoutesToCustom:- def test_returns_custom_sentinel(self):- with (- patch(- "openviking_cli.setup_wizard._prompt_choice",- return_value=len(CLOUD_PROVIDERS) + 1,- ),- patch("openviking_cli.setup_wizard._wizard_custom") as mock_custom,- patch("builtins.print"),- ):- result, _ = _wizard_cloud()-- assert result is _CUSTOM_SETUP- mock_custom.assert_called_once()-def test_run_init_exits_cleanly_on_custom_sentinel(self, tmp_path):config_path = tmp_path / "ov.conf"with (diff --git a/tests/cli/test_user_identifier.py b/tests/cli/test_user_identifier.pyindex 532126d40..f084c7ab2 100644--- a/tests/cli/test_user_identifier.py+++ b/tests/cli/test_user_identifier.py@@ -19,12 +19,6 @@ class TestUserIdentifier:u2 = UserIdentifier("acct", "beta")assert u1.user_space_name() != u2.user_space_name()- def test_memory_space_uri_uses_user_space(self):- u = UserIdentifier("acct", "user1")- assert u.user_space_name() == "user1"- assert u.memory_space_uri() == "viking://user/user1/memories"- assert u.to_dict() == {"account_id": "acct", "user_id": "user1"}-@pytest.mark.parametrize("user_id", [".", "..", "team:alice"])def test_user_id_rejects_unsafe_path_segments(self, user_id):with pytest.raises(ValueError):diff --git a/tests/integration/test_agent_memory_e2e.py b/tests/integration/test_agent_memory_e2e.pyindex 8e81dcf2a..87307d22e 100644--- a/tests/integration/test_agent_memory_e2e.py+++ b/tests/integration/test_agent_memory_e2e.py@@ -34,10 +34,11 @@ from typing import Dict, Iterator, List, Tupleimport pytestfrom openviking.client.local import LocalClient+from openviking.server.config import load_server_configfrom openviking.session.memory.session_extract_context_provider import SessionExtractContextProviderfrom openviking.session.memory.utils import MemoryFileUtilsfrom openviking.telemetry import tracer-from openviking.telemetry.tracer import init_tracer_from_config+from openviking.telemetry.tracer import init_tracer_from_server_configfrom openviking_cli.session.user_id import UserIdentifierfrom openviking_cli.utils import run_async@@ -260,10 +261,10 @@ class TestAgentMemoryE2E:- After Round 2: trajectory count grows; experience source_trajectories reference extracted trajectories."""pytest.importorskip("opentelemetry")- initialized = init_tracer_from_config()+ initialized = init_tracer_from_server_config(load_server_config())if initialized is None or not tracer.is_enabled():pytest.fail(- "failed to initialize tracer from ov.conf; please check legacy telemetry.tracer"+ "failed to initialize tracer; please check server.observability.traces")trajectories_dir = "viking://user/alice/memories/trajectories"diff --git a/tests/integration/test_watch_e2e.py b/tests/integration/test_watch_e2e.pyindex f2eaad5fa..db89ca71c 100644--- a/tests/integration/test_watch_e2e.py+++ b/tests/integration/test_watch_e2e.py@@ -2,7 +2,6 @@# SPDX-License-Identifier: AGPL-3.0"""End-to-end tests for resource watch functionality."""-import asyncioimport shutilfrom pathlib import Path@@ -10,7 +9,6 @@ import pytestimport pytest_asynciofrom openviking import AsyncOpenViking-from openviking.resource.watch_scheduler import WatchSchedulerfrom openviking.server.identity import RequestContext, Rolefrom openviking.service.resource_service import ResourceServicefrom openviking_cli.exceptions import ConflictError@@ -260,111 +258,6 @@ class TestWatchE2EConflictDetection:class TestWatchE2ESchedulerExecution:"""End-to-end tests for scheduler execution."""- @pytest.mark.asyncio- async def test_scheduler_executes_watch_task(self, temp_dir: Path, watch_test_file: Path):- """Test that scheduler executes watch tasks on schedule."""- execution_count = 0-- class MockResourceProcessor:- async def process_resource(self, **kwargs):- nonlocal execution_count- execution_count += 1- return {"root_uri": kwargs.get("to", "viking://resources/test")}-- class MockSkillProcessor:- async def process_skill(self, **kwargs):- return {"status": "ok"}-- class MockVikingDB:- pass-- resource_service = ResourceService(- vikingdb=MockVikingDB(),- viking_fs=object(),- resource_processor=MockResourceProcessor(),- skill_processor=MockSkillProcessor(),- watch_scheduler=None,- )- scheduler = WatchScheduler(- resource_service=resource_service,- viking_fs=None,- check_interval=0.1,- )- await scheduler.start()-- watch_manager = scheduler.watch_manager-- task = await watch_manager.create_task(- path=str(watch_test_file),- to_uri="viking://resources/scheduler_test",- reason="Scheduler test",- watch_interval=0.002,- )-- assert task.is_active is True-- await asyncio.sleep(0.3)-- await scheduler.stop()-- assert execution_count >= 1-- await watch_manager.clear_all_tasks()-- @pytest.mark.asyncio- async def test_scheduler_updates_execution_time(self, temp_dir: Path, watch_test_file: Path):- """Test that scheduler updates execution time after task execution."""-- class MockResourceProcessor:- async def process_resource(self, **kwargs):- return {"root_uri": kwargs.get("to", "viking://resources/test")}-- class MockSkillProcessor:- async def process_skill(self, **kwargs):- return {"status": "ok"}-- class MockVikingDB:- pass-- resource_service = ResourceService(- vikingdb=MockVikingDB(),- viking_fs=object(),- resource_processor=MockResourceProcessor(),- skill_processor=MockSkillProcessor(),- watch_scheduler=None,- )-- scheduler = WatchScheduler(- resource_service=resource_service,- viking_fs=None,- check_interval=0.1,- )- await scheduler.start()-- watch_manager = scheduler.watch_manager-- task = await watch_manager.create_task(- path=str(watch_test_file),- to_uri="viking://resources/execution_time_test",- reason="Execution time test",- watch_interval=0.002,- )-- assert task.last_execution_time is None-- await asyncio.sleep(0.3)-- await scheduler.stop()-- updated_task = await watch_manager.get_task(task.task_id)- assert updated_task is not None- assert updated_task.last_execution_time is not None- assert updated_task.next_execution_time is not None- assert updated_task.next_execution_time > updated_task.last_execution_time-- await watch_manager.clear_all_tasks()--class TestWatchE2EMultipleResources:"""End-to-end tests for multiple resources."""diff --git a/tests/metrics/core/test_registry.py b/tests/metrics/core/test_registry.pyindex ecd89240b..d17e238d7 100644--- a/tests/metrics/core/test_registry.py+++ b/tests/metrics/core/test_registry.py@@ -64,15 +64,6 @@ def test_counter_only_increases():c.inc(amount=-1)-def test_gauge_inc_dec(registry, render_prometheus):- g = registry.gauge("openviking_gauge")- g.set(1)- g.inc()- g.dec(0.5)- text = render_prometheus(registry)- assert "openviking_gauge 1.5" in text--def test_histogram_boundary_bucket(registry, render_prometheus):h = registry.histogram("openviking_latency_seconds", buckets=(0.05, 0.1))h.observe(0.05)diff --git a/tests/misc/test_vectordb_engine_loader.py b/tests/misc/test_vectordb_engine_loader.pyindex 7885254d5..f30f68f16 100644--- a/tests/misc/test_vectordb_engine_loader.py+++ b/tests/misc/test_vectordb_engine_loader.py@@ -38,7 +38,6 @@ def _load_engine_module(VolatileStore=f"VolatileStore:{backend_name}",),)-monkeypatch.setitem(sys.modules,"openviking.storage.vectordb.engine._x86_caps",@@ -202,194 +201,3 @@ def test_engine_loader_rejects_forced_unsupported_variant(monkeypatch):cpu_variants={"x86_sse3", "x86_avx2"},env_variant="x86_avx512",)---def test_engine_loader_wraps_abi3_backend_with_python_api(monkeypatch):- calls = []- engine_handle = object()- store_handle = object()- schema_handle = object()- bytes_row_handle = object()-- backend = types.SimpleNamespace(- BACKEND_NAME="native",- _ENGINE_BACKEND_API="abi3-v1",- _new_schema=lambda fields: calls.append(("new_schema", fields)) or schema_handle,- _schema_get_total_byte_length=lambda handle: calls.append(("schema_total", handle)) or 123,- _new_bytes_row=lambda handle: calls.append(("new_bytes_row", handle)) or bytes_row_handle,- _bytes_row_serialize=lambda handle, row: (- calls.append(("bytes_row_serialize", handle, row)) or b"blob"- ),- _bytes_row_serialize_batch=lambda handle, rows: (- calls.append(("bytes_row_serialize_batch", handle, rows)) or [b"blob-a", b"blob-b"]- ),- _bytes_row_deserialize=lambda handle, payload: (- calls.append(("bytes_row_deserialize", handle, payload)) or {"id": 42, "name": "viking"}- ),- _bytes_row_deserialize_field=lambda handle, payload, field_name: (- calls.append(("bytes_row_deserialize_field", handle, payload, field_name))- or (42 if field_name == "id" else "viking")- ),- _new_index_engine=lambda config: (- calls.append(("new_index_engine", config)) or engine_handle- ),- _index_engine_add_data=lambda handle, items: calls.append(("add_data", handle, items)) or 3,- _index_engine_delete_data=lambda handle, items: (- calls.append(("delete_data", handle, items)) or 2- ),- _index_engine_search=lambda handle, req: (- calls.append(("search", handle, req))- or {- "result_num": 2,- "labels": [101, 202],- "scores": [0.9, 0.8],- "extra_json": '{"ok":true}',- }- ),- _index_engine_search_with_filter_token=lambda handle, req, token: (- calls.append(("search_with_filter_token", handle, req, token))- or {- "result_num": 1,- "labels": [101],- "scores": [0.9],- "extra_json": "",- }- ),- _index_engine_set_filter_layout=lambda handle, labels: (- calls.append(("set_filter_layout", handle, labels)) or 0- ),- _index_engine_evaluate_filter=lambda handle, dsl: (- calls.append(("evaluate_filter", handle, dsl))- or {"eligible_count": 1, "bitset_words": [4]}- ),- _index_engine_evaluate_filter_cached=lambda handle, dsl, max_candidates: (- calls.append(("evaluate_filter_cached", handle, dsl, max_candidates))- or {- "eligible_count": 1,- "bitset_words": [4],- "native_filter_token": 17,- }- ),- _index_engine_dump=lambda handle, path: calls.append(("dump", handle, path)) or 11,- _index_engine_get_state=lambda handle: (- calls.append(("get_state", handle)) or {"update_timestamp": 123, "element_count": 7}- ),- _new_persist_store=lambda path: calls.append(("new_persist_store", path)) or store_handle,- _new_volatile_store=lambda: calls.append(("new_volatile_store",)) or store_handle,- _store_exec_op=lambda handle, ops: calls.append(("store_exec_op", handle, ops)) or 1,- _store_get_data=lambda handle, keys: (- calls.append(("store_get_data", handle, keys)) or [b"one", b"two"]- ),- _store_put_data=lambda handle, keys, values: (- calls.append(("store_put_data", handle, keys, values)) or 0- ),- _store_delete_data=lambda handle, keys: (- calls.append(("store_delete_data", handle, keys)) or 0- ),- _store_clear_data=lambda handle: calls.append(("store_clear_data", handle)) or 0,- _store_seek_range=lambda handle, start, end: (- calls.append(("store_seek_range", handle, start, end)) or [("aa", b"11"), ("ab", b"22")]- ),- _init_logging=lambda level, output, fmt: calls.append(("init_logging", level, output, fmt)),- )-- module = _load_engine_module_with_backend(- monkeypatch,- machine="arm64",- backend_name="native",- backend_module=backend,- )-- assert module.ENGINE_VARIANT == "native"- assert module.AVAILABLE_ENGINE_VARIANTS == ("native",)-- schema = module.Schema(- [- {"name": "id", "data_type": module.FieldType.int64, "id": 0},- {"name": "name", "data_type": module.FieldType.string, "id": 1},- ]- )- assert schema.get_total_byte_length() == 123- row = module.BytesRow(schema)- blob = row.serialize({"id": 42, "name": "viking"})- assert blob == b"blob"- assert row.serialize_batch([{"id": 1}, {"id": 2}]) == [b"blob-a", b"blob-b"]- assert row.deserialize_field(blob, "id") == 42- assert row.deserialize(blob)["name"] == "viking"-- module.init_logging("INFO", "stdout")- index = module.IndexEngine("config-json")-- add_req = module.AddDataRequest()- add_req.label = 9- add_req.vector = [0.1, 0.2]- add_req.fields_str = '{"name":"x"}'- assert index.add_data([add_req]) == 3-- search_req = module.SearchRequest()- search_req.query = [0.5, 0.4]- search_req.topk = 5- search_req.dsl = "{}"- result = index.search(search_req)- assert result.labels == [101, 202]- assert result.scores == [0.9, 0.8]- assert result.extra_json == '{"ok":true}'-- assert index.set_filter_layout([202, 999, 101]) == 0- filter_result = index.evaluate_filter('{"op":"must"}')- assert filter_result.eligible_count == 1- assert filter_result.bitset_words == [4]- assert filter_result.native_filter_token == 0-- cached_filter_result = index.evaluate_filter('{"op":"must"}', max_cached_candidates=10)- assert cached_filter_result.native_filter_token == 17- token_search_result = index.search_with_filter_token(search_req, 17)- assert token_search_result is not None- assert token_search_result.labels == [101]-- # A source checkout paired with an older native module keeps the original- # evaluate + search path instead of failing during a rolling upgrade.- del backend._index_engine_evaluate_filter_cached- del backend._index_engine_search_with_filter_token- fallback_filter_result = index.evaluate_filter('{"op":"must"}', max_cached_candidates=10)- assert fallback_filter_result.native_filter_token == 0- assert index.search_with_filter_token(search_req, 17) is None-- state = index.get_state()- assert state.update_timestamp == 123- assert state.element_count == 7- assert state.data_count == 7-- store = module.PersistStore("/tmp/test-store")- assert store.get_data(["k1", "k2"]) == [b"one", b"two"]- assert store.seek_range("a", "b") == [("aa", b"11"), ("ab", b"22")]-- op = module.StorageOp()- op.type = module.StorageOpType.PUT- op.key = "abc"- op.value = b"payload"- assert store.exec_op([op]) == 1-- assert ("new_index_engine", "config-json") in calls- assert ("new_persist_store", "/tmp/test-store") in calls- search_calls = [entry for entry in calls if entry[0] == "search"]- assert len(search_calls) == 1- _, handle, payload = search_calls[0]- assert handle is engine_handle- assert payload is search_req- assert payload.query == [0.5, 0.4]- assert payload.topk == 5- assert payload.dsl == "{}"-- add_calls = [entry for entry in calls if entry[0] == "add_data"]- assert len(add_calls) == 1- _, handle, payload = add_calls[0]- assert handle is engine_handle- assert payload == [add_req]- assert payload[0].fields_str == '{"name":"x"}'-- new_schema_calls = [entry for entry in calls if entry[0] == "new_schema"]- assert len(new_schema_calls) == 1- assert ("schema_total", schema_handle) in calls- assert ("new_bytes_row", schema_handle) in calls- assert ("bytes_row_serialize", bytes_row_handle, {"id": 42, "name": "viking"}) in callsdiff --git a/tests/observability/test_events.py b/tests/observability/test_events.pyindex 5ea01c463..cf7e70bc8 100644--- a/tests/observability/test_events.py+++ b/tests/observability/test_events.py@@ -9,16 +9,16 @@ from openviking.observability.context import (reset_root_observability_context,)from openviking.observability.events import (+ _GLOBAL_EVENT_BUS,ObservabilityEvent,register_event_subscriber,- reset_event_bus_for_tests,try_publish_event,)from openviking.telemetry.span_models import RootSpanAttributesdef test_event_bus_fans_out_and_enriches_root_metadata():- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()seen_a: list[ObservabilityEvent] = []seen_b: list[ObservabilityEvent] = []register_event_subscriber("a", seen_a.append)@@ -36,7 +36,7 @@ def test_event_bus_fans_out_and_enriches_root_metadata():try_publish_event("demo.event", {"value": 1})finally:reset_root_observability_context(token)- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()assert len(seen_a) == 1assert len(seen_b) == 1@@ -48,13 +48,13 @@ def test_event_bus_fans_out_and_enriches_root_metadata():def test_metric_datasource_publishes_to_shared_bus_without_metrics_init():- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()seen: list[ObservabilityEvent] = []register_event_subscriber("usage-audit-test", seen.append)try:EventMetricDataSource._emit("demo.metric", {"value": 3})finally:- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()assert len(seen) == 1assert seen[0].event_name == "demo.metric"diff --git a/tests/observability/test_usage_audit_runtime.py b/tests/observability/test_usage_audit_runtime.pyindex 9669dd39d..3e1a5d718 100644--- a/tests/observability/test_usage_audit_runtime.py+++ b/tests/observability/test_usage_audit_runtime.py@@ -7,7 +7,7 @@ from types import SimpleNamespaceimport pytest-from openviking.observability.events import reset_event_bus_for_tests, try_publish_event+from openviking.observability.events import _GLOBAL_EVENT_BUS, try_publish_eventfrom openviking.observability.usage_audit import (init_usage_audit_from_server_config,shutdown_usage_audit,@@ -17,7 +17,7 @@ from openviking.server.config import ObservabilityConfig, ServerConfig, UsageAud@pytest.mark.asyncioasync def test_usage_audit_runtime_subscribes_to_shared_event_bus(tmp_path):- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()app = SimpleNamespace(state=SimpleNamespace())config = ServerConfig(observability=ObservabilityConfig(@@ -55,7 +55,7 @@ async def test_usage_audit_runtime_subscribes_to_shared_event_bus(tmp_path):audit = await runtime.store.query_audit_logs(account_id="acct-runtime")finally:await shutdown_usage_audit(app=app)- reset_event_bus_for_tests()+ _GLOBAL_EVENT_BUS.clear()assert retrievals["find"] == 1assert audit["total"] == 1diff --git a/tests/parse/test_feishu_parser.py b/tests/parse/test_feishu_parser.pyindex d2c92877e..24272fdfb 100644--- a/tests/parse/test_feishu_parser.py+++ b/tests/parse/test_feishu_parser.py@@ -112,39 +112,6 @@ class TestParseFeishuUrl:FeishuParser._parse_feishu_url("https://evil.example/docx/doxcnABC123")-class TestIsFeishuUrl:- def test_feishu_docx(self):- from openviking.utils.media_processor import UnifiedResourceProcessor-- assert UnifiedResourceProcessor._is_feishu_url("https://example.feishu.cn/docx/abc123")-- def test_larksuite(self):- from openviking.utils.media_processor import UnifiedResourceProcessor-- assert UnifiedResourceProcessor._is_feishu_url(- "https://example.larksuite.com/sheets/abc123"- )-- def test_larkoffice(self):- from openviking.utils.media_processor import UnifiedResourceProcessor-- assert UnifiedResourceProcessor._is_feishu_url(- "https://example.larkoffice.com/wiki/wikicn123"- )-- def test_non_feishu_url(self):- from openviking.utils.media_processor import UnifiedResourceProcessor-- assert not UnifiedResourceProcessor._is_feishu_url("https://github.com/foo/bar")-- def test_feishu_non_doc_path(self):- from openviking.utils.media_processor import UnifiedResourceProcessor-- assert not UnifiedResourceProcessor._is_feishu_url(- "https://example.feishu.cn/profile/settings"- )--class TestBlockToMarkdown:"""Test attribute-driven block-to-markdown conversion."""diff --git a/tests/parse/test_image_ocr.py b/tests/parse/test_image_ocr.pydeleted file mode 100644index c4cc573c8..000000000--- a/tests/parse/test_image_ocr.py+++ /dev/null@@ -1,99 +0,0 @@-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.-# SPDX-License-Identifier: AGPL-3.0-"""Tests for OCR text extraction in ImageParser."""--import io-from unittest.mock import MagicMock, patch--import pytest-from PIL import Image--from openviking.parse.parsers.media.image import ImageParser-from openviking_cli.utils.config.parser_config import ImageConfig---def _create_test_image(width: int = 100, height: int = 50) -> bytes:- """Create a simple test image and return as bytes."""- img = Image.new("RGB", (width, height), color="white")- buf = io.BytesIO()- img.save(buf, format="PNG")- return buf.getvalue()---async def test_ocr_extract_returns_text():- """OCR extraction returns text when pytesseract finds text in the image."""- parser = ImageParser(config=ImageConfig(enable_ocr=True))- image_bytes = _create_test_image()-- with patch.dict("sys.modules", {"pytesseract": MagicMock()}):- import sys-- mock_pytesseract = sys.modules["pytesseract"]- mock_pytesseract.image_to_string.return_value = "Hello World"-- result = await parser._ocr_extract(image_bytes, lang="eng")- assert result == "Hello World"- mock_pytesseract.image_to_string.assert_called_once()---async def test_ocr_extract_returns_none_for_empty_text():- """OCR extraction returns None when no text is found in the image."""- parser = ImageParser(config=ImageConfig(enable_ocr=True))- image_bytes = _create_test_image()-- with patch.dict("sys.modules", {"pytesseract": MagicMock()}):- import sys-- mock_pytesseract = sys.modules["pytesseract"]- mock_pytesseract.image_to_string.return_value = " "-- result = await parser._ocr_extract(image_bytes, lang="eng")- assert result is None---async def test_ocr_extract_returns_none_when_pytesseract_not_installed():- """OCR extraction returns None gracefully when pytesseract is not installed."""- parser = ImageParser(config=ImageConfig(enable_ocr=True))- image_bytes = _create_test_image()-- # Ensure pytesseract is not importable- with patch.dict("sys.modules", {"pytesseract": None}):- result = await parser._ocr_extract(image_bytes, lang="eng")- assert result is None---async def test_ocr_extract_handles_exception():- """OCR extraction returns None and logs error when pytesseract raises."""- parser = ImageParser(config=ImageConfig(enable_ocr=True))- image_bytes = _create_test_image()-- with patch.dict("sys.modules", {"pytesseract": MagicMock()}):- import sys-- mock_pytesseract = sys.modules["pytesseract"]- mock_pytesseract.image_to_string.side_effect = RuntimeError("Tesseract not found")-- result = await parser._ocr_extract(image_bytes, lang="eng")- assert result is None---async def test_ocr_extract_passes_language_parameter():- """OCR extraction passes the lang parameter to pytesseract."""- parser = ImageParser(config=ImageConfig(enable_ocr=True, ocr_lang="chi_sim"))- image_bytes = _create_test_image()-- with patch.dict("sys.modules", {"pytesseract": MagicMock()}):- import sys-- mock_pytesseract = sys.modules["pytesseract"]- mock_pytesseract.image_to_string.return_value = "你好世界"-- result = await parser._ocr_extract(image_bytes, lang="chi_sim")- assert result == "你好世界"- call_args = mock_pytesseract.image_to_string.call_args- assert call_args[1]["lang"] == "chi_sim"diff --git a/tests/parse/test_parser_config_wiring.py b/tests/parse/test_parser_config_wiring.pyindex 8ec9caed6..cf25b215c 100644--- a/tests/parse/test_parser_config_wiring.py+++ b/tests/parse/test_parser_config_wiring.py@@ -3,60 +3,13 @@from openviking.parse.parsers.feishu import FeishuParserfrom openviking.parse.parsers.html import HTMLParserfrom openviking.parse.parsers.pdf import PDFParser-from openviking.parse.registry import ParserRegistryfrom openviking_cli.utils.config.parser_config import (FeishuConfig,HTMLConfig,- MarkdownConfig,PDFConfig,- TextConfig,)-def test_parser_registry_propagates_parser_configs_to_registered_parsers():- markdown_config = MarkdownConfig(max_section_size=4321, max_section_chars=9876)- text_config = TextConfig(max_section_size=3456, max_section_chars=8765)- pdf_config = PDFConfig(- strategy="local",- max_section_size=2345,- max_section_chars=7654,- )- html_config = HTMLConfig(max_section_size=1234, max_section_chars=6543)-- registry = ParserRegistry(- parser_configs={- "markdown": markdown_config,- "text": text_config,- "pdf": pdf_config,- "html": html_config,- }- )-- markdown_parser = registry.get_parser("markdown")- assert markdown_parser is not None- assert markdown_parser.config.max_section_size == 4321- assert markdown_parser.config.max_section_chars == 9876-- text_parser = registry.get_parser("text")- assert text_parser is not None- assert text_parser._md_parser.config.max_section_size == 3456- assert text_parser._md_parser.config.max_section_chars == 8765-- pdf_parser = registry.get_parser("pdf")- assert pdf_parser is not None- assert pdf_parser.config.max_section_size == 2345- assert pdf_parser.config.max_section_chars == 7654- assert pdf_parser._get_markdown_parser().config.max_section_size == 2345- assert pdf_parser._get_markdown_parser().config.max_section_chars == 7654-- html_parser = registry.get_parser("html")- assert html_parser is not None- assert html_parser.config.max_section_size == 1234- assert html_parser.config.max_section_chars == 6543- assert html_parser._get_markdown_parser().config.max_section_size == 1234- assert html_parser._get_markdown_parser().config.max_section_chars == 6543--def test_pdf_parser_passes_its_config_to_nested_markdown_parser():parser = PDFParser(PDFConfig(strategy="local", max_section_size=2222, max_section_chars=5555))diff --git a/tests/resource/test_watch_manager.py b/tests/resource/test_watch_manager.pyindex 9b7c2ff24..b2bc73dcf 100644--- a/tests/resource/test_watch_manager.py+++ b/tests/resource/test_watch_manager.py@@ -62,24 +62,6 @@ async def mock_viking_fs(temp_storage: Path) -> MockVikingFS:return MockVikingFS(root_path=str(temp_storage))-@pytest_asyncio.fixture-async def watch_manager(mock_viking_fs: MockVikingFS) -> AsyncGenerator[WatchManager, None]:- """Create WatchManager instance with mock VikingFS."""- manager = WatchManager(viking_fs=mock_viking_fs)- await manager.initialize()- yield manager- await manager.clear_all_tasks()---@pytest_asyncio.fixture-async def watch_manager_no_fs() -> AsyncGenerator[WatchManager, None]:- """Create WatchManager instance without VikingFS."""- manager = WatchManager(viking_fs=None)- await manager.initialize()- yield manager- await manager.clear_all_tasks()--class TestWatchTask:"""Tests for WatchTask data model."""@@ -259,97 +241,6 @@ class TestWatchManager:assert (await watch_manager_no_fs.get_task(child.task_id)).is_active is Falseassert (await watch_manager_no_fs.get_task(sibling.task_id)).is_active is True- @pytest.mark.asyncio- async def test_move_tasks_under_uri_internal_rewrites_subtree(- self, watch_manager_no_fs: WatchManager- ):- root = await watch_manager_no_fs.create_task(- path="/test/root",- to_uri="viking://resources/codeask/wiki",- parent_uri="viking://resources/codeask",- watch_interval=30.0,- )- child = await watch_manager_no_fs.create_task(- path="/test/child",- to_uri="viking://resources/codeask/wiki/page",- parent_uri="viking://resources/codeask/wiki",- watch_interval=30.0,- )-- plan = await watch_manager_no_fs.plan_move_tasks_under_uri_internal(- "viking://resources/codeask/wiki",- "viking://resources/codeask/wiki-renamed",- )- updated = await watch_manager_no_fs.move_tasks_under_uri_internal(- "viking://resources/codeask/wiki",- "viking://resources/codeask/wiki-renamed",- )-- assert plan == {- root.task_id: "viking://resources/codeask/wiki-renamed",- child.task_id: "viking://resources/codeask/wiki-renamed/page",- }- assert {task.task_id for task in updated} == {root.task_id, child.task_id}- moved_root = await watch_manager_no_fs.get_task_by_uri(- "viking://resources/codeask/wiki-renamed",- account_id=TEST_ACCOUNT_ID,- user_id=TEST_USER_ID,- role=TEST_ROLE,- )- moved_child = await watch_manager_no_fs.get_task_by_uri(- "viking://resources/codeask/wiki-renamed/page",- account_id=TEST_ACCOUNT_ID,- user_id=TEST_USER_ID,- role=TEST_ROLE,- )- assert moved_root is not None- assert moved_root.parent_uri == "viking://resources/codeask"- assert moved_child is not None- assert moved_child.parent_uri == "viking://resources/codeask/wiki-renamed"-- @pytest.mark.asyncio- async def test_move_tasks_under_uri_internal_preserves_none_parent(- self, watch_manager_no_fs: WatchManager- ):- root = await watch_manager_no_fs.create_task(- path="/test/root",- to_uri="viking://resources/codeask/wiki",- parent_uri=None,- watch_interval=30.0,- )-- updated = await watch_manager_no_fs.move_tasks_under_uri_internal(- "viking://resources/codeask/wiki",- "viking://resources/codeask/wiki-renamed",- )-- assert [task.task_id for task in updated] == [root.task_id]- moved_root = await watch_manager_no_fs.get_task(root.task_id)- assert moved_root is not None- assert moved_root.to_uri == "viking://resources/codeask/wiki-renamed"- assert moved_root.parent_uri is None-- @pytest.mark.asyncio- async def test_plan_move_tasks_under_uri_internal_detects_conflict(- self, watch_manager_no_fs: WatchManager- ):- await watch_manager_no_fs.create_task(- path="/test/root",- to_uri="viking://resources/codeask/wiki",- watch_interval=30.0,- )- await watch_manager_no_fs.create_task(- path="/test/existing",- to_uri="viking://resources/codeask/wiki-renamed",- watch_interval=30.0,- )-- with pytest.raises(ConflictError):- await watch_manager_no_fs.plan_move_tasks_under_uri_internal(- "viking://resources/codeask/wiki",- "viking://resources/codeask/wiki-renamed",- )-@pytest.mark.asyncioasync def test_sync_tasks_with_resource_move_internal_rolls_back_task_state_on_save_failure(self, watch_manager_no_fs: WatchManager@@ -642,23 +533,6 @@ class TestWatchManager:assert len(due_tasks) == 1assert due_tasks[0].task_id == task1.task_id- @pytest.mark.asyncio- async def test_clear_all_tasks(self, watch_manager: WatchManager):- """Test clearing all tasks."""- await watch_manager.create_task(path="/test/path1")- await watch_manager.create_task(path="/test/path2")-- count = await watch_manager.clear_all_tasks()-- assert count == 2-- tasks = await watch_manager.get_all_tasks(- account_id=TEST_ACCOUNT_ID,- user_id=TEST_USER_ID,- role=TEST_ROLE,- )- assert len(tasks) == 0-@pytest.mark.asyncioasync def test_create_task_with_non_positive_interval_raises(self, watch_manager: WatchManager):with pytest.raises(ValueError, match="watch_interval must be > 0"):diff --git a/tests/server/oauth/test_storage.py b/tests/server/oauth/test_storage.pyindex f2908288c..b6a8a3cd9 100644--- a/tests/server/oauth/test_storage.py+++ b/tests/server/oauth/test_storage.py@@ -250,35 +250,6 @@ async def test_refresh_token_roundtrip(store):assert await store.is_refresh_known_but_consumed(rt) is True-async def test_refresh_replay_revokes_chain(store):- """Reusing a consumed refresh must allow the caller to revoke the family."""- rt1 = "rt-1"- rt2 = "rt-2"- rt3 = "rt-3"- for rt in (rt1, rt2, rt3):- await store.insert_refresh(- token_plain=rt,- client_id="cx",- account_id="acct",- user_id="user",- role="user",- scope=None,- resource=None,- authorizing_key_fp=_FP,- ttl_seconds=86400,- )- # Consume rt1 (rotate to rt2). Then attacker replays rt1.- assert await store.consume_refresh(token_plain=rt1, replaced_by_plain=rt2) is not None- assert await store.consume_refresh(token_plain=rt1, replaced_by_plain=None) is None- # Detection — caller now revokes the chain.- revoked = await store.revoke_chain(client_id="cx", account_id="acct", user_id="user")- assert revoked >= 2 # rt2 and rt3 still active before revoke- # Both rt2 and rt3 must now be unusable.- assert await store.consume_refresh(token_plain=rt2, replaced_by_plain=None) is None- assert await store.consume_refresh(token_plain=rt3, replaced_by_plain=None) is None--@pytest.mark.asyncioasync def test_access_token_load_and_revoke(store):token = "at-secret"diff --git a/tests/server/test_api_resources.py b/tests/server/test_api_resources.pyindex 676b1d4e8..1cf287cba 100644--- a/tests/server/test_api_resources.py+++ b/tests/server/test_api_resources.py@@ -810,9 +810,9 @@ async def test_add_resource_non_wait_queue_task_queryable(sample_markdown_file,upload_temp_dir,):- from openviking.service.task_tracker import reset_task_tracker+ from openviking.service.task_tracker import set_task_tracker- reset_task_tracker()+ set_task_tracker(None)resp = await client.post("/api/v1/resources",diff --git a/tests/server/test_auth.py b/tests/server/test_auth.pyindex 9640dff28..4225d0825 100644--- a/tests/server/test_auth.py+++ b/tests/server/test_auth.py@@ -25,7 +25,6 @@ from openviking.service.task_store import PersistentTaskStorefrom openviking.service.task_tracker import (TaskTracker,get_task_tracker,- reset_task_tracker,set_task_tracker,)from openviking_cli.exceptions import InvalidArgumentError, OpenVikingError, PermissionDeniedError@@ -411,19 +410,19 @@ async def test_admin_sync_route_rejects_user_key(auth_client: httpx.AsyncClient,async def test_task_endpoints_require_auth():"""Task endpoints must reject unauthenticated callers before lookup/filtering."""- reset_task_tracker()+ set_task_tracker(None)app = _build_task_http_test_app(identity=None)transport = httpx.ASGITransport(app=app)async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:for url in ("/api/v1/tasks", "/api/v1/tasks/nonexistent-id"):resp = await client.get(url)assert resp.status_code == 401- reset_task_tracker()+ set_task_tracker(None)async def test_task_endpoints_are_user_scoped():"""Authenticated callers must not see another user's background tasks."""- reset_task_tracker()+ set_task_tracker(None)_set_fake_task_tracker()account_id = _uid()tracker = get_task_tracker()@@ -470,7 +469,7 @@ async def test_task_endpoints_are_user_scoped():assert bob_list.status_code == 200assert {task["task_id"] for task in bob_list.json()["result"]} == {bob_task.task_id}- reset_task_tracker()+ set_task_tracker(None)# ---- Role-based access tests ----diff --git a/tests/server/test_server_health.py b/tests/server/test_server_health.pyindex 5c8aba094..1a41644f5 100644--- a/tests/server/test_server_health.py+++ b/tests/server/test_server_health.py@@ -8,63 +8,11 @@ import timefrom types import SimpleNamespaceimport httpx-import pytest-from openviking.server.app import _initialize_runtime_state, _on_deferred_init_done, create_app+from openviking.server.app import _initialize_runtime_state, create_appfrom openviking.server.config import ServerConfig-class _ExitCalled(Exception):- def __init__(self, code: int):- self.code = code- super().__init__(f"os._exit({code})")---async def test_deferred_init_failure_exits_process(monkeypatch):- async def fail_init():- raise RuntimeError("init failed")-- def fake_exit(code: int):- raise _ExitCalled(code)-- monkeypatch.setattr("openviking.server.app.os._exit", fake_exit)- task = asyncio.create_task(fail_init())- with pytest.raises(RuntimeError):- await task-- with pytest.raises(_ExitCalled) as exc_info:- _on_deferred_init_done(task)-- assert exc_info.value.code == 1---async def test_deferred_init_success_does_not_exit(monkeypatch):- async def complete_init():- return None-- monkeypatch.setattr(- "openviking.server.app.os._exit",- lambda code: pytest.fail(f"os._exit({code}) should not be called"),- )- task = asyncio.create_task(complete_init())- await task-- _on_deferred_init_done(task)---async def test_deferred_init_cancellation_does_not_exit(monkeypatch):- monkeypatch.setattr(- "openviking.server.app.os._exit",- lambda code: pytest.fail(f"os._exit({code}) should not be called"),- )- task = asyncio.create_task(asyncio.sleep(60))- task.cancel()- with pytest.raises(asyncio.CancelledError):- await task-- _on_deferred_init_done(task)--async def test_health_endpoint(client: httpx.AsyncClient):resp = await client.get("/health")assert resp.status_code == 200diff --git a/tests/service/test_resource_service_watch.py b/tests/service/test_resource_service_watch.pyindex 5e3aec987..8f58b46a3 100644--- a/tests/service/test_resource_service_watch.py+++ b/tests/service/test_resource_service_watch.py@@ -91,15 +91,6 @@ def isolate_service_dependencies(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(resource_service_module, "is_git_repo_url", lambda _path: False)-@pytest_asyncio.fixture-async def watch_manager() -> AsyncGenerator[WatchManager, None]:- """Create WatchManager instance without VikingFS for testing."""- manager = WatchManager(viking_fs=None)- await manager.initialize()- yield manager- await manager.clear_all_tasks()--@pytest_asyncio.fixtureasync def resource_service(watch_manager: WatchManager) -> AsyncGenerator[ResourceService, None]:"""Create ResourceService instance with watch support."""@@ -346,9 +337,9 @@ class TestWatchTaskConflict:self, resource_service: ResourceService, request_context: RequestContext):"""A rejected watch request must not leave behind a user-invisible task."""- from openviking.service.task_tracker import get_task_tracker, reset_task_tracker+ from openviking.service.task_tracker import get_task_tracker, set_task_tracker- reset_task_tracker()+ set_task_tracker(None)to_uri = "viking://resources/conflict_no_task"await resource_service.add_resource(diff --git a/tests/session/conftest.py b/tests/session/conftest.pyindex 30dc37b58..efba44e69 100644--- a/tests/session/conftest.py+++ b/tests/session/conftest.py@@ -10,7 +10,7 @@ import pytest_asynciofrom openviking import AsyncOpenVikingfrom openviking.message import TextPart, ToolPart-from openviking.service.task_tracker import TaskStatus, get_task_tracker, reset_task_tracker+from openviking.service.task_tracker import TaskStatus, get_task_tracker, set_task_trackerfrom openviking.session import Session@@ -29,7 +29,7 @@ async def _drain_background_tasks(client: AsyncOpenViking):if not pending:breakawait asyncio.sleep(0.1)- reset_task_tracker()+ set_task_tracker(None)@pytest_asyncio.fixture(scope="function")diff --git a/tests/session/memory/test_json_stability.py b/tests/session/memory/test_json_stability.pyindex 6ffe9c06a..c76072da7 100644--- a/tests/session/memory/test_json_stability.py+++ b/tests/session/memory/test_json_stability.py@@ -17,7 +17,6 @@ from openviking.session.memory.utils import (extract_json_content,parse_json_with_stability,parse_memory_file_with_fields,- remove_json_trailing_content,value_fault_tolerance,)@@ -78,19 +77,6 @@ Trailing content."""assert extract_json_content(" ") == " "-class TestRemoveJsonTrailingContent:- """Tests for deprecated remove_json_trailing_content (alias for extract_json_content)."""-- def test_alias_works(self):- """Test that remove_json_trailing_content is an alias for extract_json_content."""- content = """Alright, let's see.-{"reasonning": "test"}-And then some."""- result1 = extract_json_content(content)- result2 = remove_json_trailing_content(content)- assert result1 == result2--class TestValueFaultTolerance:"""Tests for Layer 4: Value-level fault tolerance."""diff --git a/tests/session/memory/test_memory_react.py b/tests/session/memory/test_memory_react.pyindex 4889c90f8..de2591f8b 100644--- a/tests/session/memory/test_memory_react.py+++ b/tests/session/memory/test_memory_react.py@@ -14,7 +14,6 @@ from openviking.session.memory.dataclass import (from openviking.session.memory.extract_loop import (ExtractLoop,)-from openviking.session.memory.memory_type_registry import MemoryTypeRegistryclass TestPreFetchFileFiltering:@@ -153,34 +152,6 @@ class TestAllowedDirectoriesList:"""Create a mock VikingFS."""return MagicMock()- def test_get_allowed_directories_list(self, mock_vlm, mock_viking_fs):- """Test that allowed directories list is properly formatted."""- registry = MemoryTypeRegistry(load_schemas=False)-- schema1 = MemoryTypeSchema(- memory_type="preferences",- description="Preferences",- directory="viking://user/{{ user_space }}/memories/preferences",- filename_template="{{ topic }}.md",- fields=[],- )- schema2 = MemoryTypeSchema(- memory_type="tools",- description="Tools",- directory="viking://user/{{ user_space }}/memories/tools",- filename_template="{{ tool_name }}.md",- fields=[],- )-- registry.register(schema1)- registry.register(schema2)-- result = registry.list_search_uris(user_space="default")-- assert "viking://user/default/memories/preferences" in result- assert "viking://user/default/memories/tools" in result--class TestExtractLoopFinalJsonRetry:def test_final_instruction_includes_schema_aware_empty_json(self):extract_loop = object.__new__(ExtractLoop)diff --git a/tests/session/memory/test_memory_timestamp_parsing.py b/tests/session/memory/test_memory_timestamp_parsing.pyindex 22ff4a1af..b8d356c5f 100644--- a/tests/session/memory/test_memory_timestamp_parsing.py+++ b/tests/session/memory/test_memory_timestamp_parsing.py@@ -74,46 +74,6 @@ def test_message_range_accepts_extended_fractional_seconds():assert msg_range._first_message_time_with_weekday() == "2026-04-17 (Friday)"-def test_message_range_uses_peer_id_when_present():- msg_range = MessageRange(- [- [- Message(- id="msg-peer",- role="user",- parts=[TextPart(text="invoice follow-up")],- peer_id="web-visitor-alice",- )- ]- ]- )-- assert "**web-visitor-alice**: invoice follow-up" in msg_range.pretty_print()- assert "**default**: invoice follow-up" not in msg_range.pretty_print()---def test_message_range_renders_markdown_visible_speakers():- msg_range = MessageRange(- [- [- Message(- id="msg-self",- role="user",- parts=[TextPart(text="我今天去了趟北京")],- ),- Message(- id="msg-peer",- role="user",- parts=[TextPart(text="我今天去了趟北京")],- peer_id="xiaomei",- ),- ]- ]- )-- assert msg_range.pretty_print() == ("**user**: 我今天去了趟北京\n**xiaomei**: 我今天去了趟北京")--def test_extraction_context_chunks_long_text_and_preserves_decimal_numbers(stub_provider_config):text = ("周一 "@@ -140,144 +100,12 @@ def test_extraction_context_chunks_long_text_and_preserves_decimal_numbers(stub_assert len(extraction_messages) > 1assert merged == textassert all(message.id.startswith("msg-long#chunk_") for message in extraction_messages)- assert all(id(message) in extract_context.chunk_meta for message in extraction_messages)assert "21.9K" in mergedassert "110.2k" in mergedassert "501.0k" in mergedassert not any(message.content.startswith(("9K", "2k")) for message in extraction_messages)-def test_message_range_merges_adjacent_chunks_for_same_speaker():- first = Message(- id="msg-long#chunk_0",- role="user",- parts=[TextPart(text="first chunk. ")],- peer_id="web-visitor-alice",- )- second = Message(- id="msg-long#chunk_1",- role="user",- parts=[TextPart(text="second chunk.")],- peer_id="web-visitor-alice",- )- msg_range = MessageRange(- [[first, second]],- chunk_meta={- id(first): SimpleNamespace(- source_message_id="msg-long",- chunk_index=0,- chunk_count=2,- ),- id(second): SimpleNamespace(- source_message_id="msg-long",- chunk_index=1,- chunk_count=2,- ),- },- )-- assert msg_range.pretty_print() == "**web-visitor-alice**: first chunk. second chunk."---def test_message_range_keeps_regular_same_speaker_messages_separate():- msg_range = MessageRange(- [- [- Message(- id="msg-a",- role="user",- parts=[TextPart(text="first message")],- peer_id="web-visitor-alice",- ),- Message(- id="msg-b",- role="user",- parts=[TextPart(text="second message")],- peer_id="web-visitor-alice",- ),- ]- ]- )-- assert msg_range.pretty_print() == (- "**web-visitor-alice**: first message\n**web-visitor-alice**: second message"- )---def test_message_range_keeps_different_source_chunks_separate():- first = Message(- id="msg-a#chunk_0",- role="user",- parts=[TextPart(text="first source chunk")],- peer_id="web-visitor-alice",- )- second = Message(- id="msg-b#chunk_0",- role="user",- parts=[TextPart(text="second source chunk")],- peer_id="web-visitor-alice",- )- msg_range = MessageRange(- [[first, second]],- chunk_meta={- id(first): SimpleNamespace(- source_message_id="msg-a",- chunk_index=0,- chunk_count=2,- ),- id(second): SimpleNamespace(- source_message_id="msg-b",- chunk_index=0,- chunk_count=2,- ),- },- )-- assert msg_range.pretty_print() == (- "**web-visitor-alice**: first source chunk...\n**web-visitor-alice**: second source chunk..."- )---def test_message_range_does_not_treat_original_chunk_like_id_as_chunk():- msg_range = MessageRange(- [- [- Message(- id="msg-long#chunk_0",- role="user",- parts=[TextPart(text="original message id contains chunk marker")],- peer_id="web-visitor-alice",- ),- ]- ]- )-- assert msg_range.pretty_print() == (- "**web-visitor-alice**: original message id contains chunk marker"- )---def test_message_range_marks_middle_chunk_as_abbreviated():- message = Message(- id="msg-long#chunk_1",- role="user",- parts=[TextPart(text="middle chunk")],- peer_id="web-visitor-alice",- )- msg_range = MessageRange(- [[message]],- chunk_meta={- id(message): SimpleNamespace(- source_message_id="msg-long",- chunk_index=1,- chunk_count=3,- )- },- )-- assert msg_range.pretty_print() == "**web-visitor-alice**: ...middle chunk..."--def test_peer_id_routes_peer_memory_for_all_role_selected_types(stub_provider_config):messages = [Message(diff --git a/tests/session/memory/test_memory_tools.py b/tests/session/memory/test_memory_tools.pyindex 2c94fdfca..f0161c094 100644--- a/tests/session/memory/test_memory_tools.py+++ b/tests/session/memory/test_memory_tools.py@@ -14,7 +14,6 @@ from openviking.session.memory.tools import (MemoryReadTool,MemorySearchTool,get_tool,- get_tool_schemas,)from openviking_cli.session.user_id import UserIdentifier@@ -261,9 +260,3 @@ class TestMemoryTools:read_tool = get_tool("read")assert read_tool is not Noneassert isinstance(read_tool, MemoryReadTool)-- # Check get_tool_schemas- schemas = get_tool_schemas()- schema_names = [s["function"]["name"] for s in schemas]- assert "read" in schema_names- assert all(name in MEMORY_TOOLS_REGISTRY for name in schema_names)diff --git a/tests/session/memory/test_memory_updater.py b/tests/session/memory/test_memory_updater.pyindex 4c5de7085..12ad31213 100644--- a/tests/session/memory/test_memory_updater.py+++ b/tests/session/memory/test_memory_updater.py@@ -43,40 +43,6 @@ from openviking_cli.session.user_id import UserIdentifierclass TestMemoryUpdateResult:"""Tests for MemoryUpdateResult."""- def test_create_empty(self):- """Test creating an empty result."""- result = MemoryUpdateResult()-- assert len(result.written_uris) == 0- assert len(result.edited_uris) == 0- assert len(result.deleted_uris) == 0- assert len(result.errors) == 0- assert result.has_changes() is False-- def test_add_written(self):- """Test adding written URI."""- result = MemoryUpdateResult()- result.add_written("viking://user/test/memories/profile.md")-- assert len(result.written_uris) == 1- assert result.has_changes() is True-- def test_add_edited(self):- """Test adding edited URI."""- result = MemoryUpdateResult()- result.add_edited("viking://user/test/memories/profile.md")-- assert len(result.edited_uris) == 1- assert result.has_changes() is True-- def test_add_deleted(self):- """Test adding deleted URI."""- result = MemoryUpdateResult()- result.add_deleted("viking://user/test/memories/to_delete.md")-- assert len(result.deleted_uris) == 1- assert result.has_changes() is True-def test_summary(self):"""Test summary generation."""result = MemoryUpdateResult()@@ -113,60 +79,6 @@ class TestMemoryUpdater:assert len(split_context.messages) > 1assert len(unsplit_context.messages) == 1assert unsplit_context.messages[0] is messages[0]- assert unsplit_context.chunk_meta == {}-- def test_extract_context_resource_event_content_hides_add_resource_fields(self):- resource_uri = "viking://resources/images/2026/06/12/yueqian_jpeg"- extract_context = ExtractContext(- messages=[- Message(- id="1",- role="user",- parts=[- TextPart(- text=(- "## Resource Addition\n"- f"Resource URI: {resource_uri}\n"- "Source name: yueqian.jpeg\n"- "Added at: 2026-06-12T03:43:36.343325+00:00\n"- "Resource abstract: This directory contains an anime illustration.\n"- "User reason: 这是越前龙马的照片"- )- )- ],- created_at="2026-06-12T03:43:36.343325+00:00",- )- ]- )-- content = extract_context.get_resource_event_content(- "0",- f"2026-06-12,用户保存了粉丝创作的越前龙马动漫插画资源,资源URI为{resource_uri}。",- )-- assert (- content == f"2026-06-12,[用户保存了粉丝创作的越前龙马动漫插画资源]({resource_uri})。"- )- assert "Resource URI" not in content- assert "Added at" not in content- assert "Resource abstract" not in content- assert "User reason" not in content-- def test_extract_context_event_content_falls_back_to_range_when_summary_empty(self):- extract_context = ExtractContext(- messages=[- Message(- id="1",- role="user",- parts=[TextPart(text="Gina can expand her clothing store now.")],- created_at="2023-02-01T00:48:00",- )- ]- )-- content = extract_context.get_event_content("0", "")-- assert "Gina can expand her clothing store now." in contentdef test_create(self):"""Test creating a MemoryUpdater."""@@ -183,15 +95,6 @@ class TestMemoryUpdater:assert updater._registry == registry- def test_set_registry(self):- """Test setting registry after creation."""- updater = MemoryUpdater()- registry = MemoryTypeRegistry()-- updater.set_registry(registry)-- assert updater._registry == registry-@pytest.mark.asyncioasync def test_generate_overview_deletes_empty_overview_via_rm(self):schema = MemoryTypeSchema(diff --git a/tests/session/memory/test_schema_models.py b/tests/session/memory/test_schema_models.pyindex 1b280d1f3..5fc694d48 100644--- a/tests/session/memory/test_schema_models.py+++ b/tests/session/memory/test_schema_models.py@@ -316,42 +316,6 @@ class TestSchemaModelGenerator:profile_model = models["profile"]assert "content" in profile_model.model_fields- def test_create_discriminated_union_model(self, real_registry):- """Test creating the union model wrapper."""- generator = SchemaModelGenerator(real_registry)- union_model = generator.create_discriminated_union_model()-- # The union model is a wrapper BaseModel- assert hasattr(union_model, "model_fields")- assert "data" in union_model.model_fields-- def test_get_llm_json_schema(self, real_registry):- """Test getting the LLM JSON schema."""- generator = SchemaModelGenerator(real_registry)- json_schema = generator.get_llm_json_schema()-- # Check it's a valid JSON schema- assert "$defs" in json_schema or "definitions" in json_schema- assert "properties" in json_schema-- # Check it includes delete operations and per-memory-type operation fields- assert "delete_ids" in json_schema["properties"]- assert "profile" in json_schema["properties"]-- # Check delete_ids is an array of objects- delete_props = json_schema["properties"]["delete_ids"]- delete_items = delete_props.get("items", {})- assert delete_items.get("$ref") or delete_items.get("type") == "object"-- def test_get_memory_data_json_schema(self, real_registry):- """Test getting just the MemoryData JSON schema."""- generator = SchemaModelGenerator(real_registry)- json_schema = generator.get_memory_data_json_schema()-- # Check it's a valid JSON schema- assert "$defs" in json_schema or "definitions" in json_schema- assert "properties" in json_schema-def test_model_caching(self, registry_with_sample, sample_memory_type):"""Test that models are cached."""generator = SchemaModelGenerator(registry_with_sample)@@ -429,21 +393,3 @@ class TestWikiLink:class TestIntegration:"""Integration tests for the complete schema system."""-- def test_end_to_end_model_generation_and_validation(self):- """Test end-to-end: load schemas, generate models, validate data."""- registry = create_default_registry()-- # Create generator- generator = SchemaModelGenerator(registry)-- # Get the operations model- generator.create_structured_operations_model()-- # Get JSON schema- json_schema = generator.get_llm_json_schema()-- # Verify the schema includes descriptions from YAML- # Check that $defs has entries- defs = json_schema.get("$defs", {})- assert len(defs) > 0, "No definitions found in JSON schema"diff --git a/tests/session/test_compressor_v3.py b/tests/session/test_compressor_v3.pyindex bd30084d7..941172a6b 100644--- a/tests/session/test_compressor_v3.py+++ b/tests/session/test_compressor_v3.py@@ -132,7 +132,7 @@ def test_case_experience_links_require_policy_root_uri():@pytest.mark.asyncio-async def test_train_from_extracted_case_memories_submits_streaming_rollout(monkeypatch):+async def test_train_from_extracted_cases_submits_streaming_rollout(monkeypatch):submitted_gradients = []submitted_analyses = []@@ -221,17 +221,7 @@ async def test_train_from_extracted_case_memories_submits_streaming_rollout(monkmax_gradients_per_update=8,),)- operations = ResolvedOperations(- upsert_operations=[_case_operation()],- delete_file_contents=[],- errors=[],- )-- # The extracted case comes from the same memory operations as profile/preferences/etc.;- # no extra LLM/VLM case extractor is involved.- cases = __import__(- "openviking.session.compressor_v3", fromlist=["_operations_to_cases"]- )._operations_to_cases(operations)+ cases = [_training_case()]result = await compressor.train_from_extracted_cases(cases=cases,messages=_messages(),@@ -246,10 +236,7 @@ async def test_train_from_extracted_case_memories_submits_streaming_rollout(monk# Verify analysis was usedassert submitted_analyses[0] is not Noneassert submitted_analyses[0].trajectories[0].name == "duplicate_booking"- # Verify case info carried through correctly- assert cases[0].name == "重复预订处理"- assert cases[0].input["summary"] == "用户要求处理重复预订"- assert cases[0].rubric.criteria[0].name == "先验证重复"+ assert cases[0].name == "duplicate_booking"@pytest.mark.asynciodiff --git a/tests/session/test_session_messages.py b/tests/session/test_session_messages.pyindex ce8aa86ae..e0f27507a 100644--- a/tests/session/test_session_messages.py+++ b/tests/session/test_session_messages.py@@ -185,38 +185,3 @@ class TestAddMessage:assert [message["parts"][0]["text"] for message in context["messages"]] == ["first valid message"]---class TestUpdateToolPart:- """Test update_tool_part"""-- async def test_update_tool_completed(self, session_with_tool_call):- """Test updating tool status to completed"""- session, message_id, tool_id = session_with_tool_call-- session.update_tool_part(- message_id=message_id,- tool_id=tool_id,- output="Tool execution completed successfully",- status="completed",- )-- # Verify tool status updated- # Need to find the corresponding message and tool part- msg = next((m for m in session.messages if m.id == message_id), None)- assert msg is not None-- async def test_update_tool_failed(self, session_with_tool_call):- """Test updating tool status to failed"""- session, message_id, tool_id = session_with_tool_call-- session.update_tool_part(- message_id=message_id,- tool_id=tool_id,- output="Tool execution failed: error message",- status="failed",- )-- # Verify tool status updated- msg = next((m for m in session.messages if m.id == message_id), None)- assert msg is not Nonediff --git a/tests/session/test_tool_result_externalization.py b/tests/session/test_tool_result_externalization.pyindex bf8f73014..195b29259 100644--- a/tests/session/test_tool_result_externalization.py+++ b/tests/session/test_tool_result_externalization.py@@ -82,99 +82,6 @@ def _json_items_payload(count: int) -> str:return f'{{"items":[{items}]}}'-async def test_add_message_externalizes_large_tool_output(session: Session):- session._tool_output_externalization_config = _small_config()- raw = "alpha-" * 300-- msg = session.add_message(- "user",- [- ToolPart(- tool_id="call_1",- tool_name="read_file",- tool_input={"path": "a.txt"},- tool_output=raw,- tool_status="completed",- )- ],- peer_id="web-visitor-alice",- )-- part = msg.get_tool_parts()[0]- assert part.tool_output_truncated is True- assert part.tool_output_ref.startswith(f"{session.uri}/tool-results/")- assert part.tool_output_original_chars == len(raw)- assert part.tool_output_externalized_reason == "single_threshold"- assert raw not in part.tool_output-- stored = await session.read_tool_result(part.tool_output_ref.rsplit("/", 1)[-1], limit=-1)- assert stored["content"] == raw- assert stored["offset_unit"] == "unicode_code_point"- assert stored["metadata"]["user_id"] == session.ctx.user.user_id- assert stored["metadata"]["peer_id"] == "web-visitor-alice"---async def test_hydrate_tool_outputs_for_extraction_uses_memory_copy(session: Session):- session._tool_output_externalization_config = _small_config()- raw = "alpha-" * 300-- msg = session.add_message(- "user",- [- ToolPart(- tool_id="call_hydrate",- tool_name="read_file",- tool_output=raw,- tool_status="completed",- )- ],- )- compressed_part = msg.get_tool_parts()[0]- compressed_output = compressed_part.tool_output-- hydrated = await session._hydrate_tool_outputs_for_extraction([msg])-- assert hydrated[0] is not msg- assert hydrated[0].get_tool_parts()[0].tool_output == raw- assert hydrated[0].get_tool_parts()[0].tool_output_ref == compressed_part.tool_output_ref- assert compressed_part.tool_output == compressed_output- assert raw not in compressed_part.tool_output---async def test_externalized_tool_output_uses_typed_synopsis_stub(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- preview_chars=200,- )- raw = '{"users":[{"id":1,"name":"Ada"},{"id":2,"name":"Lin"}],"meta":{"count":2}}' * 3-- msg = session.add_message(- "user",- [- ToolPart(- tool_id="call_json_synopsis",- tool_name="fetch_json",- tool_output=raw,- tool_status="completed",- )- ],- )-- part = msg.get_tool_parts()[0]- assert part.tool_output_truncated is True- assert "kind: json" in part.tool_output- assert "Synopsis:" in part.tool_output- assert "users" in part.tool_output- assert "openviking_tool_result_search" in part.tool_output- assert raw not in part.tool_output-- tool_result_id = part.tool_output_ref.rsplit("/", 1)[-1]- stored = await session.read_tool_result(tool_result_id, limit=-1)- assert stored["content"] == raw- assert stored["metadata"]["synopsis"]["kind"] == "json"- assert stored["metadata"]["synopsis_kind"] == "json"--async def test_externalized_tool_output_generates_synopsis_once(session: Session, monkeypatch):session._tool_output_externalization_config = _small_config(threshold_chars=20,@@ -208,438 +115,6 @@ async def test_externalized_tool_output_generates_synopsis_once(session: Sessionassert calls == 1-async def test_preview_contract_fields_remain_present(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- preview_chars=40,- )- raw = "alpha-" * 20-- part = session.add_message(- "user",- [- ToolPart(- tool_id="call_contract",- tool_name="read_file",- tool_output=raw,- tool_status="completed",- )- ],- ).get_tool_parts()[0]-- assert "[OpenViking tool result externalized]" in part.tool_output- assert "tool_name: read_file" in part.tool_output- assert "original_chars:" in part.tool_output- assert "preview_chars:" in part.tool_output- assert "ref:" in part.tool_output- assert "sha256:" in part.tool_output- assert "reason: single_threshold" in part.tool_output---async def test_externalized_tool_output_uses_mime_type_for_xml(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- preview_chars=200,- )- raw = "\ufeff<root><item id='1'>A</item><item id='2'>B</item></root>"-- part = session.add_message(- "user",- [- ToolPart(- tool_id="call_xml",- tool_name="fetch_xml",- tool_output=raw,- tool_output_mime_type="application/xml",- tool_status="completed",- )- ],- ).get_tool_parts()[0]-- assert "kind: xml" in part.tool_output- assert "root: root" in part.tool_output---async def test_tool_output_at_or_below_threshold_remains_inline_when_budget_allows(- session: Session,-):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- assistant_turn_inline_budget_chars=1000,- )-- below = session.add_message(- "user",- [- ToolPart(- tool_id="call_below_threshold",- tool_name="echo",- tool_output="x" * 19,- tool_status="completed",- )- ],- ).get_tool_parts()[0]- equal = session.add_message(- "user",- [- ToolPart(- tool_id="call_equal_threshold",- tool_name="echo",- tool_output="y" * 20,- tool_status="completed",- )- ],- ).get_tool_parts()[0]-- assert below.tool_output_truncated is False- assert below.tool_output_ref == ""- assert below.tool_output == "x" * 19- assert equal.tool_output_truncated is False- assert equal.tool_output_ref == ""- assert equal.tool_output == "y" * 20---async def test_assistant_turn_budget_splits_aggregate_and_externalizes_largest_output(- session: Session,-):- session._tool_output_externalization_config = _small_config(- threshold_chars=1200,- assistant_turn_inline_budget_chars=800,- )-- start_count = len(session.messages)- returned = session.add_message(- "user",- [- ToolPart(- tool_id="call_a",- tool_name="tool_a",- tool_output=_json_items_payload(40),- tool_status="completed",- ),- ToolPart(- tool_id="call_b",- tool_name="tool_b",- tool_output=_json_items_payload(1),- tool_status="completed",- ),- ],- )-- new_messages = session.messages[start_count:]- assert len(new_messages) == 2- assert returned == new_messages[0]- assert [len(msg.parts) for msg in new_messages] == [1, 1]-- parts = [msg.get_tool_parts()[0] for msg in new_messages]- externalized = [p for p in parts if p.tool_output_truncated]- assert len(externalized) == 1- assert externalized[0].tool_id == "call_a"- assert externalized[0].tool_output_externalized_reason == "turn_budget"- assert all(- p.tool_output_group_original_chars- == len(_json_items_payload(40)) + len(_json_items_payload(1))- for p in parts- )- assert parts[0].tool_output_group_id == parts[1].tool_output_group_id---async def test_assistant_turn_budget_externalizes_multiple_largest_outputs(- session: Session,-):- session._tool_output_externalization_config = _small_config(- threshold_chars=1200,- assistant_turn_inline_budget_chars=1600,- assistant_turn_preview_budget_chars=120,- preview_chars=12,- )-- start_count = len(session.messages)- session.add_message(- "user",- [- ToolPart(- tool_id="call_a",- tool_name="tool_a",- tool_output=_json_items_payload(40),- tool_status="completed",- ),- ToolPart(- tool_id="call_b",- tool_name="tool_b",- tool_output=_json_items_payload(40),- tool_status="completed",- ),- ToolPart(- tool_id="call_c",- tool_name="tool_c",- tool_output=_json_items_payload(1),- tool_status="completed",- ),- ],- )-- parts = [msg.get_tool_parts()[0] for msg in session.messages[start_count:]]- by_id = {part.tool_id: part for part in parts}-- assert by_id["call_a"].tool_output_truncated is True- assert by_id["call_b"].tool_output_truncated is True- assert by_id["call_c"].tool_output_truncated is False- assert by_id["call_a"].tool_output_externalized_reason == "turn_budget"- assert by_id["call_b"].tool_output_externalized_reason == "turn_budget"---async def test_assistant_turn_budget_skips_externalization_when_stub_is_larger(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=100,- assistant_turn_inline_budget_chars=25,- assistant_turn_preview_budget_chars=20,- preview_chars=12,- )-- start_count = len(session.messages)- session.add_message(- "user",- [- ToolPart(- tool_id="call_a",- tool_name="tool_a",- tool_output="a" * 18,- tool_status="completed",- ),- ToolPart(- tool_id="call_b",- tool_name="tool_b",- tool_output="b" * 12,- tool_status="completed",- ),- ],- )-- parts = [msg.get_tool_parts()[0] for msg in session.messages[start_count:]]- assert [part.tool_output_truncated for part in parts] == [False, False]- assert sum(len(part.tool_output or "") for part in parts) == 30---async def test_assistant_turn_budget_uses_rendered_stub_length(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=1200,- assistant_turn_inline_budget_chars=1600,- assistant_turn_preview_budget_chars=120,- preview_chars=12,- )-- start_count = len(session.messages)- session.add_message(- "user",- [- ToolPart(- tool_id="call_a",- tool_name="tool_a",- tool_output=_json_items_payload(40),- tool_status="completed",- ),- ToolPart(- tool_id="call_b",- tool_name="tool_b",- tool_output=_json_items_payload(40),- tool_status="completed",- ),- ToolPart(- tool_id="call_c",- tool_name="tool_c",- tool_output=_json_items_payload(1),- tool_status="completed",- ),- ],- )-- parts = [msg.get_tool_parts()[0] for msg in session.messages[start_count:]]- by_id = {part.tool_id: part for part in parts}- raw_a = _json_items_payload(40)- raw_b = _json_items_payload(40)- raw_c = _json_items_payload(1)- ref_a = (- f"{session.uri}/tool-results/"- f"{tool_result_store.build_tool_result_id('call_a', tool_result_store.sha256_text(raw_a))}"- )- stub_a = tool_result_store.make_preview(- raw_a,- preview_chars=12,- ref=ref_a,- tool_name="tool_a",- sha256=tool_result_store.sha256_text(raw_a),- reason="turn_budget",- original_chars=len(raw_a),- mime_type="text/plain",- )- single_externalized_total = len(stub_a) + len(raw_b) + len(raw_c)-- assert by_id["call_a"].tool_output_truncated is True- assert by_id["call_b"].tool_output_truncated is True- assert by_id["call_c"].tool_output_truncated is False- assert single_externalized_total > 1600- assert sum(len(part.tool_output or "") for part in parts) < single_externalized_total---async def test_tool_result_aggregate_splits_when_externalization_disabled(session: Session):- session._tool_output_externalization_config = _small_config(enabled=False)- start_count = len(session.messages)-- session.add_message(- "user",- [- ToolPart(- tool_id="call_a",- tool_name="tool_a",- tool_output="a",- tool_status="completed",- ),- ToolPart(- tool_id="call_b",- tool_name="tool_b",- tool_output="b",- tool_status="completed",- ),- ],- )-- new_messages = session.messages[start_count:]- assert len(new_messages) == 2- assert [msg.get_tool_parts()[0].tool_id for msg in new_messages] == ["call_a", "call_b"]- assert all(msg.get_tool_parts()[0].tool_output_truncated is False for msg in new_messages)---async def test_read_back_tool_result_reuses_source_ref(session: Session):- session._tool_output_externalization_config = _small_config()- raw = "source-" * 20- original = session.add_message(- "user",- [- ToolPart(- tool_id="call_src",- tool_name="read_file",- tool_output=raw,- tool_status="completed",- )- ],- ).get_tool_parts()[0]-- read_msg = session.add_message(- "user",- [- ToolPart(- tool_id="call_read",- tool_name="openviking_tool_result_read",- tool_input={"tool_output_ref": original.tool_output_ref, "offset": 0, "limit": 50},- tool_output=raw[:50],- tool_status="completed",- )- ],- )-- read_part = read_msg.get_tool_parts()[0]- assert read_part.tool_output_ref == original.tool_output_ref- assert read_part.tool_output_source_ref == original.tool_output_ref- assert read_part.tool_output_source_offset == 0- assert read_part.tool_output_source_limit == 50- assert read_part.tool_output_externalized_reason == "source_read"- assert read_part.tool_output_truncated is False-- hydrated = await session._hydrate_tool_outputs_for_extraction([read_msg])- assert hydrated[0].get_tool_parts()[0].tool_output == raw[:50]---async def test_read_back_tool_result_preview_honors_min_preview_chars(session: Session):- session._tool_output_externalization_config = _small_config(- preview_chars=4,- min_preview_chars=12,- )- raw = "source-" * 20- original = session.add_message(- "user",- [- ToolPart(- tool_id="call_src_min_preview",- tool_name="read_file",- tool_output=raw,- tool_status="completed",- )- ],- ).get_tool_parts()[0]-- read_msg = session.add_message(- "user",- [- ToolPart(- tool_id="call_read_min_preview",- tool_name="openviking_tool_result_read",- tool_input={"tool_output_ref": original.tool_output_ref},- tool_output="abcdefghij" * 4,- tool_status="completed",- )- ],- )-- read_part = read_msg.get_tool_parts()[0]- assert "kind:" in read_part.tool_output- assert "preview_chars: 12" in read_part.tool_output- assert "openviking_tool_result_read" in read_part.tool_output- assert "abcdef" in read_part.tool_output- assert "efghij" in read_part.tool_output---async def test_tool_result_pairing_survives_synopsis_stubbing(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- assistant_turn_inline_budget_chars=25,- preview_chars=100,- )-- returned = session.add_message(- "user",- [- ToolPart(- tool_id="call_big",- tool_name="fetch_json",- tool_output='{"items":[{"id":1},{"id":2}]}' * 5,- tool_status="completed",- ),- ToolPart(- tool_id="call_small",- tool_name="echo",- tool_output="ok",- tool_status="completed",- ),- ],- )-- assert returned.get_tool_parts()[0].tool_id in {"call_big", "call_small"}- all_parts = [msg.get_tool_parts()[0] for msg in session.messages[-2:]]- assert {part.tool_id for part in all_parts} == {"call_big", "call_small"}- big = next(part for part in all_parts if part.tool_id == "call_big")- small = next(part for part in all_parts if part.tool_id == "call_small")- assert big.tool_output_truncated is True- assert "kind: json" in big.tool_output- assert small.tool_output == "ok"---async def test_update_tool_part_externalizes_large_output(session_with_tool_call):- session, message_id, tool_id = session_with_tool_call- session._tool_output_externalization_config = _small_config()- raw = "updated-" * 20-- session.update_tool_part(message_id, tool_id, raw, status="completed")-- msg = next(m for m in session.messages if m.id == message_id)- part = msg.find_tool_part(tool_id)- assert part is not None- assert part.tool_output_truncated is True- assert part.tool_output_ref- stored = await session.read_tool_result(part.tool_output_ref.rsplit("/", 1)[-1], limit=-1)- assert stored["content"] == raw--async def test_list_tool_results_filters_tool_name_before_limit():class FakeVikingFS:def __init__(self):@@ -669,34 +144,3 @@ async def test_list_tool_results_filters_tool_name_before_limit():result = await store.list(tool_name="target", limit=1)assert result["tool_results"] == [{"tool_result_id": "tr_target", "tool_name": "target"}]---async def test_tool_result_search_uses_raw_payload_not_stub_helper_text(session: Session):- session._tool_output_externalization_config = _small_config(- threshold_chars=20,- preview_chars=60,- )- raw = "needle\n" + ("ordinary payload\n" * 40)-- part = session.add_message(- "user",- [- ToolPart(- tool_id="call_search_raw",- tool_name="read_log",- tool_output=raw,- tool_status="completed",- )- ],- ).get_tool_parts()[0]- tool_result_id = part.tool_output_ref.rsplit("/", 1)[-1]-- assert "openviking_tool_result_read" in part.tool_output- raw_match = await session.search_tool_result(tool_result_id, query="needle")- helper_match = await session.search_tool_result(- tool_result_id,- query="openviking_tool_result_read",- )-- assert len(raw_match["matches"]) == 1- assert helper_match["matches"] == []diff --git a/tests/session/train/test_train_framework.py b/tests/session/train/test_train_framework.pyindex e4586dbe4..c3f09f4af 100644--- a/tests/session/train/test_train_framework.py+++ b/tests/session/train/test_train_framework.py@@ -749,81 +749,6 @@ async def test_batch_policy_trainer_trains_from_rollout_batch():assert result.metadata["rollout_count"] == 1-async def test_streaming_policy_trainer_flushes_on_gradient_count():- from openviking.session.train import (- PolicyPlanItem,- StreamingPolicyTrainer,- StreamingPolicyTrainerConfig,- )-- class LinkingOptimizer(DummyOptimizer):- async def plan(self, gradients, policy_set, context):- del policy_set, context- return PolicyUpdatePlan(- items=[- PolicyPlanItem(- kind="upsert",- memory_type="experiences",- target_name=f"exp_{idx}",- target_uri=f"viking://user/u/memories/experiences/exp_{idx}.md",- before_content=None,- after_content=f"content {idx}",- links=list(gradient.links),- )- for idx, gradient in enumerate(gradients)- ],- metadata={"gradient_count": len(gradients)},- )-- trainer = StreamingPolicyTrainer(- policy_set=_policy_set(),- rollout_analyzer=DummyAnalyzer(),- gradient_estimator=DummyEstimator(),- policy_optimizer=LinkingOptimizer(),- policy_updater=DummyUpdater(),- context=PipelineContext(),- config=StreamingPolicyTrainerConfig(- max_gradients_per_update=2,- max_wait_seconds=60.0,- timer_check_interval_seconds=60.0,- ),- )- rollout1 = Rollout(- case=_case(),- messages=[Message(id="s1", role="user", parts=[TextPart(text="first")])],- policy_snapshot_id="snapshot-1",- )- rollout2 = Rollout(- case=_case(),- messages=[Message(id="s2", role="user", parts=[TextPart(text="second")])],- policy_snapshot_id="snapshot-1",- )-- first, second = await asyncio.gather(- trainer.submit_rollout(rollout1),- trainer.submit_rollout(rollout2),- )- assert first is not second- assert first.batch_result is second.batch_result- assert len(first.analyses) == 1- assert len(second.analyses) == 1- assert [analysis.trajectories[0].uri for analysis in first.analyses] == [- "viking://user/u/memories/trajectories/duplicate_booking.md"- ]- assert len(first.plan.items) == 2- assert len(second.plan.items) == 2- assert second.metadata["flush_reason"] == "count"- assert second.metadata["gradient_count"] == 1- assert second.metadata["batch_gradient_count"] == 2- assert second.apply_result.updated_policy_set.policies[0].version == 2- assert await trainer.get_buffered_gradient_count() == 0- assert trainer.last_apply_result is second.batch_result.apply_result-- assert await trainer.close() is None- assert trainer.closed is True--@pytest.mark.asyncioasync def test_streaming_policy_trainer_scopes_concurrent_submit_results_by_source_trajectory():from openviking.session.train import (@@ -1158,84 +1083,6 @@ async def test_streaming_policy_trainer_mixes_categories_in_chunks():assert await trainer.close() is None-async def test_streaming_policy_trainer_flushes_on_timer():- from openviking.session.train import StreamingPolicyTrainer, StreamingPolicyTrainerConfig-- trainer = StreamingPolicyTrainer(- policy_set=_policy_set(),- rollout_analyzer=DummyAnalyzer(),- gradient_estimator=DummyEstimator(),- policy_optimizer=DummyOptimizer(),- policy_updater=DummyUpdater(),- context=PipelineContext(),- config=StreamingPolicyTrainerConfig(- max_gradients_per_update=10,- max_wait_seconds=0.01,- timer_check_interval_seconds=0.01,- ),- )- rollout = Rollout(- case=_case(),- messages=[Message(id="timer", role="user", parts=[TextPart(text="timer")])],- policy_snapshot_id="snapshot-1",- )-- result = await trainer.submit_rollout(rollout)- assert result is not None- assert result.metadata["flush_reason"] == "time"- assert result.metadata["gradient_count"] == 1- assert trainer.last_apply_result is not None- assert trainer.last_apply_result.updated_policy_set.policies[0].version == 2- assert await trainer.get_buffered_gradient_count() == 0-- assert await trainer.close() is None- assert trainer.closed is True---async def test_streaming_policy_trainer_close_flushes_buffer_and_rejects_submit():- from openviking.session.train import StreamingPolicyTrainer, StreamingPolicyTrainerConfig-- trainer = StreamingPolicyTrainer(- policy_set=_policy_set(),- rollout_analyzer=DummyAnalyzer(),- gradient_estimator=DummyEstimator(),- policy_optimizer=DummyOptimizer(),- policy_updater=DummyUpdater(),- context=PipelineContext(),- config=StreamingPolicyTrainerConfig(- max_gradients_per_update=10,- max_wait_seconds=0.01,- timer_check_interval_seconds=0.01,- ),- )- rollout = Rollout(- case=_case(),- messages=[Message(id="close", role="user", parts=[TextPart(text="close")])],- policy_snapshot_id="snapshot-1",- )-- submit_task = asyncio.create_task(trainer.submit_rollout(rollout))- await asyncio.sleep(0)- assert await trainer.get_buffered_gradient_count() == 1-- result = await trainer.close()-- assert result is not None- assert result.metadata["flush_reason"] == "close"- assert result.metadata["gradient_count"] == 1- submit_result = await submit_task- assert submit_result.batch_result is result- assert trainer.closed is True- assert await trainer.get_buffered_gradient_count() == 0- assert trainer.last_apply_result is result.apply_result- assert await trainer.close() is None-- with pytest.raises(RuntimeError, match="closed"):- await trainer.submit_rollout(rollout)--@pytest.mark.asyncioasync def test_get_streaming_policy_trainer_returns_process_global_instance():from openviking.session.train import (diff --git a/tests/storage/test_opengauss_adapter.py b/tests/storage/test_opengauss_adapter.pyindex c831ac7f8..1f4d140a8 100644--- a/tests/storage/test_opengauss_adapter.py+++ b/tests/storage/test_opengauss_adapter.py@@ -5,11 +5,9 @@ from __future__ import annotationsimport osimport uuid-from datetime import datetime, timezoneimport pytest-from openviking.storage.expr import And, Contains, Eq, PathScope, TimeRangefrom openviking.storage.vectordb.collection.result import SearchResultfrom openviking.storage.vectordb_adapters.factory import create_collection_adapterfrom openviking.storage.vectordb_adapters.opengauss_adapter import (@@ -68,78 +66,6 @@ def test_factory_creates_opengauss_adapter_without_connecting():assert adapter.physical_table_name == "ov_default_context"-def test_augments_path_fields_on_write_and_hides_them_on_read():- adapter = OpenGaussCollectionAdapter.from_config(_build_config())- source_record = {- "id": "1",- "uri": "viking://resources/acme/docs/a.md",- "vector": [0.1, 0.2],- }-- normalized = adapter._normalize_record_for_write(source_record)-- assert normalized["uri"] == "/resources/acme/docs/a.md"- assert normalized["parent_uri"] == "/resources/acme/docs"- assert normalized["scope_roots"] == [- "/",- "/resources",- "/resources/acme",- "/resources/acme/docs",- ]- assert normalized["uri_depth"] == 4-- public_record = adapter.normalize_record_for_read(normalized)- assert public_record["uri"] == "viking://resources/acme/docs/a.md"- assert "parent_uri" not in public_record- assert "scope_roots" not in public_record- assert "uri_depth" not in public_record---def test_sanitizes_scalar_index_fields():- adapter = OpenGaussCollectionAdapter.from_config(_build_config())-- result = adapter.sanitize_scalar_index_fields(- scalar_index_fields=["uri", "account_id"],- fields_meta=[],- )-- assert result == ["uri", "account_id", "parent_uri", "scope_roots", "uri_depth"]---def test_compiles_filter_exprs_for_sql_collection():- adapter = OpenGaussCollectionAdapter.from_config(_build_config())-- compiled = adapter.compile_filter(- And(- [- Eq("account_id", "acme"),- PathScope("uri", "viking://resources/acme/docs", depth=-1),- TimeRange(- "updated_at",- start=datetime(2026, 5, 1, tzinfo=timezone.utc),- end=datetime(2026, 6, 1, tzinfo=timezone.utc),- ),- Contains("abstract", "quarterly report"),- ]- )- )-- assert compiled == {- "op": "and",- "conds": [- {"op": "must", "field": "account_id", "conds": ["acme"]},- {"op": "must", "field": "scope_roots", "conds": ["/resources/acme/docs"]},- {- "op": "range",- "field": "updated_at",- "gte": "2026-05-01T00:00:00+00:00",- "lt": "2026-06-01T00:00:00+00:00",- },- {"op": "contains", "field": "abstract", "substring": "quarterly report"},- ],- }--def test_collection_filter_to_sql_for_path_scope():collection = object.__new__(OpenGaussCollection)collection._field_types = {"updated_at": "date_time"}diff --git a/tests/storage/test_qdrant_adapter.py b/tests/storage/test_qdrant_adapter.pyindex ea7333e3d..0ee35af03 100644--- a/tests/storage/test_qdrant_adapter.py+++ b/tests/storage/test_qdrant_adapter.py@@ -1,11 +1,9 @@# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.# SPDX-License-Identifier: AGPL-3.0-from datetime import datetime, timezoneimport pytest-from openviking.storage.expr import And, Contains, Eq, PathScope, TimeRangefrom openviking.storage.vectordb_adapters.factory import create_collection_adapterfrom openviking.storage.vectordb_adapters.qdrant_adapter import QdrantCollectionAdapterfrom openviking_cli.utils.config.vectordb_config import VectorDBBackendConfig@@ -70,116 +68,3 @@ def test_existing_physical_collection_without_metadata_is_rejected_and_closed(moadapter.collection_exists()assert candidate.closed is True---def test_augments_path_fields_on_write_and_hides_them_on_read():- adapter = QdrantCollectionAdapter.from_config(_build_config())- source_record = {- "id": "1",- "uri": "viking://resources/acme/docs/a.md",- "vector": [0.1, 0.2],- }-- normalized = adapter._normalize_record_for_write(source_record)-- assert normalized["uri"] == "/resources/acme/docs/a.md"- assert normalized["parent_uri"] == "/resources/acme/docs"- assert normalized["scope_roots"] == [- "/",- "/resources",- "/resources/acme",- "/resources/acme/docs",- ]- assert normalized["uri_depth"] == 4- assert source_record["uri"] == "viking://resources/acme/docs/a.md"-- public_record = adapter.normalize_record_for_read(normalized)- assert public_record["uri"] == "viking://resources/acme/docs/a.md"- assert "parent_uri" not in public_record- assert "scope_roots" not in public_record- assert "uri_depth" not in public_record---def test_sanitizes_scalar_index_fields():- adapter = QdrantCollectionAdapter.from_config(_build_config())- result = adapter.sanitize_scalar_index_fields(- scalar_index_fields=["uri", "account_id"],- fields_meta=[],- )- assert result == [- "uri",- "account_id",- "parent_uri",- "scope_roots",- "uri_depth",- "name",- "description",- "abstract",- "tags",- ]---def test_compiles_filter_exprs():- adapter = QdrantCollectionAdapter.from_config(_build_config())- compiled = adapter.compile_filter(- And(- [- Eq("account_id", "acme"),- PathScope("uri", "viking://resources/acme/docs", depth=-1),- TimeRange(- "updated_at",- start=datetime(2026, 5, 1, tzinfo=timezone.utc),- end=datetime(2026, 6, 1, tzinfo=timezone.utc),- ),- Contains("abstract", "quarterly report"),- ]- )- )-- assert compiled == {- "must": [- {"key": "account_id", "match": {"value": "acme"}},- {"key": "scope_roots", "match": {"value": "/resources/acme/docs"}},- {- "key": "updated_at",- "range": {- "gte": "2026-05-01T00:00:00+00:00",- "lt": "2026-06-01T00:00:00+00:00",- },- },- {"key": "abstract", "match": {"text": "quarterly report"}},- ]- }---def test_compiles_legacy_dict_filters():- adapter = QdrantCollectionAdapter.from_config(_build_config())- compiled = adapter.compile_filter(- {- "op": "and",- "conds": [- {"op": "must", "field": "account_id", "conds": ["acme"]},- {- "op": "time_range",- "field": "updated_at",- "gte": "2026-05-01T00:00:00Z",- "lt": "2026-06-01T00:00:00Z",- },- {"op": "prefix", "field": "uri", "prefix": "viking://resources/acme/docs"},- ],- }- )-- assert compiled == {- "must": [- {"key": "account_id", "match": {"value": "acme"}},- {- "key": "updated_at",- "range": {- "gte": "2026-05-01T00:00:00Z",- "lt": "2026-06-01T00:00:00Z",- },- },- {"key": "scope_roots", "match": {"value": "/resources/acme/docs"}},- ]- }diff --git a/tests/storage/test_vectordb_collection_loading.py b/tests/storage/test_vectordb_collection_loading.pydeleted file mode 100644index c5c9bd9e3..000000000--- a/tests/storage/test_vectordb_collection_loading.py+++ /dev/null@@ -1,105 +0,0 @@-import unittest-import sys-import os--# Add open_test path to ensure modules can be found-sys.path.insert(0, "/cloudide/workspace/open_test")--from openviking.storage.vectordb.project.vikingdb_project import (- get_or_create_vikingdb_project,- VikingDBProject,-)-from openviking.storage.vectordb.collection.vikingdb_collection import VikingDBCollection---class TestDynamicLoading(unittest.TestCase):- def test_default_loading(self):- # Test with default configuration- config = {"Host": "test_host"}- project = get_or_create_vikingdb_project(config=config)- self.assertEqual(project.CollectionClass, VikingDBCollection)- print("Default loading test passed")-- def test_explicit_loading(self):- # Test with explicit configuration pointing to MockJoiner- # MockJoiner is now in tests.storage.mock_backend-- # We assume tests package structure is available from /cloudide/workspace/open_test-- config = {- "Host": "test_host",- "Headers": {"Auth": "Token"},- "CollectionClass": "tests.storage.mock_backend.MockCollection",- "CollectionArgs": {"custom_param1": "custom_val", "custom_param2": 123},- }- project = get_or_create_vikingdb_project(config=config)-- from tests.storage.mock_backend import MockCollection-- self.assertEqual(project.CollectionClass, MockCollection)- self.assertEqual(project.host, "test_host")- self.assertEqual(project.headers, {"Auth": "Token"})- self.assertEqual(- project.collection_args, {"custom_param1": "custom_val", "custom_param2": 123}- )-- # Test collection creation to verify params are passed- collection_name = "test_collection"- meta_data = {- "test_verification": True,- "Host": "metadata_host",- "Headers": {"Meta": "Header"},- }-- # The project wrapper will pass host, headers, meta_data, AND collection_args- kwargs = {"host": project.host, "headers": project.headers, "meta_data": meta_data}- kwargs.update(project.collection_args)-- collection_instance = project.CollectionClass(**kwargs)-- # Verify custom params are set correctly- self.assertEqual(collection_instance.custom_param1, "custom_val")- self.assertEqual(collection_instance.custom_param2, 123)-- # Verify host/headers are in kwargs (since init doesn't take them explicitly anymore)- self.assertEqual(collection_instance.kwargs.get("host"), "test_host")- self.assertEqual(collection_instance.kwargs.get("headers"), {"Auth": "Token"})-- print("Explicit loading test passed (MockCollection with custom params)")-- def test_kwargs_loading(self):- # Test with CollectionArgs- config = {- "Host": "test_host",- "CollectionClass": "tests.storage.mock_backend.MockCollection",- "CollectionArgs": {"custom_param1": "extra_value", "custom_param2": 456},- }- project = get_or_create_vikingdb_project(config=config)-- self.assertEqual(- project.collection_args, {"custom_param1": "extra_value", "custom_param2": 456}- )-- # Manually verify instantiation with kwargs- kwargs = {- "host": project.host,- "headers": project.headers,- "meta_data": {"test_verification": True},- }- kwargs.update(project.collection_args)-- collection_instance = project.CollectionClass(**kwargs)- self.assertEqual(collection_instance.custom_param1, "extra_value")- self.assertEqual(collection_instance.custom_param2, 456)- print("Kwargs loading test passed")-- def test_invalid_loading(self):- # Test with invalid class path- config = {"Host": "test_host", "CollectionClass": "non.existent.module.Class"}- with self.assertRaises(ImportError):- get_or_create_vikingdb_project(config=config)- print("Invalid loading test passed")---if __name__ == "__main__":- unittest.main()diff --git a/tests/storage/test_viking_fs_actor_peer_view.py b/tests/storage/test_viking_fs_actor_peer_view.pyindex 019ed1e25..c293afc72 100644--- a/tests/storage/test_viking_fs_actor_peer_view.py+++ b/tests/storage/test_viking_fs_actor_peer_view.py@@ -254,7 +254,7 @@ async def test_actor_peer_view_blocks_read_stat_and_write_to_other_peer(fs, actoawait fs.write_file(_other_peer_uri(), "blocked", ctx=actor_ctx)await fs.write_file("viking://user/support_bot/resources/new.md", "allowed", ctx=actor_ctx)- assert "/local/acct/user/support_bot/resources/new.md" in fs._async_agfs.sync_client.writes+ assert "/local/acct/user/support_bot/resources/new.md" in fs._async_agfs._client.writes@pytest.mark.asynciodiff --git a/tests/telemetry/test_observability_context.py b/tests/telemetry/test_observability_context.pyindex 0eac617a9..f4fb6d6aa 100644--- a/tests/telemetry/test_observability_context.py+++ b/tests/telemetry/test_observability_context.py@@ -34,7 +34,6 @@ from openviking.observability.context import (get_operation_observability_context,get_root_observability_context,reset_observability_context,- set_observability_context,)from openviking.telemetry.span_models import (OperationSpanAttributes,@@ -110,28 +109,6 @@ class TestObservabilityContextBasics:assert ctx.execution_trace_id == "custom_trace_id"assert ctx.execution_span_id == "custom_span_id"- def test_set_extra(self) -> None:- """- Test that set_extra adds custom attributes.- """- ctx = ObservabilityContext()- ctx.set_extra("custom_key", "custom_value")- ctx.set_extra("number_key", 42)-- assert ctx.extra["custom_key"] == "custom_value"- assert ctx.extra["number_key"] == 42-- def test_to_log_fields_includes_extra(self) -> None:- """- Test that to_log_fields includes extra attributes.- """- ctx = ObservabilityContext()- ctx.set_extra("custom_field", "custom_value")-- fields = ctx.to_log_fields()-- assert fields["custom_field"] == "custom_value"-def test_import_from_fresh_interpreter_does_not_trigger_circular_import(self) -> None:"""Test that observability context can be imported in a fresh interpreter.@@ -480,80 +457,7 @@ class TestContextManagerIntegration:Tests for integration with context manager patterns."""- def test_set_and_reset_observability_context(self) -> None:- """- Test that set_observability_context and reset_observability_context work correctly.- """- # Create a custom context- custom_ctx = ObservabilityContext()- custom_ctx.set_extra("custom_key", "custom_value")- custom_ctx.bind_execution(trace_id="custom_trace", span_id="custom_span")-- # Set the context- token = set_observability_context(custom_ctx)-- try:- # Verify the context is set- retrieved = get_observability_context()- assert retrieved.execution_trace_id == "custom_trace"- assert retrieved.execution_span_id == "custom_span"- assert retrieved.extra["custom_key"] == "custom_value"-- finally:- # Reset the context- reset_observability_context(token)-- # After reset, should be back to default- after_reset = get_observability_context()- assert after_reset.execution_trace_id is None- assert after_reset.execution_span_id is None--class TestLogFieldsIntegration:"""Tests for log fields integration."""-- def test_to_log_fields_combines_all_contexts(self) -> None:- """- Test that to_log_fields combines all context types correctly.- """- ctx = ObservabilityContext()-- # Add root context- root_attrs = RootSpanAttributes(- http_method="GET",- http_route="/test",- request_id="req-123",- )- root_attrs.account_id = "acct-456"- ctx.bind_root(root_attrs)-- # Add operation context- operation_attrs = OperationSpanAttributes(- operation="search.find",- telemetry_id="tm-789",- )- operation_attrs.status = "ok"- ctx.bind_operation(operation_attrs)-- # Add execution context- ctx.bind_execution(trace_id="exec_trace", span_id="exec_span")-- # Add extra fields- ctx.set_extra("extra_field", "extra_value")-- # Get log fields- fields = ctx.to_log_fields()-- # Verify all fields are present- assert fields["trace_id"] == "exec_trace"- assert fields["span_id"] == "exec_span"- assert fields["request_id"] == "req-123"- assert fields["account_id"] == "acct-456"- assert fields["http_method"] == "GET"- assert fields["http_route"] == "/test"- assert fields["operation"] == "search.find"- assert fields["telemetry_id"] == "tm-789"- assert fields["status"] == "ok"- assert fields["extra_field"] == "extra_value"diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.pyindex f3605d241..366167d82 100644--- a/tests/test_edge_cases.py+++ b/tests/test_edge_cases.py@@ -24,11 +24,11 @@ import pytestsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))from openviking.parse.parsers.upload_utils import ( # noqa: I001- _sanitize_rel_path,detect_and_convert_encoding,is_text_file,upload_directory,)+from openviking.utils.path_safety import sanitize_relative_viking_pathfrom openviking_cli.utils.uri import VikingURI@@ -96,7 +96,7 @@ class TestLongFilenames:assert len(filename.encode("utf-8")) == 255# Test sanitization doesn't break at exact boundary- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)assert sanitized is not Noneassert len(sanitized) > 0@@ -108,7 +108,7 @@ class TestLongFilenames:assert len(filename.encode("utf-8")) == 256- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)# Should be handled gracefully (truncated or rejected)assert sanitized is not None@@ -120,7 +120,7 @@ class TestLongFilenames:assert len(filename.encode("utf-8")) > 400- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)assert sanitized is not None# Should handle or truncate appropriately@@ -128,7 +128,7 @@ class TestLongFilenames:"""Test filename composed entirely of special characters."""special_filename = "!@#$%^&*()_+-={}[]|\\:;\"'<>,.?/~`" + ".txt"- sanitized = _sanitize_rel_path(special_filename)+ sanitized = sanitize_relative_viking_path(special_filename)# Should sanitize dangerous characters while preserving valid onesassert sanitized is not Noneassert ".txt" in sanitized # Extension should be preserved@@ -144,7 +144,7 @@ class TestLongFilenames:for filename in dangerous_filenames:with pytest.raises(ValueError, match="Unsafe relative path rejected"):- _sanitize_rel_path(filename)+ sanitize_relative_viking_path(filename)class TestSearchByIdEdgeCases:@@ -218,30 +218,11 @@ class TestSearchByIdEdgeCases:class TestDuplicateFilenameHandling:"""Test duplicate filename handling and case sensitivity."""- @pytest.mark.asyncio- async def test_upload_same_file_multiple_times(self, tmp_path):- """Test uploading the same file 10 times - should handle duplicates gracefully."""- # Create test file- test_file = tmp_path / "duplicate_test.txt"- test_file.write_text("This is a test file for duplicate testing.")-- # Mock VikingFS- mock_fs = MagicMock()- mock_fs.write_file_bytes = AsyncMock()- mock_fs.mkdir = AsyncMock()-- # Upload the same file 10 times- for _ in range(10):- await upload_text_files([str(test_file)], "viking://test/", mock_fs)-- # Should handle duplicates without crashing- assert mock_fs.write_file_bytes.call_count == 10-def test_case_sensitivity_filenames(self):"""Test filenames that differ only in case."""filenames = ["TestFile.txt", "testfile.txt", "TESTFILE.TXT", "TestFile.TXT"]- sanitized_names = [_sanitize_rel_path(name) for name in filenames]+ sanitized_names = [sanitize_relative_viking_path(name) for name in filenames]# All should be valid but may be treated differently on case-insensitive systemsfor name in sanitized_names:@@ -258,8 +239,8 @@ class TestDuplicateFilenameHandling:assert filename_nfc != filename_nfdassert unicodedata.normalize("NFC", filename_nfd) == filename_nfc- sanitized_nfc = _sanitize_rel_path(filename_nfc)- sanitized_nfd = _sanitize_rel_path(filename_nfd)+ sanitized_nfc = sanitize_relative_viking_path(filename_nfc)+ sanitized_nfd = sanitize_relative_viking_path(filename_nfd)assert sanitized_nfc is not Noneassert sanitized_nfd is not None@@ -351,7 +332,7 @@ class TestUnicodeEdgeCases:# Zero-width characters that might cause issuesfilename = "test\u200b\u200c\u200d\ufefffile.txt" # ZWSP, ZWNJ, ZWJ, BOM- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)assert sanitized is not None# Zero-width characters should ideally be stripped@@ -362,7 +343,7 @@ class TestUnicodeEdgeCases:# Arabic/Hebrew filenamertl_filename = "ملف_اختبار.txt" # Arabic for "test file"- sanitized = _sanitize_rel_path(rtl_filename)+ sanitized = sanitize_relative_viking_path(rtl_filename)assert sanitized is not Noneassert len(sanitized) > 0@@ -374,7 +355,7 @@ class TestUnicodeEdgeCases:# Base character + multiple combining marksfilename = "e\u0301\u0302\u0303\u0304.txt" # e + acute + circumflex + tilde + macron- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)assert sanitized is not Noneassert len(sanitized) > 0@@ -383,7 +364,7 @@ class TestUnicodeEdgeCases:# Emoji that require surrogate pairs in UTF-16filename = "test🏴🧑💻👨👩👧👦.txt" # Flag, person, family- sanitized = _sanitize_rel_path(filename)+ sanitized = sanitize_relative_viking_path(filename)assert sanitized is not Noneassert len(sanitized) > 0diff --git a/tests/test_prompt_manager.py b/tests/test_prompt_manager.pyindex 9557537f6..1c6766447 100644--- a/tests/test_prompt_manager.py+++ b/tests/test_prompt_manager.py@@ -9,9 +9,6 @@ import yamlfrom openviking.prompts.manager import PromptManagerfrom openviking.session.memory.memory_type_registry import MemoryTypeRegistry-from openviking.session.memory.session_extract_context_provider import (- SessionExtractContextProvider,-)from openviking_cli.utils.config import (OPENVIKING_CONFIG_ENV,OPENVIKING_PROMPT_TEMPLATES_DIR_ENV,@@ -262,79 +259,6 @@ def test_memory_type_registry_prefers_custom_memory_dir_over_prompt_manager_tempassert registry.get("prompt_root_memory") is None-def test_context_provider_schema_directories_use_prompt_manager_resolved_templates_root(- tmp_path, monkeypatch-):- resolved_templates_dir = tmp_path / "resolved-prompts"- expected_memory_dir = resolved_templates_dir / "memory"- expected_memory_dir.mkdir(parents=True)-- monkeypatch.setattr(- PromptManager,- "_resolve_templates_dir",- classmethod(lambda cls, templates_dir=None: resolved_templates_dir),- )- monkeypatch.setattr(- "openviking.session.memory.session_extract_context_provider.get_openviking_config",- lambda: SimpleNamespace(- memory=SimpleNamespace(- custom_templates_dir="",- eager_prefetch=False,- prefetch_search_topn=5,- experimental_memory_switch=False,- link_enabled=True,- )- ),- )-- provider = SessionExtractContextProvider(messages=[])-- bundled_memory_dir = str(PromptManager._get_bundled_templates_dir() / "memory")- dirs = provider.get_schema_directories()- # Bundled is always first; resolved is appended when different from bundled- assert dirs[0] == bundled_memory_dir- assert str(expected_memory_dir) in dirs---def test_context_provider_schema_directories_prefer_custom_memory_dir_over_prompt_manager_root(- tmp_path, monkeypatch-):- resolved_templates_dir = tmp_path / "resolved-prompts"- custom_memory_dir = tmp_path / "custom-memory"-- monkeypatch.setattr(- PromptManager,- "_resolve_templates_dir",- classmethod(lambda cls, templates_dir=None: resolved_templates_dir),- )- monkeypatch.setattr(- "openviking.session.memory.session_extract_context_provider.get_openviking_config",- lambda: SimpleNamespace(- memory=SimpleNamespace(- custom_templates_dir=str(custom_memory_dir),- eager_prefetch=False,- prefetch_search_topn=5,- experimental_memory_switch=False,- link_enabled=False,- )- ),- )- monkeypatch.setattr(- "os.path.exists",- lambda path: (- path == str(custom_memory_dir)- or path == str(PromptManager._get_bundled_templates_dir() / "memory")- ),- )-- provider = SessionExtractContextProvider(messages=[])-- assert provider.get_schema_directories() == [- str(PromptManager._get_bundled_templates_dir() / "memory"),- str(custom_memory_dir),- ]--def test_memory_type_registry_loads_experimental_templates_when_switch_enabled(monkeypatch):"""When experimental_memory_switch is True, experimental templates override defaults."""monkeypatch.setattr(@@ -370,29 +294,3 @@ def test_memory_type_registry_does_not_load_experimental_templates_when_switch_dentities = registry.get("entities")assert entities is not None---def test_context_provider_includes_experimental_dir_when_switch_enabled(monkeypatch):- """When experimental_memory_switch is True, schema directories include experimental subdir."""- monkeypatch.setattr(- "openviking.session.memory.session_extract_context_provider.get_openviking_config",- lambda: SimpleNamespace(- memory=SimpleNamespace(- custom_templates_dir="",- eager_prefetch=False,- prefetch_search_topn=5,- experimental_memory_switch=True,- link_enabled=False,- )- ),- )-- provider = SessionExtractContextProvider(messages=[])- dirs = provider.get_schema_directories()-- bundled_memory_dir = str(PromptManager._get_bundled_templates_dir() / "memory")- experimental_memory_dir = str(- PromptManager._get_bundled_templates_dir() / "memory" / "experimental_memory"- )- assert bundled_memory_dir in dirs- assert experimental_memory_dir in dirsdiff --git a/tests/test_session_async_commit.py b/tests/test_session_async_commit.pyindex de0249d60..e74753765 100644--- a/tests/test_session_async_commit.py+++ b/tests/test_session_async_commit.py@@ -15,13 +15,13 @@ from openviking.server.app import create_appfrom openviking.server.config import ServerConfigfrom openviking.server.dependencies import set_servicefrom openviking.service.core import OpenVikingService-from openviking.service.task_tracker import TaskStatus, get_task_tracker, reset_task_tracker+from openviking.service.task_tracker import TaskStatus, get_task_tracker, set_task_tracker@pytest_asyncio.fixtureasync def api_client(temp_dir) -> AsyncGenerator[Tuple[httpx.AsyncClient, OpenVikingService], None]:"""Create in-process HTTP client for API endpoint tests."""- reset_task_tracker()+ set_task_tracker(None)service = OpenVikingService(path=str(temp_dir / "api_data"))await service.initialize()app = create_app(config=ServerConfig(), service=service)@@ -33,19 +33,19 @@ async def api_client(temp_dir) -> AsyncGenerator[Tuple[httpx.AsyncClient, OpenViawait service.close()await AsyncOpenViking.reset()- reset_task_tracker()+ set_task_tracker(None)@pytest_asyncio.fixtureasync def ov_client(temp_dir) -> AsyncGenerator[AsyncOpenViking, None]:"""Create AsyncOpenViking client for unit tests."""- reset_task_tracker()+ set_task_tracker(None)client = AsyncOpenViking(path=str(temp_dir / "ov_data"))await client.initialize()yield clientawait client.close()await AsyncOpenViking.reset()- reset_task_tracker()+ set_task_tracker(None)async def _new_session_with_one_message(client: httpx.AsyncClient) -> str:diff --git a/tests/test_session_task_tracking.py b/tests/test_session_task_tracking.pyindex f7af78254..101c270df 100644--- a/tests/test_session_task_tracking.py+++ b/tests/test_session_task_tracking.py@@ -15,13 +15,13 @@ from openviking.server.app import create_appfrom openviking.server.config import ServerConfigfrom openviking.server.dependencies import set_servicefrom openviking.service.core import OpenVikingService-from openviking.service.task_tracker import get_task_tracker, reset_task_tracker+from openviking.service.task_tracker import get_task_tracker, set_task_tracker@pytest_asyncio.fixtureasync def api_client(temp_dir) -> AsyncGenerator[Tuple[httpx.AsyncClient, OpenVikingService], None]:"""Create in-process HTTP client for API endpoint tests."""- reset_task_tracker()+ set_task_tracker(None)service = OpenVikingService(path=str(temp_dir / "api_data"))await service.initialize()app = create_app(config=ServerConfig(), service=service)@@ -33,7 +33,7 @@ async def api_client(temp_dir) -> AsyncGenerator[Tuple[httpx.AsyncClient, OpenViawait service.close()await AsyncOpenViking.reset()- reset_task_tracker()+ set_task_tracker(None)async def _new_session_with_message(client: httpx.AsyncClient) -> str:diff --git a/tests/test_task_tracker.py b/tests/test_task_tracker.pyindex 43e68416f..a8ddf5eb4 100644--- a/tests/test_task_tracker.py+++ b/tests/test_task_tracker.py@@ -17,7 +17,6 @@ from openviking.service.task_tracker import (TaskTracker,_sanitize_error,get_task_tracker,- reset_task_tracker,set_task_tracker,)from openviking_cli.session.user_id import UserIdentifier@@ -28,9 +27,9 @@ pytestmark = pytest.mark.asyncio@pytest.fixture(autouse=True)def clean_singleton():"""Reset singleton before and after each test."""- reset_task_tracker()+ set_task_tracker(None)yield- reset_task_tracker()+ set_task_tracker(None)@pytest.fixture@@ -422,7 +421,7 @@ async def test_singleton():async def test_singleton_reset():t1 = _set_fake_global_tracker()- reset_task_tracker()+ set_task_tracker(None)t2 = _set_fake_global_tracker()assert t1 is not t2diff --git a/tests/test_telemetry_runtime.py b/tests/test_telemetry_runtime.pyindex 5ae9e8bda..b4ad6ad85 100644--- a/tests/test_telemetry_runtime.py+++ b/tests/test_telemetry_runtime.py@@ -28,7 +28,6 @@ from openviking.storage.queuefs.semantic_msg import SemanticMsgfrom openviking.storage.queuefs.semantic_processor import SemanticProcessorfrom openviking.telemetry import (get_current_telemetry,- get_telemetry_runtime,register_telemetry,tracer_module,unregister_telemetry,@@ -41,17 +40,6 @@ from openviking_cli.session.user_id import UserIdentifierfrom openviking_cli.utils import logger as logger_module-def test_telemetry_module_exports_snapshot_and_runtime():- snapshot = TelemetrySnapshot(- telemetry_id="tm_demo",- summary={"duration_ms": 1.2},- )- usage = snapshot.to_usage_dict()-- assert usage == {"duration_ms": 1.2, "token_total": 0}- assert get_telemetry_runtime().meter() is not None--def test_root_observability_context_bind_and_reset():root = RootSpanAttributes(http_method="GET", http_route="/demo", request_id="req-1")token = bind_root_observability_context(root)diff --git a/tests/test_upload_utils.py b/tests/test_upload_utils.pyindex 35c0041c2..732fdb2ba 100644--- a/tests/test_upload_utils.py+++ b/tests/test_upload_utils.py@@ -8,14 +8,12 @@ from typing import Dict, Listimport pytestfrom openviking.parse.parsers.upload_utils import (- _sanitize_rel_path,detect_and_convert_encoding,is_text_file,- should_skip_directory,should_skip_file,upload_directory,- upload_text_files,)+from openviking.utils.path_safety import sanitize_relative_viking_path# ---------------------------------------------------------------------------# Fixtures@@ -249,78 +247,11 @@ class TestShouldSkipFile:# ----------------------------------------------------------------------------class TestShouldSkipDirectory:- def test_ignored_dirs(self) -> None:- assert should_skip_directory(".git") is True- assert should_skip_directory("__pycache__") is True- assert should_skip_directory("node_modules") is True-- def test_hidden_dirs(self) -> None:- assert should_skip_directory(".vscode") is True- assert should_skip_directory(".idea") is True-- def test_normal_dirs(self) -> None:- assert should_skip_directory("src") is False- assert should_skip_directory("tests") is False- assert should_skip_directory("docs") is False--# ---------------------------------------------------------------------------# upload_text_files# ----------------------------------------------------------------------------class TestUploadTextFiles:- @pytest.mark.asyncio- async def test_upload_success(self, tmp_path: Path, viking_fs: FakeVikingFS) -> None:- f = tmp_path / "hello.py"- f.write_text("print('hi')", encoding="utf-8")- file_paths = [(f, "hello.py")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/abc", viking_fs)-- assert count == 1- assert len(warnings) == 0- assert "viking://temp/abc/hello.py" in viking_fs.files-- @pytest.mark.asyncio- async def test_upload_multiple(self, tmp_path: Path, viking_fs: FakeVikingFS) -> None:- f1 = tmp_path / "a.py"- f1.write_text("a", encoding="utf-8")- f2 = tmp_path / "b.md"- f2.write_text("b", encoding="utf-8")- file_paths = [(f1, "a.py"), (f2, "b.md")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/x", viking_fs)-- assert count == 2- assert len(warnings) == 0-- @pytest.mark.asyncio- async def test_upload_with_encoding_conversion(- self, tmp_path: Path, viking_fs: FakeVikingFS- ) -> None:- f = tmp_path / "chinese.py"- f.write_bytes("你好".encode("gbk"))- file_paths = [(f, "chinese.py")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/enc", viking_fs)-- assert count == 1- uploaded = viking_fs.files["viking://temp/enc/chinese.py"]- assert uploaded.decode("utf-8") == "你好"-- @pytest.mark.asyncio- async def test_upload_nonexistent_file(self, tmp_path: Path, viking_fs: FakeVikingFS) -> None:- fake = tmp_path / "nonexistent.py"- file_paths = [(fake, "nonexistent.py")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/err", viking_fs)-- assert count == 0- assert len(warnings) == 1--# ---------------------------------------------------------------------------# upload_directory# ---------------------------------------------------------------------------@@ -454,47 +385,37 @@ class TestShouldSkipFileEdgeCases:# ----------------------------------------------------------------------------class TestShouldSkipDirectoryCustom:- def test_custom_ignore_dirs(self) -> None:- assert should_skip_directory("vendor", ignore_dirs={"vendor"}) is True- assert should_skip_directory("src", ignore_dirs={"vendor"}) is False-- def test_hidden_dir_with_custom_ignore(self) -> None:- # Hidden dirs should still be skipped even with custom ignore set- assert should_skip_directory(".secret", ignore_dirs={"vendor"}) is True--# ----------------------------------------------------------------------------# _sanitize_rel_path (path traversal protection)+# sanitize_relative_viking_path (path traversal protection)# ---------------------------------------------------------------------------class TestSanitizeRelPath:def test_normal_path(self) -> None:- assert _sanitize_rel_path("src/main.py") == "src/main.py"+ assert sanitize_relative_viking_path("src/main.py") == "src/main.py"def test_rejects_parent_traversal(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("../etc/passwd")+ sanitize_relative_viking_path("../etc/passwd")def test_rejects_absolute_path(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("/etc/passwd")+ sanitize_relative_viking_path("/etc/passwd")def test_rejects_windows_drive_absolute(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("C:\\Windows\\System32")+ sanitize_relative_viking_path("C:\\Windows\\System32")def test_rejects_windows_drive_relative(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("C:Windows\\System32")+ sanitize_relative_viking_path("C:Windows\\System32")def test_rejects_nested_traversal(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("foo/../../bar")+ sanitize_relative_viking_path("foo/../../bar")def test_normalizes_backslashes(self) -> None:- result = _sanitize_rel_path("src\\main.py")+ result = sanitize_relative_viking_path("src\\main.py")assert result == "src/main.py"@@ -503,38 +424,6 @@ class TestSanitizeRelPath:# ----------------------------------------------------------------------------class TestUploadTextFilesEdgeCases:- @pytest.mark.asyncio- async def test_rejects_path_traversal(self, tmp_path: Path, viking_fs: FakeVikingFS) -> None:- f = tmp_path / "evil.py"- f.write_text("hack", encoding="utf-8")- file_paths = [(f, "../../../etc/passwd")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/safe", viking_fs)-- assert count == 0- assert len(warnings) == 1-- @pytest.mark.asyncio- async def test_upload_failure_produces_warning(self, tmp_path: Path) -> None:- class FailingFS:- async def write_file_bytes(self, uri: str, content: bytes) -> None:- raise IOError("disk full")-- async def mkdir(self, uri: str, exist_ok: bool = False) -> None:- pass-- f = tmp_path / "ok.py"- f.write_text("print(1)", encoding="utf-8")- file_paths = [(f, "ok.py")]-- count, warnings = await upload_text_files(file_paths, "viking://temp/fail", FailingFS())-- assert count == 0- assert len(warnings) == 1- assert "disk full" in warnings[0]--# ---------------------------------------------------------------------------# upload_directory (additional edge cases)# ---------------------------------------------------------------------------@@ -569,15 +458,15 @@ class TestUploadDirectoryEdgeCases:# ----------------------------------------------------------------------------# _sanitize_rel_path (additional edge cases)+# sanitize_relative_viking_path (additional edge cases)# ---------------------------------------------------------------------------class TestSanitizeRelPathEdgeCases:def test_rejects_empty_path(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("")+ sanitize_relative_viking_path("")def test_rejects_backslash_absolute(self) -> None:with pytest.raises(ValueError, match="Unsafe"):- _sanitize_rel_path("\\Windows\\System32")+ sanitize_relative_viking_path("\\Windows\\System32")diff --git a/tests/transaction/test_redo_log.py b/tests/transaction/test_redo_log.pyindex 8f3ae9271..9feef74ea 100644--- a/tests/transaction/test_redo_log.py+++ b/tests/transaction/test_redo_log.py@@ -2,7 +2,6 @@# SPDX-License-Identifier: AGPL-3.0"""Tests for RedoLog crash recovery."""-import uuidimport pytest@@ -15,42 +14,6 @@ def redo(agfs_client):class TestRedoLogBasic:- async def test_write_and_read(self, redo):- task_id = uuid.uuid4().hex- info = {"archive_uri": "viking://test/archive", "session_uri": "viking://test/session"}- await redo.write_pending_async(task_id, info)-- result = await redo.read_async(task_id)- assert result["archive_uri"] == "viking://test/archive"- assert result["session_uri"] == "viking://test/session"-- await redo.mark_done_async(task_id)-- async def test_list_pending(self, redo):- t1 = uuid.uuid4().hex- t2 = uuid.uuid4().hex- await redo.write_pending_async(t1, {"key": "v1"})- await redo.write_pending_async(t2, {"key": "v2"})-- pending = await redo.list_pending_async()- assert t1 in pending- assert t2 in pending-- await redo.mark_done_async(t1)- pending_after = await redo.list_pending_async()- assert t1 not in pending_after- assert t2 in pending_after-- await redo.mark_done_async(t2)-- async def test_mark_done_removes_task(self, redo):- task_id = uuid.uuid4().hex- await redo.write_pending_async(task_id, {"x": 1})- await redo.mark_done_async(task_id)-- pending = await redo.list_pending_async()- assert task_id not in pending-async def test_read_nonexistent_returns_empty(self, redo):result = await redo.read_async("nonexistent-task-id")assert result == {}@@ -59,20 +22,3 @@ class TestRedoLogBasic:# Should not crash even if _REDO_ROOT doesn't exist yetpending = await redo.list_pending_async()assert isinstance(pending, list)-- async def test_mark_done_idempotent(self, redo):- task_id = uuid.uuid4().hex- await redo.write_pending_async(task_id, {"x": 1})- await redo.mark_done_async(task_id)- # Second mark_done should not raise- await redo.mark_done_async(task_id)-- async def test_overwrite_pending(self, redo):- task_id = uuid.uuid4().hex- await redo.write_pending_async(task_id, {"version": 1})- await redo.write_pending_async(task_id, {"version": 2})-- result = await redo.read_async(task_id)- assert result["version"] == 2-- await redo.mark_done_async(task_id)diff --git a/tests/unit/session/memory/test_page_id_map.py b/tests/unit/session/memory/test_page_id_map.pyindex 0f6459cc7..6e19bf382 100644--- a/tests/unit/session/memory/test_page_id_map.py+++ b/tests/unit/session/memory/test_page_id_map.py@@ -57,21 +57,3 @@ class TestPageIdMap:assert pim.get_page_id("viking://profile.md") == existing_idassert pim.resolve(existing_id) == "viking://profile.md"assert pim.resolve(100) == "viking://profile.md"-- def test_has_links_enabled_after_existing_page_registration(self):- pim = PageIdMap()-- assert not pim.has_links_enabled-- pim.get_page_id("viking://test")-- assert pim.has_links_enabled-- def test_has_links_enabled_after_new_page_id_registration(self):- pim = PageIdMap()-- assert not pim.has_links_enabled-- pim.register_new_page_id("viking://new-item", 100)-- assert pim.has_links_enableddiff --git a/tests/unit/session/test_session_commit_resume.py b/tests/unit/session/test_session_commit_resume.pyindex 646d5f780..fce05a8f3 100644--- a/tests/unit/session/test_session_commit_resume.py+++ b/tests/unit/session/test_session_commit_resume.py@@ -7,7 +7,7 @@ from unittest.mock import AsyncMockimport pytestfrom openviking.message import Message, TextPart-from openviking.service.task_tracker import TaskTracker, reset_task_tracker, set_task_tracker+from openviking.service.task_tracker import TaskTracker, set_task_trackerfrom openviking.session.session import Sessionfrom openviking.storage.queuefs.session_commit_msg import SessionCommitMsg@@ -77,7 +77,7 @@ async def test_resume_queued_commit_continues_phase2(monkeypatch):try:await session.resume_queued_commit(message)finally:- reset_task_tracker()+ set_task_tracker(None)session._run_memory_extraction.assert_awaited_once()assert session._run_memory_extraction.await_args.kwargs["task_id"] == "task-1"diff --git a/tests/unit/test_accessors_http.py b/tests/unit/test_accessors_http.pyindex 329ab312e..aa5098f63 100644--- a/tests/unit/test_accessors_http.py+++ b/tests/unit/test_accessors_http.py@@ -273,24 +273,6 @@ class TestHTTPAccessorPriorityRouting:assert accessor is not Noneassert accessor.__class__.__name__ == "HTTPAccessor"- def test_accessor_priority_order(self) -> None:- """Accessors should be registered in descending priority order."""- registry = AccessorRegistry(register_default=False)- http = HTTPAccessor()- git = GitAccessor()-- # Register in any order- registry.register(http)- registry.register(git)-- accessors = registry.list_accessors()-- # GitAccessor (priority 80) should come before HTTPAccessor (priority 50)- assert len(accessors) == 2- assert accessors[0].__class__.__name__ == "GitAccessor"- assert accessors[1].__class__.__name__ == "HTTPAccessor"--class TestHTTPAccessorRawUrlConversion:"""Tests for HTTPAccessor._convert_to_raw_url (GitHub/GitLab blob -> raw)."""diff --git a/tests/unit/test_accessors_registry.py b/tests/unit/test_accessors_registry.pyindex 5d5803a6f..bd8d3a629 100644--- a/tests/unit/test_accessors_registry.py+++ b/tests/unit/test_accessors_registry.py@@ -43,15 +43,6 @@ class TestAccessorRegistry:"""Create a fresh registry (without default accessors)."""return AccessorRegistry(register_default=False)- def test_register_and_list(self, registry: AccessorRegistry) -> None:- """Register an accessor and list it."""- accessor = TestAccessor("test", "test:", 50)- registry.register(accessor)-- accessors = registry.list_accessors()- assert len(accessors) == 1- assert accessors[0] == accessor-def test_get_accessor(self, registry: AccessorRegistry) -> None:"""Get an accessor that can handle a source."""accessor1 = TestAccessor("test1", "test1:", 50)@@ -68,57 +59,6 @@ class TestAccessorRegistry:result = registry.get_accessor("unknown:source")assert result is None- def test_priority_ordering(self, registry: AccessorRegistry) -> None:- """Accessors are ordered by priority (descending)."""- low_prio = TestAccessor("low", "common:", 10)- mid_prio = TestAccessor("mid", "common:", 50)- high_prio = TestAccessor("high", "common:", 100)-- # Register in random order- registry.register(low_prio)- registry.register(high_prio)- registry.register(mid_prio)-- accessors = registry.list_accessors()- assert [a.name for a in accessors] == ["high", "mid", "low"]-- # Highest priority should be selected- result = registry.get_accessor("common:source")- assert result is high_prio-- def test_list_accessors_with_filter(self, registry: AccessorRegistry) -> None:- """list_accessors filters by source capability."""- accessor1 = TestAccessor("a", "a:", 50)- accessor2 = TestAccessor("b", "b:", 50)- accessor3 = TestAccessor("both", "a:", 50) # also handles "a:"- registry.register(accessor1)- registry.register(accessor2)- registry.register(accessor3)-- filtered = registry.list_accessors("a:source")- assert len(filtered) == 2- names = {a.name for a in filtered}- assert names == {"a", "both"}-- def test_unregister(self, registry: AccessorRegistry) -> None:- """Unregister removes accessor by name."""- accessor = TestAccessor("test", "test:", 50)- registry.register(accessor)-- assert registry.unregister("TestAccessor") is True- assert len(registry.list_accessors()) == 0-- assert registry.unregister("NotFound") is False-- def test_clear(self, registry: AccessorRegistry) -> None:- """Clear removes all accessors."""- registry.register(TestAccessor("a", "a:", 50))- registry.register(TestAccessor("b", "b:", 50))-- assert len(registry.list_accessors()) == 2- registry.clear()- assert len(registry.list_accessors()) == 0-@pytest.mark.asyncioasync def test_access_fallback_to_local(self, registry: AccessorRegistry, tmp_path: Pathdiff --git a/tests/unit/test_context.py b/tests/unit/test_context.pyindex 8734b3ef3..a3f2cb40a 100644--- a/tests/unit/test_context.py+++ b/tests/unit/test_context.py@@ -273,17 +273,6 @@ class TestContextMethods:assert ctx.get_vectorization_text() == "Test abstract"- def test_update_activity(self):- """Test update_activity method."""- ctx = Context(uri="viking://test/", active_count=5)- old_updated = ctx.updated_at-- ctx.update_activity()-- assert ctx.active_count == 6- assert ctx.updated_at > old_updated--class TestContextToDict:"""Test Context.to_dict."""diff --git a/tests/unit/test_kimi_glm_vlm.py b/tests/unit/test_kimi_glm_vlm.pyindex 2917886b0..a33d11f19 100644--- a/tests/unit/test_kimi_glm_vlm.py+++ b/tests/unit/test_kimi_glm_vlm.py@@ -75,18 +75,6 @@ def test_vlm_factory_routes_first_class_kimi_and_glm_providers():assert glm_vlm.__class__.__name__ == "GLMVLM"-def test_vlm_factory_exposes_canonical_provider_names():- assert VLMFactory.get_available_providers() == [- "volcengine",- "openai",- "azure",- "kimi",- "glm",- "litellm",- "openai-codex",- ]--def test_vlm_config_uses_canonical_provider_names():config = VLMConfig(model="glm-4.6v",diff --git a/tests/unit/test_message.py b/tests/unit/test_message.pyindex e1727d9fb..a0a65f96c 100644--- a/tests/unit/test_message.py+++ b/tests/unit/test_message.py@@ -782,51 +782,6 @@ class TestMessageFromDict:class TestMessageMethods:"""Test Message methods."""- def test_get_tool_parts(self):- """Test get_tool_parts method."""- msg = Message(- id="msg-1",- role="assistant",- parts=[- TextPart(text="Hello"),- ToolPart(tool_id="call-1"),- ToolPart(tool_id="call-2"),- ],- )-- tool_parts = msg.get_tool_parts()-- assert len(tool_parts) == 2- assert all(isinstance(p, ToolPart) for p in tool_parts)-- def test_find_tool_part(self):- """Test find_tool_part method."""- msg = Message(- id="msg-1",- role="assistant",- parts=[- ToolPart(tool_id="call-1"),- ToolPart(tool_id="call-2"),- ],- )-- part = msg.find_tool_part("call-1")-- assert part is not None- assert part.tool_id == "call-1"-- def test_find_tool_part_not_found(self):- """Test find_tool_part when not found."""- msg = Message(- id="msg-1",- role="assistant",- parts=[ToolPart(tool_id="call-1")],- )-- part = msg.find_tool_part("nonexistent")-- assert part is None-def test_to_jsonl(self):"""Test to_jsonl method."""msg = Message(diff --git a/tests/unit/test_namespace_uri_classification.py b/tests/unit/test_namespace_uri_classification.pyindex 6eb9e7094..1914f365f 100644--- a/tests/unit/test_namespace_uri_classification.py+++ b/tests/unit/test_namespace_uri_classification.py@@ -9,10 +9,8 @@ from openviking.core.namespace import (canonicalize_uri,classify_uri,context_type_for_uri,- is_content_namespace_root_uri,is_content_root_uri,is_session_uri,- legacy_session_uri,owner_space_for_uri,visible_roots,)@@ -111,7 +109,6 @@ def test_session_uri_helpers_use_user_namespace():canonicalize_uri("viking://session/s1/history/archive_001/messages.jsonl", ctx)== "viking://user/alice/sessions/s1/history/archive_001/messages.jsonl")- assert legacy_session_uri("s1") == "viking://session/s1"assert is_session_uri("viking://user/alice/sessions/s1")assert is_session_uri("viking://user/sessions/s1")assert is_session_uri("viking://session/s1")@@ -144,8 +141,4 @@ def test_current_user_short_content_roots_are_canonicalized_from_content_segmentassert canonicalize_uri("viking://user/alice/resources", ctx) == ("viking://user/alice/resources")- assert is_content_namespace_root_uri("viking://user/resources", ctx)- assert is_content_namespace_root_uri("viking://user/resources/", ctx)- assert is_content_namespace_root_uri("viking://resources", ctx)assert is_content_root_uri("viking://resources", ctx, kind="resource")- assert not is_content_namespace_root_uri("viking://user/resources/docs", ctx)diff --git a/tests/unit/test_ordered_credential_switcher.py b/tests/unit/test_ordered_credential_switcher.pyindex 5f3b2baef..0e05dae94 100644--- a/tests/unit/test_ordered_credential_switcher.py+++ b/tests/unit/test_ordered_credential_switcher.py@@ -2,8 +2,6 @@# SPDX-License-Identifier: AGPL-3.0"""Unit tests for OrderedCredentialSwitcher"""-import threading-import timeimport pytest@@ -22,193 +20,6 @@ from openviking.utils.model_retry import (class TestOrderedCredentialSwitcher:"""Tests for OrderedCredentialSwitcher class."""- def test_initial_state(self):- """Test initial state with single credential."""- switcher = OrderedCredentialSwitcher(n=1)- assert switcher.n == 1- assert switcher.get_active_index() == 0- assert not switcher.is_exhausted-- def test_initial_state_with_multiple_credentials(self):- """Test initial state with multiple credentials."""- switcher = OrderedCredentialSwitcher(n=3)- assert switcher.n == 3- assert switcher.get_active_index() == 0- assert not switcher.is_exhausted-- def test_advance_on_quota_exceeded(self):- """Test advancing to next credential on quota exceeded."""- switcher = OrderedCredentialSwitcher(n=3)-- # Start at index 0- assert switcher.get_active_index() == 0-- # Quota exceeded should advance- result = switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert result is True- assert switcher.get_active_index() == 1-- # Another quota exceeded should advance again- result = switcher.on_failure(1, ERROR_CLASS_QUOTA_EXCEEDED)- assert result is True- assert switcher.get_active_index() == 2-- # One more should exhaust all- result = switcher.on_failure(2, ERROR_CLASS_QUOTA_EXCEEDED)- assert result is True- assert switcher.is_exhausted-- def test_fail_fast_on_permanent_error(self):- """PERMANENT (400 parameter error) always fails fast, even with multiple credentials.-- A 400 is request-level: the same request fails on every credential of- the same model, so switching is useless.- """- switcher = OrderedCredentialSwitcher(n=3)-- result = switcher.on_failure(0, ERROR_CLASS_PERMANENT)- assert result is False- assert switcher.get_active_index() == 0 # Should stay at current index- assert not switcher.is_exhausted-- def test_fail_fast_on_input_too_large(self):- """INPUT_TOO_LARGE fails fast: same oversized input fails on every credential."""- switcher = OrderedCredentialSwitcher(n=3)-- result = switcher.on_failure(0, ERROR_CLASS_INPUT_TOO_LARGE)- assert result is False- assert switcher.get_active_index() == 0- assert not switcher.is_exhausted-- def test_fail_fast_on_content_safety(self):- """CONTENT_SAFETY fails fast: moderation rejects the content on every credential."""- switcher = OrderedCredentialSwitcher(n=3)-- result = switcher.on_failure(0, ERROR_CLASS_CONTENT_SAFETY)- assert result is False- assert switcher.get_active_index() == 0- assert not switcher.is_exhausted-- def test_transient_error_treated_as_quota(self):- """Test that transient errors are treated as quota exceeded."""- switcher = OrderedCredentialSwitcher(n=3)-- # Transient should be treated as quota and advance- result = switcher.on_failure(0, ERROR_CLASS_TRANSIENT)- assert result is True- assert switcher.get_active_index() == 1-- def test_unknown_error_advances(self):- """Test that unknown errors cause advance."""- switcher = OrderedCredentialSwitcher(n=3)-- result = switcher.on_failure(0, ERROR_CLASS_UNKNOWN)- assert result is True- assert switcher.get_active_index() == 1-- def test_on_success_increments_counter(self):- """Test that success increments request counter when not at index 0."""- switcher = OrderedCredentialSwitcher(n=3, failback_request_count=3)-- # Advance to index 1 first- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert switcher.get_active_index() == 1-- # Success should increment counter- switcher.on_success(1)- switcher.on_success(1)- switcher.on_success(1)-- # get_active_index is a pure read and must NOT trigger failback- assert switcher.get_active_index() == 1- # After 3 successes, maybe_failback should move back to index 0- assert switcher.maybe_failback() == 0-- def test_failback_on_request_count(self):- """Test failback based on request count threshold."""- switcher = OrderedCredentialSwitcher(n=3, failback_request_count=2)-- # Advance to index 1- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert switcher.get_active_index() == 1-- # Two successes should trigger failback- switcher.on_success(1)- switcher.on_success(1)-- # Next maybe_failback should move back- assert switcher.maybe_failback() == 0-- def test_failback_on_timeout(self):- """Test failback based on timeout threshold."""- switcher = OrderedCredentialSwitcher(n=3, failback_timeout_seconds=0.1)-- # Advance to index 1- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert switcher.get_active_index() == 1-- # Wait for timeout- time.sleep(0.2)-- # Next maybe_failback should move back- assert switcher.maybe_failback() == 0-- def test_get_active_index_is_pure_read(self):- """get_active_index must never trigger failback, even when thresholds are met.-- Observers (logging/metrics reading active_credential_id/index) must not- accidentally advance the failback state machine.- """- switcher = OrderedCredentialSwitcher(- n=3, failback_request_count=1, failback_timeout_seconds=0.05- )-- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert switcher.get_active_index() == 1-- # Meet BOTH thresholds (count + timeout)- switcher.on_success(1)- time.sleep(0.1)-- # Repeated pure reads must stay at index 1 (no failback side effect)- assert switcher.get_active_index() == 1- assert switcher.get_active_index() == 1-- # Only maybe_failback actually moves back- assert switcher.maybe_failback() == 0-- def test_hierarchical_failback_one_step(self):- """Test that failback moves one step at a time, not all the way."""- switcher = OrderedCredentialSwitcher(n=4, failback_request_count=2)-- # Advance through indexes- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED) # 0 -> 1- switcher.on_failure(1, ERROR_CLASS_QUOTA_EXCEEDED) # 1 -> 2- switcher.on_failure(2, ERROR_CLASS_QUOTA_EXCEEDED) # 2 -> 3- assert switcher.get_active_index() == 3-- # Two successes should move back to 2- switcher.on_success(3)- switcher.on_success(3)- assert switcher.maybe_failback() == 2-- # Two more successes should move back to 1- switcher.on_success(2)- switcher.on_success(2)- assert switcher.maybe_failback() == 1-- def test_is_exhausted_when_all_credentials_used(self):- """Test is_exhausted property."""- switcher = OrderedCredentialSwitcher(n=2)-- assert not switcher.is_exhausted-- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED) # 0 -> 1- assert not switcher.is_exhausted-- switcher.on_failure(1, ERROR_CLASS_QUOTA_EXCEEDED) # 1 -> 2 (exhausted)- assert switcher.is_exhausted-def test_success_does_nothing_at_index_zero(self):"""Test that success at index 0 doesn't increment counter."""switcher = OrderedCredentialSwitcher(n=3, failback_request_count=2)@@ -221,46 +32,6 @@ class TestOrderedCredentialSwitcher:# Should still be at index 0assert switcher.get_active_index() == 0- def test_on_success_for_different_index_ignored(self):- """Test that success for a different index is ignored."""- switcher = OrderedCredentialSwitcher(n=3, failback_request_count=2)-- # Advance to index 1- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED)- assert switcher.get_active_index() == 1-- # Success for wrong index should be ignored- switcher.on_success(0) # Wrong index- switcher.on_success(0) # Wrong index-- # Should still be at index 1 (counter not incremented)- assert switcher.get_active_index() == 1-- def test_thread_safety(self):- """Test thread safety of the switcher."""- switcher = OrderedCredentialSwitcher(n=10)- results = []-- def worker():- for _ in range(100):- idx = switcher.get_active_index()- if idx < switcher.n - 1:- switcher.on_failure(idx, ERROR_CLASS_QUOTA_EXCEEDED)- switcher.on_success(idx)- results.append(idx)-- threads = []- for _ in range(10):- t = threading.Thread(target=worker)- threads.append(t)- t.start()-- for t in threads:- t.join()-- # All operations should have completed without errors- assert len(results) == 1000-def test_invalid_initialization(self):"""Test that n < 1 raises ValueError."""with pytest.raises(ValueError, match="Number of credentials must be >= 1"):@@ -269,43 +40,6 @@ class TestOrderedCredentialSwitcher:with pytest.raises(ValueError, match="Number of credentials must be >= 1"):OrderedCredentialSwitcher(n=-1)- def test_advance_on_auth_error_when_multi_credential(self):- """Multi-credential mode: AUTH (401/403) advances to next credential by default."""- switcher = OrderedCredentialSwitcher(n=3)-- # First credential's auth error should advance, not fail-fast- result = switcher.on_failure(0, ERROR_CLASS_AUTH)- assert result is True- assert switcher.get_active_index() == 1-- # Middle credential's auth error should also advance- result = switcher.on_failure(1, ERROR_CLASS_AUTH)- assert result is True- assert switcher.get_active_index() == 2-- def test_last_credential_auth_error_still_fails_fast(self):- """In multi-credential mode the last credential still fails fast on AUTH."""- switcher = OrderedCredentialSwitcher(n=2)-- # Advance from 0 -> 1 on auth error- assert switcher.on_failure(0, ERROR_CLASS_AUTH) is True- assert switcher.get_active_index() == 1-- # On the last credential (idx 1, n=2), still fail-fast- result = switcher.on_failure(1, ERROR_CLASS_AUTH)- assert result is False- # active_idx stays at 1 (not bumped to n=2/exhausted) so caller can raise normally- assert switcher.get_active_index() == 1- assert not switcher.is_exhausted-- def test_single_credential_auth_error_fails_fast(self):- """With only one credential, AUTH must fail-fast (it's the last)."""- switcher = OrderedCredentialSwitcher(n=1)-- result = switcher.on_failure(0, ERROR_CLASS_AUTH)- assert result is False- assert switcher.get_active_index() == 0-def test_is_fail_fast_classification(self):"""Request-level errors are fail-fast; credential/quota/transient are not."""assert OrderedCredentialSwitcher.is_fail_fast(ERROR_CLASS_PERMANENT) is True@@ -316,18 +50,6 @@ class TestOrderedCredentialSwitcher:assert OrderedCredentialSwitcher.is_fail_fast(ERROR_CLASS_TRANSIENT) is Falseassert OrderedCredentialSwitcher.is_fail_fast(ERROR_CLASS_UNKNOWN) is False- def test_commit_success_same_index_increments_failback_counter(self):- """commit_success on the active (non-zero) index advances failback counter."""- switcher = OrderedCredentialSwitcher(n=3, failback_request_count=2)-- switcher.on_failure(0, ERROR_CLASS_QUOTA_EXCEEDED) # active -> 1- assert switcher.get_active_index() == 1-- switcher.commit_success(1)- switcher.commit_success(1)- # Two successes at the active index satisfy the failback threshold.- assert switcher.maybe_failback() == 0-def test_commit_success_different_index_fast_failover(self):"""commit_success on a different index commits it as the new active one."""switcher = OrderedCredentialSwitcher(n=3)diff --git a/tests/unit/test_time_utils_comprehensive.py b/tests/unit/test_time_utils_comprehensive.pyindex 2e9b485b1..fda3f16c3 100644--- a/tests/unit/test_time_utils_comprehensive.py+++ b/tests/unit/test_time_utils_comprehensive.py@@ -7,7 +7,6 @@ from datetime import datetime, timedelta, timezonefrom openviking.utils.time_utils import (format_iso8601,- format_simplified,get_current_timestamp,parse_iso_datetime,)@@ -144,54 +143,6 @@ class TestFormatIso8601:class TestFormatSimplified:"""Test format_simplified function."""- def test_format_same_day_shows_time(self):- """Test formatting shows time for same day."""- now = datetime(2026, 3, 26, 15, 0, 0)- dt = datetime(2026, 3, 26, 10, 30, 0)-- formatted = format_simplified(dt, now)-- assert formatted == "10:30:00"-- def test_format_different_day_shows_date(self):- """Test formatting shows date for different day."""- now = datetime(2026, 3, 26, 15, 0, 0)- dt = datetime(2026, 3, 25, 10, 30, 0)-- formatted = format_simplified(dt, now)-- assert formatted == "2026-03-25"-- def test_format_older_date_shows_date(self):- """Test formatting shows date for older dates."""- now = datetime(2026, 3, 26, 15, 0, 0)- dt = datetime(2025, 12, 1, 10, 30, 0)-- formatted = format_simplified(dt, now)-- assert formatted == "2025-12-01"-- def test_format_just_under_24h_shows_time(self):- """Test formatting shows time for just under 24 hours."""- now = datetime(2026, 3, 26, 15, 0, 0)- dt = datetime(2026, 3, 25, 16, 0, 0)-- formatted = format_simplified(dt, now)-- # 16:00 is less than 24 hours ago- assert formatted == "16:00:00"-- def test_format_just_over_24h_shows_date(self):- """Test formatting shows date for just over 24 hours."""- now = datetime(2026, 3, 26, 15, 0, 0)- dt = datetime(2026, 3, 25, 14, 0, 0)-- formatted = format_simplified(dt, now)-- # 14:00 is more than 24 hours ago- assert formatted == "2026-03-25"--class TestGetCurrentTimestamp:"""Test get_current_timestamp function."""diff --git a/tests/unit/test_vlm_failover.py b/tests/unit/test_vlm_failover.pyindex d98302de5..514f70990 100644--- a/tests/unit/test_vlm_failover.py+++ b/tests/unit/test_vlm_failover.py@@ -655,7 +655,6 @@ class TestVLMConfigWithBackup:instance = config.get_vlm_instance()# Should be a MultiCredentialVLM instance- assert hasattr(instance, "active_credential_index")assert hasattr(instance, "_vlm_instances")assert len(instance._vlm_instances) == 2diff --git a/tests/unit/tool_skill/test_tool_skill_utils.py b/tests/unit/tool_skill/test_tool_skill_utils.pydeleted file mode 100644index aa6ca444d..000000000--- a/tests/unit/tool_skill/test_tool_skill_utils.py+++ /dev/null@@ -1,74 +0,0 @@-# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.-# SPDX-License-Identifier: AGPL-3.0--from openviking.message.part import ToolPart-from openviking.session.tool_skill_utils import (- calibrate_skill_name,- calibrate_tool_name,- collect_skill_stats,- collect_tool_stats,- normalize_name,-)---class TestToolSkillUtils:- def test_normalize_name_removes_common_separators(self):- assert normalize_name(" get-weather ") == normalize_name("get_weather")- assert normalize_name("Get Weather") == normalize_name("get_weather")-- def test_calibrate_tool_name_matches_hyphen_to_underscore(self):- tool_parts = [ToolPart(tool_name="get_weather", tool_status="completed")]- tool_name, status = calibrate_tool_name("get-weather", tool_parts)- assert tool_name == "get_weather"- assert status == "completed"-- def test_collect_tool_stats_aggregates_counts_and_tokens(self):- tool_parts = [- ToolPart(- tool_name="get_weather",- tool_status="completed",- duration_ms=10,- prompt_tokens=5,- completion_tokens=7,- ),- ToolPart(- tool_name="get_weather",- tool_status="error",- duration_ms=20,- prompt_tokens=1,- completion_tokens=2,- ),- ]- stats = collect_tool_stats(tool_parts)["get_weather"]- assert stats["call_count"] == 2- assert stats["success_time"] == 1- assert stats["duration_ms"] == 30- assert stats["prompt_tokens"] == 6- assert stats["completion_tokens"] == 9-- def test_calibrate_skill_name_matches_by_skill_uri_suffix(self):- tool_parts = [ToolPart(skill_uri="viking://user/skills/weather", tool_status="error")]- tool_name, status = calibrate_skill_name("weather", tool_parts)- assert tool_name == "weather"- assert status == "error"-- def test_collect_skill_stats_aggregates_by_skill_name(self):- tool_parts = [- ToolPart(- skill_uri="viking://user/skills/weather",- tool_status="completed",- duration_ms=3,- prompt_tokens=2,- completion_tokens=4,- ),- ToolPart(- skill_uri="viking://user/skills/weather",- tool_status="error",- duration_ms=7,- prompt_tokens=1,- completion_tokens=1,- ),- ]- stats = collect_skill_stats(tool_parts)["weather"]- assert stats["call_count"] == 2- assert stats["success_time"] == 1diff --git a/tests/vectordb/test_cuvs_collection.py b/tests/vectordb/test_cuvs_collection.pyindex 505832b9d..96919ba53 100644--- a/tests/vectordb/test_cuvs_collection.py+++ b/tests/vectordb/test_cuvs_collection.py@@ -1,23 +1,14 @@# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.# SPDX-License-Identifier: AGPL-3.0-import multiprocessingimport threadingimport tracebackfrom concurrent.futures import ThreadPoolExecutor-import pytest-from openviking.storage.vectordb.collection.local_collection import (- PersistCollection,get_or_create_local_collection,)from openviking.storage.vectordb.index import cuvs_index-from openviking.storage.vectordb.index.local_index import (- IndexEngineProxy,- LocalIndex,- PersistentIndex,-)from openviking.telemetry.backends.memory import MemoryOperationTelemetryfrom openviking.telemetry.context import bind_telemetry@@ -365,156 +356,6 @@ def test_persistent_collection_rehydrates_cuvs_from_local_store(monkeypatch, tmpreopened.close()-def test_persistent_cuvs_rebuild_waits_for_deletion_replay(monkeypatch, tmp_path):- path = str(tmp_path / "persistent-cuvs-recovery")- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "persistent_cuvs_recovery",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- {"FieldName": "kind", "FieldType": "string"},- ],- },- path=path,- )- collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- "ScalarIndex": ["kind"],- },- )- collection.upsert_data(- [- {- "id": "deleted",- "vector": [1.0, 0.0, 0.0, 0.0],- "kind": "deleted",- },- {- "id": "survivor",- "vector": [0.0, 1.0, 0.0, 0.0],- "kind": "survivor",- },- ]- )- collection.close()-- # Commit only the store deletion. Terminating the process leaves the native- # snapshot stale, so recovery has exactly one deletion to replay.- ctx = multiprocessing.get_context("spawn")- ready_parent, ready_child = ctx.Pipe(duplex=False)- hold = ctx.Event()- process = ctx.Process(- target=_delete_without_persisting_index,- args=(path, ready_child, hold),- )- process.start()- ready_child.close()- try:- assert ready_parent.poll(20), "deletion worker did not finish"- status, detail = ready_parent.recv()- assert status == "ok", detail- finally:- ready_parent.close()- if process.is_alive():- process.terminate()- process.join(10)- assert not process.is_alive()-- runtime = MemoryAwareFakeCuVSRuntime("inner_product", free_memory_bytes=1 << 30)- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )-- replay_completed = threading.Event()- layout_registered = threading.Event()- layouts_before_replay = []- replay_operations = []- original_init = PersistentIndex.__init__- original_replay = PersistCollection._replay_recovery_records- original_set_filter_layout = IndexEngineProxy.set_filter_layout-- def synchronize_constructor(self, *args, **kwargs):- original_init(self, *args, **kwargs)- # The old lifecycle starts the worker during construction. Waiting here- # forces its stale layout to commit before recovery can replay deletion.- if self._dense_rebuild_thread is not None:- assert layout_registered.wait(timeout=5)-- def observe_replay(self, *, index_name, index, records, operation):- replay_operations.append((operation, len(records)))- result = original_replay(- self,- index_name=index_name,- index=index,- records=records,- operation=operation,- )- replay_completed.set()- return result-- def observe_filter_layout(self, ordered_labels):- result = original_set_filter_layout(self, ordered_labels)- if not replay_completed.is_set():- layouts_before_replay.append(tuple(ordered_labels))- layout_registered.set()- return result-- monkeypatch.setattr(PersistentIndex, "__init__", synchronize_constructor)- monkeypatch.setattr(PersistCollection, "_replay_recovery_records", observe_replay)- monkeypatch.setattr(IndexEngineProxy, "set_filter_layout", observe_filter_layout)-- reopened = get_or_create_local_collection(- path=path,- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- assert replay_operations == [("delete", 1)]- assert replay_completed.is_set()- index = reopened.get_index("default")- assert index is not None- assert index.wait_for_background_rebuild(timeout=5)- assert layout_registered.wait(timeout=5)- assert layouts_before_replay == []- assert runtime.build_count == 1-- unfiltered = reopened.search_by_vector(- "default", dense_vector=[0.0, 1.0, 0.0, 0.0], limit=2- )- filtered = reopened.search_by_vector(- "default",- dense_vector=[0.0, 1.0, 0.0, 0.0],- limit=2,- filters={"op": "must", "field": "kind", "conds": ["survivor"]},- )- deleted = reopened.search_by_vector(- "default",- dense_vector=[1.0, 0.0, 0.0, 0.0],- limit=2,- filters={"op": "must", "field": "kind", "conds": ["deleted"]},- )- assert [item.id for item in unfiltered.data] == ["survivor"]- assert [item.id for item in filtered.data] == ["survivor"]- assert deleted.data == []- finally:- reopened.close()--def test_auto_cuvs_falls_back_then_retries_when_memory_is_available(monkeypatch):runtimes = []@@ -589,505 +430,6 @@ def test_auto_cuvs_falls_back_then_retries_when_memory_is_available(monkeypatch)collection.close()-def test_auto_cuvs_background_rebuild_warms_gpu_before_query(monkeypatch):- runtime = MemoryAwareFakeCuVSRuntime("inner_product", free_memory_bytes=64)- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_background",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- collection.upsert_data(- [- {"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]},- {"id": "second", "vector": [0.0, 1.0, 0.0, 0.0]},- ]- )-- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_count == 1- result = collection.search_by_vector("default", dense_vector=[1.0, 0.0, 0.0, 0.0], limit=1)- assert [item.id for item in result.data] == ["first"]- assert runtime.search_count == 1- finally:- collection.close()---def test_auto_cuvs_initial_rebuild_waits_for_native_data(monkeypatch):- runtime = MemoryAwareFakeCuVSRuntime("inner_product", free_memory_bytes=1 << 30)- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )-- native_add_done = threading.Event()- layout_registered = threading.Event()- original_add_data = IndexEngineProxy.add_data- original_set_filter_layout = IndexEngineProxy.set_filter_layout- original_schedule = LocalIndex._schedule_dense_rebuild-- def observe_native_add(self, candidates):- result = original_add_data(self, candidates)- native_add_done.set()- return result-- def observe_filter_layout(self, ordered_labels):- result = original_set_filter_layout(self, ordered_labels)- layout_registered.set()- return result-- def wait_for_early_rebuild(self):- original_schedule(self)- # Force the buggy pre-add schedule to wait until its worker publishes- # the stale layout; the fixed lifecycle never enters this branch.- if not native_add_done.is_set():- assert layout_registered.wait(timeout=5)-- monkeypatch.setattr(IndexEngineProxy, "add_data", observe_native_add)- monkeypatch.setattr(IndexEngineProxy, "set_filter_layout", observe_filter_layout)- monkeypatch.setattr(LocalIndex, "_schedule_dense_rebuild", wait_for_early_rebuild)-- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_initial_rebuild",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- {"FieldName": "kind", "FieldType": "string"},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- collection.upsert_data([{"id": "first", "vector": [1.0, 0.0, 0.0, 0.0], "kind": "x"}])- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- "ScalarIndex": ["kind"],- },- )-- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_count == 1- unfiltered = collection.search_by_vector(- "default", dense_vector=[1.0, 0.0, 0.0, 0.0], limit=1- )- filtered = collection.search_by_vector(- "default",- dense_vector=[1.0, 0.0, 0.0, 0.0],- limit=1,- filters={"op": "must", "field": "kind", "conds": ["x"]},- )- assert [item.id for item in unfiltered.data] == ["first"]- assert [item.id for item in filtered.data] == ["first"]- finally:- collection.close()---def test_auto_cuvs_background_rebuild_coalesces_mutations_and_routes_native(- monkeypatch,-):- class BlockingBuildRuntime(MemoryAwareFakeCuVSRuntime):- def __init__(self):- super().__init__("inner_product", free_memory_bytes=1 << 20)- self.build_started = threading.Event()- self.resume_build = threading.Event()-- def build(self, dataset):- self.build_started.set()- assert self.resume_build.wait(timeout=5)- return super().build(dataset)-- runtime = BlockingBuildRuntime()- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_coalesced_rebuild",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- collection.upsert_data([{"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]}])- assert runtime.build_started.wait(timeout=5)-- # The build does not hold the cross-backend lock. Queries remain- # correct through native search and writes coalesce into one follow-up.- result = collection.search_by_vector("default", dense_vector=[1.0, 0.0, 0.0, 0.0], limit=1)- assert [item.id for item in result.data] == ["first"]- assert runtime.search_count == 0- collection.update_data([{"id": "first", "vector": [0.0, 1.0, 0.0, 0.0]}])- collection.update_data([{"id": "first", "vector": [0.0, 0.0, 1.0, 0.0]}])-- runtime.resume_build.set()- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_count == 2- finally:- runtime.resume_build.set()- collection.close()---def test_auto_cuvs_background_debounce_is_not_extended_by_dirty_reads(monkeypatch):- class BuildStartedRuntime(MemoryAwareFakeCuVSRuntime):- def __init__(self):- super().__init__("inner_product", free_memory_bytes=1 << 20)- self.build_started = threading.Event()-- def build(self, dataset):- self.build_started.set()- return super().build(dataset)-- runtime = BuildStartedRuntime()- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_read_safe_debounce",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 200,- }- },- )- stop_reads = threading.Event()- reader_started = threading.Event()-- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- assert index.wait_for_background_rebuild(timeout=5)-- def keep_reading():- reader_started.set()- while not stop_reads.wait(0.005):- collection.search_by_vector(- "default",- dense_vector=[1.0, 0.0, 0.0, 0.0],- limit=1,- )-- reader = threading.Thread(target=keep_reading)- reader.start()- assert reader_started.wait(timeout=1)- collection.upsert_data([{"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]}])-- # Reads continue throughout the non-zero trailing-edge mutation debounce.- # They must not keep pushing its deadline out indefinitely.- assert runtime.build_started.wait(timeout=1)- assert reader.is_alive()- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_count == 1- finally:- stop_reads.set()- if "reader" in locals():- reader.join(timeout=5)- collection.close()---def test_auto_cuvs_clean_to_dirty_race_never_rebuilds_on_query_thread(monkeypatch):- class RaceBuildRuntime(MemoryAwareFakeCuVSRuntime):- def __init__(self):- super().__init__("inner_product", free_memory_bytes=1 << 20)- self.build_attempts = 0- self.block_build = False- self.build_started = threading.Event()- self.resume_build = threading.Event()-- def build(self, dataset):- self.build_attempts += 1- if self.block_build:- self.build_started.set()- assert self.resume_build.wait(timeout=5)- return super().build(dataset)-- runtime = RaceBuildRuntime()- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_clean_dirty_race",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- collection.upsert_data([{"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]}])- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_attempts == 1-- original_search_cuvs = index._search_cuvs- mutation_injected = threading.Event()- runtime.block_build = True-- def inject_mutation_after_clean_check(*args, **kwargs):- if not mutation_injected.is_set():- mutation_injected.set()- collection.update_data([{"id": "first", "vector": [0.0, 1.0, 0.0, 0.0]}])- assert runtime.build_started.wait(timeout=5)- return original_search_cuvs(*args, **kwargs)-- monkeypatch.setattr(index, "_search_cuvs", inject_mutation_after_clean_check)- executor = ThreadPoolExecutor(max_workers=1)- try:- future = executor.submit(- collection.search_by_vector,- "default",- dense_vector=[0.0, 1.0, 0.0, 0.0],- limit=1,- )- # The request routes to the current native index even while the sole- # rebuild for this generation is blocked in the background worker.- assert [item.id for item in future.result(timeout=1).data] == ["first"]- finally:- runtime.resume_build.set()- executor.shutdown(wait=True)-- assert runtime.build_attempts == 2- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_attempts == 2- finally:- runtime.resume_build.set()- collection.close()---def test_auto_cuvs_background_failure_surfaces_to_wait_and_query(monkeypatch):- class FailingBuildRuntime(MemoryAwareFakeCuVSRuntime):- def __init__(self):- super().__init__("inner_product", free_memory_bytes=1 << 20)- self.fail_build = True-- def build(self, dataset):- if self.fail_build:- raise RuntimeError("injected background build failure")- return super().build(dataset)-- runtime = FailingBuildRuntime()- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_background_failure",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- collection.upsert_data([{"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]}])-- with pytest.raises(RuntimeError, match="injected background build failure"):- index.wait_for_background_rebuild(timeout=5)- with pytest.raises(RuntimeError, match="injected background build failure"):- collection.search_by_vector(- "default",- dense_vector=[1.0, 0.0, 0.0, 0.0],- limit=1,- )-- # A later mutation is a new rebuild generation and clears the stale- # failure, allowing a transient runtime problem to recover.- runtime.fail_build = False- collection.update_data([{"id": "first", "vector": [0.0, 1.0, 0.0, 0.0]}])- assert index.wait_for_background_rebuild(timeout=5)- assert (- collection.search_by_vector(- "default",- dense_vector=[0.0, 1.0, 0.0, 0.0],- limit=1,- )- .data[0]- .id- == "first"- )- finally:- collection.close()---def test_auto_cuvs_background_memory_fallback_retries_on_later_query(monkeypatch):- runtime = MemoryAwareFakeCuVSRuntime("inner_product", free_memory_bytes=31)- monkeypatch.setattr(- cuvs_index,- "_CuVSRuntime",- lambda _algorithm, _metric, _build_params, _search_params, _dtype: runtime,- )- collection = get_or_create_local_collection(- meta_data={- "CollectionName": "auto_cuvs_background_memory_retry",- "Fields": [- {"FieldName": "id", "FieldType": "string", "IsPrimaryKey": True},- {"FieldName": "vector", "FieldType": "vector", "Dim": 4},- ],- },- config={- "dense_search": {- "backend": "auto_cuvs",- "algorithm": "brute_force",- "filter_cache_size": 0,- "auto_memory_reserve_mb": 0,- "auto_memory_safety_factor": 1.0,- "auto_background_rebuild": True,- "auto_rebuild_debounce_ms": 0,- }- },- )- try:- index = collection.create_index(- "default",- {- "IndexName": "default",- "VectorIndex": {"IndexType": "flat", "Distance": "cosine"},- },- )- collection.upsert_data(- [- {"id": "first", "vector": [1.0, 0.0, 0.0, 0.0]},- {"id": "second", "vector": [0.0, 1.0, 0.0, 0.0]},- ]- )- assert index._dense_rebuild_completed.wait(timeout=5)- assert index.dense_search.needs_rebuild- assert runtime.build_count == 0-- runtime.free_memory_bytes = 32- result = collection.search_by_vector("default", dense_vector=[1.0, 0.0, 0.0, 0.0], limit=1)- assert [item.id for item in result.data] == ["first"]- assert index.wait_for_background_rebuild(timeout=5)- assert runtime.build_count == 1-- result = collection.search_by_vector("default", dense_vector=[1.0, 0.0, 0.0, 0.0], limit=1)- assert [item.id for item in result.data] == ["first"]- assert runtime.search_count == 1- finally:- collection.close()--def test_auto_cuvs_selective_first_query_skips_gpu_build(monkeypatch):runtimes = []dense_search_calls = 0diff --git a/tests/vectordb/test_cuvs_config.py b/tests/vectordb/test_cuvs_config.pyindex 71b15a19d..2dc2dc9e8 100644--- a/tests/vectordb/test_cuvs_config.py+++ b/tests/vectordb/test_cuvs_config.py@@ -5,7 +5,6 @@ import pytestfrom pydantic import ValidationErrorfrom openviking.storage.vectordb_adapters.local_adapter import (- CuVSCollectionAdapter,LocalCollectionAdapter,)from openviking_cli.utils.config.vectordb_config import CuVSConfig, VectorDBBackendConfig@@ -75,21 +74,3 @@ def test_local_adapter_only_passes_auto_cuvs_config_when_enabled():assert dense_search["auto_memory_safety_factor"] == 1.5assert dense_search["auto_filter_native_threshold"] == 1000assert dense_search["auto_path_filter_native_threshold"] == 100---def test_cuvs_adapter_preserves_native_int8_index_default():- native = LocalCollectionAdapter("context", "", "default")- cuvs = CuVSCollectionAdapter("context", "", "default", {})- arguments = {- "index_name": "default",- "distance": "cosine",- "use_sparse": False,- "sparse_weight": 0.0,- "scalar_index_fields": [],- }-- native_meta = native.build_default_index_meta(**arguments)- cuvs_meta = cuvs.build_default_index_meta(**arguments)-- assert native_meta["VectorIndex"]["Quant"] == "int8"- assert cuvs_meta["VectorIndex"]["Quant"] == "int8"diff --git a/tests/vectordb/test_project_group.py b/tests/vectordb/test_project_group.pyindex 64934705f..1c463c3b0 100644--- a/tests/vectordb/test_project_group.py+++ b/tests/vectordb/test_project_group.py@@ -18,24 +18,6 @@ class TestProjectGroup(unittest.TestCase):if os.path.exists(TEST_PROJECT_ROOT):shutil.rmtree(TEST_PROJECT_ROOT)- def test_volatile_group(self):- # Path empty -> Volatile- group = get_or_create_project_group("")- self.assertTrue(group.has_project("default"))-- # Create new- p1 = group.create_project("p1")- self.assertIsNotNone(p1)- self.assertTrue(group.has_project("p1"))-- # List- names = group.list_projects()- self.assertIn("default", names)- self.assertIn("p1", names)-- # Close- group.close()-def test_persistent_group_lifecycle(self):# 1. Create and populategroup = get_or_create_project_group(TEST_PROJECT_ROOT)diff --git a/tests/vectordb/test_pydantic_validation.py b/tests/vectordb/test_pydantic_validation.pyindex f08c8091b..2536ed41a 100644--- a/tests/vectordb/test_pydantic_validation.py+++ b/tests/vectordb/test_pydantic_validation.py@@ -44,19 +44,5 @@ class TestPydanticValidation(unittest.TestCase):fields_meta = {}self.assertTrue(validation.is_valid_index_meta_data(meta, fields_meta))- def test_fix_collection_meta(self):- meta = {"CollectionName": "test", "Fields": [{"FieldName": "text", "FieldType": "string"}]}- fixed = validation.fix_collection_meta(meta)-- # Check if AUTO_ID was added- has_auto_id = any(- f["FieldName"] == "AUTO_ID" and f["IsPrimaryKey"] for f in fixed["Fields"]- )- self.assertTrue(has_auto_id)-- # Check _FieldID assignment- self.assertIn("_FieldID", fixed["Fields"][0])--if __name__ == "__main__":unittest.main()diff --git a/tests/vectordb/test_vikingdb_project.py b/tests/vectordb/test_vikingdb_project.pyindex 94f821128..6887a47b2 100644--- a/tests/vectordb/test_vikingdb_project.py+++ b/tests/vectordb/test_vikingdb_project.py@@ -2,8 +2,6 @@# SPDX-License-Identifier: AGPL-3.0import unittest-from openviking.storage.vectordb.project.vikingdb_project import get_or_create_vikingdb_project-@unittest.skip("Temporarily skip TestVikingDBProject")class TestVikingDBProject(unittest.TestCase):@@ -31,63 +29,5 @@ class TestVikingDBProject(unittest.TestCase):}self.meta_data = meta_data- def test_create_vikingdb_project(self):- """Test project initialization."""- project = get_or_create_vikingdb_project(self.project_name, self.config)- self.assertEqual(project.project_name, self.project_name)- self.assertEqual(project.host, self.config["Host"])- self.assertEqual(project.headers, self.config["Headers"])-- def test_create_collection(self):- """Test collection creation with custom headers."""- project = get_or_create_vikingdb_project(self.project_name, self.config)- meta_data = self.meta_data-- collection = project.create_collection("test_coll", meta_data)-- self.assertIsNotNone(collection)- self.assertIn("test_coll", project.list_collections())-- def test_upsert_data(self):- """Test data upsert with custom headers and path."""- project = get_or_create_vikingdb_project(self.project_name, self.config)-- # Get existing or create new collection- meta_data = self.meta_data- collection = project.get_or_create_collection("test_coll", meta_data)-- data = [{"id": "1", "vector": [0.1] * 128, "text": "123"}]- res = collection.upsert_data(data)- self.assertIsNone(res)-- def test_fetch_data(self):- """Test data fetching."""- project = get_or_create_vikingdb_project(self.project_name, self.config)-- collection = project.get_or_create_collection("test_coll", self.meta_data)-- # Upsert some data first to fetch it- data = [{"id": "1", "vector": [0.1] * 128, "text": "hello"}]- collection.upsert_data(data)-- result = collection.fetch_data(["1"])-- self.assertEqual(len(result.items), 1)- self.assertEqual(result.items[0].id, "1")- self.assertEqual(result.items[0].fields["text"], "hello")-- def test_drop_collection(self):- """Test collection dropping."""- project = get_or_create_vikingdb_project(self.project_name, self.config)-- collection = project.get_or_create_collection("test_coll", self.meta_data)- if not collection:- self.fail("Collection should exist after creation")-- collection.drop()- collection = project.get_collection("test_coll")- self.assertIsNone(collection)--if __name__ == "__main__":unittest.main()