fix(canvas): 创作工作台 - 参考内容槽位遵循模型上限并保留现有视觉
保留当前项目样式,仅吸收参考内容主槽位展示、模型上限收敛和对应行为测试。 Refs #232
This commit is contained in:
39
web/test/creation-references.test.ts
Normal file
39
web/test/creation-references.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { canvasResourceMentionToken } from "../src/lib/canvas/canvas-resource-references";
|
||||
import type { CreationAttachment } from "../src/pages/create/creation-assets";
|
||||
import { buildCreationMentionReferences, reconcileCreationAttachmentLimit, removeCreationReferenceTokens } from "../src/pages/create/creation-references";
|
||||
|
||||
function imageAttachment(id: string): CreationAttachment {
|
||||
return {
|
||||
id,
|
||||
name: `${id}.png`,
|
||||
type: "image/png",
|
||||
dataUrl: `data:image/png;base64,${id}`,
|
||||
previewUrl: `data:image/png;base64,${id}`,
|
||||
};
|
||||
}
|
||||
|
||||
describe("creation references", () => {
|
||||
test("removes attachments and prompt tokens beyond the current model limit", () => {
|
||||
const attachments = [imageAttachment("first"), imageAttachment("second"), imageAttachment("third")];
|
||||
const references = buildCreationMentionReferences([], attachments);
|
||||
const result = reconcileCreationAttachmentLimit(attachments, references, 1);
|
||||
const prompt = references.map(canvasResourceMentionToken).join(" ");
|
||||
const nextPrompt = removeCreationReferenceTokens(prompt, result.removedReferences);
|
||||
|
||||
expect(result.attachments).toEqual([attachments[0]]);
|
||||
expect(result.removedReferences.map((reference) => reference.attachmentId)).toEqual(["second", "third"]);
|
||||
expect(nextPrompt).toContain(canvasResourceMentionToken(references[0]));
|
||||
expect(nextPrompt).not.toContain(canvasResourceMentionToken(references[1]));
|
||||
expect(nextPrompt).not.toContain(canvasResourceMentionToken(references[2]));
|
||||
});
|
||||
|
||||
test("returns the original attachment list when it is already within the limit", () => {
|
||||
const attachments = [imageAttachment("first")];
|
||||
const result = reconcileCreationAttachmentLimit(attachments, buildCreationMentionReferences([], attachments), 1);
|
||||
|
||||
expect(result.attachments).toBe(attachments);
|
||||
expect(result.removedReferences).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user