Extract row rendering policy

This commit is contained in:
2026-06-27 09:35:37 +02:00
parent 55fec890a5
commit c076b22b75
5 changed files with 207 additions and 67 deletions
+69
View File
@@ -57,6 +57,7 @@ import row_generation # noqa: E402
import row_item # noqa: E402
import row_location # noqa: E402
import row_pools # noqa: E402
import row_rendering # noqa: E402
import row_route_metadata # noqa: E402
import server_routes # noqa: E402
import sdxl_formatter # noqa: E402
@@ -1402,6 +1403,73 @@ def smoke_row_normalization_policy() -> None:
_expect_no_duplicate_comma_items("row_normalization.pair.hard_row_negative", pair["hardcore_row"].get("negative_prompt"))
def smoke_row_rendering_policy() -> None:
_expect(pb.SINGLE_TEMPLATE == row_rendering.SINGLE_TEMPLATE, "Prompt builder single template should delegate to row_rendering")
_expect(
pb._format("Known {known}, missing {missing}", {"known": 7})
== row_rendering.format_template("Known {known}, missing {missing}", {"known": 7}),
"Prompt builder safe formatter should delegate to row_rendering",
)
_expect(
row_rendering.format_template("Known {known}, missing {missing}", {"known": 7}) == "Known 7, missing {missing}",
"Row rendering changed missing-field preservation",
)
_expect(
row_rendering.prompt_template_for({}, {}, {}, "woman") == row_rendering.SINGLE_TEMPLATE,
"Row rendering default woman template changed",
)
_expect(
row_rendering.prompt_template_for({}, {}, {}, "group") == row_rendering.GROUP_TEMPLATE,
"Row rendering default group template changed",
)
context = {
"trigger": Trigger,
"subject": "configured cast",
"subject_phrase": "configured adult cast",
"age": "adult",
"body": "varied",
"body_phrase": "varied",
"skin": "",
"hair": "",
"eyes": "",
"item_label": "Scene",
"item": "shared action",
"scene": "warm room",
"pose": "standing close",
"expression": "focused look",
"composition": "centered frame",
"composition_prompt": "vertical centered frame",
"positive_suffix": "clear readable bodies.",
"negative_prompt": "bad anatomy",
"cast_descriptors": "Woman A: adult woman; Man A: adult man",
}
rendered = row_rendering.render_prompt_caption(
item={},
subcategory={
"prompt_template": "Scene: {item}. Composition: {composition_prompt}. Avoid: {negative_prompt}.",
"caption_template": "{trigger}, {item}, {scene}",
},
category={},
subject_type="configured_cast",
context=context,
cast_descriptor_text="Woman A: adult woman; Man A: adult man",
pov_prompt_directive="First-person POV from Man A.",
)
prompt = rendered["prompt"]
caption = rendered["caption"]
_expect("Characters: Woman A: adult woman; Man A: adult man." in prompt, "Row rendering lost configured-cast descriptors")
_expect("First-person POV from Man A." in prompt, "Row rendering lost configured-cast POV directive")
_expect(
prompt.index("Characters:") < prompt.index("First-person POV") < prompt.index("Avoid:"),
"Row rendering did not insert configured-cast directives before negative prompt",
)
_expect(
caption.endswith("Woman A: adult woman; Man A: adult man"),
"Row rendering did not append descriptors to captions without descriptor placeholders",
)
def smoke_formatter_input_policy() -> None:
source_row = {
"prompt": "A simple adult portrait. Setting: quiet studio. Pose: standing calmly. Avoid: low quality.",
@@ -4197,6 +4265,7 @@ SMOKE_CASES: list[tuple[str, Callable[[], None]]] = [
("character_config_policy", smoke_character_config_policy),
("character_profile_policy", smoke_character_profile_policy),
("row_normalization_policy", smoke_row_normalization_policy),
("row_rendering_policy", smoke_row_rendering_policy),
("formatter_input_policy", smoke_formatter_input_policy),
("formatter_cast_policy", smoke_formatter_cast_policy),
("caption_policy", smoke_caption_policy),