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
fix(test): fix CLI and storage test regressions (#2523)
baojun-zhangeed39c593f93
diff --git a/crates/ov_cli/src/commands/admin.rs b/crates/ov_cli/src/commands/admin.rsindex 13693a89f..049024b0b 100644--- a/crates/ov_cli/src/commands/admin.rs+++ b/crates/ov_cli/src/commands/admin.rs@@ -236,6 +236,26 @@ mod tests {use super::*;use serde_json::json;+ fn strip_ansi(input: &str) -> String {+ let mut output = String::new();+ let mut chars = input.chars().peekable();++ while let Some(ch) = chars.next() {+ if ch == '\u{1b}' && chars.peek() == Some(&'[') {+ chars.next();+ for next in chars.by_ref() {+ if next.is_ascii_alphabetic() {+ break;+ }+ }+ } else {+ output.push(ch);+ }+ }++ output+ }+#[test]fn user_key_notice_appears_for_table_key_generation_response() {let response = json!({@@ -245,7 +265,7 @@ mod tests {});let lines = admin_user_key_notice_lines(&response, OutputFormat::Table, false);- let rendered = lines.join("\n");+ let rendered = strip_ansi(&lines.join("\n"));assert!(rendered.contains("New user key generated. Copy and store it securely now."));assert!(diff --git a/crates/ov_cli/src/config_wizard/wizard.rs b/crates/ov_cli/src/config_wizard/wizard.rsindex fa4e89c3f..aa3c7168d 100644--- a/crates/ov_cli/src/config_wizard/wizard.rs+++ b/crates/ov_cli/src/config_wizard/wizard.rs@@ -4421,6 +4421,10 @@ mod tests {let cloud = openviking_service_api_key_helper_lines();let local_custom = custom_api_key_helper_lines(true);let remote_custom = custom_api_key_helper_lines(false);+ let local_custom_plain: Vec<String> =+ local_custom.iter().map(|line| strip_ansi(line)).collect();+ let remote_custom_plain: Vec<String> =+ remote_custom.iter().map(|line| strip_ansi(line)).collect();assert_eq!(provider_labels(Language::En)[0],@@ -4447,9 +4451,9 @@ mod tests {.any(|line| line.contains("Usually not needed locally")));assert!(- !local_custom+ !local_custom_plain.iter()- .chain(remote_custom.iter())+ .chain(remote_custom_plain.iter()).any(|line| line.contains(';')));}diff --git a/crates/ov_cli/src/help_ui.rs b/crates/ov_cli/src/help_ui.rsindex eb420daba..fc7602dc7 100644--- a/crates/ov_cli/src/help_ui.rs+++ b/crates/ov_cli/src/help_ui.rs@@ -3250,7 +3250,7 @@ mod tests {("admin", "Manage accounts, users, roles, and API keys."),("system",- "Run server utility, health, consistency, and crypto commands.",+ "Run server utility, health, consistency, backend sync, and crypto commands.",),("observer", "Inspect specific OpenViking server subsystems."),] {diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rsindex a24d7536c..06f9c547a 100644--- a/crates/ov_cli/src/main.rs+++ b/crates/ov_cli/src/main.rs@@ -1248,6 +1248,14 @@ fn plain_help_misuse(args: &[OsString]) -> Option<PlainHelpMisuse> {{path.push(watch_subcommand.to_string());}+ if command == "system"+ && path.get(1).is_some_and(|token| token == "backend")+ && let Some(backend_subcommand) =+ tokens.get(2).map(|token| canonical_plain_help_token(token))+ && backend_subcommand != "help"+ {+ path.push(backend_subcommand.to_string());+ }return Some(PlainHelpMisuse {help_command: prefixed_help_command(&path),});@@ -2352,8 +2360,8 @@ mod tests {preprocess_privacy_args,};use crate::config::{Config, DEFAULT_CUSTOM_URL};- use crate::{SystemBackendCommands, SystemCommands, handlers};use crate::output::OutputFormat;+ use crate::{SystemBackendCommands, SystemCommands, handlers};use clap::{CommandFactory, Parser};use std::ffi::OsString;diff --git a/crates/ragfs/src/plugins/s3fs/mod.rs b/crates/ragfs/src/plugins/s3fs/mod.rsindex 5be685a0d..a7e75322d 100644--- a/crates/ragfs/src/plugins/s3fs/mod.rs+++ b/crates/ragfs/src/plugins/s3fs/mod.rs@@ -1115,6 +1115,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params: std::collections::HashMap::new(),+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_err());@@ -1128,6 +1129,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params,+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_ok());}@@ -1150,6 +1152,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params,+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_err());@@ -1167,6 +1170,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params,+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_ok());}@@ -1188,6 +1192,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params,+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_err());@@ -1204,6 +1209,7 @@ mod tests {name: "s3fs".to_string(),mount_path: "/s3".to_string(),params,+ ..PluginConfig::default()};assert!(plugin.validate(&config).await.is_ok());}diff --git a/tests/session/memory/test_memory_tools_template.py b/tests/session/memory/test_memory_tools_template.pyindex 899687d6d..27973722f 100644--- a/tests/session/memory/test_memory_tools_template.py+++ b/tests/session/memory/test_memory_tools_template.py@@ -3,9 +3,17 @@from pathlib import Path+import pytest_asyncioimport yaml-from openviking.session.memory.utils.content import serialize_with_metadata+from openviking.session.memory.dataclass import MemoryFile+from openviking.session.memory.utils.memory_file_utils import MemoryFileUtils+++@pytest_asyncio.fixture(autouse=True)+async def _drain_background_tasks():+ """Keep this pure template test independent from session client fixtures."""+ yielddef _tools_content_template() -> str:@@ -21,13 +29,15 @@ def _tools_content_template() -> str:def test_tools_template_treats_none_counts_as_zero():- rendered = serialize_with_metadata(- {- "tool_name": "read_file",- "static_desc": "Reads files",- "call_count": None,- "success_time": None,- },+ rendered = MemoryFileUtils.write(+ MemoryFile(+ extra_fields={+ "tool_name": "read_file",+ "static_desc": "Reads files",+ "call_count": None,+ "success_time": None,+ }+ ),content_template=_tools_content_template(),)@@ -35,13 +45,15 @@ def test_tools_template_treats_none_counts_as_zero():def test_tools_template_keeps_success_rate_for_positive_counts():- rendered = serialize_with_metadata(- {- "tool_name": "read_file",- "static_desc": "Reads files",- "call_count": 4,- "success_time": 3,- },+ rendered = MemoryFileUtils.write(+ MemoryFile(+ extra_fields={+ "tool_name": "read_file",+ "static_desc": "Reads files",+ "call_count": 4,+ "success_time": 3,+ }+ ),content_template=_tools_content_template(),)diff --git a/tests/storage/test_viking_fs_grep.py b/tests/storage/test_viking_fs_grep.pyindex 8fea8283b..ee74a9b31 100644--- a/tests/storage/test_viking_fs_grep.py+++ b/tests/storage/test_viking_fs_grep.py@@ -1,194 +1,123 @@# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.# SPDX-License-Identifier: AGPL-3.0-import time-import pytest-import openviking.storage.viking_fs as viking_fs_module-from openviking.storage.viking_fs import _DEFAULT_GREP_FILE_CONCURRENCY, VikingFS+from openviking.storage.viking_fs import VikingFSclass _DummyAgfs:pass-async def test_grep_preserves_dfs_order_and_node_limit(monkeypatch):- fs = VikingFS(agfs=_DummyAgfs())-- async def fake_stat(uri, ctx=None):- return {"isDir": True}-- async def fake_ls(uri, ctx=None, **kwargs):- entries = {- "viking://resources": [- {"name": "dir_a", "isDir": True},- {"name": "dir_b", "isDir": True},- ],- "viking://resources/dir_a": [- {"name": "a1.md", "isDir": False},- {"name": "a2.md", "isDir": False},- ],- "viking://resources/dir_b": [- {"name": "b1.md", "isDir": False},- ],- }- return entries.get(uri, [])-- def fake_agfs_read(path, offset=0, size=-1):- contents = {- "/resources/dir_a/a1.md": "match a1 line1\nskip\nmatch a1 line3",- "/resources/dir_a/a2.md": "match a2 line1",- "/resources/dir_b/b1.md": "match b1 line1",- }- return contents[path].encode()-- monkeypatch.setattr(fs, "stat", fake_stat)- monkeypatch.setattr(fs, "ls", fake_ls)+def fs(monkeypatch):+ viking_fs = VikingFS(agfs=_DummyAgfs())+ monkeypatch.setattr(viking_fs, "stat", _fake_stat)monkeypatch.setattr(- fs,+ viking_fs,"_uri_to_path",lambda uri, ctx=None: uri.replace("viking://", "/"),)- monkeypatch.setattr(fs.agfs, "read", fake_agfs_read, raising=False)-- result = await fs.grep("viking://resources", pattern="match", node_limit=3)-- assert result["count"] == 3- assert result["files_scanned"] == 2- assert result["matches"] == [- {- "line": 1,- "uri": "viking://resources/dir_a/a1.md",- "content": "match a1 line1",- },- {- "line": 3,- "uri": "viking://resources/dir_a/a1.md",- "content": "match a1 line3",- },- {- "line": 1,- "uri": "viking://resources/dir_a/a2.md",- "content": "match a2 line1",- },- ]---async def test_grep_parallel_reads_respect_concurrency_limit(monkeypatch):- fs = VikingFS(agfs=_DummyAgfs())-- async def fake_stat(uri, ctx=None):- return {"isDir": True}-- async def fake_ls(uri, ctx=None, **kwargs):- entries = {- "viking://resources": [{"name": f"file{i}.md", "isDir": False} for i in range(12)]- }- return entries.get(uri, [])-- active_reads = 0- max_active_reads = 0-- def fake_agfs_read(path, offset=0, size=-1):- nonlocal active_reads, max_active_reads- active_reads += 1- max_active_reads = max(max_active_reads, active_reads)- time.sleep(0.01)- active_reads -= 1- return f"match from {path}".encode()-- monkeypatch.setattr(fs, "stat", fake_stat)- monkeypatch.setattr(fs, "ls", fake_ls)monkeypatch.setattr(- fs,- "_uri_to_path",- lambda uri, ctx=None: uri.replace("viking://", "/"),+ viking_fs,+ "_path_to_uri",+ lambda path, ctx=None: path.replace("/", "viking://", 1),)- monkeypatch.setattr(fs.agfs, "read", fake_agfs_read, raising=False)+ return viking_fs- result = await fs.grep("viking://resources", pattern="match")- assert result["count"] == 12- assert result["files_scanned"] == 12- assert max_active_reads > 1- assert max_active_reads <= min(12, _DEFAULT_GREP_FILE_CONCURRENCY)+async def _fake_stat(uri, ctx=None):+ return {"name": uri.rsplit("/", 1)[-1], "isDir": True}@pytest.mark.asyncio-async def test_grep_parallel_reads_work_with_blocking_agfs_read(monkeypatch):- fs = VikingFS(agfs=_DummyAgfs())+async def test_grep_delegates_to_agfs_with_expected_filters(monkeypatch, fs):+ calls = []++ async def fake_grep(**kwargs):+ calls.append(kwargs)+ return {"matches": [], "files_scanned": 0}++ monkeypatch.setattr(fs._async_agfs, "grep", fake_grep)++ result = await fs.grep(+ "viking://resources",+ pattern="needle",+ exclude_uri="viking://resources/archive",+ case_insensitive=True,+ node_limit=10,+ level_limit=3,+ )- async def fake_stat(uri, ctx=None):- return {"isDir": True}+ assert result == {"matches": [], "count": 0, "match_count": 0, "files_scanned": 0}+ assert calls == [+ {+ "path": "/resources",+ "pattern": "needle",+ "recursive": True,+ "case_insensitive": True,+ "stream": False,+ "node_limit": 10,+ "exclude_path": "/resources/archive",+ "level_limit": 3,+ }+ ]- async def fake_ls(uri, ctx=None, **kwargs):- if uri == "viking://resources":- return [{"name": f"file{i}.md", "isDir": False} for i in range(8)]- return []- def fake_agfs_read(path, offset=0, size=-1):- time.sleep(0.05)- return f"match from {path}".encode()+async def test_grep_maps_agfs_matches_to_viking_uris(monkeypatch, fs):+ async def fake_grep(**kwargs):+ return {+ "matches": [+ {"file": "dir/a.md", "line": 2, "content": "first match"},+ {"file": "/dir/b.md", "line_number": 5, "content": "second match"},+ ],+ "files_scanned": 7,+ }- monkeypatch.setattr(fs, "stat", fake_stat)- monkeypatch.setattr(fs, "ls", fake_ls)- monkeypatch.setattr(- fs,- "_uri_to_path",- lambda uri, ctx=None: uri.replace("viking://", "/"),- )- monkeypatch.setattr(fs.agfs, "read", fake_agfs_read, raising=False)+ monkeypatch.setattr(fs._async_agfs, "grep", fake_grep)- started = time.perf_counter()result = await fs.grep("viking://resources", pattern="match")- elapsed = time.perf_counter() - started- assert result["count"] == 8- assert result["files_scanned"] == 8- assert elapsed < 0.30+ assert result == {+ "matches": [+ {+ "line": 2,+ "uri": "viking://resources/dir/a.md",+ "content": "first match",+ },+ {+ "line": 5,+ "uri": "viking://resources/dir/b.md",+ "content": "second match",+ },+ ],+ "count": 2,+ "match_count": 2,+ "files_scanned": 7,+ }@pytest.mark.asyncio-async def test_grep_stops_scheduling_later_batches_after_node_limit(monkeypatch):- fs = VikingFS(agfs=_DummyAgfs())-- async def fake_stat(uri, ctx=None):- return {"isDir": True}-- async def fake_ls(uri, ctx=None, **kwargs):- if uri == "viking://resources":- return [{"name": f"file{i}.md", "isDir": False} for i in range(6)]- return []-- read_paths = []-- def fake_agfs_read(path, offset=0, size=-1):- read_paths.append(path)- contents = {- "/resources/file0.md": "match file0 line1\nmatch file0 line2",- "/resources/file1.md": "match file1 line1",- "/resources/file2.md": "match file2 line1",- "/resources/file3.md": "match file3 line1",- "/resources/file4.md": "match file4 line1",- "/resources/file5.md": "match file5 line1",+async def test_grep_applies_node_limit_to_backend_results(monkeypatch, fs):+ async def fake_grep(**kwargs):+ return {+ "matches": [+ {"file": "a.md", "line": 1, "content": "a"},+ {"file": "b.md", "line": 1, "content": "b"},+ {"file": "c.md", "line": 1, "content": "c"},+ ]}- return contents[path].encode()- monkeypatch.setattr(fs, "stat", fake_stat)- monkeypatch.setattr(fs, "ls", fake_ls)- monkeypatch.setattr(- fs,- "_uri_to_path",- lambda uri, ctx=None: uri.replace("viking://", "/"),- )- monkeypatch.setattr(fs.agfs, "read", fake_agfs_read, raising=False)- monkeypatch.setattr(viking_fs_module, "_DEFAULT_GREP_FILE_CONCURRENCY", 2)+ monkeypatch.setattr(fs._async_agfs, "grep", fake_grep)result = await fs.grep("viking://resources", pattern="match", node_limit=2)assert result["count"] == 2- assert result["files_scanned"] == 1- assert read_paths == ["/resources/file0.md", "/resources/file1.md"]+ assert result["match_count"] == 2+ assert result["files_scanned"] == 2+ assert [match["uri"] for match in result["matches"]] == [+ "viking://resources/a.md",+ "viking://resources/b.md",+ ]