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
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.
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
"""P7 flywheel — JobCompleted→publish, RetentionIngested→winner→regenerate cascade."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.domains.publishing.experiments import VariantMetrics
|
|
from app.events.bus import (
|
|
JOB_COMPLETED,
|
|
REGENERATE_REQUESTED,
|
|
RETENTION_INGESTED,
|
|
Event,
|
|
EventBus,
|
|
)
|
|
from app.events.handlers import register_flywheel
|
|
|
|
|
|
class FakeExperiments:
|
|
def __init__(self, metrics):
|
|
self._m = metrics
|
|
|
|
def variant_metrics(self, experiment_key):
|
|
return self._m
|
|
|
|
|
|
def _conclusive_metrics():
|
|
return [
|
|
VariantMetrics("a", "hookA", views=1000, completion_rate=0.8, avg_watch_frac=0.7, rewatch_rate=0.2),
|
|
VariantMetrics("b", "hookB", views=1000, completion_rate=0.4, avg_watch_frac=0.3, rewatch_rate=0.05),
|
|
]
|
|
|
|
|
|
def _wire(metrics):
|
|
bus = EventBus()
|
|
published, regenerated = [], []
|
|
regen_events = []
|
|
register_flywheel(
|
|
bus,
|
|
on_publish=lambda key, payload: published.append((key, payload)),
|
|
on_regenerate=lambda exp, hook: regenerated.append((exp, hook)),
|
|
experiments=FakeExperiments(metrics),
|
|
)
|
|
bus.subscribe(REGENERATE_REQUESTED, lambda e: regen_events.append(e.payload))
|
|
return bus, published, regenerated, regen_events
|
|
|
|
|
|
def test_job_completed_triggers_publish():
|
|
bus, published, _, _ = _wire(_conclusive_metrics())
|
|
bus.emit(Event(type=JOB_COMPLETED, key="reel-1", payload={"output_refs": ["u"]}))
|
|
assert published == [("reel-1", {"output_refs": ["u"]})]
|
|
|
|
|
|
def test_retention_cascades_to_regenerate_when_conclusive():
|
|
bus, _, regenerated, regen_events = _wire(_conclusive_metrics())
|
|
bus.emit(Event(type=RETENTION_INGESTED, key="exp-1", payload={"experiment_key": "exp-1"}))
|
|
# Winner 'a'/hookA cascades: on_regenerate called + REGENERATE_REQUESTED emitted.
|
|
assert regenerated == [("exp-1", "hookA")]
|
|
assert regen_events and regen_events[0]["bias_hook_ref"] == "hookA"
|
|
|
|
|
|
def test_inconclusive_retention_does_not_regenerate():
|
|
# Underpowered variants -> no winner -> no cascade.
|
|
weak = [
|
|
VariantMetrics("a", "hookA", views=10, completion_rate=0.8),
|
|
VariantMetrics("b", "hookB", views=10, completion_rate=0.4),
|
|
]
|
|
bus, _, regenerated, regen_events = _wire(weak)
|
|
bus.emit(Event(type=RETENTION_INGESTED, key="exp-1"))
|
|
assert regenerated == [] and regen_events == []
|