Archived
test: audit existing suite
This commit is contained in:
@@ -3,7 +3,7 @@ import { PI_WEB_CAPABILITIES } from "./capabilities";
|
||||
import { parsePiWebComponentStatus, parsePiWebInstallationInfo, parsePiWebRuntimeResponse, parsePiWebVersionResponse } from "./piWebStatusParsing";
|
||||
|
||||
describe("PI WEB status parsing", () => {
|
||||
it("parses known runtime capabilities and ignores unknown string capabilities", () => {
|
||||
it("parses known top-level and component capabilities while ignoring unknown strings", () => {
|
||||
expect(parsePiWebRuntimeResponse({
|
||||
packageName: "@jmfederico/pi-web",
|
||||
generatedAt: "now",
|
||||
@@ -21,7 +21,7 @@ describe("PI WEB status parsing", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects malformed capability arrays", () => {
|
||||
it("rejects runtime responses with malformed component capability arrays", () => {
|
||||
expect(parsePiWebRuntimeResponse({
|
||||
packageName: "@jmfederico/pi-web",
|
||||
generatedAt: "now",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { base64ByteLength, extensionForImageMimeType, isSupportedImageMimeType, MAX_INLINE_IMAGE_BASE64_BYTES, parsePromptAttachments } from "./promptAttachments.js";
|
||||
|
||||
const tinyPngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCA',".replace(/[^A-Za-z0-9+/=]/g, "");
|
||||
const validImageBase64 = "QUJD";
|
||||
|
||||
describe("isSupportedImageMimeType", () => {
|
||||
it("accepts pi-supported image types", () => {
|
||||
@@ -43,12 +43,12 @@ describe("parsePromptAttachments", () => {
|
||||
});
|
||||
|
||||
it("normalizes valid attachments", () => {
|
||||
const result = parsePromptAttachments([{ kind: "image", mimeType: "image/png", data: tinyPngBase64, name: "shot.png" }]);
|
||||
expect(result).toEqual([{ kind: "image", mimeType: "image/png", data: tinyPngBase64, name: "shot.png" }]);
|
||||
const result = parsePromptAttachments([{ kind: "image", mimeType: "image/png", data: validImageBase64, name: "shot.png" }]);
|
||||
expect(result).toEqual([{ kind: "image", mimeType: "image/png", data: validImageBase64, name: "shot.png" }]);
|
||||
});
|
||||
|
||||
it("drops empty names", () => {
|
||||
const result = parsePromptAttachments([{ kind: "image", mimeType: "image/png", data: tinyPngBase64, name: "" }]);
|
||||
const result = parsePromptAttachments([{ kind: "image", mimeType: "image/png", data: validImageBase64, name: "" }]);
|
||||
expect(result[0]).not.toHaveProperty("name");
|
||||
});
|
||||
|
||||
@@ -57,9 +57,9 @@ describe("parsePromptAttachments", () => {
|
||||
});
|
||||
|
||||
it("rejects unsupported kinds and mime types", () => {
|
||||
expect(() => parsePromptAttachments([{ kind: "video", mimeType: "image/png", data: tinyPngBase64 }])).toThrow(/unsupported kind/);
|
||||
expect(() => parsePromptAttachments([{ kind: "file", mimeType: "application/pdf", data: tinyPngBase64 }])).toThrow(/unsupported kind/);
|
||||
expect(() => parsePromptAttachments([{ kind: "image", mimeType: "image/svg+xml", data: tinyPngBase64 }])).toThrow(/unsupported image type/);
|
||||
expect(() => parsePromptAttachments([{ kind: "video", mimeType: "image/png", data: validImageBase64 }])).toThrow(/unsupported kind/);
|
||||
expect(() => parsePromptAttachments([{ kind: "file", mimeType: "application/pdf", data: validImageBase64 }])).toThrow(/unsupported kind/);
|
||||
expect(() => parsePromptAttachments([{ kind: "image", mimeType: "image/svg+xml", data: validImageBase64 }])).toThrow(/unsupported image type/);
|
||||
});
|
||||
|
||||
it("accepts generic files only when file attachments are allowed", () => {
|
||||
@@ -83,7 +83,7 @@ describe("parsePromptAttachments", () => {
|
||||
});
|
||||
|
||||
it("keeps image MIME validation when file attachments are allowed", () => {
|
||||
expect(() => parsePromptAttachments([{ kind: "image", mimeType: "image/svg+xml", data: tinyPngBase64 }], { allowFileAttachments: true })).toThrow(/unsupported image type/);
|
||||
expect(() => parsePromptAttachments([{ kind: "image", mimeType: "image/svg+xml", data: validImageBase64 }], { allowFileAttachments: true })).toThrow(/unsupported image type/);
|
||||
});
|
||||
|
||||
it("rejects invalid base64 data", () => {
|
||||
@@ -97,7 +97,7 @@ describe("parsePromptAttachments", () => {
|
||||
});
|
||||
|
||||
it("enforces the attachment count limit", () => {
|
||||
const many = Array.from({ length: 3 }, () => ({ kind: "image", mimeType: "image/png", data: tinyPngBase64 }));
|
||||
const many = Array.from({ length: 3 }, () => ({ kind: "image", mimeType: "image/png", data: validImageBase64 }));
|
||||
expect(() => parsePromptAttachments(many, { maxAttachments: 2 })).toThrow(/too many attachments/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user