Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(resources): encrypt repository upload files (#1983)

Qin Haojie72704999c0d4
diff --git a/openviking/parse/parsers/upload_utils.py b/openviking/parse/parsers/upload_utils.py
index 24a759ac3..ce746eb5a 100644
--- a/openviking/parse/parsers/upload_utils.py
+++ b/openviking/parse/parsers/upload_utils.py
@@ -306,14 +306,13 @@ async def upload_directory(
async def _upload_one(idx: int, file_path: Path, target_uri: str) -> None:
async with sem:
- def _do() -> None:
+ def _read_and_encode() -> bytes:
content = file_path.read_bytes()
- encoded = detect_and_convert_encoding(content, file_path)
- agfs_path = viking_fs._uri_to_path(target_uri)
- viking_fs.agfs.write(agfs_path, encoded)
+ return detect_and_convert_encoding(content, file_path)
try:
- await asyncio.to_thread(_do)
+ encoded = await asyncio.to_thread(_read_and_encode)
+ await viking_fs.write_file_bytes(target_uri, encoded)
except Exception as exc:
errors[idx] = f"Failed to upload {file_path}: {exc}"
diff --git a/tests/test_upload_utils.py b/tests/test_upload_utils.py
index 1fa8f81d8..8aa6cce84 100644
--- a/tests/test_upload_utils.py
+++ b/tests/test_upload_utils.py
@@ -42,6 +42,7 @@ class FakeVikingFS:
def __init__(self) -> None:
self.files: Dict[str, bytes] = {}
self.dirs: List[str] = []
+ self.write_file_bytes_calls: List[str] = []
self.agfs = FakeAGFS(self.files)
def _uri_to_path(self, uri: str) -> str:
@@ -49,6 +50,7 @@ class FakeVikingFS:
return uri
async def write_file_bytes(self, uri: str, content: bytes) -> None:
+ self.write_file_bytes_calls.append(uri)
self.files[uri] = content
async def mkdir(self, uri: str, exist_ok: bool = False) -> None:
@@ -331,6 +333,27 @@ class TestUploadDirectory:
assert "viking://temp/test/readme.md" in viking_fs.files
assert "viking://temp/test/config.yaml" in viking_fs.files
assert "viking://temp/test/src/main.go" in viking_fs.files
+ assert "viking://temp/test/hello.py" in viking_fs.write_file_bytes_calls
+
+ @pytest.mark.asyncio
+ async def test_uses_vikingfs_write_api_for_file_content(self, tmp_path: Path) -> None:
+ class GuardedAGFS(FakeAGFS):
+ def write(self, path: str, content: bytes) -> None:
+ raise AssertionError("upload_directory must not bypass VikingFS writes")
+
+ class GuardedVikingFS(FakeVikingFS):
+ def __init__(self) -> None:
+ super().__init__()
+ self.agfs = GuardedAGFS(self.files)
+
+ (tmp_path / "hello.py").write_text("print('hello')", encoding="utf-8")
+ viking_fs = GuardedVikingFS()
+
+ count, warnings = await upload_directory(tmp_path, "viking://temp/guarded", viking_fs)
+
+ assert count == 1
+ assert warnings == []
+ assert viking_fs.files["viking://temp/guarded/hello.py"] == b"print('hello')"
@pytest.mark.asyncio
async def test_skips_hidden_files(self, tmp_dir: Path, viking_fs: FakeVikingFS) -> None:
@@ -522,9 +545,6 @@ class TestUploadDirectoryEdgeCases:
def mkdir(self, path: str) -> None:
pass
- def write(self, path: str, content: bytes) -> None:
- raise IOError("write error")
-
class FailingWriteFS:
agfs = FailingAGFS()
@@ -534,6 +554,9 @@ class TestUploadDirectoryEdgeCases:
async def mkdir(self, uri: str, exist_ok: bool = False) -> None:
pass
+ async def write_file_bytes(self, uri: str, content: bytes) -> None:
+ raise IOError("write error")
+
(tmp_path / "ok.py").write_text("print(1)", encoding="utf-8")
count, warnings = await upload_directory(tmp_path, "viking://temp/fail", FailingWriteFS())