feat: mv data folder to root

This commit is contained in:
qixinbo
2026-03-27 15:59:23 +08:00
parent 37070d7896
commit 5d479bed68
18 changed files with 175 additions and 39 deletions
+2 -1
View File
@@ -3,11 +3,12 @@ from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from app.core.data_root import get_data_root
from main import app
def _backend_data_root() -> Path:
return Path(__file__).resolve().parents[1] / "data"
return get_data_root()
def test_download_artifact_within_whitelist() -> None:
+2 -1
View File
@@ -1,10 +1,11 @@
from pathlib import Path
from app.core.artifacts import extract_artifacts
from app.core.data_root import get_data_root
def _backend_data_root() -> Path:
return Path(__file__).resolve().parents[1] / "data"
return get_data_root()
def test_extract_artifacts_from_local_and_tool_paths() -> None:
+28
View File
@@ -0,0 +1,28 @@
from pathlib import Path
from app.core import data_root
def test_data_root_prefers_env(monkeypatch, tmp_path: Path) -> None:
custom = tmp_path / "custom-data-root"
monkeypatch.setenv("DATA_ROOT", str(custom))
assert data_root.get_data_root() == custom.resolve()
def test_data_root_falls_back_to_legacy(monkeypatch, tmp_path: Path) -> None:
monkeypatch.delenv("DATA_ROOT", raising=False)
legacy = tmp_path / "legacy-data"
default = tmp_path / "default-data"
legacy.mkdir(parents=True, exist_ok=True)
monkeypatch.setattr(data_root, "LEGACY_DATA_ROOT", legacy)
monkeypatch.setattr(data_root, "DEFAULT_DATA_ROOT", default)
assert data_root.get_data_root() == legacy
def test_ensure_data_layout_creates_children(monkeypatch, tmp_path: Path) -> None:
monkeypatch.setenv("DATA_ROOT", str(tmp_path / "dr"))
data_root.ensure_data_layout()
root = data_root.get_data_root()
assert (root / "workspace").exists()
assert (root / "uploads").exists()
assert (root / "data").exists()
+12
View File
@@ -0,0 +1,12 @@
import asyncio
import json
from app.agent.nl2sql import process_nl2sql, NL2SQLRequest
async def main():
req = NL2SQLRequest(query="列出所有表", source="postgres", generate_chart=False)
res = await process_nl2sql(req)
print("SQL:", res.sql)
print("Error:", res.error)
print("Result:", res.result)
asyncio.run(main())