Merge pull request 'fix(ingest-jobs): GET /{job_id} 查不到时返回 404 而非 500' (#1553) from fix/ingest-jobs-404-not-found into develop
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check push changed paths (push) Successful in 4m7s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4m34s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 5m0s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 5m23s
CI/CD Pipeline / Build Staging API Image (push) Successful in 2m15s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m3s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m46s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 2m42s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 7m16s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 7m35s
AI Code Review / AI Code Review (pull_request) Failing after 7m34s
CI/CD Pipeline / CI Gate (pull_request) Successful in 54s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Successful in 55s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 7m56s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 8m23s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m4s
CI/CD Pipeline / Integration Tests (push) Successful in 2m23s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 2m15s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m45s
CI/CD Pipeline / Unit Tests (push) Successful in 13m34s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 5m44s
CI/CD Pipeline / Production Browser E2E (push) Failing after 411h11m45s
CI/CD Pipeline / Build Production Web Image (push) Failing after 411h11m47s
CI/CD Pipeline / Canary Release to Production (push) Failing after 411h11m46s
CI/CD Pipeline / Build Production API Image (push) Failing after 411h11m47s
CI/CD Pipeline / Deploy Production (push) Failing after 411h11m47s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 411h18m30s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 411h18m50s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 411h18m31s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 411h18m52s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 411h18m54s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 411h19m0s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 411h20m23s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 411h18m56s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 411h20m48s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 411h20m48s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 411h20m49s
CI/CD Pipeline / Build Staging Web Image (push) Failing after 411h21m15s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 411h22m25s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 411h22m29s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 411h22m33s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 411h25m5s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 411h25m7s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Failing after 411h25m11s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Failing after 411h25m13s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 411h25m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 411h25m17s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 411h25m19s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 411h25m20s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 411h25m21s
CI/CD Pipeline / PR Build Web Image (push) Failing after 411h25m22s
CI/CD Pipeline / Frontend Lint (push) Failing after 411h25m23s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 411h25m24s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 411h25m26s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 411h45m55s
CI/CD Pipeline / CI Gate (push) Failing after 411h45m55s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 411h53m6s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 411h54m55s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 411h56m39s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 411h59m17s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 411h59m26s
CI/CD Pipeline / PR Build API Image (push) Failing after 411h59m31s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check push changed paths (push) Successful in 4m7s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4m34s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 5m0s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 5m23s
CI/CD Pipeline / Build Staging API Image (push) Successful in 2m15s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m3s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m46s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 2m42s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 7m16s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 7m35s
AI Code Review / AI Code Review (pull_request) Failing after 7m34s
CI/CD Pipeline / CI Gate (pull_request) Successful in 54s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Successful in 55s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 7m56s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 8m23s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m4s
CI/CD Pipeline / Integration Tests (push) Successful in 2m23s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 2m15s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m45s
CI/CD Pipeline / Unit Tests (push) Successful in 13m34s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 5m44s
CI/CD Pipeline / Production Browser E2E (push) Failing after 411h11m45s
CI/CD Pipeline / Build Production Web Image (push) Failing after 411h11m47s
CI/CD Pipeline / Canary Release to Production (push) Failing after 411h11m46s
CI/CD Pipeline / Build Production API Image (push) Failing after 411h11m47s
CI/CD Pipeline / Deploy Production (push) Failing after 411h11m47s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 411h18m30s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 411h18m50s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 411h18m31s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 411h18m52s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 411h18m54s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 411h19m0s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 411h20m23s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 411h18m56s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 411h20m48s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 411h20m48s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 411h20m49s
CI/CD Pipeline / Build Staging Web Image (push) Failing after 411h21m15s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 411h22m25s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 411h22m29s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 411h22m33s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 411h25m5s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 411h25m7s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Failing after 411h25m11s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Failing after 411h25m13s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 411h25m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 411h25m17s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 411h25m19s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 411h25m20s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 411h25m21s
CI/CD Pipeline / PR Build Web Image (push) Failing after 411h25m22s
CI/CD Pipeline / Frontend Lint (push) Failing after 411h25m23s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 411h25m24s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 411h25m26s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 411h45m55s
CI/CD Pipeline / CI Gate (push) Failing after 411h45m55s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 411h53m6s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 411h54m55s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 411h56m39s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 411h59m17s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 411h59m26s
CI/CD Pipeline / PR Build API Image (push) Failing after 411h59m31s
This commit was merged in pull request #1553.
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Any
|
||||
from app.core.celery_app import celery_app
|
||||
from app.dependencies import get_ingest_job_repository
|
||||
from app.schemas.ingest_job import IngestJobResponse, SubmitIngestJobRequest
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
|
||||
from packages.application import SubmitIngestJobCommand, SubmitIngestJobUseCase
|
||||
|
||||
@@ -17,7 +17,7 @@ def get_ingest_job(
|
||||
) -> IngestJobResponse:
|
||||
job = ingest_job_repository.get(job_id)
|
||||
if job is None:
|
||||
raise ValueError(f"IngestJob {job_id} not found")
|
||||
raise HTTPException(status_code=404, detail=f"IngestJob {job_id} not found")
|
||||
return IngestJobResponse(
|
||||
id=job.id,
|
||||
project_id=job.project_id,
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""Ingest jobs GET route — 查不到 job_id 应返回 404,不是 500。
|
||||
|
||||
覆盖:
|
||||
- job 不存在:GET /ingest-jobs/{job_id} → 404
|
||||
- job 存在:200 + 序列化字段完整
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
os.environ.setdefault("JWT_SECRET_KEY", "unit-test-secret-key-for-testing")
|
||||
os.environ.setdefault("DATABASE_URL", "sqlite:///test.db")
|
||||
|
||||
import pytest # noqa: E402
|
||||
from fastapi import FastAPI # noqa: E402
|
||||
from fastapi.testclient import TestClient # noqa: E402
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api"))
|
||||
|
||||
from app.api.routes.ingest_jobs import get_ingest_job, router # noqa: E402
|
||||
from app.dependencies import get_ingest_job_repository # noqa: E402
|
||||
|
||||
from packages.domain import IngestJob, IngestJobStatus # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_job():
|
||||
return IngestJob(
|
||||
id="job-abc",
|
||||
project_id="proj-1",
|
||||
library_id="lib-1",
|
||||
storage_key="key/test.mp4",
|
||||
status=IngestJobStatus.COMPLETED,
|
||||
error_message="",
|
||||
result_asset_id="asset-xyz",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client_not_found():
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/ingest-jobs")
|
||||
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.get.return_value = None
|
||||
|
||||
app.dependency_overrides[get_ingest_job_repository] = lambda: mock_repo
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client_found(fake_job):
|
||||
app = FastAPI()
|
||||
app.include_router(router, prefix="/ingest-jobs")
|
||||
|
||||
mock_repo = MagicMock()
|
||||
mock_repo.get.return_value = fake_job
|
||||
|
||||
app.dependency_overrides[get_ingest_job_repository] = lambda: mock_repo
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_get_ingest_job_not_found_returns_404(client_not_found):
|
||||
"""job 不存在时应返回 404,而不是 500 ValueError。"""
|
||||
resp = client_not_found.get("/ingest-jobs/no-such-job")
|
||||
assert resp.status_code == 404, resp.text
|
||||
assert "no-such-job" in resp.json()["detail"]
|
||||
|
||||
|
||||
def test_get_ingest_job_found_returns_200(client_found, fake_job):
|
||||
"""job 存在时正常 200 + 字段完整。"""
|
||||
resp = client_found.get(f"/ingest-jobs/{fake_job.id}")
|
||||
assert resp.status_code == 200, resp.text
|
||||
body = resp.json()
|
||||
assert body["id"] == fake_job.id
|
||||
assert body["project_id"] == fake_job.project_id
|
||||
assert body["storage_key"] == fake_job.storage_key
|
||||
assert body["status"] == IngestJobStatus.COMPLETED.value
|
||||
assert body["result_asset_id"] == fake_job.result_asset_id
|
||||
Reference in New Issue
Block a user