Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

test(webv2): add failing tests for saved workflow and enum defects

Lincoln Steind1196db33afa
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
index 6768c24a3f..ed19345bd8 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/buildGraph.test.ts
@@ -1,3 +1,4 @@
+import { parseOpenApiToTemplates } from '@features/workflow/data/templates';
import { describe, expect, it, vi } from 'vitest';
import type { FieldInputTemplate, InvocationTemplate, InvocationTemplatesSnapshot, ProjectGraphState } from './types';
@@ -812,3 +813,80 @@ describe('seed inputs', () => {
expect(getWorkflowFieldSeedMode({ seedMode: 'decrement' })).toBe('decrement');
});
});
+
+describe('integer Literal enum values in the compiled graph', () => {
+ const literalEnumSchema = {
+ components: {
+ schemas: {
+ IntegerOutput: {
+ class: 'output',
+ properties: { type: { const: 'integer_output' }, value: { field_kind: 'output', type: 'integer' } },
+ type: 'object',
+ },
+ MaxSeqLenInvocation: {
+ class: 'invocation',
+ output: { $ref: '#/components/schemas/IntegerOutput' },
+ properties: {
+ max_seq_len: {
+ default: 512,
+ enum: [256, 512],
+ field_kind: 'input',
+ orig_required: false,
+ title: 'Max Seq Length',
+ type: 'integer',
+ },
+ type: { default: 'max_seq_len_invocation' },
+ },
+ title: 'MaxSeqLen',
+ type: 'object',
+ },
+ },
+ },
+ };
+
+ // End-to-end companion to the template test: whatever shape the template
+ // takes, the value that reaches the backend has to be the number the
+ // `Literal[256, 512]` annotation accepts.
+ it('sends a numeric Literal enum value', () => {
+ const parsedTemplates = parseOpenApiToTemplates(literalEnumSchema);
+ const parsedTemplate = parsedTemplates.max_seq_len_invocation;
+
+ if (!parsedTemplate) {
+ throw new Error('fixture template was not parsed');
+ }
+
+ const node = buildInvocationNode(parsedTemplate, { x: 0, y: 0 });
+ const doc = projectGraphReducer(createProjectGraph('literal-enum'), { node, type: 'addNode' });
+
+ expect(compileProjectGraph(doc, parsedTemplates).backendGraph?.nodes[node.id]).toMatchObject({
+ max_seq_len: 512,
+ });
+ });
+
+ // The default is only half the wire path: whatever the field widget offers
+ // has to compile to a number too, otherwise picking an option from the
+ // dropdown reintroduces the rejected string.
+ it('sends a numeric value for the option the field widget offers', () => {
+ const parsedTemplates = parseOpenApiToTemplates(literalEnumSchema);
+ const parsedTemplate = parsedTemplates.max_seq_len_invocation;
+ const firstOption = parsedTemplate?.inputs.max_seq_len?.options?.[0];
+
+ if (!parsedTemplate || firstOption === undefined) {
+ throw new Error('fixture template was not parsed');
+ }
+
+ const node = buildInvocationNode(parsedTemplate, { x: 0, y: 0 });
+ let doc = projectGraphReducer(createProjectGraph('literal-enum-pick'), { node, type: 'addNode' });
+
+ doc = projectGraphReducer(doc, {
+ fieldName: 'max_seq_len',
+ nodeId: node.id,
+ type: 'setFieldValue',
+ value: firstOption,
+ });
+
+ expect(compileProjectGraph(doc, parsedTemplates).backendGraph?.nodes[node.id]).toMatchObject({
+ max_seq_len: 256,
+ });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
index c303ba9685..32716b286c 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/callSavedWorkflow.test.ts
@@ -424,3 +424,30 @@ describe('Call Saved Workflow dynamic fields', () => {
).toBe(false);
});
});
+
+describe('Call Saved Workflow labels across a reload', () => {
+ // Consequence of the dropped `labelOverride`: on a parent whose dynamic
+ // templates were never persisted, the first reconcile after a reload resets
+ // the user's label to the child's generated one, and the library autosaver
+ // then writes that loss back with no user action.
+ it('keeps a user label when a template-less parent is saved and reloaded', () => {
+ const callNode = buildInvocationNode(callSavedWorkflowTemplate, { x: 0, y: 0 });
+
+ callNode.id = 'call-1';
+ callNode.data.inputs[dynamicFieldName('a')] = {
+ label: 'My Addend',
+ labelOverride: true,
+ name: dynamicFieldName('a'),
+ value: 99,
+ };
+
+ const reloaded = parseWorkflowJson(
+ serializeWorkflowJson({ ...createProjectGraph('legacy-parent'), nodes: [callNode] })
+ ).document;
+ const fields = getSavedWorkflowDynamicFields(buildChildWorkflow(), templates);
+ const synced = syncCallSavedWorkflowFields(reloaded, callNode.id, fields, []);
+ const node = synced.nodes.find((candidate): candidate is WorkflowInvocationNode => candidate.id === callNode.id);
+
+ expect(node?.data.inputs[dynamicFieldName('a')]).toMatchObject({ label: 'My Addend', value: 99 });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
index ea0e4b2139..59b304300e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/core/workflowJson.test.ts
@@ -425,3 +425,28 @@ describe('seed modes in workflow JSON', () => {
expect(degraded?.type === 'invocation' && degraded.data.inputs.prompt).not.toHaveProperty('seedMode');
});
});
+
+describe('field label overrides', () => {
+ // `serializeInvocationNode` writes `labelOverride` (it structuredClones the
+ // node data) but `parseWorkflowJson` rebuilds each instance from an explicit
+ // field list that omits it, so the flag is written and never read back.
+ it('round-trips an explicit label override', () => {
+ const node = buildInvocationNode(template, { x: 0, y: 0 });
+ let doc = createProjectGraph('label-override');
+
+ doc = projectGraphReducer(doc, { node, type: 'addNode' });
+ doc = projectGraphReducer(doc, {
+ fieldName: 'prompt',
+ label: 'My label',
+ nodeId: node.id,
+ type: 'setFieldLabel',
+ });
+
+ const reloaded = parseWorkflowJson(serializeWorkflowJson(doc)).document.nodes[0];
+
+ expect(reloaded?.type === 'invocation' ? reloaded.data.inputs.prompt : undefined).toMatchObject({
+ label: 'My label',
+ labelOverride: true,
+ });
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts
index 91da8fe5a5..421f945bbc 100644
--- a/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/data/savedWorkflowQueries.test.ts
@@ -137,3 +137,17 @@ describe('saved workflow detail query policy', () => {
}
});
});
+
+describe('detail queries built without a fetch', () => {
+ // React Query builds a query during render even when the observer is
+ // `enabled: false`, and a cancelled fetch reverts to the same state. Picking
+ // a workflow that is already in the picker list therefore leaves the detail
+ // query pending/idle with no data and nobody fetching it; with
+ // `gcTime: Infinity` nothing evicts it either, so the node is pinned at
+ // 'loading' and Invoke stays disabled until a page reload.
+ it('fetches a query that was built but never fetched', () => {
+ expect(
+ shouldFetchSavedWorkflowDetail({ state: { fetchStatus: 'idle', isInvalidated: false, status: 'pending' } })
+ ).toBe(true);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/data/templates.test.ts b/invokeai/frontend/webv2/src/features/workflow/data/templates.test.ts
index a441256643..330ccfa2bd 100644
--- a/invokeai/frontend/webv2/src/features/workflow/data/templates.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/data/templates.test.ts
@@ -332,3 +332,78 @@ describe('parseFieldType', () => {
expect(parseFieldType('nonsense')).toBeNull();
});
});
+
+describe('integer Literal enum templates', () => {
+ // The backend types these fields as `Literal[256, 512]`, so the template
+ // default has to stay numeric: pydantic rejects the string "512" with
+ // `literal_error`. Both shapes below are taken from shipped schemas, and
+ // they reach the default through different branches.
+ it('keeps a numeric Literal default numeric', () => {
+ const parsed = parseOpenApiToTemplates({
+ components: {
+ schemas: {
+ IntegerOutput: {
+ class: 'output',
+ properties: { type: { const: 'integer_output' }, value: { field_kind: 'output', type: 'integer' } },
+ type: 'object',
+ },
+ MaxSeqLenInvocation: {
+ class: 'invocation',
+ output: { $ref: '#/components/schemas/IntegerOutput' },
+ properties: {
+ max_seq_len: {
+ default: 512,
+ enum: [256, 512],
+ field_kind: 'input',
+ orig_required: false,
+ title: 'Max Seq Length',
+ type: 'integer',
+ },
+ type: { default: 'max_seq_len_invocation' },
+ },
+ title: 'MaxSeqLen',
+ type: 'object',
+ },
+ },
+ },
+ });
+
+ expect(parsed.max_seq_len_invocation?.inputs.max_seq_len?.default).toBe(512);
+ });
+
+ // `flux_text_encoder.t5_max_seq_len` is `Optional[Literal[256, 512]]` and
+ // required, so its schema default is null and the template falls back to the
+ // first option instead of the `String(property.default)` branch above. Legacy
+ // resolves the same fallback to a number.
+ it('keeps a nullable Literal fallback default numeric', () => {
+ const parsed = parseOpenApiToTemplates({
+ components: {
+ schemas: {
+ IntegerOutput: {
+ class: 'output',
+ properties: { type: { const: 'integer_output' }, value: { field_kind: 'output', type: 'integer' } },
+ type: 'object',
+ },
+ NullableMaxSeqLenInvocation: {
+ class: 'invocation',
+ output: { $ref: '#/components/schemas/IntegerOutput' },
+ properties: {
+ t5_max_seq_len: {
+ anyOf: [{ enum: [256, 512], type: 'integer' }, { type: 'null' }],
+ default: null,
+ field_kind: 'input',
+ orig_required: true,
+ title: 'T5 Max Seq Length',
+ },
+ type: { default: 'nullable_max_seq_len_invocation' },
+ },
+ title: 'NullableMaxSeqLen',
+ type: 'object',
+ },
+ },
+ },
+ });
+
+ expect(parsed.nullable_max_seq_len_invocation?.inputs.t5_max_seq_len?.default).toBe(256);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 20f2c56362..88930f3459 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -3437,6 +3437,67 @@ describe('workbenchReducer Phase 5 generation flow', () => {
expect(readNodeSeed(state)).toBe(48);
});
+ it('omits the embedded workflow when the backend would reject it', () => {
+ // `WorkflowWithoutID` rejects more than one `workflow_return` node, and
+ // the batch is validated before the enqueue route body, so attaching
+ // such a workflow turns the whole run into a 422. Legacy validates first
+ // and sends no workflow rather than failing the run.
+ const returnTemplate = {
+ category: 'workflow',
+ classification: 'stable',
+ description: '',
+ inputs: {},
+ nodePack: 'invokeai',
+ outputType: 'workflow_return_output',
+ outputs: {},
+ tags: [],
+ title: 'Workflow Return',
+ type: 'workflow_return',
+ useCache: true,
+ version: '1.0.0',
+ };
+ let state = primeWorkflow(42, 'fixed');
+
+ workflowTemplatesMock.snapshot = {
+ error: null,
+ status: 'loaded',
+ templates: { noise: seedTemplate, workflow_return: returnTemplate },
+ };
+
+ for (const id of ['return-1', 'return-2']) {
+ state = workbenchReducer(state, {
+ action: {
+ node: {
+ data: {
+ inputs: {},
+ isIntermediate: true,
+ isOpen: true,
+ label: '',
+ nodePack: 'invokeai',
+ notes: '',
+ type: 'workflow_return',
+ useCache: true,
+ version: '1.0.0',
+ },
+ id,
+ position: { x: 0, y: 0 },
+ type: 'invocation',
+ },
+ type: 'addNode',
+ },
+ type: 'applyProjectGraphAction',
+ });
+ }
+
+ const submission = readSubmission(submitWorkflow(state));
+
+ // `kind` guards the assertion below: a graph that fails to compile also
+ // yields an object with no `workflow` key, which would pass for the
+ // wrong reason.
+ expect(submission).toMatchObject({ kind: 'workflow' });
+ expect(submission).not.toHaveProperty('workflow');
+ });
+
it('holds a fixed seed as a graph constant and repeats the graph for every run', () => {
// Generate's own iteration count no longer leaks into workflow runs.
const state = submitWorkflow(