fix(media-understanding): align video base64 byte limits (#96519) · openclaw/openclaw@d3cfef3
vincentkoc
·
2026-06-25
·
via Recent Commits to openclaw:main
File tree
packages/media-understanding-common/src
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Media Understanding Common tests cover video payload sizing behavior. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { DEFAULT_VIDEO_MAX_BASE64_BYTES } from "./defaults.js"; |
| 4 | +import { estimateBase64Size, resolveVideoMaxBase64Bytes } from "./video.js"; |
| 5 | + |
| 6 | +describe("estimateBase64Size", () => { |
| 7 | +it("rounds byte counts to base64 quanta", () => { |
| 8 | +expect(estimateBase64Size(1)).toBe(4); |
| 9 | +expect(estimateBase64Size(2)).toBe(4); |
| 10 | +expect(estimateBase64Size(3)).toBe(4); |
| 11 | +expect(estimateBase64Size(4)).toBe(8); |
| 12 | +}); |
| 13 | +}); |
| 14 | + |
| 15 | +describe("resolveVideoMaxBase64Bytes", () => { |
| 16 | +it("allows raw byte limits that expand to valid base64 boundaries", () => { |
| 17 | +expect(resolveVideoMaxBase64Bytes(1)).toBe(4); |
| 18 | +expect(resolveVideoMaxBase64Bytes(2)).toBe(4); |
| 19 | +expect(resolveVideoMaxBase64Bytes(3)).toBe(4); |
| 20 | +expect(resolveVideoMaxBase64Bytes(4)).toBe(8); |
| 21 | +}); |
| 22 | + |
| 23 | +it("keeps the shared maximum base64 payload cap", () => { |
| 24 | +expect(resolveVideoMaxBase64Bytes(DEFAULT_VIDEO_MAX_BASE64_BYTES)).toBe( |
| 25 | +DEFAULT_VIDEO_MAX_BASE64_BYTES, |
| 26 | +); |
| 27 | +}); |
| 28 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,6 @@ export function estimateBase64Size(bytes: number): number {
|
10 | 10 | |
11 | 11 | /** Resolve video base64 byte limit from raw byte limit and global cap. */ |
12 | 12 | export function resolveVideoMaxBase64Bytes(maxBytes: number): number { |
13 | | -const expanded = Math.floor(maxBytes * (4 / 3)); |
| 13 | +const expanded = estimateBase64Size(maxBytes); |
14 | 14 | return Math.min(expanded, DEFAULT_VIDEO_MAX_BASE64_BYTES); |
15 | 15 | } |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。