2026-07-16 20:46:12 +08:00
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
import test from "node:test";
|
|
|
|
|
|
2026-07-17 09:07:28 +08:00
|
|
|
import { canvasNodeToReferenceImage, lastCanvasNodeIdForReferences, withLastCanvasReferenceAnchor } from "../src/ui/pages/CanvasWorkspace/canvas/nodeReferenceImages.ts";
|
2026-07-16 20:46:12 +08:00
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
});
|
2026-07-17 09:07:28 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|