Archive fork in favor of upstream and DUMAS nodes
tests / test (push) Canceled after 0s
tests / windows-storage (push) Canceled after 0s

This commit is contained in:
2026-10-20 10:46:16 +00:00
parent 881dcbcfba
commit 3716b02a57
76 changed files with 12140 additions and 4410 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ def review_queue_results():
capture_output=True, text=True, encoding="utf-8", timeout=45,
)
records = json.loads(result.stdout)
assert len(records) == 62, "The complete queue fixture must finish, including Workflow rehydration and v5 history"
assert len(records) == 90, "The complete queue fixture must finish, including rehydration, v5 history and read-only reasons"
failures = [item for item in records if not item["pass"]]
assert result.returncode == 0 and not failures, result.stdout + result.stderr
return {item["name"]: item for item in records}
File diff suppressed because one or more lines are too long
+19
View File
@@ -0,0 +1,19 @@
def _observe_model_options(options):
transformer = options.get("transformer_options")
if not isinstance(transformer, dict) or "optimized_attention_override" not in transformer:
return _observe(options)
try:
adapted = _core_attention_override(transformer["optimized_attention_override"])
except Exception:
adapted = None
if adapted is None:
# Unknown overrides keep their prior descriptor and safe-side policy.
return _observe(options)
copied = dict(options)
copied["transformer_options"] = dict(transformer)
copied["transformer_options"]["optimized_attention_override"] = None
observed, safe = _observe(copied)
if not isinstance(observed.get("transformer_options"), dict) or "truncated" in observed["transformer_options"]:
return observed, False
observed["transformer_options"]["optimized_attention_override"] = adapted[0]
return observed, safe and adapted[1]
+111
View File
@@ -193,4 +193,115 @@ oldSampler.inputs[0].link = null;
assert.equal(pruneV39LegacyReferenceInputs(oldSampler), 1);
assert.deepEqual(oldSampler.inputs.map((input) => input.name), ['reference_images']);
assert.equal(pruneV39LegacyReferenceInputs({ ...oldSampler, comfyClass: 'H3ContinuumSamplerV38' }), 0);
// External INT values are not frontend widget values. Exercise the production
// helper in fresh graphs without resolving or guessing any upstream value.
function assignmentFixture({ value = 3, external = false, link = 90, saved = 'off', missing = false, other = null } = {}) {
const graph = { links: {}, nodes: new Map(), getNodeById(id) { return this.nodes.get(id); } };
const calls = { native: 0, notify: 0, size: 0 };
const controls = Array.from({ length: 9 }, (_, i) => ({ name: `reference_r${i + 1}_chunks`,
value: i === 0 ? saved : 'off', options: {}, callback() { calls.native++; } }));
const helper = { id: 1, graph, comfyClass: 'H3ContinuumReferenceImagesV39', size: [440, 500],
widgets: [{ name: 'reference_use', value: 'Per chunk' }, ...controls],
inputs: [{ name: 'reference_image_1', link: 100 }], outputs: [{ name: 'reference_images', links: [10] }],
addDOMWidget(_name, _type, host) { this.panel = host.children[0]; this.display = { options: {} }; return this.display; },
computeSize() { return [440, 310 + this.display.computeSize(440)[1]]; },
setSize(value) { calls.size++; this.size = value; }, setDirtyCanvas() {},
};
const sampler = { id: 2, graph, comfyClass: 'H3ContinuumSamplerV39',
widgets: missing ? [] : [{ name: 'chunks', value }],
inputs: [{ name: 'reference_images', link: 10 }, { name: 'chunks', link: external ? link : null }],
__h3ContinuumIntuitiveUxRefresh() { calls.notify++; }, setDirtyCanvas() {},
};
graph.nodes.set(1, helper); graph.nodes.set(2, sampler); graph.links[10] = { origin_id: 1, target_id: 2 };
if (other !== null) {
const second = { ...sampler, id: 3, widgets: [{ name: 'chunks', value: other }],
inputs: [{ name: 'reference_images', link: 11 }, { name: 'chunks', link: null }] };
graph.nodes.set(3, second); graph.links[11] = { origin_id: 1, target_id: 3 }; helper.outputs[0].links.push(11);
}
configureV39ReferenceImages(helper);
return { graph, helper, sampler, calls, control: controls[0],
text() { const values = []; const collect = (node) => { values.push(node.textContent || ''); (node.children || []).forEach(collect); }; collect(helper.panel); return values.join('\n'); },
checkbox(n) { return visit(helper.panel, (item) => item['aria-label'] === `Image 1, Chunk ${n}`); },
action(label) { const button = visit(helper.panel, (item) => item.tag === 'button' && item.textContent === label); assert(button && !button.disabled, label); button.onclick(); },
refresh() { refreshV39ReferenceImagesForSampler(sampler); },
};
}
const externalCases = [];
function externalCase(name, run) {
try { run(); externalCases.push({ name, pass: true }); }
catch (error) { externalCases.push({ name, pass: false, error: error.message }); }
}
function unknown(f, reason) {
assert.match(f.text(), /range 1–16/);
assert.match(f.text(), reason);
assert(f.checkbox(3));
assert(!f.text().includes('saved beyond range'));
}
externalCase('J01 direct three keeps native range', () => {
const f = assignmentFixture(); assert.match(f.text(), /3 chunks/); assert(f.checkbox(3)); assert(!f.checkbox(4));
f.action('All'); assert.equal(f.control.value, '1,2,3'); f.action('Off'); assert.equal(f.control.value, 'off');
});
externalCase('J02 external three and widget two allow C3', () => unknown(assignmentFixture({ value: 2, external: true }), /connected node/));
externalCase('J03 external with matching widget remains unresolved', () => unknown(assignmentFixture({ external: true }), /connected node/));
externalCase('J04 link zero is external', () => unknown(assignmentFixture({ external: true, link: 0 }), /connected node/));
externalCase('J05 unrestored link stays external', () => unknown(assignmentFixture({ external: true, link: 99999 }), /connected node/));
externalCase('J06 disconnected or absent socket uses direct value', () => {
const f = assignmentFixture(); f.sampler.inputs.pop(); f.refresh(); assert.match(f.text(), /3 chunks/);
});
externalCase('J07 unavailable or invalid widget preserves selection', () => {
for (const options of [{ missing: true }, { value: 0 }, { value: 17 }, { value: 2.5 }, { value: 'bad' }]) {
const f = assignmentFixture({ ...options, saved: '1,2,3' }); unknown(f, /not available/); assert.equal(f.control.value, '1,2,3');
}
});
externalCase('J08 multiple direct three targets agree', () => assert.match(assignmentFixture({ other: 3 }).text(), /3 chunks/));
externalCase('J09 multiple different direct counts stay unresolved', () => unknown(assignmentFixture({ other: 2 }), /different chunk counts/));
externalCase('J10 any externally connected target makes range unresolved', () => unknown(assignmentFixture({ external: true, other: 3 }), /connected node/));
externalCase('J11 unknown reason refreshes even when range is unchanged', () => {
const f = assignmentFixture({ external: true }); unknown(f, /connected node/);
f.helper.outputs[0].links = []; f.helper.onConnectionsChange(); unknown(f, /Connect this helper to a Sampler/);
assert(!f.text().includes('connected node'));
});
externalCase('J12 upstream value changes do not rewrite or rebuild', () => {
const f = assignmentFixture({ external: true, saved: '1,2' }); const first = f.helper.panel.children[0];
const counts = { ...f.calls }; f.graph.nodes.set(90, { value: 4 }); f.refresh();
assert.equal(f.helper.panel.children[0], first); assert.equal(f.control.value, '1,2'); assert.deepEqual(f.calls, counts);
});
externalCase('J13 saved C3 remains visible and is not called outside range', () => {
const f = assignmentFixture({ value: 2, external: true, saved: '1,2,3' }); f.refresh();
assert.equal(f.control.value, '1,2,3'); assert(f.checkbox(3).checked); assert.match(f.text(), /Saved assignments: 1, 2, 3/);
});
externalCase('J14 old one-two is never automatically expanded', () => {
const f = assignmentFixture({ value: 2, external: true, saved: '1,2' }); configureV39ReferenceImages(f.helper); f.refresh();
assert.equal(f.control.value, '1,2'); assert(!f.checkbox(3).checked);
});
externalCase('J15 unknown All operates over all pages', () => {
const f = assignmentFixture({ external: true }); f.action('▶'); f.action('▶'); f.action('All 1–16');
assert.equal(f.control.value, Array.from({ length: 16 }, (_, i) => i + 1).join(','));
});
externalCase('J16 unknown Off clears future saved assignments', () => {
const f = assignmentFixture({ external: true, saved: '1,2,3,16' }); f.action('Off 1–16'); assert.equal(f.control.value, 'off');
});
externalCase('J17 direct All and Off preserve saved future six', () => {
const f = assignmentFixture({ saved: '6' }); f.action('All'); assert.equal(f.control.value, '1,2,3,6'); f.action('Off'); assert.equal(f.control.value, '6');
});
externalCase('J18 C3 updates native value and notifies once', () => {
const f = assignmentFixture({ value: 2, external: true }); const counts = { ...f.calls }; const box = f.checkbox(3);
assert(box); box.checked = true; box.onchange(); assert.equal(f.control.value, '3');
assert.equal(f.calls.native, counts.native + 1); assert.equal(f.calls.notify, counts.notify + 1); assert.equal(f.calls.size, counts.size);
});
externalCase('J19 independent helpers and multiple targets stay independent', () => {
const f = assignmentFixture({ external: true, other: 3 }), g = assignmentFixture({ external: true });
f.action('All 1–16'); assert.equal(f.calls.notify, 2); assert.equal(g.control.value, 'off'); assert.equal(g.calls.notify, 0);
});
externalCase('J20 repeated configure keeps callbacks layout and width', () => {
const f = assignmentFixture({ external: true }); const callback = f.control.callback, sizes = f.calls.size;
for (let i = 0; i < 100; i++) configureV39ReferenceImages(f.helper);
assert.equal(f.control.callback, callback); assert.equal(f.calls.size, sizes); assert.equal(f.helper.size[0], 440);
});
externalCase('J21 malformed saved selector remains disabled and unchanged', () => {
const f = assignmentFixture({ external: true, saved: 'invalid' }); assert.equal(f.control.value, 'invalid');
assert(f.checkbox(3).disabled); assert(visit(f.helper.panel, (item) => item.textContent === 'All 1–16').disabled);
});
console.log(JSON.stringify(externalCases));
assert.equal(externalCases.filter((item) => !item.pass).length, 0, 'external Chunk assignment contracts failed');
console.log('V3.9 Reference Images UI contract PASS');
+120
View File
@@ -697,5 +697,125 @@ await test('archived v5 lineage remains browsable after a v6 canonical run',asyn
const n=e.makeNode();await e.load(n,current);
assert.equal(e.f.takeCatalog(n).length,3);
});
await test('v6 read-only reports saved preview source and keeps actions disabled',async e=>{
const p=project(1),reason='KJ/Core preview implementation is outside the audited source profiles';
for(const item of [...p.group_revisions,...p.revisions]){
item.generation_reusable=false;item.resume_disabled_reasons=[reason];
}
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
assert.match(e.f.reviewStatus(n),/Sampling v6 Take is read-only/);
assert.match(e.f.reviewStatus(n),/Bypass KJ Model Preview Override/);
assert(!e.visible(n,'Use it and continue'));
const before=[e.w(n,'take_action').value,e.w(n,'take_revision_id').value,e.w(n,'run_name').value];
e.f.selectTakeAction(n,'Use This Take');e.f.selectTakeAction(n,'Continue From Here');
assert.deepEqual([e.w(n,'take_action').value,e.w(n,'take_revision_id').value,e.w(n,'run_name').value],before);
});
await test('preview setting remedies preserve generation VAE guidance',async e=>{
const cases=[
['KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration',/Keep the generation VAEs connected/],
['Core approximate-VAE preview is outside the supported configuration',/Auto or Latent2RGB/],
];
for(const [index,[reason,expected]] of cases.entries()){
const p=project(1);for(const item of [...p.group_revisions,...p.revisions]){
item.generation_reusable=false;item.resume_disabled_reasons=[reason];
}
const n=e.makeNode(312+index);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
assert.match(e.f.reviewStatus(n),expected);
assert.match(e.f.reviewStatus(n),/After correcting the configuration/);
assert(!e.visible(n,'Use it and continue'));
}
});
await test('missing compatibility metadata is not mislabeled v5 or a known KJ error',async e=>{
for(const field of ['sampling_contract_version','generation_reusable']){
const p=project(1);for(const item of [...p.group_revisions,...p.revisions])delete item[field];
const n=e.makeNode(field==='sampling_contract_version'?312:313);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
assert.match(e.f.reviewStatus(n),/metadata is incomplete or unsupported/);
assert.doesNotMatch(e.f.reviewStatus(n),/Sampling v5|Bypass KJ/);
assert(!e.visible(n,'Use it and continue'));
}
});
await test('unknown saved reasons do not expose paths or unbounded text',async e=>{
const p=project(1);for(const item of [...p.group_revisions,...p.revisions]){
item.generation_reusable=false;item.resume_disabled_reasons=Array(20).fill('C:/Users/private/file.py'+'x'.repeat(10000));
}
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);
const text=e.f.reviewStatus(n);assert.match(text,/Detailed Report/);
assert.doesNotMatch(text,/private|file.py/);assert(text.length<1500);
});
await test('history reasons follow the selected Take rather than the canonical revision',async e=>{
const p=project(2),vae='KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration';
const core='Core approximate-VAE preview is outside the supported configuration';
for(const item of [...p.group_revisions,...p.revisions])item.generation_reusable=false;
p.group_revisions[0].resume_disabled_reasons=[vae];p.group_revisions[1].resume_disabled_reasons=[core];
p.revisions[0].resume_disabled_reasons=[core];
const n=e.makeNode();e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,p);e.f.selectTakeOffset(n,-1);
const text=e.w(n,'Render History / Takes').value;
assert.match(text,/Keep the generation VAEs connected/);assert.doesNotMatch(text,/Auto or Latent2RGB/);
});
await test('saved compatibility metadata controls Review with optional real backend vectors',async e=>{
const configured=process.env.H3_READONLY_PROJECT_VECTORS;
const p=project(1);p.revisions[0].resume_disabled_reasons=['KJ preview runtime code or state could not be verified'];
const vectors=configured?JSON.parse(fs.readFileSync(configured,'utf8')):[{project:p,reusable:true}];
assert(vectors.length>0);
for(const [index,vector] of vectors.entries()){
const n=e.makeNode(800+index,vector.project.run_name);e.w(n,'generation_mode').value='Review Each Chunk';await e.load(n,vector.project);
assert.equal(e.visible(n,'Use it and continue'),vector.reusable,e.f.reviewStatus(n));
if(vector.reason)assert(e.f.reviewStatus(n).includes(vector.reason));
if(vector.reusable)assert.doesNotMatch(e.f.reviewStatus(n),/read-only|could not be verified/);
}
});
// Persisted explicit requests must survive Core's graph-restoration lifecycle.
for(const nodeClass of ['H3ContinuumSamplerV38','H3ContinuumSamplerV39']) {
for(const mode of ['Full Run','Review Each Chunk']) {
for(const boundary of ['Chunk 1','Chunk 2']) {
for(const nonce of [0,5]) {
await test(`regenerate restore: ${nodeClass} ${mode} ${boundary} nonce ${nonce}`,async e=>{
const n=e.makeNode(312,'fixture',nodeClass);await e.load(n,project(3,3));
e.w(n,'generation_mode').value=mode;
e.w(n,'reroll_from_chunk').value=boundary;e.w(n,'reroll_from_chunk').callback?.(boundary);
e.w(n,'reroll_nonce').value=nonce;
const info=JSON.parse(JSON.stringify({properties:n.properties,...n.serialize()}));
const beforeHistory=JSON.stringify(e.getSaved());
n.onRemoved?.();e.app.graph._nodes=[];e.app.extension.beforeConfigureGraph?.();
const loaded=e.makeNode(312,'',nodeClass,false);e.app.extension.nodeCreated(loaded);
loaded.properties=info.properties;loaded.configure(info);
e.app.extension.loadedGraphNode(loaded);await e.finishRestore();
assert.equal(e.w(loaded,'reroll_from_chunk').value,boundary);
assert.equal(e.w(loaded,'reroll_nonce').value,nonce);
await e.queue(loaded);const sent=e.submissions.at(-1).data.output['312'].inputs;
assert.equal(sent.reroll_from_chunk,boundary);assert.equal(sent.reroll_nonce,nonce);
assert.equal(sent.generation_mode,mode);assert.equal(sent.run_storage,'Save + Auto Resume');
assert(!Object.hasOwn(sent,'h3_continuum_regenerate_from'));
assert.equal(JSON.stringify(e.getSaved()),beforeHistory);
});
}
}
}
for(const [boundary,nonce] of [['Chunk 2',0],['Chunk 1',5]]) {
await test(`regenerate legacy: ${nodeClass} ${boundary} nonce ${nonce}`,async e=>{
e.setSaved(project(3,3));e.app.extension.beforeConfigureGraph?.();
const n=e.makeNode(312,'fixture',nodeClass,false);e.app.extension.nodeCreated(n);
e.w(n,'generation_mode').value='Review Each Chunk';e.w(n,'reroll_from_chunk').value=boundary;
e.w(n,'reroll_nonce').value=nonce;e.app.extension.loadedGraphNode(n);await e.finishRestore();
assert.equal(e.w(n,'reroll_from_chunk').value,boundary);assert.equal(e.w(n,'reroll_nonce').value,nonce);
e.w(n,'Run').callback('Review Each Chunk');
await e.queue(n);assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_from_chunk,boundary);
assert.equal(e.submissions.at(-1).data.output['312'].inputs.reroll_nonce,nonce);
});
}
await test(`regenerate intent reset: ${nodeClass}`,async e=>{
const n=e.makeNode(312,'fixture',nodeClass);await e.load(n,project(1));
e.w(n,'reroll_from_chunk').value='Chunk 1';e.w(n,'reroll_from_chunk').callback?.('Chunk 1');
assert.equal(n.properties.h3_continuum_regenerate_from,'Chunk 1');
e.w(n,'reroll_from_chunk').value='Auto';e.w(n,'reroll_from_chunk').callback?.('Auto');
assert(!Object.hasOwn(n.properties,'h3_continuum_regenerate_from'));
e.w(n,'Start again from Chunk 1').callback();await e.queue(n);
assert.equal(e.w(n,'reroll_from_chunk').value,'Auto');
assert(!Object.hasOwn(n.properties,'h3_continuum_regenerate_from'));
});
}
console.log(JSON.stringify(results,null,2));if(results.some(r=>!r.pass))process.exitCode=1;
})();
+381
View File
@@ -0,0 +1,381 @@
from __future__ import annotations
import ast
import copy
import json
import subprocess
import sys
import types
from pathlib import Path
import pytest
import torch
from ComfyUI_H3_Continuum_Join import run_storage as storage
from . import test_v31_run_storage as signatures
from . import test_v38_review_run_storage as review
ROOT = Path(__file__).resolve().parents[1]
@pytest.fixture
def core_attention(require_comfy_core, monkeypatch):
import comfy.ldm.modules.attention as attention
import comfy.model_patcher as patcher
# A CPU build may not advertise INT8. Inspect the real loaded definition;
# registration here is a fixture, not an assertion that a CPU kernel runs.
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "comfy_kitchen_int8",
attention.attention_comfy_kitchen_int8)
return attention, patcher
def model_with(core, name):
attention, patcher = core
torch.manual_seed(31)
model = signatures._Model()
model.model_options["transformer_options"] = {}
patcher.ModelPatcher.set_model_optimized_attention(
model, attention.REGISTERED_ATTENTION_FUNCTIONS[name])
return model
def observe(model):
return storage._model_signature(model, "fixture")
def remake(core, monkeypatch, name, *, raw_code=None, defaults=None):
attention, _ = core
old = attention.REGISTERED_ATTENTION_FUNCTIONS[name]
raw = old.__wrapped__
new = types.FunctionType(raw_code or raw.__code__, raw.__globals__,
raw.__name__, raw.__defaults__ if defaults is None else defaults,
raw.__closure__)
new.__module__, new.__qualname__ = raw.__module__, raw.__qualname__
new.__kwdefaults__ = copy.copy(raw.__kwdefaults__)
new.__dict__.update(raw.__dict__)
wrapped = attention.wrap_attn(new)
wrapped.container_function = old.container_function
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, name, wrapped)
monkeypatch.setattr(attention, "attention_" + name, wrapped)
return wrapped
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
def test_real_core_backend_is_finite_clone_stable_and_non_mutating(core_attention, monkeypatch, backend):
model = model_with(core_attention, backend)
wrapped = core_attention[0].REGISTERED_ATTENTION_FUNCTIONS[backend]
override = model.model_options["transformer_options"]["optimized_attention_override"]
original = (dict(vars(wrapped)), dict(vars(override)), copy.copy(model.model_options))
watched = {wrapped.__code__, wrapped.__wrapped__.__code__}
if wrapped.container_function:
watched.add(wrapped.container_function.__code__)
calls = []
previous = sys.getprofile()
sys.setprofile(lambda frame, event, arg: calls.append(frame.f_code.co_name)
if event == "call" and frame.f_code in watched else None)
try:
before, safe = observe(model)
finally:
sys.setprofile(previous)
assert safe, before["model_options"]
assert not calls
assert original == (vars(wrapped), vars(override), model.model_options)
cloned, cloned_safe = observe(copy.deepcopy(model))
assert cloned_safe and cloned == before
remake(core_attention, monkeypatch, backend)
recreated, recreated_safe = observe(model_with(core_attention, backend))
assert recreated_safe and recreated == before
attention = before["model_options"]["transformer_options"]["optimized_attention_override"]
assert attention["backend"] == backend
assert attention["core_attention_signature_version"] == 1
assert attention["wrapper"]["closure"][-1]["value"] == {"reference": "wrapper"}
def test_pytorch_and_kitchen_are_distinct(core_attention):
a, safe_a = observe(model_with(core_attention, "pytorch"))
b, safe_b = observe(model_with(core_attention, "comfy_kitchen_int8"))
assert safe_a and safe_b and a != b
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
@pytest.mark.parametrize("change", ["code", "defaults", "helper"])
def test_attention_implementation_changes_identity(core_attention, monkeypatch, backend, change):
before, safe = observe(model_with(core_attention, backend))
assert safe
attention, _ = core_attention
if change == "code":
raw = attention.REGISTERED_ATTENTION_FUNCTIONS[backend].__wrapped__
def change_constant(c):
if isinstance(c, tuple):
return tuple(change_constant(v) for v in c)
return "changed_scale" if c == "scale" else c
constants = tuple(change_constant(c) for c in raw.__code__.co_consts)
assert constants != raw.__code__.co_consts
remake(core_attention, monkeypatch, backend, raw_code=raw.__code__.replace(co_consts=constants))
elif change == "defaults":
raw = attention.REGISTERED_ATTENTION_FUNCTIONS[backend].__wrapped__
remake(core_attention, monkeypatch, backend, defaults=(17,) + raw.__defaults__[1:])
else:
helper = attention._heads_from_dim
constants = tuple(2 if c == 0 else c for c in helper.__code__.co_consts)
monkeypatch.setattr(attention, "_heads_from_dim",
types.FunctionType(helper.__code__.replace(co_consts=constants),
helper.__globals__, helper.__name__))
after, after_safe = observe(model_with(core_attention, backend))
assert after_safe and after != before
@pytest.mark.parametrize("slot", ["inner", "outer"])
@pytest.mark.parametrize("kind", ["function", "opaque", "none"])
def test_container_changes_are_recorded_and_cannot_be_certified(core_attention, monkeypatch, slot, kind):
model = model_with(core_attention, "comfy_kitchen_int8")
before, safe = observe(model)
assert safe
target = (core_attention[0].attention_comfy_kitchen_int8 if slot == "inner" else
model.model_options["transformer_options"]["optimized_attention_override"])
class Opaque:
__slots__ = ()
def __call__(self, *args):
raise AssertionError("signature must not invoke container")
def replacement(*args):
raise AssertionError("signature must not invoke container")
value = {"function": replacement, "opaque": Opaque(), "none": None}[kind]
monkeypatch.setattr(target, "container_function", value)
after, safe_after = observe(model)
assert after != before and not safe_after
def test_unrelated_opaque_cfg_is_not_promoted(core_attention):
model = model_with(core_attention, "pytorch")
assert observe(model)[1]
model.model_options["sampler_cfg_function"] = object()
assert not observe(model)[1]
contract, safe, reasons = signatures._sampling_contract(model=model)
assert contract and not safe and reasons
assert contract["global"]["sampling_contract_version"] == 6
def test_unregistered_or_foreign_setter_keeps_generic_policy(core_attention, monkeypatch):
attention, patcher = core_attention
model = model_with(core_attention, "pytorch")
callback = model.model_options["transformer_options"]["optimized_attention_override"]
monkeypatch.delitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "pytorch")
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
assert not observe(model)[1]
def foreign(_, *args, **kwargs):
return None
model.model_options["transformer_options"]["optimized_attention_override"] = foreign
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
assert model.model_options["transformer_options"]["optimized_attention_override"] is foreign
assert callback is not foreign
def test_missing_provider_and_unknown_native_binding_are_unsafe(core_attention, monkeypatch):
model = model_with(core_attention, "pytorch")
monkeypatch.setattr(torch.nn.functional, "scaled_dot_product_attention", lambda *a: 0)
result, safe = observe(model)
assert not safe
assert "observation_error" in result["model_options"]["transformer_options"]["optimized_attention_override"]
def test_no_override_existing_v6_contract_is_byte_equivalent(monkeypatch):
torch.manual_seed(31)
model, clip, vae = signatures._Model(), signatures._Clip(), signatures._VideoVAE()
model.model_options = {"transformer_options": {}, "disable_cfg1_optimization": True}
# Use the actual pre-repair function, not an expected hash generated by the fix.
original = subprocess.check_output(["git", "-C", str(ROOT), "show", "HEAD:run_storage.py"], text=True)
node = next(n for n in ast.parse(original).body if isinstance(n, ast.FunctionDef) and n.name == "_model_signature")
scope = dict(vars(storage))
exec(compile(ast.Module(body=[node], type_ignores=[]), "original_model_signature.py", "exec"), scope)
before, safe_before, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
with monkeypatch.context() as context:
context.setattr(storage, "_model_signature", scope["_model_signature"])
legacy, safe_legacy, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert safe_before and safe_legacy
assert storage._canonical(before) == storage._canonical(legacy)
assert storage.revision_identity(before) == storage.revision_identity(legacy)
assert storage.SAMPLING_CONTRACT_VERSION == 6 and storage.RUNTIME_SIGNATURE_VERSION == 1
def test_ordinary_custom_override_keeps_existing_descriptor():
model = signatures._Model()
model.model_options = {"transformer_options": {"optimized_attention_override": lambda x: x}}
assert storage._observe_model_options(model.model_options) == storage._observe(model.model_options)
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
def test_same_backend_reuses_prefix_but_changed_backend_does_not(tmp_path, core_attention, backend):
model = model_with(core_attention, backend)
torch.manual_seed(31)
clip, vae = signatures._Clip(), signatures._VideoVAE()
contract, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert safe
source = review._persist(tmp_path, contract, prefix=1, review_unit=(1, 1),
updated_utc="2026-10-14T00:00:00+00:00")
before_files = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
same, same_safe, _ = signatures._sampling_contract(model=copy.deepcopy(model), clip=clip, video_vae=vae, reroll_from_chunk=0)
assert same_safe and storage.revision_identity(same) == storage.revision_identity(contract)
reader = review._controller(tmp_path, same)
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
prefix = reader._load_validated_review_prefix(same, resume_safe=same_safe)
assert len(prefix.entries) == 1
other = "pytorch" if backend == "comfy_kitchen_int8" else "comfy_kitchen_int8"
changed, changed_safe, _ = signatures._sampling_contract(model=model_with(core_attention, other),
clip=clip, video_vae=vae, reroll_from_chunk=0)
assert changed_safe and storage.revision_identity(changed) != storage.revision_identity(contract)
changed_reader = review._controller(tmp_path, changed)
changed_reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
assert not changed_reader._load_validated_review_prefix(changed, resume_safe=changed_safe).entries
assert before_files == {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
def test_old_unsafe_attention_manifest_stays_read_only_and_unmodified(tmp_path, core_attention, monkeypatch, entry_point):
model = model_with(core_attention, "pytorch")
options = model.model_options
# Original depth-limited observation, producing the old unsafe v6 contract.
with monkeypatch.context() as context:
context.setattr(storage, "_observe_model_options", storage._observe)
old, old_safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
assert not old_safe and reasons
source = review._persist(tmp_path, old, prefix=1, review_unit=(1, 1),
updated_utc="2026-10-14T00:00:00+00:00")
source.manifest["resume_safe"] = False
source.manifest["resume_disabled_reasons"] = reasons
source._write_manifest()
before = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
reader = review._controller(tmp_path, old)
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
assert storage._reusable_manifest(source.manifest) is False
if entry_point == "review":
assert not reader._load_validated_review_prefix(old, resume_safe=True).entries
elif entry_point == "head":
assert reader.find_latest_review_head(old, resume_safe=True) is None
elif entry_point == "import":
assert reader._find_plan_import(old, resume_safe=True) is None
elif entry_point == "compatible":
assert reader._compatible_plan_prefix(source.manifest, old, resume_safe=True) == ([], [])
else:
reader.take_group = 1
reader.take_revision_id = review._project(source)["canonical_head_revision_id"]
with pytest.raises(storage.RunStorageError, match="read-only"):
reader._validated_take_selection(old, resume_safe=True)
assert before == {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
def test_provider_policy_changes_are_observed(core_attention, monkeypatch):
import comfy_kitchen.sage_attention as kitchen_attention
model = model_with(core_attention, "comfy_kitchen_int8")
before, safe = observe(model)
assert safe
monkeypatch.setattr(kitchen_attention, "LARGE_CTA_K", kitchen_attention.LARGE_CTA_K + 1)
after, safe_after = observe(model)
assert safe_after and before != after
@pytest.mark.parametrize("slot", ["setter_globals", "raw_globals", "wrapper_code"])
def test_lookalike_core_structure_is_not_promoted(core_attention, monkeypatch, slot):
attention, _ = core_attention
model = model_with(core_attention, "pytorch")
if slot == "setter_globals":
value = model.model_options["transformer_options"]["optimized_attention_override"]
value = types.FunctionType(value.__code__, dict(value.__globals__), value.__name__,
value.__defaults__, value.__closure__)
model.model_options["transformer_options"]["optimized_attention_override"] = value
elif slot == "raw_globals":
wrapped = attention.attention_pytorch
raw = wrapped.__wrapped__
new = types.FunctionType(raw.__code__, dict(raw.__globals__), raw.__name__,
raw.__defaults__, raw.__closure__)
wrapped = attention.wrap_attn(new)
monkeypatch.setitem(attention.REGISTERED_ATTENTION_FUNCTIONS, "pytorch", wrapped)
monkeypatch.setattr(attention, "attention_pytorch", wrapped)
model = model_with(core_attention, "pytorch")
else:
wrapped = attention.attention_pytorch
monkeypatch.setattr(wrapped, "__code__", wrapped.__code__.replace(
co_consts=wrapped.__code__.co_consts + ("unrecognized wrapper",)))
assert not observe(model)[1]
def test_torch_dispatch_flag_changes_identity(core_attention):
model = model_with(core_attention, "pytorch")
enabled = torch.backends.cuda.math_sdp_enabled()
before, safe = observe(model)
assert safe
try:
torch.backends.cuda.enable_math_sdp(not enabled)
after, after_safe = observe(model)
assert after_safe and after != before
finally:
torch.backends.cuda.enable_math_sdp(enabled)
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
def test_signature_is_stable_in_separate_processes_and_hash_seeds(core_attention, backend):
import os
import comfy
core_root = str(Path(core_attention[1].__file__).resolve().parent.parent)
script = r"""
import importlib.util,json,os,sys
sys.path.insert(0,CORE_ROOT)
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
import torch
torch.cuda._lazy_init=lambda: (_ for _ in ()).throw(RuntimeError("CUDA forbidden"))
from comfy.cli_args import args
args.cpu=True
from comfy.ldm.modules import attention
from comfy import model_patcher
name="ComfyUI_H3_Continuum_Join"
spec=importlib.util.spec_from_file_location(name,ROOT+"/__init__.py",submodule_search_locations=[ROOT])
sys.modules[name]=importlib.util.module_from_spec(spec)
from ComfyUI_H3_Continuum_Join import run_storage as s
from types import SimpleNamespace
class Model:
def __init__(self):
self.model=SimpleNamespace(diffusion_model=torch.nn.Linear(2,2))
self.wrappers={}
self.patches={}
self.model_options={"transformer_options":{}}
def model_dtype(self): return torch.float32
def model_size(self): return 4
torch.manual_seed(31)
model=Model()
attention.REGISTERED_ATTENTION_FUNCTIONS["comfy_kitchen_int8"]=attention.attention_comfy_kitchen_int8
model_patcher.ModelPatcher.set_model_optimized_attention(model,attention.REGISTERED_ATTENTION_FUNCTIONS[BACKEND])
descriptor,safe=s._model_signature(model,"fixture")
assert safe,descriptor["model_options"]
print(s._hash(descriptor))
"""
script = "CORE_ROOT="+repr(core_root)+"\nROOT="+repr(str(ROOT))+"\nBACKEND="+repr(backend)+"\n"+script
results = []
for seed in ("1", "93017"):
result = subprocess.run([sys.executable, "-B", "-c", script],
env={**os.environ, "CUDA_VISIBLE_DEVICES":"-1", "PYTHONHASHSEED":seed},
capture_output=True, text=True, timeout=90)
assert result.returncode == 0, result.stderr + result.stdout
results.append(result.stdout.strip().splitlines()[-1])
assert results[0] == results[1]
def test_unobservable_global_helper_state_stays_unsafe(core_attention, monkeypatch):
attention, _ = core_attention
model = model_with(core_attention, "pytorch")
before, safe = observe(model)
assert safe
scope = vars(attention)
exec("def issue31_helper(*args):\n return ISSUE31_UNOBSERVABLE_STATE", scope)
try:
monkeypatch.setattr(attention, "ISSUE31_UNOBSERVABLE_STATE", object(), raising=False)
monkeypatch.setattr(attention, "_heads_from_dim", scope["issue31_helper"])
after, after_safe = observe(model)
assert after != before and not after_safe
finally:
scope.pop("issue31_helper", None)
def test_fallback_pytorch_implementation_changes_kitchen_identity(core_attention, monkeypatch):
attention, _ = core_attention
model = model_with(core_attention, "comfy_kitchen_int8")
before, safe = observe(model)
assert safe
raw = attention.attention_pytorch.__wrapped__
remake(core_attention, monkeypatch, "pytorch", defaults=(19,) + raw.__defaults__[1:])
after, after_safe = observe(model)
assert after != before
@@ -0,0 +1,328 @@
"""Phase A: real audited KJ wrapper, CPU-only observation and Run Storage gates."""
from __future__ import annotations
import importlib
import json
import os
import sys
import types
from pathlib import Path
import pytest
import torch
from PIL import Image
from ComfyUI_H3_Continuum_Join import preview_override_signature as adapter
from ComfyUI_H3_Continuum_Join import run_storage as storage
from . import test_v31_run_storage as signatures
from . import test_v38_review_run_storage as review
from . import test_issue31_attention_signature as attention
from .test_issue31_attention_signature import core_attention
from .test_issue31_spectrum_signature import spectrum, binding
@pytest.fixture(params=["local", "public"])
def kj(require_comfy_core, request):
root = os.environ.get("H3_KJ_PREVIEW_TEST_ROOT" if request.param == "local" else "H3_KJ_PREVIEW_PUBLIC_TEST_ROOT")
if not root:
pytest.skip("real audited KJ Preview Override provider is not configured")
package = types.ModuleType("issue31_kj_preview_tests_" + request.param)
package.__path__ = [str(Path(root) / "nodes")]
sys.modules[package.__name__] = package
return importlib.import_module(package.__name__ + ".preview_override_node")
def wrapper(kj, **settings):
values = dict(max_resolution=512, node_id="100", jpeg_quality=90,
suppress_default=True, preview_frames=1, preview_fps=12)
values.update(settings)
return kj._PreviewOverrideWrapper(**values)
def model_with(item):
model = signatures._Model()
model.wrappers = {"outer_sample": {"kj_preview_override": [item]}}
return model
def observe(model):
return storage._model_signature(model, "fixture")
def test_no_kj_observer_and_full_sampling_contract_are_exact(monkeypatch):
model = signatures._Model()
model.wrappers = {"outer_sample": {"other": [lambda executor: executor()]}}
current = observe(model)
torch.manual_seed(31016)
clip, vae = signatures._Clip(), signatures._VideoVAE()
contract = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
with monkeypatch.context() as ctx:
ctx.setattr(storage, "observe_model_wrappers", lambda value, observer: observer(value))
assert observe(model) == current
old = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert storage._canonical(contract) == storage._canonical(old)
assert storage.revision_identity(contract[0]) == storage.revision_identity(old[0])
def test_real_provider_frames_and_recreated_wrapper_keep_contract(kj):
item = wrapper(kj)
model = model_with(item)
before = observe(model)
assert before[1], before[0]
clip, vae = signatures._Clip(), signatures._VideoVAE()
original = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert original[1]
for count in (1, 3, 0):
item.frames[:] = [Image.new("RGB", (2, 2)) for _ in range(count)]
frames = item.frames
state = dict(vars(item))
assert observe(model) == before
current = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert current == original
assert vars(item) == state and item.frames is frames
model.wrappers["outer_sample"]["kj_preview_override"] = [wrapper(kj)]
assert observe(model) == before
@pytest.mark.parametrize("setting,value", [("max_resolution", 768), ("node_id", "101"),
("jpeg_quality", 80), ("suppress_default", False), ("preview_frames", 4), ("preview_fps", 24)])
def test_every_fixed_setting_changes_identity(kj, setting, value):
item = wrapper(kj)
before, safe = adapter.preview_override_signature(item)
assert safe, before
setattr(item, setting, value)
after, safe = adapter.preview_override_signature(item)
assert safe and after != before
def test_full_audit_profile_is_part_of_identity(kj, monkeypatch):
item = wrapper(kj)
before, safe = adapter.preview_override_signature(item)
assert safe
# An audit revision must change identity even with the same display ID and
# wrapper source, so dependency-profile upgrades cannot reuse old Takes.
profile, _ = adapter._provider_source(kj.__file__)
monkeypatch.setitem(profile, "audit_revision", 2)
after, safe = adapter.preview_override_signature(item)
assert safe and before["profile"] == after["profile"]
assert before["profile_sha256"] != after["profile_sha256"]
def other_wrapper(executor, *args, **kwargs):
return executor(*args, **kwargs)
def test_key_and_list_execution_order_change_identity(kj):
a, b = wrapper(kj), wrapper(kj, jpeg_quality=80)
model = model_with(a)
model.wrappers["outer_sample"] = {"other": [other_wrapper], "kj_preview_override": [a, b]}
before, safe = observe(model)
assert safe
model.wrappers["outer_sample"] = {"kj_preview_override": [a, b], "other": [other_wrapper]}
after, safe = observe(model)
assert safe and after != before
model.wrappers["outer_sample"]["kj_preview_override"] = [b, a]
reordered, safe = observe(model)
assert safe and reordered != after
@pytest.mark.parametrize("change", ["source", "call_code", "helper_code", "defaults", "class_attribute",
"instance_attribute", "frames_tuple", "frames_subclass", "vae", "audio_vae", "tiny_vae",
"foreign", "subclass", "invalid_setting", "core_factory", "imported_helper_code",
"core_preview_code", "dispatcher_code", "core_tiny_vae"])
def test_unknown_implementations_and_out_of_scope_state_reject_reuse(kj, monkeypatch, change):
item = wrapper(kj)
if change == "source":
profile, _ = adapter._provider_source(kj.__file__)
monkeypatch.setitem(profile, "source_sha256", "f" * 64)
elif change in ("call_code", "helper_code"):
fn = type(item).__call__ if change == "call_code" else kj._normalize_packed_x0
monkeypatch.setattr(fn, "__code__", fn.__code__.replace(co_consts=fn.__code__.co_consts + ("changed",)))
elif change == "defaults":
monkeypatch.setattr(type(item).__init__, "__defaults__", (2, 12, None, "none", None))
elif change == "class_attribute":
monkeypatch.setattr(type(item), "unrecognized", True, raising=False)
elif change == "instance_attribute":
item.unrecognized = True
elif change == "frames_tuple":
item.frames = ()
elif change == "frames_subclass":
class Frames(list):
pass
item.frames = Frames()
elif change in ("vae", "audio_vae"):
setattr(item, change, object())
elif change == "tiny_vae":
item.tiny_vae = "taeh3"
elif change == "foreign":
item = types.SimpleNamespace(**vars(item))
elif change == "subclass":
class Extra(type(item)):
pass
item = Extra(512, "100", 90, True)
elif change == "invalid_setting":
item.preview_frames = True
elif change == "core_factory":
monkeypatch.setattr(kj.latent_preview, "get_previewer", lambda *a: None)
elif change == "core_tiny_vae":
import latent_preview
monkeypatch.setattr(latent_preview.args, "preview_method", latent_preview.LatentPreviewMethod.TAESD)
else:
if change == "imported_helper_code":
fn = kj.load_tiny_vae_decoder
elif change == "core_preview_code":
fn = kj.latent_preview.Latent2RGBPreviewer.decode_latent_to_preview
else:
fn = sys.modules["comfy.patcher_extension"].get_all_wrappers
monkeypatch.setattr(fn, "__code__", fn.__code__.replace(co_consts=fn.__code__.co_consts + ("changed",)))
assert not observe(model_with(item))[1]
def test_unknown_other_wrapper_is_not_promoted(kj):
model = model_with(wrapper(kj))
model.wrappers["outer_sample"]["unknown"] = [torch.nn.Linear(2, 2)]
assert not observe(model)[1]
@pytest.mark.parametrize("items", [None, (), [], object()])
def test_unknown_target_container_is_not_promoted(items):
assert not adapter.observe_model_wrappers({"outer_sample": {"kj_preview_override": items}}, storage._observe)[1]
@pytest.mark.parametrize("container", ["root", "outer", "items"])
def test_observation_limit_rejects_reuse_without_interrupting_generation(container):
wrappers = {"outer_sample": {"kj_preview_override": [object()]}}
if container == "items":
wrappers["outer_sample"]["kj_preview_override"] *= 4097
else:
target = wrappers if container == "root" else wrappers["outer_sample"]
target.update({str(i): [] for i in range(4097)})
result, safe = adapter.observe_model_wrappers(wrappers, storage._observe)
assert not safe and result["unsupported"]
def test_observation_never_executes_provider_or_initializes_cuda(kj, monkeypatch):
item = wrapper(kj)
# Even frame objects whose representation or data cannot be inspected are
# ignored. The exact builtin list is the only permitted transient container.
class UnreadableFrame:
def __repr__(self):
raise AssertionError("frame inspected")
item.frames.append(UnreadableFrame())
def forbidden(*args, **kwargs):
raise AssertionError("signature tried to execute GPU/preview code")
monkeypatch.setattr(torch.cuda, "_lazy_init", forbidden)
# Trace calls instead of patching the audited callable (which must reject).
called = []
watched = {kj._PreviewOverrideWrapper.__call__.__code__, kj._get_core_previewer.__code__,
kj._frame_to_pil.__code__, kj.load_tiny_vae_decoder.__code__}
def trace(frame, event, arg):
if event == "call" and frame.f_code in watched:
called.append(frame.f_code.co_name)
return trace
previous = sys.gettrace()
try:
sys.settrace(trace)
result, safe = observe(model_with(item))
finally:
sys.settrace(previous)
assert safe, result
assert called == [] and not torch.cuda.is_initialized()
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
def test_attention_and_spectrum_combination_is_stable(kj, core_attention, spectrum, backend):
model = attention.model_with(core_attention, backend)
model.model_options["spectrum_h3_binding"] = binding(spectrum)
base, safe = observe(model)
assert safe
item = wrapper(kj)
model.wrappers = {"outer_sample": {"kj_preview_override": [item]}}
before, safe = observe(model)
assert safe
assert before["model_options"] == base["model_options"]
item.frames.append(Image.new("RGB", (2, 2)))
assert observe(model) == (before, safe)
def test_saved_prefix_is_reusable_after_preview_only_change(kj, tmp_path):
item = wrapper(kj)
model = model_with(item)
clip, vae = signatures._Clip(), signatures._VideoVAE()
contract, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert safe
saved = signatures._persist_contract_prefix(tmp_path, contract, count=1)
before = {str(p): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
item.frames.append(Image.new("RGB", (2, 2)))
current, safe, _ = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert safe and storage.revision_identity(current) == storage.revision_identity(contract)
_, entries, records = signatures._load_compatible_prefix(tmp_path, saved, current)
assert len(entries) == len(records) == 1
assert before == {str(p): p.read_bytes() for p in tmp_path.rglob("*") if p.is_file()}
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
def test_old_unsafe_preview_history_is_never_promoted(kj, tmp_path, monkeypatch, entry_point):
item = wrapper(kj)
item.frames.append(Image.new("RGB", (2, 2)))
model = model_with(item)
with monkeypatch.context() as ctx:
ctx.setattr(storage, "observe_model_wrappers", lambda value, observer: observer(value))
old, safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
assert not safe
source = review._persist(tmp_path, old, prefix=1, review_unit=(1, 1), updated_utc="2026-10-16T00:00:00+00:00")
source.manifest["resume_safe"] = False
source.manifest["resume_disabled_reasons"] = reasons
source._write_manifest()
before = {str(p): p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
reader = review._controller(tmp_path, old)
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
assert not storage._reusable_manifest(source.manifest)
if entry_point == "review": assert not reader._load_validated_review_prefix(old, resume_safe=True).entries
elif entry_point == "head": assert reader.find_latest_review_head(old, resume_safe=True) is None
elif entry_point == "import": assert reader._find_plan_import(old, resume_safe=True) is None
elif entry_point == "compatible": assert reader._compatible_plan_prefix(source.manifest, old, resume_safe=True) == ([], [])
else:
reader.take_group = 1
reader.take_revision_id = review._project(source)["canonical_head_revision_id"]
with pytest.raises(storage.RunStorageError, match="read-only"):
reader._validated_take_selection(old, resume_safe=True)
assert before == {str(p): p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
def test_other_profile_registration_does_not_change_identity(kj, monkeypatch):
item = wrapper(kj)
before, safe = adapter.preview_override_signature(item)
assert safe
active, _ = adapter._provider_source(kj.__file__)
monkeypatch.setattr(adapter, "_PROFILES", (active,))
assert adapter.preview_override_signature(item) == (before, True)
monkeypatch.setattr(adapter, "_PROFILES", (active, dict(active, source_sha256="e" * 64)))
assert adapter.preview_override_signature(item) == (before, True)
monkeypatch.setattr(adapter, "_PROFILES", (active, active))
assert not adapter.preview_override_signature(item)[1]
@pytest.mark.parametrize("contents", [None, "invalid json", "null", "[]", "{}"])
def test_missing_or_malformed_optional_profile_does_not_break_existing_paths(tmp_path, contents):
path = tmp_path / "public.json"
if contents is not None:
path.write_text(contents, encoding="utf-8")
assert adapter._load_public_profile(path) is None
model = signatures._Model()
assert observe(model)[1]
@pytest.mark.parametrize("field", ["id", "source_sha256"])
def test_optional_profile_collision_cannot_disable_original_profile(kj, tmp_path, monkeypatch, field):
candidate = dict(adapter._PUBLIC_PROFILE)
candidate[field] = adapter._PROFILE[field]
path = tmp_path / "public.json"
path.write_text(json.dumps(candidate), encoding="utf-8")
loaded = adapter._load_public_profile(path)
assert loaded is None
monkeypatch.setattr(adapter, "_PROFILES", (adapter._PROFILE,))
item = wrapper(kj)
expected = "_local." in kj.__name__
assert adapter.preview_override_signature(item)[1] is expected
assert observe(signatures._Model())[1]
+329
View File
@@ -0,0 +1,329 @@
from __future__ import annotations
import ast
import dataclasses
import hashlib
import importlib
import json
import os
import subprocess
import sys
import types
from pathlib import Path
import pytest
import torch
from ComfyUI_H3_Continuum_Join import run_storage as storage
from ComfyUI_H3_Continuum_Join import spectrum_signature as adapter
from . import test_issue31_attention_signature as attention_tests
from .test_issue31_attention_signature import core_attention
from . import test_v31_run_storage as signatures
from . import test_v38_review_run_storage as review
@pytest.fixture(params=["local", "public029"])
def spectrum(require_comfy_core, request):
root = os.environ.get("H3_SPECTRUM_TEST_ROOT" if request.param == "local" else "H3_SPECTRUM_PUBLIC_TEST_ROOT")
if not root:
pytest.skip("real audited Spectrum checkout is not configured")
package = types.ModuleType("issue31_spectrum_tests_" + request.param)
package.__path__ = [root]
sys.modules[package.__name__] = package
prefix = package.__name__ + ".comfyui_spectrum_h3"
sampling = importlib.import_module(prefix + ".sampling")
runtime = importlib.import_module(prefix + ".runtime")
config = importlib.import_module(prefix + ".config")
return sampling, runtime, config
def binding(spectrum, **settings):
sampling, runtime, config = spectrum
return sampling.SpectrumH3Binding(runtime.SpectrumH3Runtime(config.SpectrumH3Config(**settings)))
def signature(value):
result, safe = adapter.spectrum_binding_signature(value)
assert safe, result.get("unsupported")
return result
def test_recreated_runtime_and_transient_history_keep_identity(spectrum):
a, b = binding(spectrum), binding(spectrum)
before = signature(a)
assert signature(b) == before
a.runtime._run_counter += 8
a.runtime._consecutive_forecasts = 3
a.runtime._current_window = 3.25
a.runtime.forecaster.update(0.0, torch.arange(12, dtype=torch.float32).reshape(1,12))
a.runtime.forecaster.update(1.0, torch.arange(12, dtype=torch.float32).reshape(1,12) + 1)
a.runtime.model_aware.anchor_count = 7
a.runtime.stats.current_window = 4.0
assert signature(a) == before
CHANGES = {
"enabled": {"enabled": False}, "blend_weight": {"blend_weight": 0.6},
"degree": {"degree": 2, "bootstrap_first_forecast": False},
"ridge_lambda": {"ridge_lambda": 0.2}, "window_size": {"window_size": 3.0},
"flex_window": {"flex_window": 1.0},
"warmup_steps": {"warmup_steps": 2, "bootstrap_first_forecast": False},
"tail_actual_steps": {"tail_actual_steps": 2}, "max_history": {"max_history": 9},
"history_storage": {"history_storage": "vram"}, "debug": {"debug": True},
"force_actual": {"force_actual": True},
"bootstrap_first_forecast": {"bootstrap_first_forecast": False},
"anchor_residual_feedback": {"anchor_residual_feedback": True, "offline_smoothing_replay": False},
"selective_rollback_correction": {"selective_rollback_correction": True, "offline_smoothing_replay": False},
"offline_smoothing_replay": {"offline_smoothing_replay": False},
"audio_blend_weight": {"audio_blend_weight": 0.1},
"offline_archive_storage": {"offline_archive_storage": "vram"},
"model_aware_mode": {"model_aware_mode": "full"},
"model_aware_risk_threshold": {"model_aware_risk_threshold": 0.5},
"model_aware_trust_shrinkage": {"model_aware_mode": "full", "model_aware_trust_shrinkage": True},
"model_aware_replay_generic_correction": {"model_aware_replay_generic_correction": True},
"generic_correction_mode": {"generic_correction_mode": "legacy"},
"generic_correction_limiter": {"generic_correction_limiter": "tanh"},
"generic_correction_limit": {"generic_correction_limit": 0.3},
"generic_correction_attenuation": {"generic_correction_attenuation": "general_confidence"},
"sa_pece_forecast_policy": {"sa_pece_forecast_policy": "stable_start"},
}
@pytest.mark.parametrize("field", sorted(CHANGES))
def test_every_config_field_changes_identity(spectrum, field):
before = signature(binding(spectrum))
changed = signature(binding(spectrum, **CHANGES[field]))
assert set(before["config"]) == set(CHANGES) == set(adapter.CONFIG_FIELDS)
assert before != changed and before["config"][field] != changed["config"][field]
@pytest.mark.parametrize("change", ["runtime_code", "wrapper_code", "wrapper_closure", "class_attribute", "source_digest"])
def test_implementation_changes_are_rejected(spectrum, monkeypatch, change):
item = binding(spectrum)
signature(item)
if change == "runtime_code":
old = spectrum[1].SpectrumH3Runtime.__init__
monkeypatch.setattr(old, "__code__", old.__code__.replace(co_consts=old.__code__.co_consts + ("changed",)))
elif change == "wrapper_code":
old = spectrum[0].outer_sample_wrapper
monkeypatch.setattr(old, "__code__", old.__code__.replace(co_consts=old.__code__.co_consts + ("changed",)))
elif change == "wrapper_closure":
old = spectrum[0].run_selective_rollback_euler
assert old.__closure__
cells = list(old.__closure__)
cells[0] = (lambda value: lambda: value)(object()).__closure__[0]
changed = types.FunctionType(old.__code__, old.__globals__, old.__name__, old.__defaults__, tuple(cells))
changed.__module__, changed.__qualname__ = old.__module__, old.__qualname__
monkeypatch.setattr(spectrum[0], "run_selective_rollback_euler", changed)
elif change == "class_attribute":
monkeypatch.setattr(spectrum[1].SpectrumH3Runtime, "extra_contract", 1, raising=False)
else:
source, _ = adapter._select_source_profile(Path(spectrum[0].__file__).resolve().parent)
monkeypatch.setitem(source, "sampling.py", "f" * 64)
after, safe = adapter.spectrum_binding_signature(item)
assert not safe and after.get("unsupported")
@pytest.mark.parametrize("change", ["foreign_binding", "binding_subclass", "runtime_extra", "component_extra", "component_setting", "nan_config", "stats_replaced", "missing_runtime_field"])
def test_unknown_binding_and_additional_state_are_not_promoted(spectrum, change):
item = binding(spectrum)
if change == "foreign_binding":
@dataclasses.dataclass(slots=True)
class SpectrumH3Binding:
runtime: object
item = SpectrumH3Binding(item.runtime)
elif change == "binding_subclass":
class ExtraBinding(type(item)):
pass
item = ExtraBinding(item.runtime)
elif change == "runtime_extra":
item.runtime.unrecognized = object()
elif change == "component_extra":
item.runtime.forecaster.unrecognized = 1
elif change == "component_setting":
item.runtime.forecaster.degree += 1
elif change == "stats_replaced":
item.runtime.stats = object()
elif change == "missing_runtime_field":
del item.runtime._run_counter
else:
object.__setattr__(item.runtime.config, "blend_weight", float("nan"))
assert adapter.spectrum_binding_signature(item)[1] is False
@pytest.mark.parametrize("backend", ["pytorch", "comfy_kitchen_int8"])
def test_attention_and_spectrum_remain_clone_stable(core_attention, spectrum, backend):
model = attention_tests.model_with(core_attention, backend)
original = attention_tests.observe(model)
model.model_options["spectrum_h3_binding"] = binding(spectrum)
combined = attention_tests.observe(model)
assert original[1] and combined[1]
assert combined[0]["model_options"]["transformer_options"] == original[0]["model_options"]["transformer_options"]
model.model_options["spectrum_h3_binding"] = binding(spectrum)
assert attention_tests.observe(model) == combined
@pytest.mark.parametrize("backend", [None, "pytorch", "comfy_kitchen_int8"])
def test_spectrum_absent_preserves_full_phase1_descriptor(core_attention, monkeypatch, backend):
model = signatures._Model() if backend is None else attention_tests.model_with(core_attention, backend)
current = attention_tests.observe(model)
old = storage._observe_attention_model_options(model.model_options)
assert storage._observe_model_options(model.model_options) == old
# Independent Phase 1 implementation is frozen in the reviewed test fixture.
source = (Path(__file__).parent / "fixtures" / "issue31_phase1_model_options.py.txt").read_text()
scope = dict(vars(storage))
exec(compile(source, "phase1_options_fixture", "exec"), scope)
before = scope["_observe_model_options"](model.model_options)
assert before == old
torch.manual_seed(315)
clip, vae = signatures._Clip(), signatures._VideoVAE()
contract, safe, reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
with monkeypatch.context() as context:
context.setattr(storage, "_observe_model_options", scope["_observe_model_options"])
previous, previous_safe, previous_reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae, reroll_from_chunk=0)
assert safe == previous_safe and reasons == previous_reasons
assert storage._canonical(contract) == storage._canonical(previous)
assert storage.revision_identity(contract) == storage.revision_identity(previous)
@pytest.mark.parametrize("entry_point", ["review", "head", "import", "compatible", "take"])
def test_old_unsafe_spectrum_history_is_unmodified(tmp_path, core_attention, spectrum, monkeypatch, entry_point):
model = attention_tests.model_with(core_attention, "pytorch")
model.model_options["spectrum_h3_binding"] = binding(spectrum)
with monkeypatch.context() as ctx:
ctx.setattr(storage, "_observe_model_options", storage._observe_attention_model_options)
old, safe, reasons = signatures._sampling_contract(model=model, reroll_from_chunk=0)
assert not safe and reasons
source = review._persist(tmp_path, old, prefix=1, review_unit=(1,1), updated_utc="2026-10-15T00:00:00+00:00")
source.manifest["resume_safe"] = False
source.manifest["resume_disabled_reasons"] = reasons
source._write_manifest()
before = {str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
current, current_safe, _ = signatures._sampling_contract(model=model, reroll_from_chunk=0)
assert current_safe and storage.revision_identity(current) != storage.revision_identity(old)
reader = review._controller(tmp_path, old)
reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW, review_action=review.REVIEW_ACTION_CONTINUE)
assert not storage._reusable_manifest(source.manifest)
if entry_point == "review": assert not reader._load_validated_review_prefix(old,resume_safe=True).entries
elif entry_point == "head": assert reader.find_latest_review_head(old,resume_safe=True) is None
elif entry_point == "import": assert reader._find_plan_import(old,resume_safe=True) is None
elif entry_point == "compatible": assert reader._compatible_plan_prefix(source.manifest,old,resume_safe=True)==([],[])
else:
reader.take_group=1;reader.take_revision_id=review._project(source)["canonical_head_revision_id"]
with pytest.raises(storage.RunStorageError,match="read-only"):reader._validated_take_selection(old,resume_safe=True)
assert before=={str(p):p.read_bytes() for p in source.run_root.rglob("*") if p.is_file()}
def test_imports_and_profile_cache_do_not_change_identity(spectrum, monkeypatch):
item=binding(spectrum);before=signature(item)
prefix=spectrum[0].__name__.rsplit('.',1)[0]
importlib.import_module(prefix+'.experiments')
aware=importlib.import_module(prefix+'.model_aware')
monkeypatch.setitem(aware._PROFILE_CACHE,('temporary',),object())
assert signature(item)==before
def test_imported_original_implementation_changes_are_rejected(spectrum, monkeypatch):
item=binding(spectrum);signature(item)
module=importlib.import_module(spectrum[0].__name__.rsplit('.',1)[0]+'.generic_correction')
old=module._ORIGINAL_FORECASTER_UPDATE
changed=types.FunctionType(old.__code__.replace(co_consts=old.__code__.co_consts+('changed imported original',)),old.__globals__,old.__name__,old.__defaults__,old.__closure__)
changed.__module__,changed.__qualname__=old.__module__,old.__qualname__
monkeypatch.setattr(module,'_ORIGINAL_FORECASTER_UPDATE',changed)
assert adapter.spectrum_binding_signature(item)[1] is False
@pytest.mark.parametrize('backend',['pytorch','comfy_kitchen_int8'])
def test_spectrum_same_settings_reuse_and_changed_settings_reject(tmp_path,core_attention,spectrum,backend):
model=attention_tests.model_with(core_attention,backend)
model.model_options['spectrum_h3_binding']=binding(spectrum)
torch.manual_seed(315);clip,vae=signatures._Clip(),signatures._VideoVAE()
contract,safe,_=signatures._sampling_contract(model=model,clip=clip,video_vae=vae,reroll_from_chunk=0);assert safe
source=review._persist(tmp_path,contract,prefix=1,review_unit=(1,1),updated_utc='2026-10-15T00:00:00+00:00')
before={str(p):p.read_bytes() for p in source.run_root.rglob('*') if p.is_file()}
reader=review._controller(tmp_path,contract);reader.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,review_action=review.REVIEW_ACTION_CONTINUE)
assert len(reader._load_validated_review_prefix(contract,resume_safe=True).entries)==1
model.model_options['spectrum_h3_binding']=binding(spectrum,blend_weight=0.6)
changed,changed_safe,_=signatures._sampling_contract(model=model,clip=clip,video_vae=vae,reroll_from_chunk=0);assert changed_safe
other=review._controller(tmp_path,changed);other.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,review_action=review.REVIEW_ACTION_CONTINUE)
assert not other._load_validated_review_prefix(changed,resume_safe=True).entries
assert before=={str(p):p.read_bytes() for p in source.run_root.rglob('*') if p.is_file()}
def test_signature_stable_across_processes_and_module_aliases(spectrum,core_attention):
root=str(Path(spectrum[0].__file__).resolve().parents[1])
core_root=str(Path(core_attention[1].__file__).resolve().parents[1])
adapter_path=str(Path(adapter.__file__).resolve())
script=r"""
import os,sys,types,importlib,importlib.util,json,hashlib
os.environ['CUDA_VISIBLE_DEVICES']='-1'
sys.path.insert(0,CORE_ROOT)
import torch
torch.cuda._lazy_init=lambda: (_ for _ in ()).throw(RuntimeError('CUDA forbidden'))
from comfy.cli_args import args
args.cpu=True
package=types.ModuleType('process_alias_'+os.environ['PYTHONHASHSEED']);package.__path__=[PROVIDER_ROOT];sys.modules[package.__name__]=package
prefix=package.__name__+'.comfyui_spectrum_h3'
s=importlib.import_module(prefix+'.sampling');r=importlib.import_module(prefix+'.runtime');c=importlib.import_module(prefix+'.config')
spec=importlib.util.spec_from_file_location('process_adapter',ADAPTER_FILE);a=importlib.util.module_from_spec(spec);spec.loader.exec_module(a)
value,safe=a.spectrum_binding_signature(s.SpectrumH3Binding(r.SpectrumH3Runtime(c.SpectrumH3Config())))
assert safe,value.get('unsupported')
print(hashlib.sha256(json.dumps(value,sort_keys=True,separators=(',',':')).encode()).hexdigest())
"""
script=script.replace('CORE_ROOT',repr(core_root)).replace('PROVIDER_ROOT',repr(root)).replace('ADAPTER_FILE',repr(adapter_path))
outputs=[]
for seed in ('13','71'):
env=dict(os.environ,PYTHONHASHSEED=seed,PYTHONDONTWRITEBYTECODE='1')
output=subprocess.check_output([sys.executable,'-c',script],env=env,text=True)
outputs.append(output.strip().splitlines()[-1])
assert outputs[0]==outputs[1]
def test_core_node_registration_location_is_not_generation_identity(spectrum,monkeypatch):
item=binding(spectrum);before=signature(item)
prefix=spectrum[0].__name__.rsplit('.',1)[0]
for suffix in ['nodes','objective_media_nodes']:
module=importlib.import_module(prefix+'.'+suffix)
for cls in module.NODE_CLASS_MAPPINGS.values():
monkeypatch.setattr(cls,'RELATIVE_PYTHON_MODULE','custom_nodes.test_location',raising=False)
assert signature(item)==before
def test_original_local_profile_descriptor_is_unchanged(spectrum):
item=binding(spectrum)
source, _ = adapter._select_source_profile(Path(spectrum[0].__file__).resolve().parent)
if source is not adapter.SUPPORTED_SOURCE:
pytest.skip("original descriptor fixture covers the pre-existing local profile")
scope={"__file__":adapter.__file__}
fixture=Path(__file__).parent/"fixtures"/"issue31_local_spectrum_signature.py.txt"
exec(compile(fixture.read_text(),str(fixture),"exec"),scope)
previous = scope["spectrum_binding_signature"](item)
current = adapter.spectrum_binding_signature(item)
if sys.version_info[:2] == (3, 13):
assert previous == current
else:
# Python 3.12 was never accepted by the original 3.13-only profile.
# New support changes current observation, never a stored unsafe Take.
assert sys.version_info[:2] == (3, 12)
assert previous[1] is False and current[1] is True
def test_foreign_provider_file_set_stays_unsafe(tmp_path):
(tmp_path/"unknown.py").write_text("pass")
with pytest.raises(ValueError,match="unsupported provider source set"):
adapter._select_source_profile(tmp_path)
def test_foreign_module_closure_is_rejected():
with pytest.raises(ValueError, match="unsupported provider module closure"):
adapter._callable_value(types.ModuleType("foreign_provider"),provider_prefix="known.comfyui_spectrum_h3")
def test_unloaded_module_cannot_impersonate_provider():
with pytest.raises(ValueError, match="provider module closure is not loaded"):
adapter._callable_value(types.ModuleType("known.comfyui_spectrum_h3.runtime"),provider_prefix="known.comfyui_spectrum_h3")
def test_loaded_implementation_profiles_are_packaged():
root=Path(adapter.__file__).parent
for filename in ["spectrum_provider_v1.json","spectrum_provider_v029.json"]:
assert json.loads((root/filename).read_text())["format"]=="audited_spectrum_loaded_implementation_v1"
assert len(adapter.SUPPORTED_SOURCE)==44 and len(adapter.PUBLIC_SOURCE_029)==55
+162
View File
@@ -0,0 +1,162 @@
"""Saved reason projection and real-provider Review continuation, CPU only."""
import copy
import hashlib
import json
from pathlib import Path
import pytest
import torch
from ComfyUI_H3_Continuum_Join import run_storage as storage
from ComfyUI_H3_Continuum_Join import preview_override_signature as adapter
from . import test_v31_run_storage as signatures
from . import test_v38_review_run_storage as review
from .test_issue31_preview_override_signature import kj, wrapper, model_with
def prepare_kwargs(model):
return dict(model=model, model_fingerprint_value="f" * 64, clip=signatures._Clip(),
video_vae=signatures._VideoVAE(), sampler=signatures._Sampler(), sigmas=torch.tensor([1., 0.]),
prompt_plan={"chunks": 3, "hashes": [str(i) * 64 for i in (1, 2, 3)],
"mode": "list", "prompts": ["prompt 1", "prompt 2", "prompt 3"]},
width=96, height=64, chunk_seconds=5., continuity="Balanced", audio_continuity=True,
base_seed=1, reroll_from_chunk=0, reroll_nonce=0, first_frame_hash="a" * 64,
last_frame_hash="", identity_hash="fixture", strict_compatibility=True,
existing_session=None, conditioning_mode="i2va")
def controller_at(path):
controller = storage.RunStorageController("preview-reuse-test")
controller.run_root = path
controller.revisions_root = path / "revisions"
controller.set_prompt_graph(signatures._prompt_graph(), "42")
controller.configure_review(generation_mode=review.GENERATION_MODE_REVIEW,
review_action=review.REVIEW_ACTION_CONTINUE)
return controller
@pytest.mark.parametrize("setting", [None, "vae", "audio_vae", "tiny_vae"])
def test_real_provider_saved_take_and_separate_controller_continue(kj, tmp_path, setting):
item = wrapper(kj)
if setting is not None:
setattr(item, setting, "taeh3" if setting == "tiny_vae" else object())
kwargs = prepare_kwargs(model_with(item))
source = controller_at(tmp_path)
source.prepare(**kwargs)
entry = review._entry(0, source.contract)
source.commit_group((entry,), positions=(0,))
source.mark_review_group(start=1, end=1, physical_group=1)
source.finalize(session={"session_id": "fixture", "chunks": [entry]}, report="CPU fixture",
review_pause_metadata=source.review_pause_metadata())
project = review._project(source)
take = project["group_revisions"][0]
expected_safe = setting is None
assert take["generation_reusable"] is expected_safe
assert take["sampling_contract_version"] == 6
if expected_safe:
assert "resume_disabled_reasons" not in take
else:
expected = "KJ preview VAE/Audio VAE or Tiny VAE is outside the supported configuration"
assert expected in source.manifest["resume_disabled_reasons"]
assert expected in take["resume_disabled_reasons"]
assert take["resume_disabled_reasons"] == project["revisions"][0]["resume_disabled_reasons"]
original_raw = {str(p): hashlib.sha256(p.read_bytes()).hexdigest() for p in tmp_path.rglob("*.safetensors")}
original_identity = storage.revision_identity(source.contract)
item.frames.append(object())
again = controller_at(tmp_path)
session = again.prepare(**kwargs)
assert again.reused_count == int(expected_safe)
assert len((session or {}).get("chunks", [])) == int(expected_safe)
assert again.review_execution.next_review_unit_start == (2 if expected_safe else 1)
if expected_safe:
assert storage.revision_identity(again.contract) == original_identity
assert original_raw and all(hashlib.sha256(Path(p).read_bytes()).hexdigest() == digest
for p, digest in original_raw.items())
@pytest.mark.parametrize("failure,expected", [
("provider source is outside the audited profile", "KJ/Core preview implementation is outside the audited source profiles"),
("Core approximate VAE is outside Phase A", "Core approximate-VAE preview is outside the supported configuration"),
("loaded code differs from audited source", "KJ preview runtime code or state could not be verified"),
("private /local/path exception", "KJ preview runtime code or state could not be verified"),
])
def test_reason_classification_uses_only_observed_slot(failure, expected):
descriptor = {"wrappers": {"outer_sample": {"kj_preview_override": [
{"adapter": "kj_preview_override_v1", "unsupported": failure}]}}}
before = copy.deepcopy(descriptor)
assert adapter.preview_override_reuse_reasons(descriptor) == [expected]
assert descriptor == before
assert adapter.preview_override_reuse_reasons({"other": descriptor}) == []
def test_reasons_do_not_enter_sampling_identity(kj, monkeypatch):
item = wrapper(kj)
item.tiny_vae = "taeh3"
model, clip, vae = model_with(item), signatures._Clip(), signatures._VideoVAE()
original, safe, reasons = signatures._sampling_contract(model=model, clip=clip, video_vae=vae)
assert not safe and any(reason in adapter.PREVIEW_REUSE_REASONS for reason in reasons)
monkeypatch.setattr(storage, "preview_override_reuse_reasons", lambda descriptor: [])
current, safe, generic = signatures._sampling_contract(model=model, clip=clip, video_vae=vae)
assert not safe and len(generic) < len(reasons)
assert storage._canonical(original) == storage._canonical(current)
assert storage.revision_identity(original) == storage.revision_identity(current)
def test_projection_sanitizes_and_omits_safe_or_missing_reasons():
contract, safe, _ = signatures._sampling_contract(reroll_from_chunk=0)
assert safe
manifest = {"sampling_contract_version": 6, "resume_safe": True, "contract": contract,
"resume_disabled_reasons": list(adapter.PREVIEW_REUSE_REASONS)}
assert storage._project_resume_diagnostics(manifest) == {}
manifest["resume_safe"] = False
private = "C:/Users/private/file.py" + "x" * 2000
manifest["resume_disabled_reasons"] = [private] * 12
projected = storage._project_resume_diagnostics(manifest)["resume_disabled_reasons"]
assert projected == [storage._UNKNOWN_REUSE_REASON]
assert private not in json.dumps(projected) and max(map(len, projected)) <= 256
manifest.pop("resume_disabled_reasons")
assert storage._project_resume_diagnostics(manifest) == {}
def test_project_reason_belongs_to_its_saved_revision(tmp_path):
contract, safe, _ = signatures._sampling_contract(reroll_from_chunk=0)
assert safe
source = review._persist(tmp_path, contract, prefix=1, review_unit=(1, 1),
updated_utc="2026-10-19T00:00:00+00:00")
source.manifest["resume_safe"] = False
source.manifest["resume_disabled_reasons"] = ["KJ preview runtime code or state could not be verified"]
source._write_manifest()
manifest_before = source._manifest_path().read_bytes()
source._write_project()
project = review._project(source)
assert project["group_revisions"][0]["resume_disabled_reasons"] == source.manifest["resume_disabled_reasons"]
assert source._manifest_path().read_bytes() == manifest_before
@pytest.mark.parametrize("display_id", [None, "display-node"])
def test_public_node_uses_core_hidden_display_id(kj, monkeypatch, display_id):
has_display_mapping = "dynprompt" in kj.ModelPreviewOverrideKJ.execute.__code__.co_names
from comfy_api.latest import io
# Full-suite helpers can put the plugin ahead of Core; both contain nodes.py.
core_root = Path(kj.latent_preview.__file__).resolve().parent
monkeypatch.syspath_prepend(str(core_root))
from comfy_execution.graph import DynamicPrompt
import nodes as core_nodes
assert Path(core_nodes.__file__).resolve() == core_root / "nodes.py"
node_class = kj.ModelPreviewOverrideKJ
dynprompt = None
if display_id is not None:
dynprompt = DynamicPrompt({display_id: {}})
dynprompt.add_ephemeral_node("generated-node", {}, display_id, display_id)
hidden = io.HiddenHolder.from_dict({io.Hidden.unique_id: "generated-node", io.Hidden.dynprompt: dynprompt})
monkeypatch.setattr(node_class, "hidden", hidden)
class Model:
def clone(self):
return self
def add_wrapper_with_key(self, kind, key, value):
self.wrapper = value
model = Model()
node_class.execute(model, 512, 80, True, 1, 12)
assert model.wrapper.node_id == ((display_id or "generated-node") if has_display_mapping else "generated-node")
assert adapter.preview_override_signature(model.wrapper)[1]
+13
View File
@@ -0,0 +1,13 @@
import pytest
@pytest.mark.parametrize("case", [
"v6 read-only reports saved preview source and keeps actions disabled",
"preview setting remedies preserve generation VAE guidance",
"missing compatibility metadata is not mislabeled v5 or a known KJ error",
"unknown saved reasons do not expose paths or unbounded text",
"history reasons follow the selected Take rather than the canonical revision",
"saved compatibility metadata controls Review with optional real backend vectors",
])
def test_readonly_reason_with_real_frontend(review_queue_results, case):
assert review_queue_results[case]["pass"]
+1 -1
View File
@@ -6,7 +6,7 @@ import tomllib
ROOT = Path(__file__).resolve().parents[1]
EXPECTED_VERSION = "3.9.4"
EXPECTED_VERSION = "3.9.10"
def test_v35_release_metadata_is_consistent():
-124
View File
@@ -1,124 +0,0 @@
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 @image2."}]},
{"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
def test_builder_routes_references_mentioned_anywhere_in_each_chunk_prompt():
value = {
"clips": [
{"slots": [{"start": 0, "end": 4, "text": "The subject walks."}]},
{"slots": [{"start": 0, "end": 4, "text": "The subject stops."}]},
]
}
result = DumasH3SequencePromptBuilder().build(
2,
4,
"Preserve the environment from @R1.",
json.dumps(value),
"Use ambience from @R2.",
"Music follows @R3.",
reference_image_1=object(),
reference_image_2=object(),
reference_image_3=object(),
)
assert result[3].selectors[:3] == ("1,2", "1,2", "1,2")
+104
View File
@@ -0,0 +1,104 @@
"""Preserve audited Spectrum identity across harmless newline/runtime differences."""
from __future__ import annotations
import hashlib
import importlib
import json
from pathlib import Path
import sys
import types
import pytest
from ComfyUI_H3_Continuum_Join import spectrum_signature as adapter
from .test_issue31_spectrum_signature import binding, signature, spectrum
def _relocate_provider(spectrum, tmp_path, monkeypatch, *, crlf=False):
folder = Path(spectrum[0].__file__).resolve().parent
for path in folder.glob("*.py"):
data = path.read_bytes()
if crlf:
data = data.replace(b"\r\n", b"\n").replace(b"\n", b"\r\n")
(tmp_path / path.name).write_bytes(data)
prefix = spectrum[0].__name__.rsplit(".", 1)[0]
for name, module in tuple(sys.modules.items()):
if name == prefix or name.startswith(prefix + "."):
original = getattr(module, "__file__", None)
if original and Path(original).resolve().parent == folder:
monkeypatch.setattr(module, "__file__", str(tmp_path / Path(original).name))
return prefix
def test_source_digest_normalizes_only_crlf(tmp_path):
path = tmp_path / "provider.py"
source = b"def value():\n return 'unchanged'\n"
path.write_bytes(source)
expected = hashlib.sha256(source).hexdigest()
assert adapter._source_digest(path) == expected
path.write_bytes(source.replace(b"\n", b"\r\n"))
assert adapter._source_digest(path) == expected
path.write_bytes(source.replace(b"unchanged", b"changed"))
assert adapter._source_digest(path) != expected
@pytest.mark.parametrize("newlines", ["all", "one"])
def test_crlf_preserves_full_existing_descriptor(spectrum, tmp_path, monkeypatch, newlines):
item = binding(spectrum)
before = signature(item)
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=newlines == "all")
if newlines == "one":
path = tmp_path / "config.py"
path.write_bytes(path.read_bytes().replace(b"\r\n", b"\n").replace(b"\n", b"\r\n"))
assert signature(item) == before
def test_module_closure_crlf_keeps_original_digest(spectrum, tmp_path, monkeypatch):
prefix = spectrum[0].__name__.rsplit(".", 1)[0]
module = importlib.import_module(prefix + ".runtime")
before = adapter._callable_value(module, provider_prefix=prefix)
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=True)
assert adapter._callable_value(module, provider_prefix=prefix) == before
@pytest.mark.parametrize("change", ["code", "extra_file"])
def test_real_source_changes_remain_unsafe(spectrum, tmp_path, monkeypatch, change):
item = binding(spectrum)
signature(item)
_relocate_provider(spectrum, tmp_path, monkeypatch, crlf=True)
if change == "code":
path = tmp_path / "config.py"
path.write_bytes(path.read_bytes() + b"\nUNKNOWN_ADDITIONAL_SETTING = True\n")
else:
(tmp_path / "unimported_helper.py").write_text("pass\n", encoding="utf-8")
descriptor, safe = adapter.spectrum_binding_signature(item)
assert not safe and descriptor.get("unsupported")
@pytest.mark.parametrize("version,suffix", [((3, 12, 10), "_py312"), ((3, 13, 12), "")])
def test_runtime_selects_explicit_audited_profile(monkeypatch, version, suffix):
monkeypatch.setattr(adapter, "sys", types.SimpleNamespace(version_info=version))
for name in ("spectrum_provider_v1.json", "spectrum_provider_v029.json"):
assert adapter._runtime_metadata_file(name) == Path(name).stem + suffix + ".json"
@pytest.mark.parametrize("version", [(3, 10, 0), (3, 11, 0), (3, 14, 0)])
def test_unaudited_python_runtime_stays_unsafe(monkeypatch, version):
monkeypatch.setattr(adapter, "sys", types.SimpleNamespace(version_info=version))
with pytest.raises(ValueError, match="unsupported provider Python runtime"):
adapter._runtime_metadata_file("spectrum_provider_v029.json")
def test_original_py313_profile_bytes_and_new_profile_packaging():
root = Path(adapter.__file__).parent
original = {
"spectrum_provider_v1.json": "0efc8d65cb6f59042457ad843fe1b77a4bee45e59d3732f5c83fbc75a31ae77b",
"spectrum_provider_v029.json": "8f786989af6339be8cec8f2bf602da89344cf96202d29c980af5c07175eea3d3",
}
for name, digest in original.items():
assert hashlib.sha256((root / name).read_bytes()).hexdigest() == digest
old = json.loads((root / name).read_text(encoding="utf-8"))
current = json.loads((root / (Path(name).stem + "_py312.json")).read_text(encoding="utf-8"))
assert old["format"] == current["format"] == "audited_spectrum_loaded_implementation_v1"
assert set(old["modules"]) == set(current["modules"])
assert old != current
-125
View File
@@ -1,125 +0,0 @@
import importlib.util
import pathlib
import unittest
MODULE_PATH = pathlib.Path(__file__).parents[1] / "v3" / "tiled_latent_upscale_nodes.py"
SPEC = importlib.util.spec_from_file_location("h3_tiled_test", MODULE_PATH)
MODULE = importlib.util.module_from_spec(SPEC)
assert SPEC.loader is not None
SPEC.loader.exec_module(MODULE)
class FakeSamples:
def __init__(self, shape):
self.shape = shape
self.ndim = len(shape)
class FakeNoise:
def get_noise(self, seed):
return ("noise", seed)
class FakeSampler:
def get_sampler(self, name):
return ("sampler", name)
class FakeScheduler:
def get_sigmas(self, model, scheduler, steps, denoise):
return ("sigmas", scheduler, steps, denoise)
class FakeNodeOutput:
def __init__(self, *args):
self.result = args
class FakeUpscale:
FUNCTION = "execute"
calls = []
def execute(self, **kwargs):
if "value" in kwargs:
return ({"samples": FakeSamples((1, 16, kwargs["value"], 1, 1))},)
self.calls.append(kwargs)
source = kwargs["latent"]["samples"]
_, _, frames, height, width = source.shape
return ({"samples": FakeSamples((1, 16, frames, height * 2, width * 2))},)
class TiledUpscaleTests(unittest.TestCase):
def setUp(self):
self.original = MODULE._native_node
FakeUpscale.calls = []
MODULE._native_node = lambda name: {
"MMH3UltimateUpscale": FakeUpscale,
"RandomNoise": FakeNoise,
"KSamplerSelect": FakeSampler,
"BasicScheduler": FakeScheduler,
}.get(name)
def tearDown(self):
MODULE._native_node = self.original
def test_each_clip_is_upscaled_independently(self):
node = MODULE.H3ContinuumTiledLatentUpscalePerClip()
clips = [
{"samples": FakeSamples((1, 16, 85, 48, 84))},
{"samples": FakeSamples((1, 16, 141, 48, 84))},
]
outputs, report = node.upscale(
model=["model"], clip=["clip"], video_latents=clips,
assembly_plan=["plan"], refine_context=["context"],
latent_upscale_param=["upscale"], spatial_split_param=["spatial"],
upscale_sampler=["euler"], upscale_scheduler=["simple"],
upscale_steps=[3], upscale_denoise=[0.2], upscale_cfg=[1.0],
upscale_noise_seed=[100], conditioning=["conditioning"],
)
self.assertEqual(len(outputs), 2)
self.assertEqual([call["latent"] for call in FakeUpscale.calls], clips)
self.assertEqual([call["noise"] for call in FakeUpscale.calls], [("noise", 100), ("noise", 101)])
self.assertIn("clips=2", report)
def test_native_function_name_is_taken_from_comfy_contract(self):
result = MODULE._call_native(FakeUpscale, {"value": 7})
self.assertEqual(result[0]["samples"].shape, (1, 16, 7, 1, 1))
def test_node_output_wrapper_is_unwrapped_for_single_values(self):
self.assertEqual(
MODULE._unwrap_single_output(FakeNodeOutput("tensor"), "schedule"),
"tensor",
)
self.assertEqual(
MODULE._unwrap_single_output(("legacy", "tuple"), "legacy"),
("legacy", "tuple"),
)
def test_rejects_temporal_resize(self):
class BadUpscale(FakeUpscale):
def execute(self, **kwargs):
source = kwargs["latent"]["samples"]
return ({"samples": FakeSamples((1, 16, source.shape[2] + 1, 96, 168))},)
MODULE._native_node = lambda name: {
"MMH3UltimateUpscale": BadUpscale,
"RandomNoise": FakeNoise,
"KSamplerSelect": FakeSampler,
"BasicScheduler": FakeScheduler,
}.get(name)
node = MODULE.H3ContinuumTiledLatentUpscalePerClip()
with self.assertRaisesRegex(RuntimeError, "temporal length"):
node.upscale(
model=["model"], clip=["clip"],
video_latents=[{"samples": FakeSamples((1, 16, 85, 48, 84))}],
assembly_plan=["plan"], refine_context=["context"],
latent_upscale_param=["upscale"], spatial_split_param=["spatial"],
upscale_sampler=["euler"], upscale_scheduler=["simple"],
upscale_steps=[3], upscale_denoise=[0.2], upscale_cfg=[1.0],
upscale_noise_seed=[100], conditioning=["conditioning"],
)
if __name__ == "__main__":
unittest.main()
+1 -1
View File
@@ -145,4 +145,4 @@ def test_v217_result_pack_expands_legacy_outputs():
def test_v217_has_no_frontend_display_controller():
assert not (ROOT / "web" / "h3_continuum_v2.js").exists()
version_source = (ROOT / "version.py").read_text(encoding="utf-8")
assert 'PACKAGE_VERSION = "3.9.4"' in version_source
assert 'PACKAGE_VERSION = "3.9.10"' in version_source
+2
View File
@@ -89,6 +89,8 @@ def test_run_storage_off_normalizes_widgets_reload_and_queued_inputs(tmp_path):
source = PROJECT_ID_JS.read_text(encoding="utf-8")
functions = "\n".join(
[
next(line for line in source.splitlines()
if line.startswith("const REGENERATE_INTENT_PROPERTY = ")),
_function_source(source, "findWidget", "setWidgetVisible"),
_function_source(source, "setWidgetVisible", "hidePersistentWidget"),
_function_source(source, "linkedInput", "attachRefresh"),
-93
View File
@@ -543,99 +543,6 @@ def test_second_pass_node_forwards_optional_refine_context_and_video_vae(monkeyp
assert captured["refine_schedule"] is schedule
def test_tiled_second_pass_prefers_connected_sigma_socket_over_node_steps(monkeypatch):
captured = {}
class FakeNative:
pass
class FakeNoise:
pass
class FakeSampler:
def get_sampler(self, name):
return f"sampler:{name}"
class FakeScheduler:
pass
def fake_run(**kwargs):
captured.update(kwargs)
return ([], [], {"plan": True}, "status")
monkeypatch.setattr(
"ComfyUI_H3_Continuum_Join.v3.second_pass_nodes.run_second_pass_groups",
fake_run,
)
monkeypatch.setattr(
"ComfyUI_H3_Continuum_Join.v3.second_pass_nodes._native_node",
lambda name: {
"MMH3UltimateUpscale": FakeNative,
"RandomNoise": FakeNoise,
"KSamplerSelect": FakeSampler,
"BasicScheduler": FakeScheduler,
}[name],
)
socket_sigmas = object()
result = H3ContinuumSecondPassV35().refine(
["model"], ["clip"], ["sampler"], [socket_sigmas],
[], [], [{"second_pass_contract": {}}], [7],
tiled_upscale=[True], latent_upscale_param=["upscale"],
spatial_split_param=["spatial"], upscale_steps=[3],
upscale_denoise=[0.2], upscale_cfg=[1.0], upscale_noise_seed=[11],
)
assert result[0] == []
config = captured["tiled_upscale_config"]
assert config["sigmas"] is socket_sigmas
assert config["sigma_source"] == "sigmas_socket"
def test_tiled_second_pass_prefers_dedicated_sigma_socket(monkeypatch):
captured = {}
class FakeNative:
pass
class FakeNoise:
pass
class FakeSampler:
def get_sampler(self, name):
return name
class FakeScheduler:
pass
monkeypatch.setattr(
"ComfyUI_H3_Continuum_Join.v3.second_pass_nodes.run_second_pass_groups",
lambda **kwargs: captured.update(kwargs) or ([], [], {}, ""),
)
monkeypatch.setattr(
"ComfyUI_H3_Continuum_Join.v3.second_pass_nodes._native_node",
lambda name: {
"MMH3UltimateUpscale": FakeNative,
"RandomNoise": FakeNoise,
"KSamplerSelect": FakeSampler,
"BasicScheduler": FakeScheduler,
}[name],
)
main_sigmas = object()
tiled_sigmas = object()
H3ContinuumSecondPassV35().refine(
["model"], ["clip"], ["sampler"], [main_sigmas],
[], [], [{"second_pass_contract": {}}], [7],
tiled_upscale=[True], latent_upscale_param=["upscale"],
spatial_split_param=["spatial"], upscale_sigmas=[tiled_sigmas],
upscale_steps=[3], upscale_denoise=[0.2], upscale_cfg=[1.0],
upscale_noise_seed=[11],
)
config = captured["tiled_upscale_config"]
assert config["sigmas"] is tiled_sigmas
assert config["sigma_source"] == "upscale_sigmas_socket"
def test_second_pass_node_is_registered_and_not_deprecated():
node_class = NODE_CLASS_MAPPINGS["H3ContinuumSecondPassV35"]
assert node_class is H3ContinuumSecondPassV35
+3
View File
@@ -194,6 +194,9 @@ def test_registry_manifest_matches_every_declared_source_file():
"examples/workflows/MiniMax_H3_Continuum_V39.json",
"examples/workflows/MiniMax_H3_Continuum_V39.zip",
"examples/MiniMax_H3_Continuum_V39.json",
"examples/MiniMax_H3_Continuum_V39_Turbo_Sample.json",
"examples/workflows/MiniMax_H3_Continuum_V39_Turbo_Sample.json",
"examples/workflows/MiniMax_H3_Continuum_V39_Turbo_Sample.zip",
"examples/MiniMax_H3_Continuum_V38X2.json",
}
+102 -2
View File
@@ -13,6 +13,7 @@ import pytest
from ComfyUI_H3_Continuum_Join.v3.driving_nodes import (
H3ContinuumSamplerV37,
H3ContinuumSamplerV38,
H3ContinuumSamplerV39,
)
from ComfyUI_H3_Continuum_Join.v3.easy_nodes import H3ContinuumEasyV38
from ComfyUI_H3_Continuum_Join.v3.review_control import (
@@ -28,7 +29,7 @@ ROOT = Path(__file__).resolve().parents[1]
DEFAULT_COMFY_ROOT = Path(
os.environ.get(
"H3_CONTINUUM_COMFY_ROOT",
r"D:\StabilityMatrix\Data\Packages\ComfyUI_W",
str(ROOT.parent / "ComfyUI"),
)
)
@@ -71,6 +72,25 @@ def test_v38_full_run_keeps_stable_core_cache_behavior(review_action):
) is False
@pytest.mark.parametrize("node_class", [H3ContinuumSamplerV38, H3ContinuumSamplerV39])
@pytest.mark.parametrize("boundary,nonce,storage,changed", [
("Chunk 1", 0, "Save + Auto Resume", True),
("Chunk 2", 0, "Save + Auto Resume", True),
(2, 0, "Save + Auto Resume", True),
("Chunk 2", 5, "Save + Auto Resume", False),
("Auto", 0, "Save + Auto Resume", False),
(0, 0, "Save + Auto Resume", False),
("Chunk 2", 0, "Off", False),
])
def test_full_run_automatic_reroll_reaches_storage(node_class, boundary, nonce, storage, changed):
value = node_class.IS_CHANGED(generation_mode=GENERATION_MODE_FULL_RUN,
run_storage=storage, reroll_from_chunk=boundary, reroll_nonce=nonce, chunks=3)
if changed:
assert math.isnan(value)
else:
assert value is False
def test_v37_and_easy_do_not_inherit_the_v38_cache_contract():
assert "IS_CHANGED" not in H3ContinuumSamplerV37.__dict__
assert "IS_CHANGED" not in H3ContinuumEasyV38.__dict__
@@ -78,6 +98,37 @@ def test_v37_and_easy_do_not_inherit_the_v38_cache_contract():
assert not hasattr(H3ContinuumEasyV38, "IS_CHANGED")
@pytest.mark.parametrize("node_class", [H3ContinuumSamplerV38, H3ContinuumSamplerV39])
@pytest.mark.parametrize("changes,changed", [
({"chunks": None}, True),
({"chunks": 1}, True),
({"chunks": "not resolved"}, True),
({"reroll_nonce": None}, True),
({"run_storage": None}, True),
({"reroll_from_chunk": None}, True),
({"generation_mode": None}, True),
({"chunks": None, "reroll_nonce": None, "run_storage": None}, True),
({"chunks": None, "reroll_nonce": 5}, False),
({"run_storage": None, "reroll_nonce": 5}, False),
({"reroll_from_chunk": None, "reroll_nonce": 5}, False),
({"reroll_from_chunk": "Auto", "reroll_nonce": None}, False),
({"reroll_from_chunk": "Auto", "run_storage": None}, False),
({"run_storage": "Off", "reroll_nonce": None}, False),
({"run_storage": "Off", "reroll_from_chunk": None}, False),
({"run_storage": "invalid"}, False),
({"reroll_nonce": "invalid"}, False),
({"reroll_from_chunk": "invalid"}, False),
({"reroll_from_chunk": "Chunk 17"}, False),
({"generation_mode": GENERATION_MODE_REVIEW, "run_storage": "Off"}, True),
])
def test_cache_intent_handles_unresolved_inputs_without_validating_chunk_range(node_class, changes, changed):
inputs = dict(generation_mode=GENERATION_MODE_FULL_RUN, run_storage="Save + Auto Resume",
reroll_from_chunk="Chunk 2", reroll_nonce=0, chunks=3)
inputs.update(changes)
value = node_class.IS_CHANGED(**inputs)
assert math.isnan(value) if changed else value is False
def test_real_comfy_cache_signature_is_stable_only_for_full_run(tmp_path):
comfy_root = DEFAULT_COMFY_ROOT
if not (comfy_root / "execution.py").is_file():
@@ -130,7 +181,7 @@ def test_real_comfy_cache_signature_is_stable_only_for_full_run(tmp_path):
comfy_kitchen.int8_attention_is_available = lambda *a, **k: False
import nodes as comfy_nodes
from comfy_execution.caching import CacheKeySetInputSignature
from comfy_execution.caching import BasicCache, CacheKeySetInputSignature
from comfy_execution.graph import DynamicPrompt
from execution import IsChangedCache
@@ -187,7 +238,49 @@ def test_real_comfy_cache_signature_is_stable_only_for_full_run(tmp_path):
review_finish_2 = await signature(
"Review Each Chunk", "Finish Remaining"
)
cache_results = {{}}
for node_name in ["H3ContinuumSamplerV38", "H3ContinuumSamplerV39"]:
comfy_nodes.NODE_CLASS_MAPPINGS[class_type] = package.NODE_CLASS_MAPPINGS[node_name]
observed_counts = {{}}
for label, boundary, nonce, linked in [
("ordinary", "Auto", 0, None),
("automatic", "Chunk 2", 0, None),
("fixed", "Chunk 2", 5, None),
("linked_chunks", "Chunk 2", 0, "chunks"),
("linked_nonce", "Chunk 2", 0, "reroll_nonce"),
("linked_storage", "Chunk 2", 0, "run_storage"),
("linked_boundary", "Chunk 2", 0, "reroll_from_chunk"),
("linked_mode", "Chunk 2", 5, "generation_mode"),
("fixed_linked_chunks", "Chunk 2", 5, "chunks"),
("ordinary_linked_nonce", "Auto", 0, "reroll_nonce"),
("fixed_linked_nonce", "Chunk 2", 5, "reroll_nonce"),
]:
cache = BasicCache(CacheKeySetInputSignature)
executions = 0
for queue in range(2):
prompt = {{"305": {{"class_type": class_type, "inputs": {{
"generation_mode": "Full Run", "review_action": "Continue / Next",
"run_storage": "Save + Auto Resume", "reroll_from_chunk": boundary,
"reroll_nonce": nonce, "chunks": 3}}}}}}
if linked:
class ScalarProbe:
@classmethod
def INPUT_TYPES(cls):
return {{"required": {{"value": ("*",)}}}}
comfy_nodes.NODE_CLASS_MAPPINGS["H3CacheScalarProbe"] = ScalarProbe
value = prompt["305"]["inputs"][linked]
prompt["900"] = {{"class_type": "H3CacheScalarProbe", "inputs": {{"value": value}}}}
prompt["305"]["inputs"][linked] = ["900", 0]
dynprompt = DynamicPrompt(prompt)
await cache.set_prompt(dynprompt, ["305"], IsChangedCache(str(queue), dynprompt, None))
if cache.get_local("305") is None:
executions += 1
cache.set_local("305", ("CPU fixture output",))
observed_counts[label] = executions
cache_results[node_name] = observed_counts
print(json.dumps({{
"cache_executions": cache_results,
"full_stable": full_1 == full_2,
"review_continue_changed": review_continue_1 != review_continue_2,
"review_regenerate_changed": review_regen_1 != review_regen_2,
@@ -210,6 +303,13 @@ def test_real_comfy_cache_signature_is_stable_only_for_full_run(tmp_path):
)
observed = json.loads(result.stdout.strip().splitlines()[-1])
assert observed == {
"cache_executions": {
name: {"ordinary": 1, "automatic": 2, "fixed": 1,
"linked_chunks": 2, "linked_nonce": 2, "linked_storage": 2,
"linked_boundary": 2, "linked_mode": 2, "fixed_linked_chunks": 1,
"ordinary_linked_nonce": 1, "fixed_linked_nonce": 2}
for name in ("H3ContinuumSamplerV38", "H3ContinuumSamplerV39")
},
"full_stable": True,
"review_continue_changed": True,
"review_regenerate_changed": True,
+8
View File
@@ -471,3 +471,11 @@ def test_n2c_history_refresh_hooks_and_multiline_surface_are_present():
assert 'const TAKE_TOGGLE_WIDGET = "Render History";' in source
assert "app.queuePrompt =" not in source
assert "api.__h3ContinuumReviewQueueAdapter" in source
def test_explicit_regenerate_restore_and_legacy_compatibility(review_queue_results):
selected = [record for name, record in review_queue_results.items()
if name.startswith(("regenerate restore:", "regenerate legacy:",
"regenerate intent reset:"))]
assert len(selected) == 22
assert all(record["pass"] for record in selected)
+1
View File
@@ -98,6 +98,7 @@ def test_template_gallery_uses_official_workflows_only():
gallery = ROOT / "examples"
assert {path.name for path in gallery.glob("*.json")} == {
"MiniMax_H3_Continuum_V39.json",
"MiniMax_H3_Continuum_V39_Turbo_Sample.json",
"MiniMax_H3_Continuum_V38X2.json",
}
assert (gallery / WORKFLOW.name).read_bytes() == WORKFLOW.read_bytes()
+22
View File
@@ -177,6 +177,28 @@ def test_inline_helper_keeps_sparse_slot_ids_and_saved_future_chunks():
assert bundle.selectors[0] == "1,3,6"
@pytest.mark.parametrize("saved,expected", [
("1,2", [("R1",), ("R1",), ()]),
("1,2,3", [("R1",), ("R1",), ("R1",)]),
(",".join(str(n) for n in range(1, 17)), [("R1",), ("R1",), ("R1",)]),
("off", [(), (), ()]),
])
def test_external_assignment_range_uses_actual_chunks_without_rewriting_saved_value(saved, expected):
bundle, = H3ContinuumReferenceImagesV39().pack(
reference_use="Per chunk", reference_r1_chunks=saved,
reference_image_1=object(),
)
original = bundle.selectors
_, _, selectors = effective_reference_inputs(bundle, chunks=3)
schedule = compile_reference_routing_schedule(
total_chunks=3, terminal_merge_enabled=False,
mode="Custom", selectors_by_slot=selectors,
)
assert schedule.valid
assert [route.reference_slot_ids for route in schedule.logical_routes] == expected
assert bundle.selectors == original
def test_new_workflow_rewires_all_nine_slots_and_isolates_saved_runs():
directory = Path(__file__).resolve().parents[1] / "examples" / "workflows"
old = json.loads((directory / "MiniMax_H3_Continuum_V38X2.json").read_text(encoding="utf-8"))
+36
View File
@@ -0,0 +1,36 @@
import json
from pathlib import Path
from zipfile import ZipFile
ROOT = Path(__file__).resolve().parents[1]
NAME = "MiniMax_H3_Continuum_V39_Turbo_Sample.json"
def test_turbo_sample_is_installable_and_keeps_prompt_and_explicit_settings():
path = ROOT / "examples/workflows" / NAME
payload = path.read_bytes()
assert (ROOT / "examples" / NAME).read_bytes() == payload
with ZipFile(path.with_suffix(".zip")) as archive:
assert archive.testzip() is None
assert archive.namelist() == [NAME]
assert archive.read(NAME) == payload
graph = json.loads(payload)
nodes = {n["id"]: n for n in graph["nodes"]}
named = nodes[312]["widgets_values_named"]
assert nodes[312]["widgets_values"] == list(named.values())
assert (named["prompt_mode"], named["chunks"], named["chunk_seconds"]) == ("Auto", 2, 8)
assert named["run_storage"] == "Off"
assert named["project_id"] != "1fefd563-68c4-45f7-a33f-8a2911850a9c"
assert nodes[317]["mode"] == 0
assert next(i for i in nodes[312]["inputs"] if i["name"] == "first_frame")["link"] == 382
prompt = nodes[188]["widgets_values"][0]
assert prompt == nodes[188]["widgets_values_named"]["value"]
assert prompt.startswith("[Chunk 1]\nFor the target video")
assert "<Picture 1>" in prompt and "[Chunk 2]\n" in prompt
assert "Continuation of Chunk 1." in prompt
assert prompt.count("<d>[Thai]") == 2
assert "background unchanged" in prompt
enabled = [v for v in nodes[286]["widgets_values"] if isinstance(v, dict) and v.get("on")]
assert len(enabled) == 1 and "turbo_4step" in enabled[0]["lora"]
assert nodes[150]["widgets_values"][0] is False
assert "models" not in nodes[147]["properties"]
assert nodes[191]["widgets_values"][0].endswith("_Turbo_Sample")