feat: CONAI Phase 1 MVP 초기 구현
소형 건설업체(100억 미만)를 위한 AI 기반 토목공사 통합관리 플랫폼 Backend (FastAPI): - SQLAlchemy 모델 13개 (users, projects, wbs, tasks, daily_reports, reports, inspections, quality, weather, permits, rag, settings) - API 라우터 11개 (auth, projects, tasks, daily_reports, reports, inspections, weather, rag, kakao, permits, settings) - Services: Claude AI 래퍼, CPM Gantt 계산, 기상청 API, RAG(pgvector), 카카오 Skill API - Alembic 마이그레이션 (pgvector 포함) - pytest 테스트 (CPM, 날씨 경보) Frontend (Next.js 15): - 11개 페이지 (대시보드, 프로젝트, Gantt, 일보, 검측, 품질, 날씨, 인허가, RAG, 설정) - TanStack Query + Zustand + Tailwind CSS 인프라: - Docker Compose (PostgreSQL pgvector + backend + frontend) - 한국어 README 및 설치 가이드 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import pytest
|
||||
import asyncio
|
||||
from httpx import AsyncClient, ASGITransport
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
|
||||
from app.main import app
|
||||
from app.core.database import Base, get_db
|
||||
from app.core.security import get_password_hash
|
||||
from app.models.user import User, UserRole
|
||||
|
||||
TEST_DB_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/conai_test"
|
||||
|
||||
test_engine = create_async_engine(TEST_DB_URL, echo=False)
|
||||
TestSessionLocal = async_sessionmaker(test_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop():
|
||||
loop = asyncio.get_event_loop_policy().new_event_loop()
|
||||
yield loop
|
||||
loop.close()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
async def db_setup():
|
||||
async with test_engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield
|
||||
async with test_engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def db(db_setup):
|
||||
async with TestSessionLocal() as session:
|
||||
yield session
|
||||
await session.rollback()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def client(db):
|
||||
async def override_get_db():
|
||||
yield db
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
yield ac
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def test_user(db):
|
||||
user = User(
|
||||
email="test@conai.app",
|
||||
hashed_password=get_password_hash("testpass123"),
|
||||
name="테스트 현장소장",
|
||||
role=UserRole.SITE_MANAGER,
|
||||
)
|
||||
db.add(user)
|
||||
await db.commit()
|
||||
await db.refresh(user)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def auth_headers(client, test_user):
|
||||
resp = await client.post("/api/v1/auth/login", data={"username": "test@conai.app", "password": "testpass123"})
|
||||
token = resp.json()["access_token"]
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Tests for CPM Gantt calculation."""
|
||||
import pytest
|
||||
from datetime import date
|
||||
from unittest.mock import MagicMock
|
||||
import uuid
|
||||
from app.services.gantt import compute_cpm
|
||||
|
||||
|
||||
def make_task(name: str, start: str, end: str) -> MagicMock:
|
||||
t = MagicMock()
|
||||
t.id = uuid.uuid4()
|
||||
t.name = name
|
||||
t.planned_start = date.fromisoformat(start)
|
||||
t.planned_end = date.fromisoformat(end)
|
||||
return t
|
||||
|
||||
|
||||
def make_dep(pred_id, succ_id) -> MagicMock:
|
||||
d = MagicMock()
|
||||
d.predecessor_id = pred_id
|
||||
d.successor_id = succ_id
|
||||
return d
|
||||
|
||||
|
||||
def test_cpm_no_dependencies():
|
||||
tasks = [
|
||||
make_task("A", "2026-04-01", "2026-04-05"),
|
||||
make_task("B", "2026-04-01", "2026-04-10"),
|
||||
]
|
||||
result = compute_cpm(tasks, [])
|
||||
assert isinstance(result, tuple)
|
||||
cpm_data, duration = result
|
||||
assert len(cpm_data) == 2
|
||||
assert duration > 0
|
||||
|
||||
|
||||
def test_cpm_serial_tasks():
|
||||
t1 = make_task("A", "2026-04-01", "2026-04-05")
|
||||
t2 = make_task("B", "2026-04-06", "2026-04-10")
|
||||
dep = make_dep(t1.id, t2.id)
|
||||
|
||||
result = compute_cpm([t1, t2], [dep])
|
||||
assert isinstance(result, tuple)
|
||||
cpm_data, duration = result
|
||||
|
||||
# Serial tasks: both should be critical
|
||||
assert cpm_data[t1.id]["is_critical"] is True
|
||||
assert cpm_data[t2.id]["is_critical"] is True
|
||||
|
||||
|
||||
def test_cpm_parallel_tasks():
|
||||
"""In parallel paths, only the longer path is critical."""
|
||||
t_start = make_task("Start", "2026-04-01", "2026-04-02")
|
||||
t_long = make_task("Long Path", "2026-04-03", "2026-04-20") # 18 days
|
||||
t_short = make_task("Short Path", "2026-04-03", "2026-04-10") # 8 days
|
||||
t_end = make_task("End", "2026-04-21", "2026-04-22")
|
||||
|
||||
deps = [
|
||||
make_dep(t_start.id, t_long.id),
|
||||
make_dep(t_start.id, t_short.id),
|
||||
make_dep(t_long.id, t_end.id),
|
||||
make_dep(t_short.id, t_end.id),
|
||||
]
|
||||
|
||||
result = compute_cpm([t_start, t_long, t_short, t_end], deps)
|
||||
assert isinstance(result, tuple)
|
||||
cpm_data, duration = result
|
||||
|
||||
# Long path and start/end should be critical; short path should not
|
||||
assert cpm_data[t_long.id]["is_critical"] is True
|
||||
assert cpm_data[t_short.id]["is_critical"] is False
|
||||
|
||||
|
||||
def test_cpm_empty_tasks():
|
||||
result = compute_cpm([], [])
|
||||
assert result == {}
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Tests for weather service."""
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
import uuid
|
||||
from app.services.weather_service import evaluate_weather_alerts, _detect_work_type, _parse_short_term
|
||||
|
||||
|
||||
def make_task(name: str) -> MagicMock:
|
||||
t = MagicMock()
|
||||
t.id = uuid.uuid4()
|
||||
t.name = name
|
||||
return t
|
||||
|
||||
|
||||
def test_detect_work_type_concrete():
|
||||
assert _detect_work_type("콘크리트 타설") == "CONCRETE"
|
||||
assert _detect_work_type("레미콘 타설 공사") == "CONCRETE"
|
||||
|
||||
|
||||
def test_detect_work_type_high_work():
|
||||
assert _detect_work_type("고소 작업") == "HIGH_WORK"
|
||||
assert _detect_work_type("비계 설치") == "HIGH_WORK"
|
||||
|
||||
|
||||
def test_detect_work_type_unknown():
|
||||
assert _detect_work_type("기타 공사") is None
|
||||
|
||||
|
||||
def test_evaluate_cold_concrete_alert():
|
||||
task = make_task("콘크리트 타설")
|
||||
forecast = {
|
||||
"date": "2026-04-01",
|
||||
"temperature_low": 3.0,
|
||||
"wind_speed_ms": 2.0,
|
||||
"precipitation_mm": 0.0,
|
||||
}
|
||||
alerts = evaluate_weather_alerts(forecast, [task])
|
||||
assert len(alerts) == 1
|
||||
assert alerts[0]["alert_type"] == "cold_concrete"
|
||||
assert alerts[0]["severity"] == "warning"
|
||||
|
||||
|
||||
def test_evaluate_rain_concrete_alert():
|
||||
task = make_task("콘크리트 타설")
|
||||
forecast = {
|
||||
"date": "2026-04-01",
|
||||
"temperature_low": 15.0,
|
||||
"wind_speed_ms": 2.0,
|
||||
"precipitation_mm": 5.0,
|
||||
}
|
||||
alerts = evaluate_weather_alerts(forecast, [task])
|
||||
assert any(a["alert_type"] == "rain_concrete" for a in alerts)
|
||||
|
||||
|
||||
def test_no_alert_good_weather():
|
||||
task = make_task("콘크리트 타설")
|
||||
forecast = {
|
||||
"date": "2026-04-01",
|
||||
"temperature_low": 15.0,
|
||||
"wind_speed_ms": 3.0,
|
||||
"precipitation_mm": 0.0,
|
||||
}
|
||||
alerts = evaluate_weather_alerts(forecast, [task])
|
||||
assert len(alerts) == 0
|
||||
|
||||
|
||||
def test_wind_alert_high_work():
|
||||
task = make_task("고소 작업 비계")
|
||||
forecast = {
|
||||
"date": "2026-04-01",
|
||||
"temperature_low": 10.0,
|
||||
"wind_speed_ms": 12.0,
|
||||
"precipitation_mm": 0.0,
|
||||
}
|
||||
alerts = evaluate_weather_alerts(forecast, [task])
|
||||
assert any(a["alert_type"] == "wind_high_work" for a in alerts)
|
||||
Reference in New Issue
Block a user