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

Merged via squash.

Prepared head SHA: e37e577cd4
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
This commit is contained in:
Vincent Koc
2026-06-25 02:02:59 +08:00
committed by GitHub
parent f163d778c0
commit d3cfef3bd8
2 changed files with 29 additions and 1 deletions

View File

@@ -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,
);
});
});

View File

@@ -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);
}