Stabilize Continuum cloning and workflow guidance

This commit is contained in:
ukr8b3g-cmyk
2026-08-11 02:33:36 +09:00
parent 921ed1b090
commit 9b039aae84
13 changed files with 721 additions and 61 deletions
+95
View File
@@ -1,13 +1,20 @@
import pytest
from ComfyUI_H3_Continuum_Join.constants import (
PROMPT_FORMAT_AUTO,
PROMPT_FORMAT_FIXED,
PROMPT_MODE_FIXED,
PROMPT_MODE_LIST,
PROMPT_MODE_TIMELINE,
)
from ComfyUI_H3_Continuum_Join.v2.prompts import (
PromptPlanError,
apply_prompt_overrides,
build_sampler_prompt_plan,
detect_prompt_mode,
make_prompt_plan,
parse_sparse_prompt_overrides,
validate_sparse_prompt_overrides,
validate_prompt_plan,
)
@@ -19,6 +26,31 @@ def test_fixed_prompt_repeats_without_mutation():
assert validate_prompt_plan(plan) is plan
@pytest.mark.parametrize(
("script", "expected"),
[
("one continuous prompt", PROMPT_MODE_FIXED),
("first\n---\nsecond", PROMPT_MODE_LIST),
("[0-5s]\nfirst", PROMPT_MODE_TIMELINE),
("[Chunk 1]\nfirst", PROMPT_MODE_TIMELINE),
],
)
def test_auto_detects_prompt_format(script, expected):
assert detect_prompt_mode(script) == expected
def test_auto_plan_records_detected_format_without_changing_schema_mode():
plan = make_prompt_plan(mode=PROMPT_FORMAT_AUTO, script="first\n---\nsecond", chunks=2, chunk_seconds=5)
assert plan["mode"] == PROMPT_MODE_LIST
assert plan["prompts"] == ["first", "second"]
assert plan["notes"][0] == "Auto detected List"
def test_simple_fixed_format_maps_to_stable_fixed_plan_mode():
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="same", chunks=2, chunk_seconds=5)
assert plan["mode"] == PROMPT_MODE_FIXED
def test_list_prompt_uses_separator_and_repeats_last():
plan = make_prompt_plan(
mode=PROMPT_MODE_LIST,
@@ -53,3 +85,66 @@ def test_timeline_requires_coverage():
def test_native_h3_chunk_duration_rejects_sub_four_seconds():
with pytest.raises(PromptPlanError):
make_prompt_plan(mode=PROMPT_MODE_FIXED, script="x", chunks=1, chunk_seconds=3.9)
def test_external_prompt_overrides_only_the_connected_clip_and_rehashes_it():
plan = make_prompt_plan(mode=PROMPT_MODE_LIST, script="first\n---\nsecond\n---\nthird", chunks=3, chunk_seconds=5)
updated = apply_prompt_overrides(plan, [None, "external second", None])
assert updated["prompts"] == ["first", "external second", "third"]
assert updated["hashes"][0] == plan["hashes"][0]
assert updated["hashes"][1] != plan["hashes"][1]
assert updated["hashes"][2] == plan["hashes"][2]
assert updated["notes"][-1] == "external Clip Prompt input(s): 2"
def test_external_prompt_with_same_text_keeps_the_same_hash():
plan = make_prompt_plan(mode=PROMPT_MODE_FIXED, script="same", chunks=2, chunk_seconds=5)
assert apply_prompt_overrides(plan, [None, "same"])["hashes"] == plan["hashes"]
def test_external_prompt_rejects_empty_connected_text():
plan = make_prompt_plan(mode=PROMPT_MODE_FIXED, script="fallback", chunks=1, chunk_seconds=5)
with pytest.raises(PromptPlanError):
apply_prompt_overrides(plan, [" "])
def test_sequence_prompt_precedes_connected_plan_and_legacy_script():
connected = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="connected plan", chunks=2, chunk_seconds=5)
resolved = build_sampler_prompt_plan(prompt_mode=PROMPT_FORMAT_AUTO, prompt_script="legacy", sequence_prompt="first\n---\nsecond", prompt_plan=connected, chunks=2, chunk_seconds=5)
assert resolved["prompts"] == ["first", "second"]
def test_connected_plan_precedes_legacy_script_without_sequence_input():
connected = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="connected plan", chunks=2, chunk_seconds=5)
resolved = build_sampler_prompt_plan(prompt_mode=PROMPT_FORMAT_AUTO, prompt_script="legacy", sequence_prompt=None, prompt_plan=connected, chunks=2, chunk_seconds=5)
assert resolved is connected
def test_sparse_overrides_replace_only_explicit_clips_and_rehash():
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="Sequence Prompt", chunks=5, chunk_seconds=5)
sparse = validate_sparse_prompt_overrides(parse_sparse_prompt_overrides("[Clip 2]\nclose-up\n\n[Clip 5]\nfinish naturally"), chunks=5)
updated = apply_prompt_overrides(plan, [sparse.get(index) for index in range(1, 6)])
assert updated["prompts"] == ["Sequence Prompt", "close-up", "Sequence Prompt", "Sequence Prompt", "finish naturally"]
assert updated["hashes"][0] == plan["hashes"][0]
assert updated["hashes"][1] != plan["hashes"][1]
assert updated["hashes"][2] == plan["hashes"][2]
assert updated["hashes"][3] == plan["hashes"][3]
assert updated["hashes"][4] != plan["hashes"][4]
def test_sparse_override_clip_one_leaves_remaining_clips_unchanged():
plan = make_prompt_plan(mode=PROMPT_FORMAT_FIXED, script="base", chunks=5, chunk_seconds=5)
sparse = validate_sparse_prompt_overrides(parse_sparse_prompt_overrides("[Clip 1]\nopening override"), chunks=5)
updated = apply_prompt_overrides(plan, [sparse.get(index) for index in range(1, 6)])
assert updated["prompts"] == ["opening override", "base", "base", "base", "base"]
def test_sparse_override_rejects_out_of_range_clip():
sparse = parse_sparse_prompt_overrides("[Clip 6]\noutside")
with pytest.raises(PromptPlanError, match="outside"):
validate_sparse_prompt_overrides(sparse, chunks=5)
def test_sparse_override_rejects_duplicate_clip():
with pytest.raises(PromptPlanError, match="more than once"):
parse_sparse_prompt_overrides("[Clip 2]\nfirst\n\n[Chunk 2]\nsecond")