mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
async function loadSubject() {
|
||||
return import("./image-attachments.ts");
|
||||
}
|
||||
|
||||
const image = { type: "image", mimeType: "image/png", data: "YWJj" };
|
||||
|
||||
test("calculates padded base64 byte lengths and rejects invalid data", async () => {
|
||||
const { getBase64DecodedByteLength } = await loadSubject();
|
||||
|
||||
assert.equal(getBase64DecodedByteLength("YQ=="), 1);
|
||||
assert.equal(getBase64DecodedByteLength("YWI="), 2);
|
||||
assert.equal(getBase64DecodedByteLength("YWJj"), 3);
|
||||
assert.equal(getBase64DecodedByteLength("not base64!"), null);
|
||||
});
|
||||
|
||||
test("rejects invalid, oversized, and too many image attachments", async () => {
|
||||
const { MAX_ATTACHED_IMAGE_BYTES, MAX_ATTACHED_IMAGES, validateAgentImages } = await loadSubject();
|
||||
const oversizedData = "AAAA".repeat(Math.ceil((MAX_ATTACHED_IMAGE_BYTES + 1) / 3));
|
||||
|
||||
assert.equal(validateAgentImages([image]), null);
|
||||
assert.match(validateAgentImages([{ ...image, mimeType: "text/plain" }]), /valid base64 image/);
|
||||
assert.match(validateAgentImages([{ ...image, data: oversizedData }]), /10MB/);
|
||||
assert.match(validateAgentImages(Array.from({ length: MAX_ATTACHED_IMAGES + 1 }, () => image)), /at most/);
|
||||
});
|
||||
Reference in New Issue
Block a user