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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(canvas): verify cleared layer prompts
Josh Corbett13a73dba1dd8
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.tsindex 5be8c6ea9e..9c4398e532 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/documentModel.test.ts@@ -866,6 +866,24 @@ describe('createDocumentModel', () => {expect(Object.hasOwn(mask, 'noise')).toBe(false);});+ it('round-trips setting and clearing a regional prompt, which the layer stores as null', () => {+ const project = projectWith([layer('g1', 'regional_guidance'), layer('r1')], 'g1');+ const set = roundTrip(project, {+ before: { layerType: 'regional_guidance', negativePrompt: null },+ config: { layerType: 'regional_guidance', negativePrompt: 'blurry' },+ id: 'g1',+ type: 'patch-config',+ });+ const cleared = roundTrip(set.after, {+ before: { layerType: 'regional_guidance', negativePrompt: 'blurry' },+ config: { layerType: 'regional_guidance', negativePrompt: null },+ id: 'g1',+ type: 'patch-config',+ });+ const region = getDocumentLeaves(cleared.after.canvas.document).find((leaf) => leaf.id === 'g1')!;+ expect(region).toMatchObject({ negativePrompt: null });+ });+it('round-trips an atomic cross-layer config batch and refuses malformed batches', () => {const ref = {config: {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.test.tsnew file mode 100644index 0000000000..591bfcf3b6--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.test.ts@@ -0,0 +1,75 @@+import type {+ CanvasInpaintMaskLayerContract,+ CanvasRegionalGuidanceLayerContract,+} from '@workbench/canvas-engine/contracts';++import { describe, expect, it } from 'vitest';++import { isConfigApplied } from './postconditions';++const regional = (+ overrides: Partial<CanvasRegionalGuidanceLayerContract> = {}+): CanvasRegionalGuidanceLayerContract => ({+ autoNegative: false,+ blendMode: 'normal',+ id: 'rg',+ isEnabled: true,+ isLocked: false,+ mask: { bitmap: null, fill: { color: '#ff0000', style: 'solid' } },+ name: 'Region',+ negativePrompt: null,+ opacity: 0.5,+ positivePrompt: null,+ referenceImages: [],+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },+ type: 'regional_guidance',+ ...overrides,+});++const inpaint = (overrides: Partial<CanvasInpaintMaskLayerContract> = {}): CanvasInpaintMaskLayerContract => ({+ blendMode: 'normal',+ id: 'mask',+ isEnabled: true,+ isLocked: false,+ mask: { bitmap: null, fill: { color: '#ff0000', style: 'solid' } },+ name: 'Mask',+ opacity: 1,+ transform: { rotation: 0, scaleX: 1, scaleY: 1, x: 0, y: 0 },+ type: 'inpaint_mask',+ ...overrides,+});++describe('isConfigApplied', () => {+ it('accepts a cleared prompt, which the layer stores as null', () => {+ expect(isConfigApplied(regional(), { layerType: 'regional_guidance', negativePrompt: null })).toBe(true);+ expect(isConfigApplied(regional(), { layerType: 'regional_guidance', positivePrompt: null })).toBe(true);+ });++ it('rejects a prompt that still holds text after a clear', () => {+ expect(+ isConfigApplied(regional({ negativePrompt: 'blurry' }), { layerType: 'regional_guidance', negativePrompt: null })+ ).toBe(false);+ });++ it('matches a set prompt by value', () => {+ expect(+ isConfigApplied(regional({ negativePrompt: 'blurry' }), {+ layerType: 'regional_guidance',+ negativePrompt: 'blurry',+ })+ ).toBe(true);+ expect(+ isConfigApplied(regional({ negativePrompt: 'blurry' }), {+ layerType: 'regional_guidance',+ negativePrompt: 'sharp',+ })+ ).toBe(false);+ });++ it('accepts a removed mask modifier, which the reducer deletes', () => {+ expect(isConfigApplied(inpaint(), { layerType: 'inpaint_mask', noise: null })).toBe(true);+ expect(+ isConfigApplied(inpaint({ noise: { isEnabled: true, level: 0.5 } }), { layerType: 'inpaint_mask', noise: null })+ ).toBe(false);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.tsindex 599c5c5298..bdb2e0eea4 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document-model/postconditions.ts@@ -69,8 +69,8 @@ export const isPatchApplied = (node: CanvasNodeContract, patch: CanvasLayerBaseP/*** Whether every field named by `config` already holds its value; nested- * partials compare field by field, and a `null` config value asserts the- * field's ABSENCE — the reducer deletes the key for it.+ * partials compare field by field, and a `null` config value asserts the field+ * is cleared: absent (the reducer deletes mask modifiers) or stored as null (prompts).*/export const isConfigApplied = (node: CanvasNodeContract, config: CanvasLayerConfigPatch): boolean => {if (node.type !== config.layerType) {@@ -83,7 +83,7 @@ export const isConfigApplied = (node: CanvasNodeContract, config: CanvasLayerCon}const current = target[key];if (value === null) {- return current === undefined;+ return current === undefined || current === null;}return isRecord(value) && isRecord(current) && (key === 'adapter' || key === 'mask')? Object.entries(value).every(([field, expected]) => sameValue(current[field], expected))