feat(protocol): make highway media download limits configurable (#632)
Bound the two hardcoded limits of the shared HTTP media download engine (`loadBinarySource` / `stageSourceToDisk`) with deployment-wide environment settings, following the existing `positiveIntEnv` convention: - SNOWLUMA_HTTP_DOWNLOAD_TIMEOUT_MS (default 60000): one download attempt. - SNOWLUMA_MAX_BINARY_DOWNLOAD_BYTES (default 1073741824): the implicit cap on a binary source buffered in memory. Both defaults are unchanged, so an unconfigured deployment behaves exactly as before, and unusable values are logged and ignored. Callers that pass their own ceiling keep it: group/private files and flash transfer still use 4 GiB, inline `base64://` / `data:` flash sources keep the 1 GiB buffered-load ceiling, and video upload has its own limit. Documented in HIGHWAY_UPLOADS.md.
This commit is contained in:
1 parent
60733aacab
commit
bd40ac3522
4 files changed
+155
-9
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import {
|
||||
DEFAULT_HTTP_DOWNLOAD_TIMEOUT_MS,
|
||||
DEFAULT_MAX_BINARY_DOWNLOAD_BYTES,
|
||||
httpDownloadTimeoutMs,
|
||||
maxBinaryDownloadBytes,
|
||||
} from '../src/highway/download-settings';
|
||||
import { downloadHttp } from '../src/highway/utils';
|
||||
|
||||
const memorySink = (): {
|
||||
write: () => void;
|
||||
done: () => undefined;
|
||||
discard: () => void;
|
||||
} => ({ write: () => undefined, done: () => undefined, discard: () => undefined });
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('highway download settings', () => {
|
||||
it('keeps the documented defaults when nothing is configured', () => {
|
||||
expect(httpDownloadTimeoutMs({})).toBe(60_000);
|
||||
expect(maxBinaryDownloadBytes({})).toBe(1024 * 1024 * 1024);
|
||||
expect(DEFAULT_HTTP_DOWNLOAD_TIMEOUT_MS).toBe(60_000);
|
||||
expect(DEFAULT_MAX_BINARY_DOWNLOAD_BYTES).toBe(1024 * 1024 * 1024);
|
||||
});
|
||||
|
||||
it('reads both knobs from the environment', () => {
|
||||
expect(httpDownloadTimeoutMs({ SNOWLUMA_HTTP_DOWNLOAD_TIMEOUT_MS: '180000' })).toBe(
|
||||
180_000,
|
||||
);
|
||||
expect(
|
||||
maxBinaryDownloadBytes({ SNOWLUMA_MAX_BINARY_DOWNLOAD_BYTES: String(2 ** 31) }),
|
||||
).toBe(2 ** 31);
|
||||
});
|
||||
|
||||
it('ignores unusable values instead of failing the download', () => {
|
||||
expect(httpDownloadTimeoutMs({ SNOWLUMA_HTTP_DOWNLOAD_TIMEOUT_MS: '0' })).toBe(60_000);
|
||||
expect(httpDownloadTimeoutMs({ SNOWLUMA_HTTP_DOWNLOAD_TIMEOUT_MS: 'soon' })).toBe(60_000);
|
||||
expect(maxBinaryDownloadBytes({ SNOWLUMA_MAX_BINARY_DOWNLOAD_BYTES: '-5' })).toBe(
|
||||
DEFAULT_MAX_BINARY_DOWNLOAD_BYTES,
|
||||
);
|
||||
});
|
||||
|
||||
it('feeds the configured timeout into the fetch signal', async () => {
|
||||
vi.stubEnv('SNOWLUMA_HTTP_DOWNLOAD_TIMEOUT_MS', '1234');
|
||||
const timeoutSpy = vi.spyOn(AbortSignal, 'timeout');
|
||||
const fetchStub = vi.fn(
|
||||
async () => new Response(new Uint8Array([1, 2, 3]), { status: 200 }),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchStub);
|
||||
|
||||
await downloadHttp('https://example.test/media.bin', 'media', 1024, memorySink);
|
||||
|
||||
expect(timeoutSpy).toHaveBeenCalledWith(1234);
|
||||
expect(fetchStub).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user