videogen/tests/reelforge/test_hook_suggestions.py
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

77 lines
2.7 KiB
Python

"""Hook suggestions — cold-open rewrites + endpoint integration."""
from __future__ import annotations
import importlib
from fastapi import FastAPI
from starlette.responses import JSONResponse
from starlette.testclient import TestClient
from app.models.exception import HttpException
from app.services.loops.hook_suggestions import needs_suggestions, suggest_hooks
from app.utils import utils
def test_passing_hook_gets_no_suggestions():
assert suggest_hooks("anything", passes_gate=True) == []
def test_weak_hook_returns_rewrites():
sug = suggest_hooks("so basically my sister read my diary", passes_gate=False)
shapes = {s.shape for s in sug}
assert {"shock_first", "curiosity_gap", "question"} <= shapes
# Filler ('so basically') is stripped from the rewrite payload.
assert all("basically" not in s.text.lower() for s in sug)
def test_reason_biases_shock_first_to_top():
sug = suggest_hooks(
"the setup takes a while", passes_gate=False,
reasons=("open on the spiciest spoken line first, not setup",),
)
assert sug[0].shape == "shock_first"
def test_needs_suggestions_gate():
assert needs_suggestions(0.5) is True # below 0.70 gate
assert needs_suggestions(0.85) is False
# --------------------------------------------------------------------------- #
# Endpoint: hook-score includes suggestions when below the gate
# --------------------------------------------------------------------------- #
def _client():
mod = importlib.import_module("app.domains.captions.router")
app = FastAPI()
app.include_router(mod.router)
app.add_exception_handler(
HttpException,
lambda r, exc: JSONResponse(status_code=exc.status_code,
content=utils.get_response(exc.status_code, exc.data, exc.message)),
)
return TestClient(app)
def test_hook_score_endpoint_returns_suggestions_when_weak():
client = _client()
resp = client.post("/api/v1/captions/hook-score", json={
"motion": 0.1, "text": 0.0, "audio_onset": 0.1, "early_cut": 0.0,
"speech": 0.1, "face_or_subject": 0.1, "hook_end_s": 3.0,
"opening_line": "so basically I tried this thing",
})
assert resp.status_code == 200
data = resp.json()["data"]
assert not data["passes_gate"]
assert data["suggestions"] and data["suggestions"][0]["shape"]
def test_hook_score_no_suggestions_when_strong():
client = _client()
resp = client.post("/api/v1/captions/hook-score", json={
"motion": 1, "text": 1, "audio_onset": 1, "early_cut": 1, "speech": 1,
"face_or_subject": 1, "hook_end_s": 2.0, "opening_line": "shocking line",
})
data = resp.json()["data"]
assert data["passes_gate"] and data["suggestions"] == []