fix(media-understanding): align video base64 byte limits

(cherry picked from commit 622d0df5eb)
This commit is contained in:
linhongkuan
2026-06-24 21:04:49 +08:00
committed by Vincent Koc
parent f163d778c0
commit e37e577cd4
2 changed files with 29 additions and 1 deletions
@@ -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,
);
});
});
@@ -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);
}