Files
wehub-resource-sync 0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:03:20 +08:00

127 lines
4.0 KiB
Python

"""Tests for EXTERNAL memory backends (entry-point plugins).
Three extension groups let packages register memory backends via
setuptools entry points:
- headroom.memory_store
- headroom.memory_vector
- headroom.memory_text
A package registers a callable under one of these groups; the factory
loads it when the corresponding backend enum is EXTERNAL.
These tests do not require hnswlib and must remain independent of it.
"""
from __future__ import annotations
import pytest
from headroom.memory.config import (
MemoryConfig,
StoreBackend,
TextBackend,
VectorBackend,
)
from headroom.memory.factory import (
_create_store,
_create_text_index,
_create_vector_index,
)
class _FakeEntryPoint:
"""Minimal stand-in for importlib.metadata.EntryPoint used in tests."""
def __init__(self, name: str, target):
self.name = name
self._target = target
def load(self):
return self._target
def _patch_entry_points(monkeypatch, expected_group: str, name: str, target):
"""Patch headroom.memory.factory.entry_points to return our fake EP."""
from headroom.memory import factory as factory_mod
def fake_entry_points(*, group: str):
if group == expected_group:
return [_FakeEntryPoint(name, target)]
return []
monkeypatch.setattr(factory_mod, "entry_points", fake_entry_points)
class TestExternalStoreBackend:
"""EXTERNAL store backend loads via entry_points(group='headroom.memory_store')."""
def test_loads_external_store(self, monkeypatch):
sentinel = object()
def make_store(config):
assert isinstance(config, MemoryConfig)
return sentinel
_patch_entry_points(monkeypatch, "headroom.memory_store", "myvec", make_store)
config = MemoryConfig(
store_backend=StoreBackend.EXTERNAL,
store_backend_name="myvec",
)
assert _create_store(config) is sentinel
def test_external_without_name_raises(self):
config = MemoryConfig(store_backend=StoreBackend.EXTERNAL)
with pytest.raises(ValueError, match="store_backend_name is required"):
_create_store(config)
def test_external_unknown_name_raises(self, monkeypatch):
from headroom.memory import factory as factory_mod
monkeypatch.setattr(factory_mod, "entry_points", lambda *, group: [])
config = MemoryConfig(
store_backend=StoreBackend.EXTERNAL,
store_backend_name="nonexistent",
)
with pytest.raises(ValueError, match="No entry point .* 'nonexistent'"):
_create_store(config)
class TestExternalVectorBackend:
"""EXTERNAL vector backend loads via entry_points(group='headroom.memory_vector')."""
def test_loads_external_vector(self, monkeypatch):
sentinel = object()
_patch_entry_points(monkeypatch, "headroom.memory_vector", "myvec", lambda cfg: sentinel)
config = MemoryConfig(
vector_backend=VectorBackend.EXTERNAL,
vector_backend_name="myvec",
)
assert _create_vector_index(config) is sentinel
def test_external_without_name_raises(self):
config = MemoryConfig(vector_backend=VectorBackend.EXTERNAL)
with pytest.raises(ValueError, match="vector_backend_name is required"):
_create_vector_index(config)
class TestExternalTextBackend:
"""EXTERNAL text backend loads via entry_points(group='headroom.memory_text')."""
def test_loads_external_text(self, monkeypatch):
sentinel = object()
_patch_entry_points(monkeypatch, "headroom.memory_text", "mytext", lambda cfg: sentinel)
config = MemoryConfig(
text_backend=TextBackend.EXTERNAL,
text_backend_name="mytext",
)
assert _create_text_index(config) is sentinel
def test_external_without_name_raises(self):
config = MemoryConfig(text_backend=TextBackend.EXTERNAL)
with pytest.raises(ValueError, match="text_backend_name is required"):
_create_text_index(config)