103 lines
3.8 KiB
Python
103 lines
3.8 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from ComfyUI_H3_Continuum_Join.prompt_builder import (
|
|
DumasH3SequencePromptBuilder,
|
|
default_sequence,
|
|
format_sequence_prompt,
|
|
normalize_sequence,
|
|
)
|
|
|
|
|
|
def test_builder_emits_one_absolute_timeline_prompt_from_clip_local_slots():
|
|
sequence = normalize_sequence(
|
|
{"clips": [
|
|
{"duration": 4, "slots": [{"start": 0, "end": 2, "text": "Walk forward."}]},
|
|
{"duration": 5, "slots": [{"start": 1, "end": 4, "text": "Turn toward the light."}]},
|
|
]},
|
|
clip_count=2,
|
|
default_seconds=4,
|
|
)
|
|
result = format_sequence_prompt(
|
|
shared_directive="Preserve the same character and environment.",
|
|
sequence=sequence,
|
|
soundscape="Quiet street ambience.",
|
|
music="Low cinematic pulse.",
|
|
)
|
|
assert "[0-4s]\n0-2s: First." in result
|
|
assert "[4-8s]\n1-4s: Turn toward the light." in result
|
|
assert "[0-2s]" not in result
|
|
assert "[5-9s]" not in result
|
|
assert "overall_soundscape: Quiet street ambience." in result
|
|
assert "non_diegetic_music: Low cinematic pulse." in result
|
|
assert result.count("Preserve the same character and environment.") == 2
|
|
assert result.count("overall_soundscape: Quiet street ambience.") == 2
|
|
assert result.count("non_diegetic_music: Low cinematic pulse.") == 2
|
|
|
|
|
|
def test_normalizer_orders_slots_fills_missing_clips_and_shares_duration():
|
|
value = normalize_sequence(
|
|
json.dumps({"clips": [{"duration": 6, "slots": [
|
|
{"start": 3, "end": 6, "text": "Second."},
|
|
{"start": 0, "end": 3, "text": "First."},
|
|
]}]}),
|
|
clip_count=2,
|
|
default_seconds=4,
|
|
)
|
|
assert value["clips"][0]["slots"][0]["text"] == "First."
|
|
assert value["clips"][0]["duration"] == 4.0
|
|
assert value["clips"][1]["duration"] == 4.0
|
|
|
|
|
|
@pytest.mark.parametrize("bad", [
|
|
{"clips": [{"duration": 4, "slots": [{"start": 3, "end": 2, "text": "bad"}]}]},
|
|
{"clips": [{"duration": 4, "slots": [{"start": 0, "end": 5, "text": "bad"}]}]},
|
|
])
|
|
def test_normalizer_rejects_invalid_slot_ranges(bad):
|
|
with pytest.raises(ValueError):
|
|
normalize_sequence(bad, clip_count=1, default_seconds=4)
|
|
|
|
|
|
def test_node_schema_has_prompt_outputs_reference_bundle_and_serialized_editor_state():
|
|
inputs = DumasH3SequencePromptBuilder.INPUT_TYPES()
|
|
schema = inputs["required"]
|
|
assert DumasH3SequencePromptBuilder.RETURN_TYPES == (
|
|
"STRING", "INT", "FLOAT", "H3_CONTINUUM_REFERENCE_IMAGES_V39"
|
|
)
|
|
assert "reference_image_1" in inputs["optional"]
|
|
assert schema["timeline_json"][1]["multiline"] is True
|
|
result = DumasH3SequencePromptBuilder().build(1, 4, "Directive", json.dumps(default_sequence(1, 4)), "N/A", "N/A")
|
|
assert result[0].startswith("[0-4s]\nDirective")
|
|
assert result[0].count("overall_soundscape:") == 1
|
|
assert result[1] == 1
|
|
assert result[2] == 4.0
|
|
assert result[3].reference_use == "Per chunk"
|
|
assert result[3].selectors == ("off",) * 9
|
|
|
|
|
|
def test_builder_routes_connected_references_only_to_mentioning_chunks():
|
|
value = {
|
|
"clips": [
|
|
{"slots": [{"start": 0, "end": 4, "text": "@R1 walks toward @R2."}]},
|
|
{"slots": [{"start": 0, "end": 4, "text": "The camera follows @r2."}]},
|
|
{"slots": [{"start": 0, "end": 4, "text": "A wide shot with no reference."}]},
|
|
]
|
|
}
|
|
result = DumasH3SequencePromptBuilder().build(
|
|
3,
|
|
4,
|
|
"",
|
|
json.dumps(value),
|
|
"",
|
|
"",
|
|
reference_image_1=object(),
|
|
reference_image_2=object(),
|
|
)
|
|
bundle = result[3]
|
|
assert bundle.reference_use == "Per chunk"
|
|
assert bundle.selectors == ("1", "1,2", "off", "off", "off", "off", "off", "off", "off")
|
|
assert bundle.images[0] is not None and bundle.images[1] is not None
|