Extract caption format dispatch route

This commit is contained in:
2026-06-27 12:29:11 +02:00
parent 1ee0b6e91a
commit c67be207ab
5 changed files with 207 additions and 16 deletions
+73
View File
@@ -25,6 +25,7 @@ if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
import caption_naturalizer # noqa: E402
import caption_format_route # noqa: E402
import caption_metadata_routes # noqa: E402
import caption_policy # noqa: E402
import caption_text_policy # noqa: E402
@@ -2532,6 +2533,77 @@ def smoke_caption_policy() -> None:
_expect(browsing_method == "text(fallback)", "Caption browsing profile changed fallback method")
def smoke_caption_format_route_policy() -> None:
row = _prompt_row(
name="caption_format_route_single",
category="woman",
subcategory="random",
seed=3801,
men_count=0,
)
metadata_request = caption_format_route.CaptionFormatRequest(
source_text="",
metadata_json=_json(row),
input_hint="metadata_json",
trigger=Trigger,
include_trigger=False,
detail_level="concise",
style_policy="keep_style_terms",
caption_profile="training_dense",
)
typed_metadata = caption_format_route.naturalize_caption_result(
metadata_request,
caption_naturalizer._caption_format_dependencies(),
)
public_metadata = caption_naturalizer.naturalize_caption(
"",
metadata_json=metadata_request.metadata_json,
input_hint=metadata_request.input_hint,
trigger=metadata_request.trigger,
include_trigger=metadata_request.include_trigger,
detail_level=metadata_request.detail_level,
style_policy=metadata_request.style_policy,
caption_profile=metadata_request.caption_profile,
)
_expect(typed_metadata.as_tuple() == public_metadata, "Typed caption format route should match public metadata output")
_expect(typed_metadata.branch == "metadata", "Typed caption format route changed metadata branch")
_expect(typed_metadata.input_hint == "metadata_json", "Typed caption route lost input hint")
_expect(typed_metadata.detail_level == "dense", "Typed caption route lost training_dense detail override")
_expect(typed_metadata.style_policy == "drop_style_tail", "Typed caption route lost training_dense style override")
_expect(typed_metadata.include_trigger is True, "Typed caption route lost training_dense trigger override")
_expect(typed_metadata.caption.startswith(Trigger), "Typed caption metadata route should prepend training trigger")
fallback_request = caption_format_route.CaptionFormatRequest(
source_text="woman, red dress, studio, coloured pencil comic illustration",
input_hint="bad_hint",
trigger=Trigger,
include_trigger=True,
detail_level="dense",
style_policy="drop_style_tail",
caption_profile="browsing",
)
typed_fallback = caption_format_route.naturalize_caption_result(
fallback_request,
caption_naturalizer._caption_format_dependencies(),
)
public_fallback = caption_naturalizer.naturalize_caption(
fallback_request.source_text,
input_hint=fallback_request.input_hint,
trigger=fallback_request.trigger,
include_trigger=fallback_request.include_trigger,
detail_level=fallback_request.detail_level,
style_policy=fallback_request.style_policy,
caption_profile=fallback_request.caption_profile,
)
_expect(typed_fallback.as_tuple() == public_fallback, "Typed caption format route should match public fallback output")
_expect(typed_fallback.branch == "text", "Typed caption format route changed fallback branch")
_expect(typed_fallback.input_hint == "auto", "Typed caption route should normalize invalid input hint")
_expect(typed_fallback.include_trigger is False, "Typed caption browsing profile should disable trigger")
_expect(typed_fallback.keep_style is True, "Typed caption browsing profile should keep style terms")
_expect(not typed_fallback.caption.startswith(Trigger), "Typed caption fallback route should not prepend browsing trigger")
_expect(typed_fallback.method == "text(fallback)", "Typed caption fallback method changed")
def smoke_caption_text_policy() -> None:
row = {
"primary_subject": "woman",
@@ -5746,6 +5818,7 @@ SMOKE_CASES: list[tuple[str, Callable[[], None]]] = [
("krea_format_route_policy", smoke_krea_format_route_policy),
("formatter_cast_policy", smoke_formatter_cast_policy),
("caption_policy", smoke_caption_policy),
("caption_format_route_policy", smoke_caption_format_route_policy),
("caption_text_policy", smoke_caption_text_policy),
("caption_metadata_routes", smoke_caption_metadata_routes),
("sdxl_presets_policy", smoke_sdxl_presets_policy),