mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-27 21:05:34 +00:00
DGX Spark Fix (#231)
This commit is contained in:
+14
@@ -90,4 +90,18 @@ CLAUDE.md
|
||||
research_mining_*
|
||||
.python-version
|
||||
src/openjarvis/channels/whatsapp_baileys_bridge/node_modules/
|
||||
|
||||
# SQLite in-memory artifacts
|
||||
:memory:
|
||||
MagicMock/
|
||||
|
||||
# Second Repos
|
||||
Inline/
|
||||
scratch/
|
||||
|
||||
# SQLite in-memory artifacts
|
||||
:memory:
|
||||
MagicMock/
|
||||
|
||||
# Second Repos
|
||||
Inline/
|
||||
|
||||
@@ -12,17 +12,9 @@ from starlette.responses import JSONResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Paths exempt from API key auth
|
||||
_EXEMPT_PREFIXES = (
|
||||
"/health",
|
||||
"/webhooks/",
|
||||
"/docs",
|
||||
"/openapi.json",
|
||||
)
|
||||
|
||||
|
||||
class AuthMiddleware(BaseHTTPMiddleware):
|
||||
"""Validates ``Authorization: Bearer <key>`` on ``/v1/*`` routes.
|
||||
"""Validates ``Authorization: Bearer <key>`` on ``/v1/*`` and ``/api/*`` routes.
|
||||
|
||||
Webhook routes and health checks are exempt — they use
|
||||
per-channel signature verification instead.
|
||||
@@ -33,7 +25,7 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
||||
self._api_key = api_key or os.environ.get("OPENJARVIS_API_KEY", "")
|
||||
|
||||
async def dispatch(self, request: Request, call_next): # noqa: ANN001
|
||||
if self._api_key and not self._is_exempt(request.url.path):
|
||||
if self._api_key and self._requires_auth(request.url.path):
|
||||
auth = request.headers.get("Authorization", "")
|
||||
if not auth:
|
||||
return JSONResponse(
|
||||
@@ -49,8 +41,10 @@ class AuthMiddleware(BaseHTTPMiddleware):
|
||||
return await call_next(request)
|
||||
|
||||
@staticmethod
|
||||
def _is_exempt(path: str) -> bool:
|
||||
return any(path.startswith(p) for p in _EXEMPT_PREFIXES)
|
||||
def _requires_auth(path: str) -> bool:
|
||||
"""Only protect API routes, not the frontend UI or static assets."""
|
||||
return path.startswith("/v1/") or path.startswith("/api/")
|
||||
|
||||
|
||||
|
||||
def generate_api_key() -> str:
|
||||
|
||||
@@ -167,9 +167,7 @@ class TestBuildMessages:
|
||||
|
||||
empty_cfg = JarvisConfig()
|
||||
empty_cfg.agent.default_system_prompt = ""
|
||||
monkeypatch.setattr(
|
||||
"openjarvis.agents._stubs.load_config", lambda: empty_cfg
|
||||
)
|
||||
monkeypatch.setattr("openjarvis.agents._stubs.load_config", lambda: empty_cfg)
|
||||
|
||||
engine = MagicMock()
|
||||
agent = _ConcreteAgent(engine, "m")
|
||||
|
||||
@@ -120,7 +120,10 @@ def test_connector_has_metadata(
|
||||
|
||||
|
||||
def test_knowledge_store_has_data() -> None:
|
||||
"""KnowledgeStore at default path has data (if it exists)."""
|
||||
"""Assert a populated default-path KnowledgeStore has chunks and sources.
|
||||
|
||||
Skips if the DB is missing or has no indexed rows (fresh install / empty store).
|
||||
"""
|
||||
from openjarvis.connectors.store import KnowledgeStore
|
||||
from openjarvis.core.config import DEFAULT_CONFIG_DIR
|
||||
|
||||
@@ -129,20 +132,26 @@ def test_knowledge_store_has_data() -> None:
|
||||
pytest.skip("No knowledge.db found")
|
||||
|
||||
store = KnowledgeStore(str(db_path))
|
||||
count = store.count()
|
||||
assert count > 0, "KnowledgeStore has no data"
|
||||
try:
|
||||
count = store.count()
|
||||
if count == 0:
|
||||
pytest.skip("KnowledgeStore exists but has no indexed data")
|
||||
|
||||
# Check sources exist
|
||||
rows = store._conn.execute(
|
||||
"SELECT DISTINCT source FROM knowledge_chunks"
|
||||
).fetchall()
|
||||
sources = [r[0] for r in rows]
|
||||
assert len(sources) > 0, "No sources in KnowledgeStore"
|
||||
store.close()
|
||||
# Check sources exist
|
||||
rows = store._conn.execute(
|
||||
"SELECT DISTINCT source FROM knowledge_chunks"
|
||||
).fetchall()
|
||||
sources = [r[0] for r in rows]
|
||||
assert len(sources) > 0, "No sources in KnowledgeStore"
|
||||
finally:
|
||||
store.close()
|
||||
|
||||
|
||||
def test_knowledge_store_sources_have_chunks() -> None:
|
||||
"""Each connected source has at least 1 chunk in the store."""
|
||||
"""Each source row in a populated store has at least 1 chunk.
|
||||
|
||||
Skips if the DB is missing or empty (same as test_knowledge_store_has_data).
|
||||
"""
|
||||
from openjarvis.connectors.store import KnowledgeStore
|
||||
from openjarvis.core.config import DEFAULT_CONFIG_DIR
|
||||
|
||||
@@ -151,12 +160,16 @@ def test_knowledge_store_sources_have_chunks() -> None:
|
||||
pytest.skip("No knowledge.db found")
|
||||
|
||||
store = KnowledgeStore(str(db_path))
|
||||
rows = store._conn.execute(
|
||||
"SELECT source, COUNT(*) as n FROM knowledge_chunks "
|
||||
"GROUP BY source ORDER BY n DESC"
|
||||
).fetchall()
|
||||
try:
|
||||
if store.count() == 0:
|
||||
pytest.skip("KnowledgeStore exists but has no indexed data")
|
||||
|
||||
for source, count in rows:
|
||||
assert count > 0, f"Source '{source}' has 0 chunks"
|
||||
rows = store._conn.execute(
|
||||
"SELECT source, COUNT(*) as n FROM knowledge_chunks "
|
||||
"GROUP BY source ORDER BY n DESC"
|
||||
).fetchall()
|
||||
|
||||
store.close()
|
||||
for source, count in rows:
|
||||
assert count > 0, f"Source '{source}' has 0 chunks"
|
||||
finally:
|
||||
store.close()
|
||||
|
||||
Reference in New Issue
Block a user