feat: add real PDF ingestion workflow

This commit is contained in:
Codex
2026-08-02 00:29:40 +08:00
parent 0eb2a86f36
commit 4d97a30616
18 changed files with 986 additions and 93 deletions
+4
View File
@@ -3,7 +3,9 @@ import pytest
from pathlib import Path
from app.config import Settings
from app.api.routes import get_project_repository
from app.main import app
from app.repositories.memory import InMemoryProjectRepository
from app.runtime_settings import EncryptedSettingsStore, get_runtime_store
@@ -17,7 +19,9 @@ def transport(tmp_path: Path) -> httpx.ASGITransport:
redis_url="redis://:secret@redis:6379/0",
)
)
repository = InMemoryProjectRepository()
app.dependency_overrides[get_runtime_store] = lambda: store
app.dependency_overrides[get_project_repository] = lambda: repository
return httpx.ASGITransport(app=app)
+19
View File
@@ -0,0 +1,19 @@
from pathlib import Path
from app.services.plan_ingestion import inspect_pdf
def test_sample_pdf_detects_two_plan_regions() -> None:
workspace = Path(__file__).resolve().parents[3]
sample = workspace / "11-2-104-模型.pdf"
result = inspect_pdf(sample.read_bytes())
assert result.page_count == 1
assert result.vector_based is True
assert result.vector_element_count > 10_000
assert result.preview_width == 1600
assert len(result.regions) == 2
assert result.regions[0].name.startswith("上方")
assert result.regions[0].recommended is True
assert result.regions[1].name.startswith("下方")
+14
View File
@@ -43,3 +43,17 @@ def test_invalid_command_is_rejected() -> None:
expected_revision=project.revision,
),
)
def test_unknown_region_is_rejected() -> None:
project = create_demo_project()
project.stage = WorkflowStage.REGION_SELECTION
with pytest.raises(InvalidTransitionError):
apply_command(
project,
CommandRequest(
command=WorkflowCommand.SELECT_REGION,
expected_revision=project.revision,
payload={"region_id": "missing-region"},
),
)