fix preview inputs and markup preview

This commit is contained in:
2026-03-27 21:34:51 -07:00
parent 66f1bca046
commit 63bdc70456
13 changed files with 501 additions and 316 deletions

View File

@@ -25,7 +25,7 @@ test('serializeExecutionGraph excludes isolated nodes from the backend prompt',
data: {
className: 'PreviewImage',
definition: {
input: { required: { field: ['DATA_FIELD', {}] }, optional: {} },
input: { required: {}, optional: { input: ['ANNOTATION_SOURCE', {}] } },
manual_trigger: false,
},
widgetValues: {},
@@ -48,7 +48,7 @@ test('serializeExecutionGraph excludes isolated nodes from the backend prompt',
source: '1',
sourceHandle: 'output::0::DATA_FIELD',
target: '2',
targetHandle: 'input::field::DATA_FIELD',
targetHandle: 'input::input::ANNOTATION_SOURCE',
},
];
@@ -61,7 +61,7 @@ test('serializeExecutionGraph excludes isolated nodes from the backend prompt',
},
'2': {
class_type: 'PreviewImage',
inputs: { field: ['1', 0] },
inputs: { input: ['1', 0] },
},
});
assert.equal('3' in prompt, false);
@@ -85,7 +85,7 @@ test('serializeExecutionGraph includes isolated preview-load nodes alongside con
data: {
className: 'PreviewImage',
definition: {
input: { required: { field: ['DATA_FIELD', {}] }, optional: {} },
input: { required: {}, optional: { input: ['ANNOTATION_SOURCE', {}] } },
manual_trigger: false,
},
widgetValues: {},
@@ -119,7 +119,7 @@ test('serializeExecutionGraph includes isolated preview-load nodes alongside con
source: '1',
sourceHandle: 'output::0::DATA_FIELD',
target: '2',
targetHandle: 'input::field::DATA_FIELD',
targetHandle: 'input::input::ANNOTATION_SOURCE',
},
];
@@ -132,7 +132,7 @@ test('serializeExecutionGraph includes isolated preview-load nodes alongside con
},
'2': {
class_type: 'PreviewImage',
inputs: { field: ['1', 0] },
inputs: { input: ['1', 0] },
},
'3': {
class_type: 'ImageDemo',
@@ -220,7 +220,7 @@ test('serializeExecutionGraph ignores group shells and resolves collapsed proxy
data: {
className: 'PreviewImage',
definition: {
input: { required: { field: ['DATA_FIELD', {}] }, optional: {} },
input: { required: {}, optional: { input: ['ANNOTATION_SOURCE', {}] } },
manual_trigger: false,
},
widgetValues: {},
@@ -233,12 +233,12 @@ test('serializeExecutionGraph ignores group shells and resolves collapsed proxy
source: '1',
sourceHandle: 'output::0::DATA_FIELD',
target: '10',
targetHandle: 'group-proxy::in::2::DATA_FIELD::input%3A%3Afield%3A%3ADATA_FIELD',
targetHandle: 'group-proxy::in::2::ANNOTATION_SOURCE::input%3A%3Ainput%3A%3AANNOTATION_SOURCE',
data: {
groupProxyOwner: '10',
groupProxyOriginal: {
target: '2',
targetHandle: 'input::field::DATA_FIELD',
targetHandle: 'input::input::ANNOTATION_SOURCE',
},
},
},
@@ -253,7 +253,7 @@ test('serializeExecutionGraph ignores group shells and resolves collapsed proxy
},
'2': {
class_type: 'PreviewImage',
inputs: { field: ['1', 0] },
inputs: { input: ['1', 0] },
},
});
assert.equal('10' in prompt, false);
@@ -365,7 +365,7 @@ test('getAutoRunnableNodes includes isolated preview-load nodes with selections'
source: '1',
sourceHandle: 'output::0::DATA_FIELD',
target: '2',
targetHandle: 'input::field::DATA_FIELD',
targetHandle: 'input::input::ANNOTATION_SOURCE',
},
];

View File

@@ -0,0 +1,67 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
MARKUP_DEFAULT_COLOR,
MARKUP_DEFAULT_SHAPE,
getArrowGeometry,
getMarkupPreviewStrokeWidth,
sanitizeMarkupColor,
sanitizeMarkupShape,
} from '../src/markupShapeGeometry.js';
test('markup defaults use arrow and red', () => {
assert.equal(MARKUP_DEFAULT_SHAPE, 'arrow');
assert.equal(MARKUP_DEFAULT_COLOR, '#ff0000');
assert.equal(sanitizeMarkupColor(undefined), '#ff0000');
});
test('sanitizeMarkupShape falls back to arrow and red', () => {
assert.deepEqual(
sanitizeMarkupShape(
{
kind: 'triangle',
x1: 0.1,
y1: 0.2,
x2: 0.9,
y2: 0.8,
width: 5,
color: 'not-a-color',
},
MARKUP_DEFAULT_SHAPE,
MARKUP_DEFAULT_COLOR,
3,
),
{
kind: 'arrow',
x1: 0.1,
y1: 0.2,
x2: 0.9,
y2: 0.8,
width: 5,
color: '#ff0000',
},
);
});
test('getArrowGeometry keeps the shaft at the head base with no rounded overlap', () => {
const arrow = getArrowGeometry(
{
x1: 0,
y1: 0,
x2: 1,
y2: 0,
width: 4,
},
100,
100,
);
assert.equal(arrow.line, '0,0 84,0');
assert.equal(arrow.head, '100,0 84,6 84,-6');
});
test('getMarkupPreviewStrokeWidth matches backend preview scaling', () => {
assert.equal(getMarkupPreviewStrokeWidth(10, 256, 256), 10);
assert.equal(getMarkupPreviewStrokeWidth(10, 1024, 768), 20);
});

View File

@@ -0,0 +1,31 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { buildDefaultWidgetValues, getDefaultWidgetValue } from '../src/nodeWidgetDefaults.js';
test('enum widget defaults honor opts.default instead of the first option', () => {
assert.equal(
getDefaultWidgetValue([['line', 'rectangle', 'circle', 'arrow'], { default: 'arrow' }]),
'arrow',
);
});
test('buildDefaultWidgetValues keeps non-data required widget defaults', () => {
assert.deepEqual(
buildDefaultWidgetValues({
input: {
required: {
input: ['ANNOTATION_SOURCE', { label: 'Input' }],
shape: [['line', 'rectangle', 'circle', 'arrow'], { default: 'arrow' }],
stroke_color: ['STRING', { default: '#ff0000', color_picker: true }],
stroke_width: ['INT', { default: 3 }],
},
},
}),
{
shape: 'arrow',
stroke_color: '#ff0000',
stroke_width: 3,
},
);
});