mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
Skip invalid research CLI records (#1394)
This commit is contained in:
+13
-10
@@ -26,14 +26,19 @@ from pathlib import Path
|
|||||||
_DATA_DIR = _REPO_ROOT / "data" / "deep_research"
|
_DATA_DIR = _REPO_ROOT / "data" / "deep_research"
|
||||||
|
|
||||||
|
|
||||||
|
def _load_path(path: Path) -> dict | None:
|
||||||
|
try:
|
||||||
|
data = json.loads(path.read_text())
|
||||||
|
except (json.JSONDecodeError, OSError):
|
||||||
|
return None
|
||||||
|
return data if isinstance(data, dict) else None
|
||||||
|
|
||||||
|
|
||||||
def _load(rp_id: str) -> dict | None:
|
def _load(rp_id: str) -> dict | None:
|
||||||
path = _DATA_DIR / f"{rp_id}.json"
|
path = _DATA_DIR / f"{rp_id}.json"
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return None
|
return None
|
||||||
try:
|
return _load_path(path)
|
||||||
return json.loads(path.read_text())
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _preview_text(value, limit: int = 200) -> str:
|
def _preview_text(value, limit: int = 200) -> str:
|
||||||
@@ -64,9 +69,8 @@ def cmd_list(args):
|
|||||||
out = []
|
out = []
|
||||||
for path in sorted(_DATA_DIR.glob("*.json")):
|
for path in sorted(_DATA_DIR.glob("*.json")):
|
||||||
rp_id = path.stem
|
rp_id = path.stem
|
||||||
try:
|
data = _load_path(path)
|
||||||
data = json.loads(path.read_text())
|
if data is None:
|
||||||
except Exception:
|
|
||||||
continue
|
continue
|
||||||
if args.status and (data.get("status") or "") != args.status:
|
if args.status and (data.get("status") or "") != args.status:
|
||||||
continue
|
continue
|
||||||
@@ -108,9 +112,8 @@ def cmd_search(args):
|
|||||||
out = []
|
out = []
|
||||||
for path in _DATA_DIR.glob("*.json"):
|
for path in _DATA_DIR.glob("*.json"):
|
||||||
rp_id = path.stem
|
rp_id = path.stem
|
||||||
try:
|
data = _load_path(path)
|
||||||
data = json.loads(path.read_text())
|
if data is None:
|
||||||
except Exception:
|
|
||||||
continue
|
continue
|
||||||
haystack = " ".join([
|
haystack = " ".join([
|
||||||
(data.get("query") or "").lower(),
|
(data.get("query") or "").lower(),
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import importlib.machinery
|
||||||
|
import importlib.util
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
|
|
||||||
|
def _load_cli():
|
||||||
|
path = ROOT / "scripts" / "odysseus-research"
|
||||||
|
loader = importlib.machinery.SourceFileLoader("odysseus_research_cli", str(path))
|
||||||
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_skips_non_object_research_records(tmp_path, monkeypatch):
|
||||||
|
cli = _load_cli()
|
||||||
|
cli._DATA_DIR = tmp_path
|
||||||
|
(tmp_path / "good.json").write_text(json.dumps({"query": "hello", "status": "complete"}))
|
||||||
|
(tmp_path / "list.json").write_text("[]")
|
||||||
|
(tmp_path / "broken.json").write_text("{")
|
||||||
|
|
||||||
|
emitted = []
|
||||||
|
monkeypatch.setattr(cli, "emit", lambda value, args: emitted.append(value))
|
||||||
|
|
||||||
|
cli.cmd_list(SimpleNamespace(status=None, limit=50))
|
||||||
|
|
||||||
|
assert emitted == [[{
|
||||||
|
"id": "good",
|
||||||
|
"query": "hello",
|
||||||
|
"category": "",
|
||||||
|
"status": "complete",
|
||||||
|
"started_at": "",
|
||||||
|
"completed_at": "",
|
||||||
|
"sources": 0,
|
||||||
|
"stats": {},
|
||||||
|
}]]
|
||||||
Reference in New Issue
Block a user