SnowLuma v2.4.2 source snapshot
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
This commit is contained in:
commit
fa9c73363d
1367 files changed
+355735
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