c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
149 lines
4.7 KiB
Python
149 lines
4.7 KiB
Python
"""CloudClient.remember(content_type='skills') reads local SKILL.md files
|
|
and uploads their contents — not the path string.
|
|
|
|
Before the fix, a remote ``cognee.remember("./skills", content_type="skills")``
|
|
sent the literal string ``"./skills"`` (10 bytes) as the form body. The pod
|
|
then handed an UploadFile containing that string to ``add_skills`` which
|
|
rejected it with PermissionError because no such path exists pod-side.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from cognee.api.v1.serve.cloud_client import CloudClient
|
|
|
|
|
|
class _FakeResponse:
|
|
status = 200
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *exc):
|
|
return False
|
|
|
|
async def json(self):
|
|
return {"status": "completed"}
|
|
|
|
async def text(self):
|
|
return ""
|
|
|
|
|
|
class _FakeSession:
|
|
"""Minimal aiohttp.ClientSession stand-in that captures the POST body."""
|
|
|
|
def __init__(self):
|
|
self.last_form = None
|
|
self.closed = False
|
|
|
|
def post(self, _url, data=None, **kwargs):
|
|
self.last_form = data
|
|
return _FakeResponse()
|
|
|
|
async def close(self):
|
|
self.closed = True
|
|
|
|
|
|
def _form_field_dump(form):
|
|
"""Extract (name, filename, body_bytes) tuples from an aiohttp.FormData."""
|
|
out = []
|
|
# FormData stores fields in ._fields (list of (type_options, headers, value))
|
|
for type_options, _headers, value in form._fields:
|
|
name = type_options.get("name")
|
|
filename = type_options.get("filename")
|
|
if hasattr(value, "read"):
|
|
body = value.read()
|
|
elif isinstance(value, (bytes, bytearray)):
|
|
body = bytes(value)
|
|
else:
|
|
body = str(value).encode("utf-8")
|
|
out.append((name, filename, body))
|
|
return out
|
|
|
|
|
|
def test_remember_skills_with_file_path_uploads_bytes(tmp_path):
|
|
skill = tmp_path / "demo" / "SKILL.md"
|
|
skill.parent.mkdir(parents=True)
|
|
skill.write_text("# Demo Skill\n\nDoes the thing.\n", encoding="utf-8")
|
|
|
|
client = CloudClient(service_url="https://example.test", api_key="k")
|
|
fake_session = _FakeSession()
|
|
|
|
async def run():
|
|
with patch.object(client, "_get_session", return_value=fake_session):
|
|
await client.remember(
|
|
str(tmp_path),
|
|
dataset_name="ds",
|
|
content_type="skills",
|
|
)
|
|
|
|
asyncio.run(run())
|
|
|
|
fields = _form_field_dump(fake_session.last_form)
|
|
skill_fields = [(name, fn, body) for name, fn, body in fields if name == "data"]
|
|
assert skill_fields, "expected at least one 'data' field"
|
|
# filename preserves the relative layout under the source dir
|
|
assert skill_fields[0][1] == "demo/SKILL.md", skill_fields[0][1]
|
|
# body is the FILE contents, not the path string
|
|
assert skill_fields[0][2].decode("utf-8").startswith("# Demo Skill"), skill_fields[0][2]
|
|
# content_type=skills made it onto the form
|
|
ct = [(name, body.decode("utf-8")) for name, _fn, body in fields if name == "content_type"]
|
|
assert ct == [("content_type", "skills")], ct
|
|
|
|
|
|
def test_remember_skills_rejects_missing_source(tmp_path):
|
|
client = CloudClient(service_url="https://example.test", api_key="k")
|
|
fake_session = _FakeSession()
|
|
|
|
async def run():
|
|
with patch.object(client, "_get_session", return_value=fake_session):
|
|
await client.remember(
|
|
str(tmp_path / "nope"),
|
|
dataset_name="ds",
|
|
content_type="skills",
|
|
)
|
|
|
|
try:
|
|
asyncio.run(run())
|
|
except FileNotFoundError:
|
|
return
|
|
raise AssertionError("expected FileNotFoundError for missing skills source")
|
|
|
|
|
|
def test_remember_skills_rejects_empty_folder(tmp_path):
|
|
client = CloudClient(service_url="https://example.test", api_key="k")
|
|
fake_session = _FakeSession()
|
|
|
|
async def run():
|
|
with patch.object(client, "_get_session", return_value=fake_session):
|
|
await client.remember(
|
|
str(tmp_path),
|
|
dataset_name="ds",
|
|
content_type="skills",
|
|
)
|
|
|
|
try:
|
|
asyncio.run(run())
|
|
except ValueError as e:
|
|
assert "No SKILL.md files" in str(e)
|
|
return
|
|
raise AssertionError("expected ValueError for empty skills folder")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import tempfile
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
p = Path(tmp)
|
|
test_remember_skills_with_file_path_uploads_bytes(p)
|
|
# Fresh dir for the missing-source case
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
test_remember_skills_rejects_missing_source(Path(tmp))
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
test_remember_skills_rejects_empty_folder(Path(tmp))
|
|
print("OK")
|