79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
|
||
|
|
|
||
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||
|
|
|
||
|
|
|
||
|
|
def test_web_import_keeps_plantai_new_api_bundle_when_rag_import_sets_deepseek_key(
|
||
|
|
tmp_path: Path,
|
||
|
|
) -> None:
|
||
|
|
rag_root = tmp_path / "rag"
|
||
|
|
module_dir = rag_root / "src" / "rag" / "unified"
|
||
|
|
module_dir.mkdir(parents=True)
|
||
|
|
for package_dir in (rag_root / "src", rag_root / "src" / "rag", module_dir):
|
||
|
|
(package_dir / "__init__.py").write_text("", encoding="utf-8")
|
||
|
|
(module_dir / "bbav5_methodology_config.py").write_text(
|
||
|
|
(
|
||
|
|
"import os\n"
|
||
|
|
"os.environ.setdefault('DEEPSEEK_API_KEY', 'external-stale-key')\n"
|
||
|
|
"def build_bbav5_methodology_config(*args, **kwargs):\n"
|
||
|
|
" return {}\n"
|
||
|
|
),
|
||
|
|
encoding="utf-8",
|
||
|
|
)
|
||
|
|
|
||
|
|
runtime_root = tmp_path / "runtime"
|
||
|
|
runtime_root.mkdir()
|
||
|
|
env = os.environ.copy()
|
||
|
|
for name in (
|
||
|
|
"DEEPSEEK_API_KEY",
|
||
|
|
"deepseek_api_key",
|
||
|
|
"NEW_API_KEY",
|
||
|
|
"NEW_API_BASE_URL",
|
||
|
|
"NEW_API_MODEL",
|
||
|
|
):
|
||
|
|
env.pop(name, None)
|
||
|
|
env.update(
|
||
|
|
{
|
||
|
|
"NEW_API_KEY": "plantai-current-key",
|
||
|
|
"NEW_API_BASE_URL": "https://api.deepseek.com",
|
||
|
|
"NEW_API_MODEL": "deepseek-v4-flash",
|
||
|
|
"PLANTAI_RAG_ROOT": str(rag_root),
|
||
|
|
"GF_MAS_ROOT": str(tmp_path / "missing-gf-mas"),
|
||
|
|
"BBAV5_PROJECT_ROOT": str(runtime_root),
|
||
|
|
"PLANTAI_PROJECT_ROOT": str(runtime_root),
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
result = subprocess.run(
|
||
|
|
[
|
||
|
|
sys.executable,
|
||
|
|
"-c",
|
||
|
|
(
|
||
|
|
"import os\n"
|
||
|
|
"from pathlib import Path\n"
|
||
|
|
f"path = Path({str(PROJECT_ROOT / 'apps/web/vue3/main.py')!r})\n"
|
||
|
|
"source = path.read_text(encoding='utf-8')\n"
|
||
|
|
"marker = 'try:\\n from gfa_core.mas.agents.interpretation_evidence'\n"
|
||
|
|
"prefix, separator, _ = source.partition(marker)\n"
|
||
|
|
"assert separator\n"
|
||
|
|
"namespace = {'__file__': str(path), '__name__': 'web_import_prefix'}\n"
|
||
|
|
"exec(compile(prefix, str(path), 'exec'), namespace)\n"
|
||
|
|
"assert 'DEEPSEEK_API_KEY' not in os.environ\n"
|
||
|
|
),
|
||
|
|
],
|
||
|
|
cwd=PROJECT_ROOT,
|
||
|
|
env=env,
|
||
|
|
capture_output=True,
|
||
|
|
text=True,
|
||
|
|
timeout=120,
|
||
|
|
check=False,
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result.returncode == 0, result.stdout + result.stderr
|