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(canvas): pin adapter mask sources and cover the inpaint adapter picker

Josh Corbettd7f8137d0672
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
index c77f2d143b..96ce06cdd6 100644
--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/anima.mdx
@@ -134,7 +134,7 @@ transformer on an image. Each adapter model may be used only once per generation
Adapter** in the Generate panel's **Components** section, and set its **Inpaint adapter weight** (1 by
default). Invoke then conditions the adapter on the raster image and the region being generated; the
setting is ignored for text-to-image and image-to-image. The adapter and its weight are recorded in the
- image's metadata and restored by **Recall all** and **Remix**.
+ image's metadata and restored by **Recall All** and **Remix Image**.
- **In the workflow editor**, add an **Anima ControlNet-LLLite** node, give it the conditioning image and
a control model, and connect it to the **Control LLLite** input of **Denoise - Anima**, collecting
several nodes to combine them.
diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
index 373fc7b75f..5bc142abe3 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts
@@ -1057,19 +1057,55 @@ describe('compileCanvasGraph — Anima ControlNet-LLLite (integration)', () => {
);
});
- it.each(['inpaint', 'outpaint'] as const)('leaves the %s graph unchanged without an adapter', (mode) => {
- // Only the metadata node id is minted per compile; pin it so the graphs compare structurally.
- const pinned = (graph: BackendGraphContract) => {
- const metadataId = getNodeByType(graph, 'core_metadata')!.id;
- return JSON.parse(JSON.stringify({ edges: graph.edges, nodes: graph.nodes }).replaceAll(metadataId, 'metadata'));
- };
- const unset = compile(animaModel, mode, { settings: { animaInpaintAdapterModel: null } }).backendGraph;
- const defaults = compile(animaModel, mode).backendGraph;
+ it.each(['inpaint', 'outpaint'] as const)(
+ 'adds no adapter nodes, edges or metadata to the %s graph without one',
+ (mode) => {
+ const { backendGraph } = compile(animaModel, mode, { settings: { animaInpaintAdapterModel: null } });
+
+ expect(backendGraph.nodes.anima_inpaint_adapter).toBeUndefined();
+ expect(backendGraph.nodes.invert_anima_inpaint_adapter_mask).toBeUndefined();
+ expect(backendGraph.nodes.control_lllite_collector).toBeUndefined();
+ expect(getEdge(backendGraph, 'denoise_latents', 'control_lllite')).toBeUndefined();
+ expect(getNodeByType(backendGraph, 'core_metadata')).not.toHaveProperty('anima_inpaint_adapter');
+ expect(getNodeByType(backendGraph, 'core_metadata')).not.toHaveProperty('anima_inpaint_adapter_weight');
+ }
+ );
+
+ it('outpaint with Scale Before Processing: the adapter reads the resized combined mask (legacy addOutpaint.ts:182)', () => {
+ const { backendGraph } = compile(animaModel, 'outpaint', {
+ maskImageName: 'canvas-mask.png',
+ scaling: { height: 1024, method: 'manual', width: 1024 },
+ settings: withAdapter(),
+ });
+
+ expect(getEdge(backendGraph, 'canvas_resize_outpaint_mask_to_processing', 'image')?.source.node_id).toBe(
+ 'mask_combine'
+ );
+ expect(getEdge(backendGraph, 'invert_anima_inpaint_adapter_mask', 'image')?.source.node_id).toBe(
+ 'canvas_resize_outpaint_mask_to_processing'
+ );
+ expect(getEdge(backendGraph, 'anima_inpaint_adapter', 'image')?.source.node_id).toBe('infill');
+ expect(backendGraph.nodes.invert_anima_inpaint_adapter_mask?.image).toBeUndefined();
+ });
+
+ it('inpaint with a noise mask: the adapter reads the image before noise is added (legacy addInpaint.ts:223/316)', () => {
+ const unscaled = compile(animaModel, 'inpaint', {
+ noiseMaskImageName: 'noise-mask.png',
+ settings: withAdapter(),
+ }).backendGraph;
+ expect(getEdge(unscaled, 'canvas_i2l', 'image')?.source.node_id).toBe('add_inpaint_noise');
+ expect(unscaled.nodes.anima_inpaint_adapter?.image).toEqual({ image_name: 'canvas-composite.png' });
+ expect(getEdge(unscaled, 'anima_inpaint_adapter', 'image')).toBeUndefined();
- expect(pinned(unset)).toEqual(pinned(defaults));
- expect(unset.nodes.anima_inpaint_adapter).toBeUndefined();
- expect(getEdge(unset, 'denoise_latents', 'control_lllite')).toBeUndefined();
- expect(getNodeByType(unset, 'core_metadata')?.anima_inpaint_adapter).toBeUndefined();
+ const scaled = compile(animaModel, 'inpaint', {
+ noiseMaskImageName: 'noise-mask.png',
+ scaling: { height: 1024, method: 'manual', width: 1024 },
+ settings: withAdapter(),
+ }).backendGraph;
+ expect(getEdge(scaled, 'add_inpaint_noise', 'image')?.source.node_id).toBe('canvas_resize_initial_to_processing');
+ expect(getEdge(scaled, 'anima_inpaint_adapter', 'image')?.source.node_id).toBe(
+ 'canvas_resize_initial_to_processing'
+ );
});
it('ignores a picked adapter outside inpaint/outpaint and outside Anima', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
index 2fbcdc5045..1d0400d661 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts
@@ -548,6 +548,7 @@ export const findVaeSource = (
const node = graph.nodes[edge.source.node_id];
return node ? { field: edge.source.field, node } : null;
}
+ // The fallback holds because each builder wires exactly one `vae` edge into its decode node, from `model_loader`.
const modelLoader = graph.nodes.model_loader;
const decodesWithPid = Object.values(graph.nodes).some((node) => isPidDecodeNodeType(node.type));
return modelLoader && decodesWithPid ? { field: 'vae', node: modelLoader } : null;
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
index be4d28dd86..64ed5b2381 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateSettingsForm.browser.test.tsx
@@ -88,16 +88,43 @@ const CATALOG: readonly GenerationModelCatalogItem[] = [MODEL];
const OTHER_SDXL = { ...MODEL, key: 'sdxl-2', name: 'SDXL 2' } as GenerationModelCatalogItem;
// A coarser size grid than SDXL's, and no SDXL LoRAs.
const FLUX = { ...MODEL, base: 'flux', key: 'flux', name: 'FLUX' } as GenerationModelCatalogItem;
+const ANIMA = { ...MODEL, base: 'anima', key: 'anima', name: 'Anima' } as GenerationModelCatalogItem;
+const ANIMA_INPAINT_ADAPTER = {
+ base: 'anima',
+ cond_in_channels: 4,
+ key: 'anima-inpaint',
+ name: 'Anima LLLite Inpainting',
+ type: 'controlnet',
+} as GenerationModelCatalogItem;
+const ANIMA_SKETCH_ADAPTER = {
+ ...ANIMA_INPAINT_ADAPTER,
+ cond_in_channels: 3,
+ key: 'anima-sketch',
+ name: 'Anima LLLite Sketch',
+} as GenerationModelCatalogItem;
-/** The model card's picker, reduced to buttons that hand a model to its real selection handler. */
-const MainModelPicker = ({ modelTypes, onChange }: GenerationModelSelectProps) =>
- modelTypes.includes('external_image_generator')
- ? [OTHER_SDXL, FLUX].map((model) => (
- <button key={model.key} data-model-pick={model.key} type="button" onClick={() => onChange(model)}>
- {model.name}
- </button>
- ))
- : null;
+/**
+ * The picker, reduced to buttons that hand a model to its real selection handler: the model card's main picks, and
+ * for a component slot the catalog models of its types that pass its filter.
+ */
+const MainModelPicker = ({ filter, modelTypes, onChange }: GenerationModelSelectProps) =>
+ modelTypes.includes('external_image_generator') ? (
+ [OTHER_SDXL, FLUX].map((model) => (
+ <button key={model.key} data-model-pick={model.key} type="button" onClick={() => onChange(model)}>
+ {model.name}
+ </button>
+ ))
+ ) : (
+ <div data-component-types={modelTypes.join(',')}>
+ {stableGroups.models.catalog
+ .filter((model) => modelTypes.includes(model.type) && (filter?.(model) ?? true))
+ .map((model) => (
+ <button key={model.key} data-component-pick={model.key} type="button" onClick={() => onChange(model)}>
+ {model.name}
+ </button>
+ ))}
+ </div>
+ );
const INITIAL_VALUES: Record<string, unknown> = {
...getDefaultGenerateSettings(MODEL as never),
modelKey: MODEL.key,
@@ -273,6 +300,46 @@ afterEach(async () => {
accountLifecycle.invalidate();
});
+describe('GenerateSettingsForm Anima inpaint adapter', () => {
+ const adapterSlot = () => host!.querySelector<HTMLElement>('[data-component-types="controlnet"]');
+ const adapterPicks = () =>
+ [...(adapterSlot()?.querySelectorAll('[data-component-pick]') ?? [])].map((pick) =>
+ pick.getAttribute('data-component-pick')
+ );
+ const weightLabel = 'widgets.generate.animaInpaintAdapterWeight';
+ const weightScrubber = () =>
+ [...document.querySelectorAll('[data-scope="scrubber"]')].find(
+ (candidate) => candidate.querySelector('[data-part="label"]')?.textContent === weightLabel
+ );
+
+ it('offers the slot to Anima only, lists only 4-channel adapters, and shows the weight once one is picked', async () => {
+ stableGroups.models.catalog = [MODEL, ANIMA, ANIMA_INPAINT_ADAPTER, ANIMA_SKETCH_ADAPTER];
+ await renderAdapter(buildAdapter());
+
+ expect(adapterSlot()).toBeNull();
+
+ await settle(() =>
+ storedValues().patchSnapshot({ ...getDefaultGenerateSettings(ANIMA as never), modelKey: ANIMA.key })
+ );
+
+ expect(adapterPicks()).toEqual([ANIMA_INPAINT_ADAPTER.key]);
+ expect(weightScrubber()).toBeUndefined();
+
+ await settle(() => host!.querySelector<HTMLElement>('[data-component-pick="anima-inpaint"]')?.click());
+ await settle(flushGenerateDrafts);
+
+ expect(storedValues().getSnapshot()).toMatchObject({ animaInpaintAdapterModel: ANIMA_INPAINT_ADAPTER });
+ const slider = sliderNamed(weightLabel);
+ expect(slider.getAttribute('aria-valuenow')).toBe('1');
+ expect(document.getElementById(slider.getAttribute('aria-labelledby') ?? '')?.textContent).toBe(weightLabel);
+
+ await pressRight(sliderNamed(weightLabel));
+ await settle(flushGenerateDrafts);
+
+ expect(storedValues().getSnapshot()).toMatchObject({ animaInpaintAdapterWeight: 1.05 });
+ });
+});
+
describe('GenerateSettingsForm render isolation', () => {
it('preserves a settled weight draft when removing another concept from an already open menu', async () => {
const first: LoraModelConfig = { base: 'sdxl', key: 'ink', name: 'Ink', type: 'lora' };
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts
index e7841ea976..45dc748a72 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/imageRecall.test.ts
@@ -1243,6 +1243,23 @@ describe('anima inpaint adapter', () => {
}
);
+ it('leaves the slot alone but still recalls the weight when the recorded adapter is not installed', () => {
+ const result = buildImageRecallSettings({
+ currentValues: createValues({ animaInpaintAdapterModel: inpaintAdapter, animaInpaintAdapterWeight: 1 }),
+ image,
+ kind: 'all',
+ metadata: { ...canvasInpaintMetadata, anima_inpaint_adapter: { key: 'gone' } },
+ models: [animaModel, animaQwen3, qwenImageVae],
+ supportedModels: [animaModel],
+ vaeModels: [qwenImageVae],
+ });
+
+ // Recall clones the current values, so the untouched slot keeps the same pick by value.
+ expect(result?.values.animaInpaintAdapterModel).toEqual(inpaintAdapter);
+ expect(result?.values.animaInpaintAdapterWeight).toBe(0.7);
+ expect(result?.fields).toContain('animaInpaintAdapterWeight');
+ });
+
it('skips the adapter and weight when the image is not an Anima image or the adapter is a control adapter', () => {
const notAnima = buildImageRecallSettings({
currentValues: createValues({ animaInpaintAdapterWeight: 1 }),