Files
moteva/frontend/tests/nodeReferenceImages.test.mjs
T
root f5a1ae7961 feat(canvas): send the last referenced canvas node as a generation anchor
Resolve the most recent canvas-node reference from the prompt's reference
images (by node id or matching asset URL) and append it as a hidden
"reference anchor node:" settings directive on agent submissions, so the
server can place generated images beside the source. Keep the persisted
user-visible copy unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 09:07:28 +08:00

53 lines
2.1 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { canvasNodeToReferenceImage, lastCanvasNodeIdForReferences, withLastCanvasReferenceAnchor } from "../src/ui/pages/CanvasWorkspace/canvas/nodeReferenceImages.ts";
test("keeps the SVG source for model preparation and uses WebP for the visible capsule", () => {
const reference = canvasNodeToReferenceImage({
id: "cad-1",
type: "image",
title: "drawing.svg",
x: 0,
y: 0,
width: 1200,
height: 800,
content: "https://assets.example/drawing.svg",
renderContent: "https://assets.example/drawing.render.webp",
tone: "transparent-image",
status: "success",
layerRole: "cad-vector",
semanticContext: "CAD context"
});
assert.equal(reference.publicUrl, "https://assets.example/drawing.svg");
assert.equal(reference.previewUrl, "https://assets.example/drawing.render.webp");
assert.equal(reference.semanticContext, "CAD context");
});
test("anchors generation to the last canvas-backed image capsule", () => {
const nodes = [
{ id: "image-1", content: "/assets/one.webp" },
{ id: "image-2", content: "/assets/two.webp" }
];
const references = [
{ id: "canvas-node:image-1", publicUrl: "/assets/one.webp" },
{ id: "upload-external", publicUrl: "/assets/external.webp" },
{ id: "canvas-node:image-2", publicUrl: "/assets/two.webp" }
];
assert.equal(lastCanvasNodeIdForReferences(references, nodes), "image-2");
assert.equal(lastCanvasNodeIdForReferences(references.slice(0, 2), nodes), "image-1");
assert.equal(lastCanvasNodeIdForReferences([{ id: "upload-two", publicUrl: "/assets/two.webp" }], nodes), "image-2");
const contents = withLastCanvasReferenceAnchor([{ type: "text", text: "generate", textSource: "input" }], references, nodes);
assert.deepEqual(contents.at(-1), {
type: "text",
text: "Reference anchor node: image-2",
textSource: "settings"
});
const unanchoredContents = [{ type: "text", text: "generate", textSource: "input" }];
assert.equal(withLastCanvasReferenceAnchor(unanchoredContents, [{ id: "upload-external", publicUrl: "/assets/external.webp" }], nodes), unanchoredContents);
});