返回 last30days-skill
test_mcp_engine_bundle.py
根目录 / tests / test_mcp_engine_bundle.py
1 """Exercise the Python engine layout produced for the MCP binary."""
2
3 import json
4 import shutil
5 import sqlite3
6 import subprocess
7 import sys
8 from contextlib import closing
9 from pathlib import Path
10
11
12 ROOT = Path(__file__).resolve().parents[1]
13
14
15 def test_synced_engine_persists_research_and_emits_json(tmp_path):
16 staged_repo = tmp_path / "bundle source"
17 scripts = staged_repo / "skills" / "last30days" / "scripts"
18 shutil.copytree(
19 ROOT / "skills" / "last30days" / "scripts",
20 scripts,
21 ignore=shutil.ignore_patterns("__pycache__", "*.pyc"),
22 )
23 sync_script = staged_repo / "mcp" / "scripts" / "sync-engine.sh"
24 sync_script.parent.mkdir(parents=True)
25 shutil.copy2(ROOT / "mcp" / "scripts" / "sync-engine.sh", sync_script)
26 subprocess.run(
27 ["bash", str(sync_script)],
28 cwd=tmp_path,
29 check=True,
30 capture_output=True,
31 text=True,
32 timeout=30,
33 )
34
35 engine = staged_repo / "mcp" / "internal" / "engine" / "vendored"
36 save_dir = tmp_path / "saved research"
37 topic = "MCP persistence regression"
38 result = subprocess.run(
39 [
40 sys.executable,
41 "-I",
42 str(engine / "last30days.py"),
43 topic,
44 "--mock",
45 "--quick",
46 "--search=reddit",
47 "--no-browser-cookies",
48 "--emit=json",
49 "--save-dir",
50 str(save_dir),
51 ],
52 cwd=tmp_path,
53 env={
54 "PATH": str(tmp_path / "empty-bin"),
55 "LAST30DAYS_CONFIG_DIR": str(tmp_path / "config"),
56 "LAST30DAYS_CACHE_DIR": str(tmp_path / "cache"),
57 "LAST30DAYS_SKIP_KEYCHAIN": "1",
58 "LAST30DAYS_STORE": "1",
59 },
60 capture_output=True,
61 text=True,
62 timeout=30,
63 )
64
65 assert result.returncode == 0, result.stderr
66 assert json.loads(result.stdout)["query"] == topic
67 db_path = save_dir / "research.db"
68 assert db_path.is_file()
69 with closing(sqlite3.connect(db_path)) as conn:
70 assert conn.execute("SELECT name FROM topics").fetchall() == [(topic,)]
71 assert conn.execute("SELECT status FROM research_runs").fetchall() == [("completed",)]
72 assert conn.execute("SELECT COUNT(*) FROM findings").fetchone()[0] > 0
73
73 lines PYTHON