diff --git a/packages/media-understanding-common/src/video.test.ts b/packages/media-understanding-common/src/video.test.ts new file mode 100644 index 00000000000..f775ae79caa --- /dev/null +++ b/packages/media-understanding-common/src/video.test.ts @@ -0,0 +1,28 @@ +// Media Understanding Common tests cover video payload sizing behavior. +import { describe, expect, it } from "vitest"; +import { DEFAULT_VIDEO_MAX_BASE64_BYTES } from "./defaults.js"; +import { estimateBase64Size, resolveVideoMaxBase64Bytes } from "./video.js"; + +describe("estimateBase64Size", () => { + it("rounds byte counts to base64 quanta", () => { + expect(estimateBase64Size(1)).toBe(4); + expect(estimateBase64Size(2)).toBe(4); + expect(estimateBase64Size(3)).toBe(4); + expect(estimateBase64Size(4)).toBe(8); + }); +}); + +describe("resolveVideoMaxBase64Bytes", () => { + it("allows raw byte limits that expand to valid base64 boundaries", () => { + expect(resolveVideoMaxBase64Bytes(1)).toBe(4); + expect(resolveVideoMaxBase64Bytes(2)).toBe(4); + expect(resolveVideoMaxBase64Bytes(3)).toBe(4); + expect(resolveVideoMaxBase64Bytes(4)).toBe(8); + }); + + it("keeps the shared maximum base64 payload cap", () => { + expect(resolveVideoMaxBase64Bytes(DEFAULT_VIDEO_MAX_BASE64_BYTES)).toBe( + DEFAULT_VIDEO_MAX_BASE64_BYTES, + ); + }); +}); diff --git a/packages/media-understanding-common/src/video.ts b/packages/media-understanding-common/src/video.ts index 501a9fc9536..515aa86b21b 100644 --- a/packages/media-understanding-common/src/video.ts +++ b/packages/media-understanding-common/src/video.ts @@ -10,6 +10,6 @@ export function estimateBase64Size(bytes: number): number { /** Resolve video base64 byte limit from raw byte limit and global cap. */ export function resolveVideoMaxBase64Bytes(maxBytes: number): number { - const expanded = Math.floor(maxBytes * (4 / 3)); + const expanded = estimateBase64Size(maxBytes); return Math.min(expanded, DEFAULT_VIDEO_MAX_BASE64_BYTES); }