test: unskip the main-module unit tests and enable the real-backend browser lane
- tests/conftest.py installs minimal ultralytics/mediapipe stand-ins only when the real packages are absent, so clipwright.pipeline.main imports in the thin unit env instead of pytest.importorskip skipping 15 modules (63 tests). Unit suite is now 779 passed / 0 skipped. - requirements-test.txt pins uvicorn==0.46.0 (the real-backend server). - dashboard: vite preview proxies /api,/videos,/thumbnails to a locally-launched backend; Playwright gains a gated (CW_E2E_REAL) real project + uvicorn webServer running the pipeline stub_env; real-backend.spec.js drives the real upload->process->clip flow. CI dashboard job installs the backend test deps. - Verified: real lane 20 passed twice in the CI container; mock-only 19 passed without the flag; backend unit/API/pipeline 779/209/127.
This commit is contained in:
parent
6911a2665c
commit
d03ef799f4
6 changed files with 192 additions and 25 deletions
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
|
|
@ -67,13 +67,23 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
container: nikolaik/python-nodejs:python3.11-nodejs20
|
||||
# Turn on the real-backend lane: Playwright's second webServer boots a real
|
||||
# uvicorn (pipeline stub_env) and the `real` project drives it.
|
||||
env:
|
||||
CW_E2E_REAL: "1"
|
||||
defaults:
|
||||
run:
|
||||
working-directory: dashboard
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install ffmpeg (E2E media fixture)
|
||||
run: apt-get update -qq && apt-get install -y -qq --no-install-recommends ffmpeg
|
||||
# ffmpeg builds the media fixture and renders the real pipeline's clips;
|
||||
# libgl1 satisfies opencv (pulled by scenedetect) at import time.
|
||||
- name: Install ffmpeg + opencv system libs
|
||||
run: apt-get update -qq && apt-get install -y -qq --no-install-recommends ffmpeg libgl1
|
||||
# Backend deps for the uvicorn server the real lane launches (uvicorn is
|
||||
# pinned in requirements-test.txt alongside fastapi/scenedetect/...).
|
||||
- name: Install backend test dependencies
|
||||
run: pip install -r ../requirements-test.txt
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Install Playwright browsers
|
||||
|
|
|
|||
|
|
@ -3,12 +3,58 @@
|
|||
// worker. This is the lane that must stay green in CI.
|
||||
// - `real`: drives the real backend (uvicorn + stub pipeline). Kept separate
|
||||
// so the mocked lane never depends on Python.
|
||||
//
|
||||
// The `real` project and its backend webServer only exist when CW_E2E_REAL is
|
||||
// set (CI sets it). A bare `npm run test:e2e` therefore stays mock-only and
|
||||
// needs no Python deps.
|
||||
/* global process */
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import path from 'node:path';
|
||||
|
||||
const dashboardDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const repoRoot = path.resolve(dashboardDir, '..');
|
||||
|
||||
const realBackend = !!process.env.CW_E2E_REAL;
|
||||
|
||||
const webServers = [
|
||||
{
|
||||
command: 'npm run build && npx vite preview --port 4173 --strictPort --host 127.0.0.1',
|
||||
cwd: dashboardDir,
|
||||
url: 'http://127.0.0.1:4173',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120_000,
|
||||
stdout: 'ignore',
|
||||
stderr: 'pipe',
|
||||
},
|
||||
];
|
||||
|
||||
if (realBackend) {
|
||||
// Real `uvicorn clipwright.api.app:app` with the pipeline's stub_env on
|
||||
// PYTHONPATH: sitecustomize stubs the ML/network edges so the real CLI runs
|
||||
// with real ffmpeg, no model downloads and no outbound requests. The env
|
||||
// values mirror tests/e2e/pipeline's deterministic, no-ML configuration.
|
||||
webServers.push({
|
||||
command: 'python -m uvicorn clipwright.api.app:app --host 127.0.0.1 --port 8000 --log-level warning',
|
||||
cwd: repoRoot,
|
||||
url: 'http://127.0.0.1:8000/health',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120_000,
|
||||
stdout: 'ignore',
|
||||
stderr: 'pipe',
|
||||
env: {
|
||||
PYTHONPATH: ['tests/e2e/pipeline/stub_env', '.'].join(path.delimiter),
|
||||
GEMINI_API_KEY: 'test',
|
||||
MIN_SOURCE_SECONDS: '0',
|
||||
QUALITY_GATE_MIN_HEIGHT: '0',
|
||||
AUTO_LAYOUT: '0',
|
||||
SCENE_ENGINE: 'pyscenedetect',
|
||||
ASR_HOST_SLOTS: '0',
|
||||
FFMPEG_ENCODER: 'x264',
|
||||
TZ: 'UTC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './specs',
|
||||
|
|
@ -35,19 +81,14 @@ export default defineConfig({
|
|||
testIgnore: /real-backend\.spec\.js/,
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
// The real lane runs the full pipeline, which needs more than the 30s
|
||||
// default. Gated so a mock-only run never tries to boot Python.
|
||||
...(realBackend ? [{
|
||||
name: 'real',
|
||||
testMatch: /real-backend\.spec\.js/,
|
||||
timeout: 120_000,
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
}] : []),
|
||||
],
|
||||
webServer: {
|
||||
command: 'npm run build && npx vite preview --port 4173 --strictPort --host 127.0.0.1',
|
||||
cwd: dashboardDir,
|
||||
url: 'http://127.0.0.1:4173',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120_000,
|
||||
stdout: 'ignore',
|
||||
stderr: 'pipe',
|
||||
},
|
||||
webServer: webServers,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,17 +1,33 @@
|
|||
import { test, expect } from '@playwright/test';
|
||||
import { seedApp } from '../fixtures/app.js';
|
||||
import { SIXTY_MP4 } from '../fixtures/media.js';
|
||||
|
||||
// Real-backend lane.
|
||||
//
|
||||
// The plan calls for driving a real `uvicorn clipwright.api.app:app` with the
|
||||
// pipeline's stub_env (tests/e2e/pipeline/stub_env) so the browser talks to the
|
||||
// actual API instead of route mocks. That pipeline/stub environment is owned by
|
||||
// the backend E2E lanes, and the dashboard CI job provisions Node + Chromium
|
||||
// only (no Python deps, no ffmpeg), so this stays fixme until the backend lane
|
||||
// exposes a server the dashboard job can launch. The same routes are covered
|
||||
// end-to-end over HTTP by tests/e2e/api.
|
||||
// Drives the built app against a real `uvicorn clipwright.api.app:app` whose
|
||||
// pipeline runs the real CLI through tests/e2e/pipeline/stub_env (fake ML/ASR/
|
||||
// Gemini, real ffmpeg). No route mocks: the preview server proxies /api,
|
||||
// /videos and /thumbnails to the backend (vite.config.js preview.proxy), so
|
||||
// every request in this spec is served by Python. The spec is only collected
|
||||
// when CW_E2E_REAL is set; the `mock` lane ignores it.
|
||||
test.describe('real backend', () => {
|
||||
test.fixme('generates clips against a real uvicorn + stub_env server', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await expect(page).toHaveTitle(/Clipwright/);
|
||||
test('generates a clip against a real uvicorn + stub_env server', async ({ page }) => {
|
||||
// Seed the BYOK Gemini key (and consent) exactly like the mock specs.
|
||||
// No installApiMocks: this lane talks to the real server.
|
||||
await seedApp(page, { geminiKey: 'e2e-gemini-key' });
|
||||
await page.goto('/#app');
|
||||
|
||||
await expect(page.getByRole('heading', { name: /create viral shorts/i })).toBeVisible();
|
||||
|
||||
// Upload the ffmpeg-built fixture, attest rights, submit.
|
||||
await page.setInputFiles('input[type="file"][accept="video/*"]', SIXTY_MP4);
|
||||
await page.locator('form input[type="checkbox"]').first().check();
|
||||
await page.getByRole('button', { name: /generate clips/i }).click();
|
||||
|
||||
// The app polls /api/status every 2s; the real pipeline (real ffmpeg,
|
||||
// stubbed ML) finishes in well under a minute. Bounded auto-wait, no
|
||||
// sleeps: the clip count badge only renders once results carry clips.
|
||||
await expect(page.getByText(/\d+ Clips/)).toBeVisible({ timeout: 60_000 });
|
||||
await expect(page.getByText('Clip 1', { exact: true })).toBeVisible({ timeout: 60_000 });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@ import seo from './vite-plugin-seo'
|
|||
// the host against a backend reachable at localhost (no CORS, same-origin).
|
||||
const backend = process.env.VITE_PROXY_TARGET || 'http://backend:8000'
|
||||
|
||||
// Backend target for the *preview* server (the built app). The Playwright
|
||||
// real-backend lane serves `vite preview` and needs same-origin /api, /videos
|
||||
// and /thumbnails to reach a locally-launched uvicorn instead of the compose
|
||||
// service. Defaults to the loopback backend the config's second webServer
|
||||
// starts; CW_BACKEND_URL overrides it for other setups. Proxying keeps the
|
||||
// built bundle origin-relative (no absolute VITE_API_URL baked in).
|
||||
const previewBackend = process.env.CW_BACKEND_URL || 'http://127.0.0.1:8000'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
// seo() runs on build only. It injects the crawler-visible homepage content
|
||||
|
|
@ -36,5 +44,14 @@ export default defineConfig({
|
|||
'/videos': { target: backend, changeOrigin: true },
|
||||
'/thumbnails': { target: backend, changeOrigin: true },
|
||||
}
|
||||
},
|
||||
// Mirror of server.proxy for `vite preview`, so the production bundle talks
|
||||
// to the real backend same-origin (the browser E2E real-backend lane).
|
||||
preview: {
|
||||
proxy: {
|
||||
'/api': { target: previewBackend, changeOrigin: true },
|
||||
'/videos': { target: previewBackend, changeOrigin: true },
|
||||
'/thumbnails': { target: previewBackend, changeOrigin: true },
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ opencv-python-headless
|
|||
python-dotenv
|
||||
google-genai
|
||||
fastapi
|
||||
uvicorn==0.46.0
|
||||
python-multipart
|
||||
pytest-asyncio==1.4.0
|
||||
asgi-lifespan==2.1.0
|
||||
|
|
|
|||
|
|
@ -2,6 +2,88 @@
|
|||
|
||||
The repo-root ``clipwright/`` package is made importable by
|
||||
``[tool.pytest.ini_options] pythonpath = ["."]`` in the root ``pyproject.toml``,
|
||||
so no manual ``sys.path`` manipulation is needed here. This module is kept for
|
||||
future shared fixtures.
|
||||
so no manual ``sys.path`` manipulation is needed here.
|
||||
|
||||
The unit test environment deliberately omits the heavy ML stack
|
||||
(torch/ultralytics/mediapipe/faster-whisper) so CI stays fast.
|
||||
``clipwright.pipeline.main`` imports ``ultralytics`` and ``mediapipe`` at module
|
||||
level, which made every test that does ``pytest.importorskip("...main")`` skip.
|
||||
To keep that coverage without pulling gigabytes into CI, we install minimal
|
||||
stand-ins *only when the real packages are absent* (the production image and a
|
||||
developer machine with the real deps installed are unaffected).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import types
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
class _FakeYOLO:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.args = args
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return []
|
||||
|
||||
def predict(self, *args, **kwargs):
|
||||
return []
|
||||
|
||||
def track(self, *args, **kwargs):
|
||||
return []
|
||||
|
||||
|
||||
class _FakeDetection:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def process(self, *args, **kwargs):
|
||||
return SimpleNamespace(detections=None)
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
|
||||
def _is_importable(name: str) -> bool:
|
||||
try:
|
||||
__import__(name)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _install_heavy_stubs() -> None:
|
||||
if not _is_importable("ultralytics"):
|
||||
ultralytics = types.ModuleType("ultralytics")
|
||||
ultralytics.YOLO = _FakeYOLO
|
||||
sys.modules["ultralytics"] = ultralytics
|
||||
|
||||
if not _is_importable("mediapipe"):
|
||||
mediapipe = types.ModuleType("mediapipe")
|
||||
solutions = types.ModuleType("mediapipe.solutions")
|
||||
|
||||
def _solution(name: str) -> types.ModuleType:
|
||||
mod = types.ModuleType(f"mediapipe.solutions.{name}")
|
||||
mod.FaceDetection = _FakeDetection
|
||||
mod.Detection = _FakeDetection
|
||||
sys.modules[f"mediapipe.solutions.{name}"] = mod
|
||||
return mod
|
||||
|
||||
for name in (
|
||||
"face_detection",
|
||||
"face_mesh",
|
||||
"pose",
|
||||
"hands",
|
||||
"holistic",
|
||||
"selfie_segmentation",
|
||||
):
|
||||
setattr(solutions, name, _solution(name))
|
||||
|
||||
mediapipe.solutions = solutions
|
||||
sys.modules["mediapipe"] = mediapipe
|
||||
sys.modules["mediapipe.solutions"] = solutions
|
||||
|
||||
|
||||
_install_heavy_stubs()
|
||||
|
|
|
|||
Loading…
Reference in a new issue