Harden V3.2.1 release contracts

This commit is contained in:
ukr8b3g-cmyk
2026-08-13 21:55:51 +09:00
parent a3c8151c96
commit 683ad512a7
19 changed files with 617 additions and 145 deletions
+12 -1
View File
@@ -1,8 +1,9 @@
from types import SimpleNamespace
import hashlib
import torch
from ComfyUI_H3_Continuum_Join.constants import CONTINUUM_INTEROP_KEY, DIAGNOSTICS_BASIC, PROMPT_MODE_FIXED, V2_CONTINUITY_OPTIONS
from ComfyUI_H3_Continuum_Join.temporal import audio_latent_t, video_latent_t
from ComfyUI_H3_Continuum_Join.v2.h3_builder import IdentityAssets
from ComfyUI_H3_Continuum_Join.v2.h3_builder import IdentityAssets, _tensor_fingerprint
from ComfyUI_H3_Continuum_Join.v2.prompts import make_prompt_plan
from ComfyUI_H3_Continuum_Join.v2 import sequence
@@ -17,6 +18,16 @@ class FakeClip:
def tokenize(self,prompt,images): self.events.append(("tokenize",prompt,len(images))); return prompt
def encode_from_tokens_scheduled(self,tokens): self.events.append(("encode",tokens)); return [[torch.zeros(1,1,2),{}]]
def test_identity_fingerprint_hashes_full_resized_rgb_tensor():
image = torch.zeros((1, 96, 64, 3), dtype=torch.float32)
image[0, 95, 63, 2] = 1.0
digest = hashlib.sha256()
digest.update(str(tuple(image.shape)).encode("ascii"))
digest.update(str(image.dtype).encode("ascii"))
digest.update(image.contiguous().view(torch.uint8).numpy().tobytes(order="C"))
assert _tensor_fingerprint(image) == digest.hexdigest()
def test_v2_samples_every_chunk_before_any_decode(monkeypatch):
events=[]; width,height=96,64
fake_model=SimpleNamespace(model=SimpleNamespace(diffusion_model=SimpleNamespace()),model_options={},wrappers={},model_dtype=lambda:torch.bfloat16,model_size=lambda:0)
+125 -1
View File
@@ -5,17 +5,28 @@ import json
from types import SimpleNamespace
import torch
import pytest
import ctypes
from ComfyUI_H3_Continuum_Join.run_storage import (
RunStorageController,
_apply_nonce_contract,
_fsync_file,
_pid_exists_windows,
automatic_project_key,
build_sampling_contract,
resolve_run_storage_name,
revision_identity,
)
from ComfyUI_H3_Continuum_Join.graph_contract import build_upstream_graph_contract
from ComfyUI_H3_Continuum_Join.graph_contract import (
CHECKPOINT_FL2VA,
CHECKPOINT_REF2VA,
build_upstream_graph_contract,
classify_h3_checkpoint,
)
from ComfyUI_H3_Continuum_Join.state import make_plan
from ComfyUI_H3_Continuum_Join.v2.session import make_chunk_entry
from ComfyUI_H3_Continuum_Join.v3.nodes import _validate_regenerate_storage
class _Nested:
@@ -97,6 +108,7 @@ def test_three_chunks_are_committed_to_distinct_files(tmp_path):
records = controller.manifest["chunks"]
assert [record["sequence_index"] for record in records] == [0, 1, 2]
assert [record["entry"]["sequence_index"] for record in records] == [0, 1, 2]
assert all(len(record["file_sha256"]) == 64 for record in records)
assert [entry["sequence_index"] for entry in source_entries] == [0, 0, 0]
persisted = json.loads(controller._manifest_path().read_text(encoding="utf-8"))
@@ -137,6 +149,65 @@ def test_fsync_file_accepts_a_completed_file_on_windows(tmp_path):
_fsync_file(target)
def test_chunk_sha256_rejects_same_size_corruption(tmp_path):
controller, _ = _controller(tmp_path)
controller.commit_chunk(_entry(0), position=0)
record = controller.manifest["chunks"][0]
target = controller.revision_root / "chunks" / record["filename"]
payload = bytearray(target.read_bytes())
payload[-1] ^= 1
target.write_bytes(payload)
with pytest.raises(Exception, match="SHA-256 mismatch"):
controller._load_entry(record, "same fixed prompt")
def test_automatic_storage_name_is_stable_for_sampler_node():
first = resolve_run_storage_name(
project_id="", legacy_run_name="", automatic_key="242"
)
second = resolve_run_storage_name(
project_id="", legacy_run_name="", automatic_key="242"
)
assert first == second
assert first.startswith("run_auto_")
def test_windows_pid_probe_uses_open_process(monkeypatch):
class Function:
def __init__(self, result):
self.result = result
self.argtypes = None
self.restype = None
def __call__(self, *args):
return self.result
class Kernel32:
OpenProcess = Function(123)
CloseHandle = Function(True)
monkeypatch.setattr(ctypes, "WinDLL", lambda *args, **kwargs: Kernel32(), raising=False)
monkeypatch.setattr(ctypes, "set_last_error", lambda value: None)
monkeypatch.setattr(ctypes, "get_last_error", lambda: 0)
assert _pid_exists_windows(12345)
def test_automatic_project_key_ignores_settings_but_tracks_topology():
prompt = _prompt_graph()
first = automatic_project_key(prompt, "42")
prompt["10"]["inputs"]["unet_name"] = "different-model.safetensors"
assert automatic_project_key(prompt, "42") == first
prompt["42"]["inputs"]["model"] = ["10", 0]
assert automatic_project_key(prompt, "42") != first
def test_regenerate_from_requires_run_storage():
_validate_regenerate_storage("Off", 0)
_validate_regenerate_storage("Save + Auto Resume", 2)
with pytest.raises(ValueError, match="requires Run Storage"):
_validate_regenerate_storage("Off", 2)
def _sample_function(*args, **kwargs):
return None
@@ -206,6 +277,8 @@ def _sampling_contract(
*, model=None, clip=None, video_vae=None, sampler=None, reroll_nonce=0,
conditioning_mode="i2va", first_frame_hash="a" * 64,
last_frame_hash="", reference_contract=None,
upstream_graph_contract=None, upstream_graph_safe=None,
upstream_graph_reasons=None,
):
return build_sampling_contract(
model=model or _Model(),
@@ -232,6 +305,9 @@ def _sampling_contract(
strict_compatibility=True,
reference_contract=reference_contract,
conditioning_mode=conditioning_mode,
upstream_graph_contract=upstream_graph_contract,
upstream_graph_safe=upstream_graph_safe,
upstream_graph_reasons=upstream_graph_reasons,
)
@@ -420,6 +496,46 @@ def test_upstream_graph_fingerprint_tracks_loader_and_patch_order():
assert model_route["inputs"]["model"]["node"]["class_type"] == "PathchSageAttentionKJ"
def test_sampling_contract_combines_graph_and_runtime_weight_probe():
graph, graph_safe, graph_reasons = build_upstream_graph_contract(
_prompt_graph(), "42", require_video_vae=True
)
model = _Model()
first, safe, reasons = _sampling_contract(
model=model,
upstream_graph_contract=graph,
upstream_graph_safe=graph_safe,
upstream_graph_reasons=graph_reasons,
)
assert safe, reasons
assert "runtime" in first["global"]["model"]
assert "graph_route" in first["global"]["model"]
with torch.no_grad():
model.model.diffusion_model.weight.add_(1)
changed, safe, reasons = _sampling_contract(
model=model,
upstream_graph_contract=graph,
upstream_graph_safe=graph_safe,
upstream_graph_reasons=graph_reasons,
)
assert safe, reasons
assert revision_identity(first) != revision_identity(changed)
def test_official_h3_sigma_shift_is_accepted_in_model_route():
prompt = _prompt_graph()
prompt["13"] = {
"class_type": "MiniMaxH3SigmaShift",
"inputs": {"model": ["12", 0], "shift": 3.0},
}
prompt["42"]["inputs"]["model"] = ["13", 0]
graph, safe, reasons = build_upstream_graph_contract(
prompt, "42", require_video_vae=True
)
assert safe, reasons
assert graph["routes"]["model"]["node"]["class_type"] == "MiniMaxH3SigmaShift"
def test_upstream_graph_fingerprint_accepts_runtime_turbo_and_sage_nodes():
prompt = _prompt_graph()
prompt["11"] = {
@@ -442,6 +558,14 @@ def test_upstream_graph_fingerprint_accepts_runtime_turbo_and_sage_nodes():
prompt, "42", require_video_vae=True
)
assert safe, reasons
def test_checkpoint_classifier_uses_base_unet_filename():
prompt = _prompt_graph()
prompt["10"]["inputs"]["unet_name"] = "minimax_h3_ref2va_pruned_int8.safetensors"
assert classify_h3_checkpoint(prompt, "42") == CHECKPOINT_REF2VA
prompt["10"]["inputs"]["unet_name"] = "minimax_h3_fl2va_pruned_int8.safetensors"
assert classify_h3_checkpoint(prompt, "42") == CHECKPOINT_FL2VA
changed_prompt = copy.deepcopy(prompt)
changed_prompt["12"]["inputs"]["lora_1"]["strength"] = 0.8
changed, changed_safe, changed_reasons = build_upstream_graph_contract(
+45
View File
@@ -7,8 +7,10 @@ from ComfyUI_H3_Continuum_Join.reference import (
REFERENCE_SIZE_MATCH_OUTPUT,
ReferenceAssets,
ReferenceConditioningError,
prepare_reference_assets,
validate_reference_prompts,
)
from ComfyUI_H3_Continuum_Join.v3.nodes import _validate_reference_checkpoint
def test_reference_size_is_appended_after_v31_widgets():
@@ -51,3 +53,46 @@ def test_picture_tags_must_match_connected_references():
def test_missing_picture_tag_is_a_warning_not_an_error():
warning = validate_reference_prompts(["The same person walks forward."], 1)
assert "no <Picture N> tag" in warning
def test_reference_socket_rejects_image_batches():
with pytest.raises(ReferenceConditioningError, match="batch size B=1"):
prepare_reference_assets(
reference_image_1=torch.zeros((2, 32, 32, 3)),
reference_image_2=None,
output_width=32,
output_height=32,
size_mode=REFERENCE_SIZE_MATCH_OUTPUT,
)
def _reference_prompt(checkpoint_name: str) -> dict:
return {
"1": {
"class_type": "UNETLoader",
"inputs": {"unet_name": checkpoint_name},
},
"2": {
"class_type": "H3ContinuumSamplerProduction",
"inputs": {"model": ["1", 0]},
},
}
def test_strict_reference_requires_ref2va_checkpoint():
assert _validate_reference_checkpoint(
_reference_prompt("minimax_h3_ref2va_pruned_int8.safetensors"),
"2",
strict_compatibility=True,
) == "ref2va"
with pytest.raises(ValueError, match="FL2VA checkpoint"):
_validate_reference_checkpoint(
_reference_prompt("minimax_h3_fl2va_pruned_int8.safetensors"),
"2",
strict_compatibility=True,
)
assert _validate_reference_checkpoint(
_reference_prompt("minimax_h3_fl2va_pruned_int8.safetensors"),
"2",
strict_compatibility=False,
) == "fl2va"