Skip to content

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

test(ci): mock models for integration tests without credentials (#6657)

zhanglistardb808df316ce
diff --git a/.github/workflows/api_test.yml b/.github/workflows/api_test.yml
index 5f0982cf9..8bd3f91a1 100644
--- a/.github/workflows/api_test.yml
+++ b/.github/workflows/api_test.yml
@@ -198,7 +198,7 @@ jobs:
HAS_SECRETS=true
echo "Using full configuration with VLM and Embedding"
else
- echo "Using minimal configuration (no VLM/Embedding)"
+ echo "Using minimal configuration (mock embedding and VLM)"
fi
echo "HAS_SECRETS=$HAS_SECRETS" >> $GITHUB_ENV
@@ -275,7 +275,7 @@ jobs:
$hasSecrets = "true"
Write-Host "Using full configuration with VLM and Embedding"
} else {
- Write-Host "Using minimal configuration (no VLM/Embedding)"
+ Write-Host "Using minimal configuration (mock embedding and VLM)"
}
echo "HAS_SECRETS=$hasSecrets" >> $env:GITHUB_ENV
@@ -359,7 +359,11 @@ jobs:
echo "Starting OpenViking Server on port $SERVER_PORT..."
export ROOT_API_KEY=test-root-api-key
export SERVER_PORT=$SERVER_PORT
- nohup uv run python -m openviking.server.bootstrap > openviking-server.log 2>&1 &
+ SERVER_MODULE=openviking.server.bootstrap
+ if [ "$HAS_SECRETS" != "true" ]; then
+ SERVER_MODULE=tests.api_test.mock_embedding_server
+ fi
+ nohup uv run python -m "$SERVER_MODULE" --workers 1 > openviking-server.log 2>&1 &
echo $! > openviking-server.pid
echo "SERVER_PID=$(cat openviking-server.pid)" >> $GITHUB_ENV
@@ -395,7 +399,11 @@ jobs:
$errFile = Join-Path $PWD "openviking-server-error.log"
$batchFile = Join-Path $PWD "start-server.bat"
- $batchContent = "@echo off`r`nset ROOT_API_KEY=test-root-api-key`r`nset SERVER_PORT=$port`r`nuv run python -m openviking.server.bootstrap`r`n"
+ $serverModule = "openviking.server.bootstrap"
+ if ($env:HAS_SECRETS -ne "true") {
+ $serverModule = "tests.api_test.mock_embedding_server"
+ }
+ $batchContent = "@echo off`r`nset ROOT_API_KEY=test-root-api-key`r`nset SERVER_PORT=$port`r`nuv run python -m $serverModule --workers 1`r`n"
Set-Content -Path $batchFile -Value $batchContent -Encoding ASCII
Write-Host "Batch file created at: $batchFile"
@@ -486,7 +494,7 @@ jobs:
Write-Host "Running full test suite with VLM/Embedding (Windows: skipping filesystem and slow tests)"
uv run python -m pytest . -v -n 4 --html=api-test-report.html --self-contained-html --ignore=filesystem/ --ignore=scenarios/resources_retrieval_slow/ --ignore=scenarios/resources_retrieval/ --ignore=common/slow/ --ignore=content/slow/ --ignore=resources/slow/ --ignore=retrieval/slow/ --ignore=sessions/slow/ --ignore=tasks/slow/ --ignore=skills/slow/ --ignore=scenarios/slow/ --ignore=scenarios/stability_error/slow/
} else {
- Write-Host "Running basic tests only (no VLM/Embedding, Windows: skipping filesystem and slow tests)"
+ Write-Host "Running basic tests only (mock embedding and VLM, Windows: skipping filesystem and slow tests)"
uv run python -m pytest . -v -n 4 --html=api-test-report.html --self-contained-html --ignore=retrieval/ --ignore=resources/test_add_resource.py --ignore=resources/test_pack.py --ignore=resources/test_wait_processed.py --ignore=admin/ --ignore=skills/ --ignore=system/test_system_status.py --ignore=system/test_is_healthy.py --ignore=system/test_system_wait.py --ignore=filesystem/ --ignore=scenarios/ --ignore=common/slow/ --ignore=content/slow/ --ignore=resources/slow/ --ignore=sessions/slow/ --ignore=tasks/slow/ --ignore=skills/slow/ -k "not test_observer"
}
- name: Install released OpenViking CLI for compatibility tests (Unix)
@@ -573,7 +581,7 @@ jobs:
run: |
if [ -f openviking-server.pid ]; then
kill $(cat openviking-server.pid) 2>/dev/null || true
- pkill -f "openviking.server.bootstrap" 2>/dev/null || true
+ pkill -f "openviking.server.bootstrap|tests.api_test.mock_embedding_server" 2>/dev/null || true
fi
- name: Stop OpenViking Server (Windows)
diff --git a/tests/api_test/common/test_edge_cases.py b/tests/api_test/common/test_edge_cases.py
index fcb068ab1..23b2c8917 100644
--- a/tests/api_test/common/test_edge_cases.py
+++ b/tests/api_test/common/test_edge_cases.py
@@ -124,6 +124,11 @@ class TestContentEdgeCases:
assert write_resp.status_code == 200, (
f"write empty content with create mode should return 200, got {write_resp.status_code}: {write_resp.text[:200]}"
)
+ assert write_resp.json().get("status") == "ok"
+
+ read_resp = api_client.fs_read(test_uri)
+ assert read_resp.status_code == 200
+ assert read_resp.json().get("result") == ""
finally:
try:
api_client.fs_rm(test_uri.rsplit("/", 1)[0], recursive=True)
diff --git a/tests/api_test/mock_embedding_server.py b/tests/api_test/mock_embedding_server.py
new file mode 100644
index 000000000..af20c6df6
--- /dev/null
+++ b/tests/api_test/mock_embedding_server.py
@@ -0,0 +1,69 @@
+"""Run the API test server with mock models when CI has no model credentials."""
+
+import hashlib
+import math
+from unittest.mock import patch
+
+from openviking.models.embedder.base import DenseEmbedderBase, EmbedResult
+from openviking.models.vlm.base import VLMBase, VLMResponse
+from openviking.server.bootstrap import main
+from openviking_cli.utils.config.embedding_config import EmbeddingConfig
+from openviking_cli.utils.config.vlm_config import VLMConfig
+
+
+class MockEmbedder(DenseEmbedderBase):
+ def __init__(self, dimension: int):
+ super().__init__(model_name="api-test-mock-embedding")
+ self.dimension = dimension
+
+ def embed(self, content, is_query: bool = False) -> EmbedResult:
+ digest = hashlib.shake_256(str(content).encode("utf-8")).digest(self.dimension)
+ vector = [value / 255.0 - 0.5 for value in digest]
+ norm = math.sqrt(sum(value * value for value in vector))
+ return EmbedResult(dense_vector=[value / norm for value in vector])
+
+ def get_dimension(self) -> int:
+ return self.dimension
+
+
+class MockVLM(VLMBase):
+ def __init__(self):
+ super().__init__({"provider": "mock", "model": "api-test-mock-vlm"})
+
+ def get_completion(self, prompt: str = "", **kwargs) -> str | VLMResponse:
+ content = "API test mock summary."
+ if prompt.lstrip().startswith("Analyze the following skill content"):
+ # The API/CLI skill fixture contains no private configuration values.
+ content = '{"values": {}}'
+ elif any(
+ "Output Format: restricted Python memory SDK" in str(message.get("content", ""))
+ for message in kwargs.get("messages") or []
+ ):
+ content = "sdk.commit()"
+ if kwargs.get("tools") is not None:
+ return VLMResponse(content=content)
+ return content
+
+ async def get_completion_async(self, prompt: str = "", **kwargs) -> str | VLMResponse:
+ return self.get_completion(prompt, **kwargs)
+
+ def get_vision_completion(self, prompt: str = "", **kwargs) -> str | VLMResponse:
+ return self.get_completion(prompt, **kwargs)
+
+ async def get_vision_completion_async(self, prompt: str = "", **kwargs) -> str | VLMResponse:
+ return self.get_completion(prompt, **kwargs)
+
+
+def get_mock_embedder(config: EmbeddingConfig) -> MockEmbedder:
+ if not config.dense or not config.dense.dimension or config.sparse or config.hybrid:
+ raise ValueError("API mock server requires a dense embedding dimension")
+ return MockEmbedder(config.dense.dimension)
+
+
+if __name__ == "__main__":
+ mock_vlm = MockVLM()
+ with (
+ patch.object(EmbeddingConfig, "get_embedder", get_mock_embedder),
+ patch.object(VLMConfig, "get_vlm_instance", lambda self: mock_vlm),
+ ):
+ main()