* fix(resolver): identical sampler branches resolve to their shared prompt pair
A LoRA epoch-compare grid runs one sampler per epoch, every one fed by the
same positive encode and the same ConditioningZeroOut negative, and saves
one concatenated image. `_resolve` returned "Multiple sampler branches"
(ambiguous) whenever more than one sampler was found, even though every
branch used the same pair, so the workspace inspector fell back to the
legacy parser and the image could not be paired.
When every branch resolves to identical texts and stored recipes, the
result is now that pair: state resolved, no sampler named (none alone made
the output), reason "Every sampler branch uses the same prompt pair", the
first branch's sides and provenance, and every branch kept in `candidates`
as evidence. A branch that differs, cannot be read, or is not resolved
keeps the result ambiguous. Both profiles share the rule; the default
profile still cannot read ConditioningZeroOut, so the zero-out grid stays
ambiguous for ingestion and keeps the scan's legacy-parser fallback.
Workspace facts: a resolved result without a named sampler over several
listed samplers merges facts per field, as an ambiguous one does (the
grid's shared seed/steps are known, the per-epoch model is ambiguous).
Tests that encoded the old behavior (identical branches => ambiguous):
- test_prompt_pair_resolver: test_multiple_samplers_are_ambiguous_even_when_texts_match
-> test_multiple_samplers_with_matching_texts_resolve_to_the_shared_pair
(plus a new differing-texts case that stays ambiguous);
test_raw_and_detailed_saves_stay_ambiguous_without_an_anchor (same prompt)
-> ..._of_one_prompt_share_it_without_an_anchor (anchored cases unchanged).
- test_pair_scan: two samplers sharing one prompt now ingest the pair
("cat"/"blur") instead of the positive-only fallback.
- test_api_prompt_inspector, test_inspection_outcomes, test_pair_image_linking:
their "ambiguous" fixtures now use samplers with different prompts.
No parity vector changes (f01/f09 branches are not all resolved).
* fix(inspector): never show the positive as a zeroed negative from the legacy fill
When the server leaves the negative undecided, the workspace fills it from
the legacy browser parser (comfy-metadata.js), which follows
ConditioningZeroOut back to its input and so reads the positive text as
the negative. The workspace now checks the prompt graph first:
- every sampler's negative is a ConditioningZeroOut (Reroutes allowed):
the negative shows the server's explicitly empty zeroed state
({status: resolved, text: "", source: zeroed-conditioning});
- a zero-out elsewhere in a negative path (one branch zeroed, another
encoded; a zero-out combined with other conditioning), or a
workflow-only file holding one: the negative is not filled and keeps
the server's status;
- graphs without a zero-out keep the legacy fill unchanged.
comfy-metadata.js is untouched; the legacy pages keep their reading.
* fix(images): explain why Set category has nothing to set
Set category on a selection where no image is linked to a Library prompt
said only "None of the selected images has a linked prompt." It now says
why and what it means: "The selected images aren't in your Library yet,
so there is no prompt category to set." Unit and page-workflow tests
follow the copy.
* fix(inspector): check only the negative the legacy parse read for a zero-out
Review I1/M2/M3/M5 of the zero-out legacy-fill guard. The guard decided
over every node with a `negative` input, so a graph whose read sampler
encodes "blurry" lost that legacy-filled negative when another branch
zeroed its own (fewer than the legacy pages: below the parity floor).
- comfy-metadata.js gains `legacyNegativeSource`, which returns the graph
and sampler `negative` link that `extractGenerationParams` reads from.
It reuses the parser's own sampler pick (`selectSampler`, factored out
of `fromPromptGraph` without changing any reading). The workspace
checks only that link: a direct zero-out shows the zeroed empty
negative, a zero-out further up the path leaves it unfilled, and
anything else keeps the legacy fill.
- Workflow-only files go through the parser's own workflow conversion,
so bypassed (mode 4) and muted (mode 2) zero-outs and unconnected ones
behave as the legacy reading does. A subgraph instance whose definition
runs a zero-out (directly or nested) leaves the negative unfilled.
- One bounded walk with an index pointer replaces a walk per negative
input with queue.shift().
- An ambiguous fact that the legacy parse knows (a grid's per-branch
model) is still filled, documented: the legacy pages show it and this
page never shows less.
Tests: the reversed mixed graph shows "blurry"; the mixed graph whose
read sampler is zeroed, the zero-out-only grid and a direct workflow
zero-out show the zeroed empty negative; a combined zero-out and a
zero-out subgraph instance stay unfilled; bypassed and unconnected
workflow zero-outs keep the legacy reading. An API-graph Reroute in
front of a zero-out gives the legacy parse no negative, so the server
answer stays (that expectation changed from zeroed).
* fix(images): name the missing link in the Set category toast
Review M4: say that no selected image is linked to a saved prompt, in
the same terms as the partial-success toast and right for one image.
Also review M1: a monitor test that two parallel samplers sharing one
positive and one negative write that pair (the resolver collapse).
705 lines
50 KiB
JavaScript
705 lines
50 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createRequire } from 'node:module';
|
|
const require = createRequire(import.meta.url);
|
|
const { extractGenerationFacts } = require('../../web/js/comfy-metadata.js');
|
|
const { ApiError } = require('../../web/js/api-client.js');
|
|
const module = await import('../../web/js/workspace/inspection-state.mjs').catch(error => {
|
|
if (error.code !== 'ERR_MODULE_NOT_FOUND') throw error;
|
|
return {};
|
|
});
|
|
const scopeA = 'a'.repeat(64), scopeB = 'b'.repeat(64);
|
|
const refreshMessage = 'The source changed. Refresh the image collection before inspecting this file.';
|
|
const fields = ['seed', 'steps', 'cfg', 'sampler', 'scheduler', 'model'];
|
|
function contract(name) { assert.equal(typeof module[name], 'function', `${name} contract is exported`); return module[name]; }
|
|
function image(root_scope = scopeA) {
|
|
return { root_index: 0, path: 'folder/a #%.png', filename: 'a #%.png', url: `/prompt_manager/images/serve/folder/a%20%23%25.png?root=0${root_scope === undefined ? '' : `&root_scope=${root_scope}`}`, ...(root_scope === undefined ? {} : { root_scope }) };
|
|
}
|
|
function envelope(entry = image()) {
|
|
return {
|
|
success: true, inspection_version: 1, root_scope: entry.root_scope ?? scopeA,
|
|
image: { root_index: entry.root_index, path: entry.path, filename: entry.filename },
|
|
file: { observation: 'current-file', source_label: 'same label', media_type: 'image', extension: '.png', format: 'PNG', size: 123, width: 720, height: 480, modified_time: 1234 },
|
|
prompts: { positive: { status: 'resolved', text: 'exact\npositive', source: 'execution' }, negative: { status: 'ambiguous', text: null, source: null } },
|
|
metadata: {
|
|
status: 'available', omitted_reason: null, raw: { prompt: '{"rounded":"raw copy"}' }, record_formats: { prompt: 'reserialized-json' },
|
|
prompt_graph: { status: 'parsed', value: { s: { class_type: 'KSampler', inputs: { seed: '9007199254740993', steps: 28, cfg: '6.5000000000000000001', sampler_name: 'euler', scheduler: 'normal', model: ['model', 0] } }, model: { class_type: 'CheckpointLoaderSimple', inputs: { ckpt_name: 'model.safetensors' } } } },
|
|
workflow_graph: { status: 'absent', value: null }, parameters: null,
|
|
},
|
|
resolution: { state: 'ambiguous', sampler_id: null, reason: 'unknown negative' },
|
|
library: { status: 'linked', scope: 'saved-library', positive_id: 7, pair_id: 8, title: 'Recipe', category: 'Subject', tags: ['cat'], category_scope: 'pair', tags_scope: 'pair' },
|
|
};
|
|
}
|
|
function pendingApi() {
|
|
const requests = [];
|
|
const api = { get: (url, { signal }) => new Promise((resolve, reject) => requests.push({ url, signal, resolve, reject })) };
|
|
return { api, requests };
|
|
}
|
|
|
|
test('original media validation is strict before inspection and preserves rooted URLs', () => {
|
|
const validate = contract('originalMediaDownload'), entry = image();
|
|
assert.deepEqual(validate(entry), {url:entry.url,filename:'a #%.png'});
|
|
for (const change of [{url:'https://other.test/prompt_manager/images/serve/folder/a%20%23%25.png?root=0'},
|
|
{url:entry.url.replace('root=0','root=1')},{url:entry.url.replace(scopeA,scopeB)},
|
|
{url:entry.url.replace('folder/a','elsewhere/a')},{url:entry.url.replace(`&root_scope=${scopeA}`,'')},
|
|
{url:entry.url+'&root=0'},{url:entry.url+'#wrong'},{path:'../a.png'},{root_scope:''}]) {
|
|
assert.throws(() => validate({...entry,...change}), TypeError);
|
|
}
|
|
const before = Object.getOwnPropertyDescriptor(globalThis,'window');
|
|
Object.defineProperty(globalThis,'window',{configurable:true,value:{location:{href:'https://example.test/proxy/prompt_manager/workspace'},ApiClient:{resolveUrl:url=>`/proxy${url}`}}});
|
|
try { assert.deepEqual(validate(entry),{url:`/proxy${entry.url}`,filename:'a #%.png'}); }
|
|
finally { if (before) Object.defineProperty(globalThis,'window',before); else delete globalThis.window; }
|
|
});
|
|
|
|
test('record preserves exact projections and unknown roles without execution fact promotion', () => {
|
|
const entry = image(), data = envelope(entry);
|
|
const record = contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
assert.deepEqual(record.identity, { kind: 'rooted-file', key: '0:folder/a #%.png', root_index: 0, path: entry.path, root_scope: scopeA });
|
|
assert.equal(record.generation.seed.value, '9007199254740993');
|
|
assert.equal(record.generation.cfg.value, '6.5000000000000000001');
|
|
assert.equal(record.generation.seed.evidence, 'configuration');
|
|
assert.equal(record.prompts.negative.status, 'ambiguous');
|
|
assert.equal(record.prompts.negative.text, null);
|
|
assert.equal(record.historyTarget, '#/library/7');
|
|
assert.deepEqual(record.download, { url: entry.url, filename: entry.filename });
|
|
assert.equal(record.file.source_label, 'same label');
|
|
for (const status of ['none', 'ambiguous', 'unavailable', 'limited']) {
|
|
const result = envelope(entry); result.library.status = status;
|
|
assert.equal(module.toInspectionRecord(result, entry, extractGenerationFacts).historyTarget, null);
|
|
}
|
|
});
|
|
|
|
test('record format validation never guesses original text', () => {
|
|
const toRecord = contract('toInspectionRecord'), entry = image();
|
|
for (const mutate of [
|
|
data => delete data.metadata.record_formats,
|
|
data => { data.metadata.record_formats = { prompt: 'guess' }; },
|
|
data => { data.metadata.record_formats.extra = 'original-text'; },
|
|
data => { data.metadata.record_formats.prompt = 'invalid'; },
|
|
data => { data.metadata.raw.workflow = '{}'; },
|
|
data => { data.metadata.raw.prompt = {}; },
|
|
data => { data.metadata.raw.extra = 'secret'; },
|
|
data => { data.metadata.parameters = 'manufactured'; },
|
|
data => { data.metadata.prompt_graph = { status: 'absent', value: null }; },
|
|
data => { data.metadata.record_formats = {}; data.metadata.raw = {}; },
|
|
data => { data.metadata.status = 'limited'; },
|
|
]) {
|
|
const data = envelope(entry); mutate(data);
|
|
assert.throws(() => toRecord(data, entry, extractGenerationFacts), TypeError);
|
|
}
|
|
const data = envelope(entry);
|
|
data.metadata.record_formats.workflow = 'invalid';
|
|
data.metadata.workflow_graph = { status: 'malformed', value: null };
|
|
assert.equal(toRecord(data, entry, extractGenerationFacts).metadata.record_formats.workflow, 'invalid');
|
|
data.metadata.raw = {}; data.metadata.status = 'limited'; data.metadata.omitted_reason = 'response-size-limit';
|
|
data.metadata.prompt_graph = { status: 'limited', value: null };
|
|
data.metadata.workflow_graph = { status: 'limited', value: null };
|
|
const limited = toRecord(data, entry, extractGenerationFacts);
|
|
assert.deepEqual(limited.metadata.record_formats, { prompt: 'reserialized-json', workflow: 'invalid' });
|
|
assert.equal(limited.generation.seed.status, 'unresolved');
|
|
assert.equal(limited.generation.seed.reason, 'projection-limited');
|
|
let seen;
|
|
toRecord(envelope(entry), entry, input => { seen = input; return extractGenerationFacts(input); });
|
|
assert.deepEqual(seen.recordFormats, { prompt: 'reserialized-json' });
|
|
assert.equal(seen.raw, undefined, 'facts never receive raw graphs for reparsing');
|
|
});
|
|
|
|
test('record accepts actual atomic omission producer states', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
for (const wholeRaw of [false, true]) {
|
|
const data = envelope();
|
|
data.metadata.record_formats.workflow = 'invalid';
|
|
data.metadata.prompt_graph = { status: 'limited', value: null };
|
|
data.metadata.workflow_graph = { status: 'limited', value: null };
|
|
if (wholeRaw) Object.assign(data.metadata, { raw: {}, parameters: null, status: 'limited', omitted_reason: 'response-size-limit' });
|
|
let record;
|
|
assert.doesNotThrow(() => { record = toRecord(data, image(), extractGenerationFacts); }, 'actual producer omission remains renderable');
|
|
assert.deepEqual(record.metadata.raw, wholeRaw ? {} : { prompt: '{"rounded":"raw copy"}' });
|
|
assert.equal(record.metadata.status, wholeRaw ? 'limited' : 'available');
|
|
assert.equal(record.metadata.omitted_reason, wholeRaw ? 'response-size-limit' : null);
|
|
assert.deepEqual(record.metadata.record_formats, { prompt: 'reserialized-json', workflow: 'invalid' });
|
|
assert.equal(record.prompts.positive.text, 'exact\npositive');
|
|
assert.equal(record.download.url, image().url);
|
|
assert.ok(Object.values(record.generation).every(fact => fact.status === 'unresolved' && fact.reason === 'projection-limited'));
|
|
}
|
|
const absent = envelope();
|
|
Object.assign(absent.metadata, { status: 'limited', omitted_reason: 'response-size-limit', raw: {}, record_formats: { parameters: 'original-text' }, parameters: null, prompt_graph: { status: 'absent', value: null } });
|
|
assert.equal(toRecord(absent, image(), extractGenerationFacts).generation.seed.reason, 'projection-limited');
|
|
});
|
|
|
|
test('record rejects contradictory omission provenance before extracting facts', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
for (const mutate of [
|
|
data => Object.assign(data.metadata, { status: 'limited', omitted_reason: 'response-size-limit' }),
|
|
data => Object.assign(data.metadata, { status: 'limited', omitted_reason: 'response-size-limit', raw: {} }),
|
|
data => { data.metadata.raw = {}; },
|
|
data => { data.metadata.record_formats.workflow = 'original-text'; data.metadata.workflow_graph = { status: 'parsed', value: { nodes: [] } }; },
|
|
data => { Object.assign(data.metadata, { status: 'limited', omitted_reason: 'response-size-limit', raw: {}, prompt_graph: { status: 'limited', value: null } }); data.metadata.record_formats.workflow = 'invalid'; data.metadata.workflow_graph = { status: 'malformed', value: null }; },
|
|
data => { data.metadata.record_formats.workflow = 'invalid'; data.metadata.raw.workflow = 'null'; data.metadata.workflow_graph = { status: 'limited', value: null }; },
|
|
// The response budget omits the workflow graph before the prompt graph, so an
|
|
// omitted invalid prompt graph means the workflow graph was omitted too.
|
|
data => { data.metadata.record_formats.prompt = 'invalid'; data.metadata.raw = {}; data.metadata.prompt_graph = { status: 'limited', value: null }; data.metadata.record_formats.workflow = 'original-text'; data.metadata.raw.workflow = '{"nodes":[]}'; data.metadata.workflow_graph = { status: 'parsed', value: { nodes: [] } }; },
|
|
]) {
|
|
const data = envelope(); mutate(data); let extractions = 0;
|
|
assert.throws(() => toRecord(data, image(), () => { extractions++; return extractGenerationFacts({}); }), TypeError);
|
|
assert.equal(extractions, 0, 'contradictory transport cannot produce known facts');
|
|
}
|
|
});
|
|
|
|
function limitedWorkflow(data = envelope()) {
|
|
data.metadata.record_formats.workflow = 'limited';
|
|
data.metadata.workflow_graph = { status: 'limited', value: null };
|
|
return data;
|
|
}
|
|
|
|
test('record accepts limited workflow format without raw and with a limited graph', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
const record = toRecord(limitedWorkflow(), image(), extractGenerationFacts);
|
|
assert.deepEqual(record.metadata.record_formats, { prompt: 'reserialized-json', workflow: 'limited' });
|
|
assert.deepEqual(record.metadata.raw, { prompt: '{"rounded":"raw copy"}' });
|
|
assert.deepEqual(record.metadata.workflow_graph, { status: 'limited', value: null });
|
|
assert.equal(record.metadata.status, 'available');
|
|
assert.equal(record.generation.seed.value, '9007199254740993', 'a limited workflow never hides prompt-graph facts');
|
|
const workflowOnly = limitedWorkflow();
|
|
Object.assign(workflowOnly.metadata, { raw: {}, record_formats: { workflow: 'limited' }, prompt_graph: { status: 'absent', value: null } });
|
|
const facts = toRecord(workflowOnly, image(), extractGenerationFacts).generation;
|
|
assert.ok(Object.values(facts).every(fact => fact.status === 'unresolved' && fact.reason === 'projection-limited'));
|
|
const omitted = limitedWorkflow();
|
|
Object.assign(omitted.metadata, { raw: {}, parameters: null, status: 'limited', omitted_reason: 'response-size-limit', prompt_graph: { status: 'limited', value: null } });
|
|
assert.deepEqual(toRecord(omitted, image(), extractGenerationFacts).metadata.record_formats, { prompt: 'reserialized-json', workflow: 'limited' });
|
|
});
|
|
|
|
test('record rejects limited format with raw present', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
for (const mutate of [
|
|
data => { data.metadata.raw.workflow = '{"nodes":[]}'; },
|
|
data => { data.metadata.workflow_graph = { status: 'parsed', value: { nodes: [] } }; },
|
|
data => { data.metadata.workflow_graph = { status: 'malformed', value: null }; },
|
|
data => { data.metadata.workflow_graph = { status: 'absent', value: null }; },
|
|
// Role records fail closed on the server: they are never limited.
|
|
data => { data.metadata.record_formats.prompt = 'limited'; delete data.metadata.raw.prompt; data.metadata.prompt_graph = { status: 'limited', value: null }; },
|
|
data => { data.metadata.record_formats.parameters = 'limited'; },
|
|
]) {
|
|
const data = limitedWorkflow(); mutate(data); let extractions = 0;
|
|
assert.throws(() => toRecord(data, image(), () => { extractions++; return extractGenerationFacts({}); }), TypeError);
|
|
assert.equal(extractions, 0);
|
|
}
|
|
});
|
|
|
|
test('record accepts the workflow-first response omission of an invalid workflow record', () => {
|
|
const data = envelope();
|
|
data.metadata.record_formats.workflow = 'invalid';
|
|
data.metadata.workflow_graph = { status: 'limited', value: null };
|
|
const record = contract('toInspectionRecord')(data, image(), extractGenerationFacts);
|
|
assert.deepEqual(record.metadata.prompt_graph.status, 'parsed', 'prompt evidence outlives workflow evidence');
|
|
assert.equal(record.generation.seed.value, '9007199254740993');
|
|
});
|
|
|
|
test('record accepts closed reason codes and rejects contradictory ones', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
const codes = ['work-limit', 'depth-limit', 'text-limit', 'graph-ceiling', 'unsupported-node', 'runtime-value', 'composite', 'no-sampler', 'malformed', 'multistage-differs'];
|
|
for (const reason_code of codes) {
|
|
const data = envelope(); Object.assign(data.resolution, { state: 'unresolved', reason_code, node: null });
|
|
assert.doesNotThrow(() => toRecord(data, image(), extractGenerationFacts), reason_code);
|
|
}
|
|
const node = envelope(); Object.assign(node.resolution, { state: 'unresolved', reason_code: 'unsupported-node', node: { id: '7', class_type: 'LoRAfromText' } });
|
|
assert.doesNotThrow(() => toRecord(node, image(), extractGenerationFacts));
|
|
node.resolution.node.class_type = null; // the server names a non-string class as null
|
|
assert.doesNotThrow(() => toRecord(node, image(), extractGenerationFacts));
|
|
for (const state of ['resolved', 'absent', 'ambiguous', 'unresolved']) {
|
|
const data = envelope(); Object.assign(data.resolution, { state, reason_code: null, node: null });
|
|
assert.doesNotThrow(() => toRecord(data, image(), extractGenerationFacts), state);
|
|
}
|
|
for (const change of [
|
|
{ state: 'unresolved', reason_code: 'guess' }, { state: 'unresolved', reason_code: 1 },
|
|
{ state: 'resolved', reason_code: 'work-limit' }, { state: 'absent', reason_code: 'no-sampler' },
|
|
{ state: 'unresolved', reason_code: null, node: { id: '7', class_type: 'X' } },
|
|
{ state: 'unresolved', reason_code: 'unsupported-node', node: { id: 7, class_type: 'X' } },
|
|
{ state: 'unresolved', reason_code: 'unsupported-node', node: { id: '7' } },
|
|
{ state: 'unresolved', reason_code: 'unsupported-node', node: { id: '7', class_type: 7 } },
|
|
{ state: 'unresolved', reason_code: 'unsupported-node', node: 'X' },
|
|
]) {
|
|
const data = envelope(); Object.assign(data.resolution, change); let extractions = 0;
|
|
assert.throws(() => toRecord(data, image(), () => { extractions++; return extractGenerationFacts({}); }), TypeError, JSON.stringify(change));
|
|
assert.equal(extractions, 0);
|
|
}
|
|
});
|
|
|
|
test('resolution validator accepts closed reason codes and a bounded node record, rejects others', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
for (const reason_code of ['unsupported-node', 'runtime-value', 'composite']) {
|
|
for (const node of [{ id: '7', class_type: 'N'.repeat(200) }, { id: '7'.repeat(200), class_type: null }, null]) {
|
|
const data = envelope(); Object.assign(data.resolution, { state: 'unresolved', reason_code, node });
|
|
assert.doesNotThrow(() => toRecord(data, image(), extractGenerationFacts), JSON.stringify({ reason_code, node }));
|
|
}
|
|
}
|
|
for (const change of [
|
|
{ reason_code: 'unsupported-node', node: { id: '7', class_type: 'N'.repeat(201) } },
|
|
{ reason_code: 'unsupported-node', node: { id: '7'.repeat(201), class_type: 'X' } },
|
|
{ reason_code: 'unsupported-node', node: { id: '', class_type: 'X' } },
|
|
{ reason_code: 'unsupported-node', node: { id: '7', class_type: 'X', extra: true } },
|
|
{ reason_code: 'unsupported-node', node: [] },
|
|
{ reason_code: 'malformed', node: { id: '7', class_type: 'X' } },
|
|
{ reason_code: 'work-limit', node: { id: '7', class_type: 'X' } },
|
|
{ reason_code: 'no-sampler', node: { id: '7', class_type: 'X' } },
|
|
{ reason_code: 'Unsupported-Node', node: null },
|
|
{ reason_code: '', node: null },
|
|
]) {
|
|
const data = envelope(); Object.assign(data.resolution, { state: 'unresolved', ...change });
|
|
assert.throws(() => toRecord(data, image(), extractGenerationFacts), TypeError, JSON.stringify(change));
|
|
}
|
|
});
|
|
|
|
test('role outcome lines are bounded text on non-resolved roles only', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
const line = 'Prompt uses a node the inspector does not support (<img src=x onerror=alert(1)>).';
|
|
const data = envelope(); data.prompts.negative = { status: 'unresolved', text: null, source: null, message: line };
|
|
assert.equal(toRecord(data, image(), extractGenerationFacts).prompts.negative.message, line);
|
|
for (const [role, record] of [
|
|
['positive', { status: 'resolved', text: 'exact', source: 'execution', message: 'Hidden reason.' }],
|
|
['negative', { status: 'unresolved', text: null, source: null, message: '' }],
|
|
['negative', { status: 'unresolved', text: null, source: null, message: 7 }],
|
|
['negative', { status: 'unresolved', text: null, source: null, message: null }],
|
|
['negative', { status: 'unresolved', text: null, source: null, message: 'x'.repeat(513) }],
|
|
]) {
|
|
const bad = envelope(); bad.prompts[role] = record;
|
|
assert.throws(() => toRecord(bad, image(), extractGenerationFacts), TypeError, JSON.stringify(record));
|
|
}
|
|
});
|
|
|
|
test('record rejects root path media and invalid versioned fields with retryable TypeError', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
for (const mutate of [
|
|
data => { data.image.root_index = 1; }, data => { data.image.path = 'other.png'; },
|
|
data => { data.inspection_version = 2; }, data => { data.file.width = 0; },
|
|
data => { delete data.success; },
|
|
data => { data.file.size = -1; }, data => { data.library.positive_id = 9007199254740992; },
|
|
data => { data.metadata.prompt_graph = { status: 'limited', value: {} }; },
|
|
data => { data.resolution.sampler_id = {}; },
|
|
data => { data.library.tags_scope = 'recipe'; },
|
|
data => { data.library.category_scope = 'recipe'; },
|
|
data => { delete data.library.category_scope; },
|
|
data => { delete data.library.tags_scope; },
|
|
]) {
|
|
const data = envelope(); mutate(data);
|
|
assert.throws(() => toRecord(data, image(), extractGenerationFacts), error => error instanceof TypeError && !error.refreshRequired);
|
|
}
|
|
for (const url of ['https://attacker.invalid/prompt_manager/images/serve/folder/a%20%23%25.png?root=0', 'data:text/plain,unsafe', '/other/a.png', '/prompt_manager/images/serve/other.png?root=0', `/prompt_manager/images/serve/folder/a%20%23%25.png?root=1&root_scope=${scopeA}`, `/prompt_manager/images/serve/folder/a%20%23%25.png?root=0&root_scope=${scopeB}`, `/prompt_manager/images/serve/folder/a%20%23%25.png?root=0&root=1&root_scope=${scopeA}`]) {
|
|
assert.throws(() => toRecord(envelope(), { ...image(), url }, extractGenerationFacts), TypeError);
|
|
}
|
|
});
|
|
|
|
test('record preserves proxy originals and rejects opaque or normalized path escapes', () => {
|
|
const toRecord = contract('toInspectionRecord');
|
|
const previousLocation = globalThis.location, previousApi = globalThis.ApiClient;
|
|
globalThis.location = { href: 'https://workspace.example/nested/proxy/prompt_manager/workspace', pathname: '/nested/proxy/prompt_manager/workspace' };
|
|
globalThis.ApiClient = require('../../web/js/api-client.js');
|
|
try {
|
|
assert.equal(toRecord(envelope(), image(), extractGenerationFacts).download.url, `/nested/proxy${image().url}`);
|
|
const absolute = { ...image(), url: `https://workspace.example:443/nested/proxy${image().url}` };
|
|
assert.equal(toRecord(envelope(), absolute, extractGenerationFacts).download.url, absolute.url);
|
|
for (const url of [`https://workspace.example.attacker.invalid/nested/proxy${image().url}`, `/nested/proxy/prompt_manager/images/serve/folder/../a%20%23%25.png?root=0&root_scope=${scopeA}`, `//attacker.invalid${image().url}`]) assert.throws(() => toRecord(envelope(), { ...image(), url }, extractGenerationFacts), TypeError);
|
|
} finally { globalThis.location = previousLocation; globalThis.ApiClient = previousApi; }
|
|
});
|
|
|
|
test('inspectPath does not coerce or strip malformed scopes', () => {
|
|
const inspectPath = contract('inspectPath');
|
|
assert.equal(inspectPath(image()), `/prompt_manager/images/inspect/folder/a%20%23%25.png?root=0&root_scope=${scopeA}`);
|
|
assert.equal(inspectPath({ root_index: 2, path: 'a b/x#%.png' }), '/prompt_manager/images/inspect/a%20b/x%23%25.png?root=2');
|
|
for (const root_scope of [null, true, 1, {}, 'a'.repeat(63), 'A'.repeat(64), scopeA + '\n']) {
|
|
assert.throws(() => inspectPath({ ...image(), root_scope }), TypeError);
|
|
}
|
|
for (const entry of [{ root_index: '0', path: 'a.png' }, { root_index: 0, path: '../a.png' }, { root_index: 0, path: 'a//b.png' }, { root_index: 0, path: '/a.png' }, { root_index: 0, path: 'C:file.png' }]) assert.throws(() => inspectPath(entry), TypeError);
|
|
});
|
|
|
|
test('controller shares current request across subscribers', async () => {
|
|
const { api, requests } = pendingApi(), updates = [[], []];
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
const off = controller.subscribe(state => updates[0].push(state));
|
|
controller.subscribe(state => updates[1].push(state));
|
|
assert.equal(updates[0][0].record, null);
|
|
const first = controller.select(image()), second = controller.select({ ...image() });
|
|
assert.equal(requests.length, 1);
|
|
assert.equal(controller.state.loading, true);
|
|
requests[0].resolve(envelope()); await Promise.all([first, second]);
|
|
assert.equal(controller.state.record.generation.seed.value, '9007199254740993');
|
|
assert.equal(updates[0].at(-1), updates[1].at(-1));
|
|
await controller.select(image()); assert.equal(requests.length, 1);
|
|
off(); const count = updates[0].length;
|
|
const retry = controller.retry(); assert.equal(controller.state.record, null); assert.equal(controller.state.prompts, undefined);
|
|
assert.equal(requests.length, 2); assert.ok(requests[1].url.endsWith(`root_scope=${scopeA}`));
|
|
requests[1].resolve(envelope()); await retry;
|
|
assert.equal(updates[0].length, count);
|
|
controller.clear(); assert.equal(controller.state.record, null); assert.equal(controller.state.loading, false);
|
|
const reselect = controller.select(image()); assert.equal(requests.length, 3);
|
|
requests[2].resolve(envelope()); await reselect; controller.dispose();
|
|
});
|
|
|
|
test('root scope echo and source-changed require refresh', async () => {
|
|
const SourceChanged = contract('InspectionSourceChangedError'), toRecord = contract('toInspectionRecord');
|
|
for (const root_scope of [undefined, scopeB]) {
|
|
const data = envelope();
|
|
if (root_scope === undefined) delete data.root_scope; else data.root_scope = root_scope;
|
|
assert.throws(() => toRecord(data, image(), extractGenerationFacts), error => error instanceof SourceChanged && error.refreshRequired && error.message === refreshMessage);
|
|
const { api, requests } = pendingApi();
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
const load = controller.select(image()); requests[0].resolve(data); await load;
|
|
assert.deepEqual([controller.state.error, controller.state.refreshRequired, controller.state.record, controller.state.prompts, controller.state.message], [true, true, null, undefined, refreshMessage]);
|
|
await controller.retry(); assert.equal(requests.length, 1); controller.dispose();
|
|
}
|
|
for (const [status, code, refresh] of [[409, 'source-changed', true], [409, null, false], [409, 'file-changed', false], [500, 'source-changed', false]]) {
|
|
const { api, requests } = pendingApi();
|
|
const controller = module.createInspectionController({ api, extractFacts: extractGenerationFacts });
|
|
const load = controller.select(image()); requests[0].reject(new ApiError(status, refreshMessage, code)); await load;
|
|
assert.equal(controller.state.refreshRequired, refresh);
|
|
const retry = controller.retry(); assert.equal(requests.length, refresh ? 1 : 2);
|
|
if (!refresh) { requests[1].resolve(envelope()); await retry; assert.equal(controller.state.error, false); }
|
|
controller.dispose();
|
|
}
|
|
});
|
|
|
|
test('same image key with changed scope supersedes pending actions', async () => {
|
|
const { api, requests } = pendingApi();
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
const first = controller.select(image());
|
|
requests[0].resolve(envelope()); await first;
|
|
const changed = image(scopeB), next = controller.select(changed);
|
|
assert.equal(controller.state.record, null); assert.equal(controller.state.prompts, undefined);
|
|
assert.equal(requests.length, 2);
|
|
requests[1].resolve(envelope(changed)); await next;
|
|
assert.equal(controller.state.record.identity.root_scope, scopeB);
|
|
assert.equal(controller.state.record.file.source_label, 'same label');
|
|
controller.dispose();
|
|
});
|
|
|
|
test('unscoped role-only callers stay compatible', async () => {
|
|
const toRecord = contract('toInspectionRecord'), entry = { root_index: 0, path: 'old.png' };
|
|
const data = { prompts: { positive: { status: 'resolved', text: 'old', source: 'graph-inferred' }, negative: { status: 'unresolved', text: null, source: null } } };
|
|
const record = toRecord(data, entry, extractGenerationFacts);
|
|
assert.equal(record.identity.root_scope, null); assert.equal(record.identity.key, '0:old.png');
|
|
for (const key of ['file', 'metadata', 'library', 'download', 'historyTarget']) assert.equal(record[key], null);
|
|
for (const field of fields) assert.deepEqual(record.generation[field], { status: 'unresolved', value: null, source: null, evidence: null, reason: null, sampler_id: null });
|
|
assert.deepEqual(record.prompts, data.prompts);
|
|
const changes = [];
|
|
const loader = contract('createInspectionLoader')({ get: async () => data }, value => changes.push(value));
|
|
await loader.load(entry);
|
|
assert.deepEqual(changes.at(-1).prompts, data.prompts); assert.equal(changes.at(-1).record.identity.key, '0:old.png');
|
|
loader.dispose();
|
|
assert.throws(() => toRecord(data, image(), extractGenerationFacts), error => error.refreshRequired === true);
|
|
const scoped = toRecord({ ...data, root_scope: scopeA }, image(), extractGenerationFacts);
|
|
assert.equal(scoped.metadata, null); assert.equal(scoped.download.url, image().url);
|
|
});
|
|
|
|
test('disposed or superseded responses never publish', async () => {
|
|
const { api, requests } = pendingApi(), updates = [];
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
controller.subscribe(state => updates.push(state));
|
|
const first = controller.select(image()), newer = image(scopeB), second = controller.select(newer);
|
|
assert.equal(requests[0].signal.aborted, true);
|
|
requests[1].resolve(envelope(newer)); await second;
|
|
const count = updates.length;
|
|
requests[0].reject(new ApiError(409, refreshMessage, 'source-changed')); await first;
|
|
assert.equal(updates.length, count); assert.equal(controller.state.record.identity.root_scope, scopeB);
|
|
const third = controller.retry(); controller.clear();
|
|
assert.equal(requests[2].signal.aborted, true);
|
|
requests[2].resolve(envelope(newer)); await third;
|
|
assert.equal(controller.state.record, null);
|
|
const final = controller.select(image()); controller.dispose(); const disposedCount = updates.length;
|
|
requests[3].resolve(envelope()); await final;
|
|
await controller.select(newer); await controller.retry(); controller.clear();
|
|
assert.equal(updates.length, disposedCount); assert.equal(requests.length, 4);
|
|
});
|
|
|
|
const invalidSelections = () => [null, undefined, 0, 'new.png', {}, { ...image(), path: '../new.png' }, { ...image(), root_scope: null }, { ...image(), root_scope: 'malformed' }];
|
|
|
|
test('invalid attempted selections clear completed actions and retry validation only', async () => {
|
|
for (const invalid of invalidSelections()) {
|
|
const { api, requests } = pendingApi();
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
const previous = controller.select(image()); requests[0].resolve(envelope()); await previous;
|
|
assert.equal(controller.state.prompts.positive.text, 'exact\npositive');
|
|
let rejected, thrown;
|
|
try { rejected = controller.select(invalid); } catch (error) { thrown = error; }
|
|
assert.equal(controller.state.record, null, 'invalid navigation cannot retain completed actions'); assert.equal(controller.state.prompts, undefined);
|
|
assert.equal(thrown, undefined, 'selection validation uses the retryable state');
|
|
await rejected;
|
|
assert.deepEqual([controller.state.loading, controller.state.error, controller.state.refreshRequired, controller.state.message], [false, true, false, 'Could not read details from this file.']);
|
|
await controller.retry(); await controller.retry(); assert.equal(requests.length, 1);
|
|
const valid = controller.select(image()); assert.equal(requests.length, 2);
|
|
requests[1].resolve(envelope()); await valid;
|
|
await controller.select({ ...image() }); assert.equal(requests.length, 2);
|
|
controller.dispose();
|
|
}
|
|
});
|
|
|
|
test('invalid attempted selections abort pending reads and suppress late results', async () => {
|
|
for (const invalid of invalidSelections()) {
|
|
const { api, requests } = pendingApi(), changes = [];
|
|
const controller = contract('createInspectionController')({ api, extractFacts: extractGenerationFacts });
|
|
controller.subscribe(state => changes.push(state));
|
|
const previous = controller.select(image());
|
|
let rejected, thrown;
|
|
try { rejected = controller.select(invalid); } catch (error) { thrown = error; }
|
|
assert.equal(requests[0].signal.aborted, true);
|
|
assert.equal(thrown, undefined, 'selection validation uses the retryable state');
|
|
assert.equal(controller.state.record, null); assert.equal(controller.state.prompts, undefined);
|
|
await rejected; const count = changes.length;
|
|
requests[0].resolve(envelope()); await previous;
|
|
assert.equal(changes.length, count); assert.equal(controller.state.error, true);
|
|
assert.equal(controller.state.record, null); assert.equal(controller.state.prompts, undefined);
|
|
await controller.retry(); assert.equal(requests.length, 1);
|
|
controller.dispose();
|
|
}
|
|
});
|
|
|
|
test('explicit rooted adapter preserves the strict default identity and download contract', () => {
|
|
assert.ok(module.rootedFileAdapter, 'the default rooted adapter is exported');
|
|
const a = module.rootedFileAdapter, entry = image();
|
|
assert.equal(a.key(entry), '0:folder/a #%.png'); assert.equal(a.scope(entry), scopeA);
|
|
assert.equal(a.inspectionPath(entry), module.inspectPath(entry));
|
|
assert.deepEqual(a.originalDownload(entry), module.originalMediaDownload(entry));
|
|
assert.deepEqual(a.toRecord(envelope(), entry, extractGenerationFacts), module.toInspectionRecord(envelope(), entry, extractGenerationFacts));
|
|
assert.throws(() => a.validate({kind:'reported-location',path:'a.png'}), TypeError);
|
|
});
|
|
|
|
test('rooted controller keeps legacy descriptors with ignored noncloneable fields source compatible', async () => {
|
|
const {api,requests}=pendingApi(),controller=module.createInspectionController({api,extractFacts:extractGenerationFacts});
|
|
const selected={...image(),ignoredCallback(){}};
|
|
let pending;assert.doesNotThrow(()=>{pending=controller.select(selected);});
|
|
requests[0].resolve(envelope());await pending;assert.equal(controller.state.record.identity.key,'0:folder/a #%.png');controller.dispose();
|
|
});
|
|
|
|
// The maintainer's standard pipeline: one PromptManager pair feeds a base pass, an
|
|
// upscale pass and a FaceDetailer, saved by a custom saver. Text and seeds are invented.
|
|
function detailerPipelineGraph() {
|
|
return {
|
|
1: { class_type: 'CheckpointLoaderSimple', inputs: { ckpt_name: 'Base/example_model.safetensors' } },
|
|
5: { class_type: 'KSampler', inputs: { seed: 111, steps: 4, cfg: 1.0, sampler_name: 'lcm', scheduler: 'normal', denoise: 1.0, model: ['47', 0], positive: ['25', 0], negative: ['26', 0], latent_image: ['20', 0] } },
|
|
6: { class_type: 'VAEDecode', inputs: { samples: ['5', 0], vae: ['1', 2] } },
|
|
7: { class_type: 'PreviewImage', inputs: { images: ['6', 0] } },
|
|
8: { class_type: 'UpscaleModelLoader', inputs: { model_name: 'upscaler.pth' } },
|
|
9: { class_type: 'ImageUpscaleWithModel', inputs: { upscale_model: ['8', 0], image: ['6', 0] } },
|
|
10: { class_type: 'ImageScaleBy', inputs: { upscale_method: 'lanczos', scale_by: 0.75, image: ['9', 0] } },
|
|
11: { class_type: 'VAEEncode', inputs: { pixels: ['10', 0], vae: ['1', 2] } },
|
|
12: { class_type: 'KSampler', inputs: { seed: 222, steps: 6, cfg: 1.0, sampler_name: 'lcm', scheduler: 'normal', denoise: 0.45, model: ['47', 0], positive: ['25', 0], negative: ['26', 0], latent_image: ['11', 0] } },
|
|
13: { class_type: 'VAEDecode', inputs: { samples: ['12', 0], vae: ['1', 2] } },
|
|
17: { class_type: 'FaceDetailer', inputs: { seed: 333, steps: 4, cfg: 1.0, sampler_name: 'lcm', scheduler: 'normal', denoise: 0.4, image: ['13', 0], model: ['47', 0], clip: ['47', 1], vae: ['1', 2], positive: ['25', 0], negative: ['26', 0] } },
|
|
20: { class_type: 'EmptyLatentBatch', inputs: { width: 640, height: 1536, batch_size: 1 } },
|
|
25: { class_type: 'PromptManager', inputs: { text: 'a lighthouse at dusk, oil painting', category: '', tags: '', search_text: '', prepend_text: '', append_text: '', clip: ['47', 1] } },
|
|
26: { class_type: 'PromptManager', inputs: { text: 'blurry, watermark', category: '', tags: '', search_text: '', prepend_text: '', append_text: '', clip: ['47', 1] } },
|
|
47: { class_type: 'Lora Loader (LoraManager)', inputs: { text: '', model: ['1', 0], clip: ['1', 1] } },
|
|
48: { class_type: 'KikoSaveImage', inputs: { filename_prefix: ['49', 0], format: 'PNG', images: ['17', 0] } },
|
|
49: { class_type: 'KikoProjectFilePath', inputs: { project_name: 'example', filename: 'image' } },
|
|
};
|
|
}
|
|
|
|
test('workflow prompts and settings match the legacy parser when the server cannot decide', t => {
|
|
const parser = require('../../web/js/comfy-metadata.js'), { extractGenerationParams } = parser;
|
|
globalThis.ComfyMetadata = parser;
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const entry = image(), data = envelope(entry);
|
|
data.prompts = { positive: { status: 'ambiguous', text: null, source: null }, negative: { status: 'ambiguous', text: null, source: null } };
|
|
data.metadata.prompt_graph = { status: 'parsed', value: detailerPipelineGraph() };
|
|
data.resolution = { state: 'ambiguous', sampler_id: null, reason: 'Multiple sampler branches' };
|
|
const record = contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
const legacy = extractGenerationParams({ prompt: detailerPipelineGraph() });
|
|
assert.deepEqual(record.prompts.positive, { status: 'resolved', text: legacy.positivePrompt, source: 'graph-inferred' });
|
|
assert.deepEqual(record.prompts.negative, { status: 'resolved', text: legacy.negativePrompt, source: 'graph-inferred' });
|
|
assert.equal(record.prompts.positive.text, 'a lighthouse at dusk, oil painting');
|
|
assert.equal(record.prompts.negative.text, 'blurry, watermark');
|
|
for (const [field, key] of [['seed', 'seed'], ['steps', 'steps'], ['cfg', 'cfgScale'], ['sampler', 'sampler'], ['model', 'checkpoint']]) {
|
|
assert.equal(record.generation[field].status, 'known', field);
|
|
assert.equal(record.generation[field].value, String(legacy[key]), field);
|
|
}
|
|
});
|
|
|
|
test('recorded and saved prompts are never replaced by the workflow parse', t => {
|
|
globalThis.ComfyMetadata = require('../../web/js/comfy-metadata.js');
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const entry = image(), data = envelope(entry);
|
|
data.metadata.prompt_graph = { status: 'parsed', value: detailerPipelineGraph() };
|
|
const record = contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
assert.deepEqual(record.prompts.positive, { status: 'resolved', text: 'exact\npositive', source: 'execution' });
|
|
assert.equal(record.prompts.negative.text, 'blurry, watermark');
|
|
});
|
|
|
|
test('a definite server prompt is kept even when the legacy parser reads it differently', t => {
|
|
globalThis.ComfyMetadata = require('../../web/js/comfy-metadata.js');
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const entry = image(), data = envelope(entry);
|
|
// The legacy parser follows ConditioningZeroOut back to the positive text node.
|
|
const graph = detailerPipelineGraph();
|
|
graph[30] = { class_type: 'ConditioningZeroOut', inputs: { conditioning: ['25', 0] } };
|
|
graph[5].inputs.negative = ['30', 0];
|
|
data.metadata.prompt_graph = { status: 'parsed', value: graph };
|
|
data.prompts = { positive: { status: 'ambiguous', text: null, source: null }, negative: { status: 'resolved', text: '', source: 'zeroed-conditioning' } };
|
|
const record = contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
assert.deepEqual(record.prompts.negative, { status: 'resolved', text: '', source: 'zeroed-conditioning' });
|
|
assert.equal(record.prompts.positive.text, 'a lighthouse at dusk, oil painting');
|
|
});
|
|
|
|
// #249: a LoRA compare grid. Every sampler's negative is a ConditioningZeroOut of the
|
|
// positive encode; the legacy parser follows the zero-out back to the positive text.
|
|
function zeroedGridGraph(samplers = 3) {
|
|
const graph = {
|
|
1: { class_type: 'UNETLoader', inputs: { unet_name: 'base.safetensors', weight_dtype: 'default' } },
|
|
2: { class_type: 'CLIPLoader', inputs: { clip_name: 'te.safetensors', type: 'stable_diffusion' } },
|
|
4: { class_type: 'CLIPTextEncode', inputs: { text: 'a woman holding a coffee cup', clip: ['2', 0] } },
|
|
5: { class_type: 'ConditioningZeroOut', inputs: { conditioning: ['4', 0] } },
|
|
6: { class_type: 'EmptyLatentImage', inputs: { width: 512, height: 512, batch_size: 1 } },
|
|
};
|
|
for (let index = 0; index < samplers; index++) {
|
|
graph[`1${index}`] = { class_type: 'LoraLoaderModelOnly', inputs: { lora_name: `epoch_${index}.safetensors`, strength_model: 1, model: ['1', 0] } };
|
|
graph[`2${index}`] = { class_type: 'KSampler', inputs: { seed: 42, steps: 8, cfg: 1, sampler_name: 'euler', scheduler: 'simple', denoise: 1,
|
|
model: [`1${index}`, 0], positive: ['4', 0], negative: ['5', 0], latent_image: ['6', 0] } };
|
|
}
|
|
return graph;
|
|
}
|
|
|
|
function undecided(graph) {
|
|
const entry = image(), data = envelope(entry);
|
|
data.prompts = { positive: { status: 'ambiguous', text: null, source: null }, negative: { status: 'ambiguous', text: null, source: null } };
|
|
data.metadata.prompt_graph = { status: 'parsed', value: graph };
|
|
data.resolution = { state: 'ambiguous', sampler_id: null, reason: 'Multiple sampler branches' };
|
|
return contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
}
|
|
|
|
test('a zeroed negative is never filled with the positive text from the legacy parse (#249)', t => {
|
|
const parser = require('../../web/js/comfy-metadata.js');
|
|
globalThis.ComfyMetadata = parser;
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
// The legacy pages keep their reading: the zero-out passes the positive through.
|
|
assert.equal(parser.extractGenerationParams({ prompt: zeroedGridGraph() }).negativePrompt, 'a woman holding a coffee cup');
|
|
const record = undecided(zeroedGridGraph());
|
|
assert.deepEqual(record.prompts.positive, { status: 'resolved', text: 'a woman holding a coffee cup', source: 'graph-inferred' });
|
|
assert.deepEqual(record.prompts.negative, { status: 'resolved', text: '', source: 'zeroed-conditioning' });
|
|
// Behind an API-graph Reroute the legacy parse reads no negative, so there is nothing
|
|
// to correct: the server's answer stays.
|
|
const rerouted = zeroedGridGraph(1);
|
|
rerouted[7] = { class_type: 'Reroute', inputs: { value: ['5', 0] } };
|
|
rerouted[20].inputs.negative = ['7', 0];
|
|
assert.equal(parser.legacyNegativeSource({ prompt: rerouted }), null);
|
|
assert.deepEqual(undecided(rerouted).prompts.negative, { status: 'ambiguous', text: null, source: null });
|
|
});
|
|
|
|
test('the zero-out check follows the sampler the legacy parse read (#249)', t => {
|
|
const parser = require('../../web/js/comfy-metadata.js');
|
|
globalThis.ComfyMetadata = parser;
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const zeroed = { status: 'resolved', text: '', source: 'zeroed-conditioning' };
|
|
// The legacy parse reads the first sampler (20): its negative is the zero-out.
|
|
const mixed = zeroedGridGraph(2);
|
|
mixed[8] = { class_type: 'CLIPTextEncode', inputs: { text: 'blurry', clip: ['2', 0] } };
|
|
mixed[21].inputs.negative = ['8', 0];
|
|
assert.deepEqual(undecided(mixed).prompts.negative, zeroed);
|
|
// Reversed: the sampler it reads encodes "blurry", which it showed before and still does.
|
|
const reversed = zeroedGridGraph(2);
|
|
reversed[8] = { class_type: 'CLIPTextEncode', inputs: { text: 'blurry', clip: ['2', 0] } };
|
|
reversed[20].inputs.negative = ['8', 0];
|
|
assert.equal(parser.extractGenerationParams({ prompt: reversed }).negativePrompt, 'blurry');
|
|
assert.deepEqual(undecided(reversed).prompts.negative, { status: 'resolved', text: 'blurry', source: 'graph-inferred' });
|
|
// The positive fills from the legacy parse in both cases.
|
|
assert.equal(undecided(mixed).prompts.positive.text, 'a woman holding a coffee cup');
|
|
assert.equal(undecided(reversed).prompts.positive.text, 'a woman holding a coffee cup');
|
|
});
|
|
|
|
test('a zero-out mixed into the read negative leaves it as the server left it (#249)', t => {
|
|
globalThis.ComfyMetadata = require('../../web/js/comfy-metadata.js');
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
// A zero-out combined with another conditioning is not an empty negative.
|
|
const combined = zeroedGridGraph(1);
|
|
combined[8] = { class_type: 'CLIPTextEncode', inputs: { text: 'blurry', clip: ['2', 0] } };
|
|
combined[9] = { class_type: 'ConditioningCombine', inputs: { conditioning_1: ['5', 0], conditioning_2: ['8', 0] } };
|
|
combined[20].inputs.negative = ['9', 0];
|
|
assert.deepEqual(undecided(combined).prompts.negative, { status: 'ambiguous', text: null, source: null });
|
|
});
|
|
|
|
function workflowOnly(workflow) {
|
|
const entry = image(), data = envelope(entry);
|
|
data.prompts = { positive: { status: 'unresolved', text: null, source: null }, negative: { status: 'unresolved', text: null, source: null } };
|
|
Object.assign(data.metadata, { raw: { workflow: JSON.stringify(workflow) }, record_formats: { workflow: 'reserialized-json' },
|
|
prompt_graph: { status: 'absent', value: null }, workflow_graph: { status: 'parsed', value: workflow } });
|
|
return contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
}
|
|
|
|
// A UI workflow: encode 4 -> zero-out 5 -> sampler 3's negative, encode 4 -> positive.
|
|
function zeroedWorkflow({ zeroMode = 0, extraNodes = [], extraLinks = [], negativeLink = 3 } = {}) {
|
|
return { nodes: [
|
|
{ id: 4, type: 'CLIPTextEncode', inputs: [], outputs: [{ links: [1, 2] }], widgets_values: ['a woman holding a coffee cup'] },
|
|
{ id: 5, type: 'ConditioningZeroOut', mode: zeroMode, inputs: [{ name: 'conditioning', type: 'CONDITIONING', link: 1 }], outputs: [{ links: [3] }] },
|
|
{ id: 1, type: 'UNETLoader', inputs: [], outputs: [{ links: [4] }], widgets_values: ['base.safetensors', 'default'] },
|
|
{ id: 3, type: 'KSampler', inputs: [{ name: 'model', link: 4 }, { name: 'positive', link: 2 }, { name: 'negative', link: negativeLink }], widgets_values: [42, 'fixed', 8, 1, 'euler', 'simple', 1] },
|
|
...extraNodes,
|
|
], links: [[1, 4, 0, 5, 0, 'CONDITIONING'], [2, 4, 0, 3, 1, 'CONDITIONING'], [3, 5, 0, 3, 2, 'CONDITIONING'], [4, 1, 0, 3, 0, 'MODEL'], ...extraLinks] };
|
|
}
|
|
|
|
test('workflow-only files follow the legacy reading of their zero-out (#249)', t => {
|
|
const parser = require('../../web/js/comfy-metadata.js');
|
|
globalThis.ComfyMetadata = parser;
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
// A connected zero-out on the read sampler's negative is the zeroed empty negative.
|
|
const direct = zeroedWorkflow();
|
|
assert.equal(parser.extractGenerationParams({ workflow: direct }).negativePrompt, 'a woman holding a coffee cup', 'the legacy parse would fill it');
|
|
assert.deepEqual(workflowOnly(direct).prompts.negative, { status: 'resolved', text: '', source: 'zeroed-conditioning' });
|
|
// A bypassed zero-out (mode 4) passes its conditioning through: the legacy reading is right.
|
|
const bypassed = workflowOnly(zeroedWorkflow({ zeroMode: 4 }));
|
|
assert.deepEqual(bypassed.prompts.negative, { status: 'resolved', text: 'a woman holding a coffee cup', source: 'graph-inferred' });
|
|
// An unconnected zero-out beside a text negative changes nothing.
|
|
const unconnected = workflowOnly(zeroedWorkflow({ negativeLink: 6,
|
|
extraNodes: [{ id: 6, type: 'CLIPTextEncode', inputs: [], outputs: [{ links: [6] }], widgets_values: ['blurry'] }],
|
|
extraLinks: [[6, 6, 0, 3, 2, 'CONDITIONING']] }));
|
|
assert.deepEqual(unconnected.prompts.negative, { status: 'resolved', text: 'blurry', source: 'graph-inferred' });
|
|
});
|
|
|
|
test('a negative read through a subgraph holding a zero-out is not filled (#249)', t => {
|
|
const parser = require('../../web/js/comfy-metadata.js');
|
|
globalThis.ComfyMetadata = parser;
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
// The sampler's negative comes from a subgraph instance whose definition zeroes it.
|
|
const definition = 'aaaaaaaa-0000-4000-8000-000000000001';
|
|
const workflow = zeroedWorkflow({ negativeLink: 7,
|
|
extraNodes: [{ id: 9, type: definition, inputs: [{ name: 'conditioning', type: 'CONDITIONING', link: 8 }], outputs: [{ links: [7] }] }],
|
|
extraLinks: [[7, 9, 0, 3, 2, 'CONDITIONING'], [8, 4, 0, 9, 0, 'CONDITIONING']] });
|
|
workflow.definitions = { subgraphs: [{ id: definition, nodes: [{ id: 1, type: 'ConditioningZeroOut', inputs: [], outputs: [] }], links: [] }] };
|
|
assert.equal(parser.extractGenerationParams({ workflow }).negativePrompt, 'a woman holding a coffee cup', 'the legacy parse would fill it');
|
|
assert.deepEqual(workflowOnly(workflow).prompts.negative, { status: 'unresolved', text: null, source: null });
|
|
// The same instance of a definition without a zero-out keeps the legacy fill.
|
|
workflow.definitions.subgraphs[0].nodes[0].type = 'Reroute';
|
|
assert.equal(workflowOnly(workflow).prompts.negative.text, 'a woman holding a coffee cup');
|
|
});
|
|
|
|
test('callers without the browser global pass the legacy parser explicitly', () => {
|
|
const parser = require('../../web/js/comfy-metadata.js');
|
|
const entry = image(), data = envelope(entry);
|
|
data.prompts = { positive: { status: 'ambiguous', text: null, source: null }, negative: { status: 'ambiguous', text: null, source: null } };
|
|
data.metadata.prompt_graph = { status: 'parsed', value: detailerPipelineGraph() };
|
|
const identity = { kind: 'rooted-file', key: '0:x', root_index: 0, path: entry.path, root_scope: scopeA };
|
|
const record = contract('projectInspectionPayload')(data, identity, null, extractGenerationFacts, false, parser);
|
|
assert.equal(record.prompts.positive.text, 'a lighthouse at dusk, oil painting');
|
|
assert.equal(record.prompts.negative.text, 'blurry, watermark');
|
|
});
|
|
|
|
test('a setting the file does not record is never filled from the legacy parse', t => {
|
|
globalThis.ComfyMetadata = require('../../web/js/comfy-metadata.js');
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const entry = image(), data = envelope(entry);
|
|
data.metadata.prompt_graph = { status: 'parsed', value: detailerPipelineGraph() };
|
|
const extract = input => ({ ...extractGenerationFacts(input), cfg: { status: 'not-recorded', value: null, source: null, evidence: null, reason: null, sampler_id: null } });
|
|
const record = contract('toInspectionRecord')(data, entry, extract);
|
|
assert.equal(record.generation.cfg.status, 'not-recorded');
|
|
assert.equal(record.generation.cfg.value, null);
|
|
});
|
|
|
|
test('a workflow the legacy parser throws on keeps the server result instead of failing the record', t => {
|
|
globalThis.ComfyMetadata = require('../../web/js/comfy-metadata.js');
|
|
t.after(() => { delete globalThis.ComfyMetadata; });
|
|
const entry = image(), data = envelope(entry);
|
|
// The browser parser throws on a null workflow node (it reads properties of it).
|
|
data.metadata.workflow_graph = { status: 'parsed', value: { nodes: [null], links: [] } };
|
|
data.metadata.raw.workflow = '{"nodes":[null],"links":[]}';
|
|
data.metadata.record_formats.workflow = 'reserialized-json';
|
|
const record = contract('toInspectionRecord')(data, entry, extractGenerationFacts);
|
|
assert.deepEqual(record.prompts.positive, { status: 'resolved', text: 'exact\npositive', source: 'execution' });
|
|
assert.equal(record.prompts.negative.status, 'ambiguous');
|
|
});
|