Files
DemonGatanjieu-Anomalous_Mo…/tests/activity_diff.mjs
T
DemonGatanjieuandClaude Opus 5.5 854e63ba71 The AI builds workflows on the canvas the user sees
find_nodes looks up this ComfyUI's node types (inputs, outputs, choices)
from its own /object_info. new_workflow opens a new tab, blank or built and
laid out from a workflow in API form, never touching the open one;
add_node, connect_nodes, set_values and remove_nodes edit it. Everything is
checked against the nodes before the canvas changes (types, loops, settings,
choices with close matches); each is one Ctrl+Z step, logged as the AI's
and shown under its workbench step. Receipts now show rewiring ("wired":
what feeds an input, before and after). A run ComfyUI refuses reports
ComfyUI's own reason instead of "Prompt execution failed".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:56:23 +08:00

57 lines
3.3 KiB
JavaScript

// node tests/activity_diff.mjs — canvas snapshots and their difference for the activity log.
import assert from 'node:assert/strict';
import { changeNodeId, diffSnapshots, snapshotGraph } from '../web/modules/activity_diff.js';
const graph = (nodes) => ({ _nodes: nodes });
const node = (id, title, widgets) => ({ id, type: title, title, widgets: Object.entries(widgets).map(([name, value]) => ({ name, value })) });
const before = snapshotGraph(graph([
node(3, 'KSampler', { steps: 20, cfg: 7, seed: 1 }),
node(4, 'CheckpointLoaderSimple', { ckpt_name: 'a.safetensors' }),
node(9, 'Note', { text: 'hello' }),
]));
const after = snapshotGraph(graph([
node(3, 'KSampler', { steps: 30, cfg: 7, seed: 1 }),
node(4, 'CheckpointLoaderSimple', { ckpt_name: 'b.safetensors' }),
node(12, 'LoraLoader', { lora_name: 'x.safetensors', strength_model: 1 }),
]));
assert.deepEqual(diffSnapshots(before, after).map(c => [c.kind, c.node, c.widget, c.before, c.after]), [
['changed', 'KSampler #3', 'steps', '20', '30'],
['changed', 'CheckpointLoaderSimple #4', 'ckpt_name', 'a.safetensors', 'b.safetensors'],
['added', 'LoraLoader #12', undefined, undefined, undefined],
['removed', 'Note #9', undefined, undefined, undefined],
]);
assert.deepEqual(diffSnapshots(before, before), []);
// Buttons and nameless widgets hold no value.
const withButton = snapshotGraph(graph([{ id: 1, type: 'X', title: 'X', widgets: [{ name: 'run', type: 'button', value: 1 }, { value: 5 }] }]));
assert.deepEqual(withButton.get('1').widgets, {});
// Object values compare by content; a widget that appears counts as a change.
const a = snapshotGraph(graph([node(1, 'Img', { image: { name: 'a.png' } })]));
const b = snapshotGraph(graph([node(1, 'Img', { image: { name: 'a.png' }, extra: 2 })]));
assert.deepEqual(diffSnapshots(a, b).map(c => [c.widget, c.before, c.after]), [['extra', '', '2']]);
// Rewiring: what feeds an input, in words; not the inputs a removed node fed.
const wired = (links, extra = []) => {
const nodes = [
{ id: 1, type: 'CheckpointLoaderSimple', title: 'Load', outputs: [{ name: 'MODEL' }] },
{ id: 2, type: 'LoraLoader', title: 'LoRA', outputs: [{ name: 'MODEL' }] },
{ id: 3, type: 'KSampler', title: 'KSampler', inputs: [{ name: 'model', link: links.model ?? null }] },
...extra,
];
const table = new Map([[10, { origin_id: 1, origin_slot: 0 }], [11, { origin_id: 2, origin_slot: 0 }]]);
return snapshotGraph({ _nodes: nodes, links: table, getNodeById: id => nodes.find(n => n.id === id) });
};
assert.deepEqual(diffSnapshots(wired({}), wired({ model: 10 })).map(c => [c.kind, c.node, c.widget, c.before, c.after]),
[['wired', 'KSampler #3', 'model', '', 'Load #1 · MODEL']]);
assert.deepEqual(diffSnapshots(wired({ model: 10 }), wired({ model: 11 }))[0].after, 'LoRA #2 · MODEL');
const gone = snapshotGraph({ _nodes: [{ id: 3, type: 'KSampler', title: 'KSampler', inputs: [{ name: 'model', link: null }] }] });
assert.deepEqual(diffSnapshots(wired({ model: 10 }), gone).map(c => c.kind), ['removed', 'removed'], 'the removal says it');
assert.equal(changeNodeId({ node: 'KSampler #12' }), '12');
assert.equal(changeNodeId({ node: 'Title with # sign #7' }), '7');
assert.equal(changeNodeId({ node: 'no id' }), null);
console.log('activity_diff: ok');