implement a generic user_job_events table for tracking compute job creation enforce configurable burst and sustained limits for PDF layout parsing add admin panel controls for compute rate limiting and max upload size update API routes to apply and record rate checks for PDF parse jobs document new environment variables and admin settings for compute limits improve IP extraction logic for rate limiting accuracy add tests for request IP extraction and test namespace gating This change introduces a robust mechanism to throttle expensive compute operations, such as PDF parsing, on a per-user basis. It provides both burst and sustained rate controls, with admin-tunable parameters and clear user feedback on throttling. The job event ledger enables accurate concurrency and rate enforcement, while new documentation and tests ensure maintainability and clarity.
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { getOpenReaderTestNamespace } from '../../src/lib/server/testing/test-namespace';
|
|
import { withEnv } from './support/env';
|
|
|
|
function headers(value: string): Headers {
|
|
return new Headers({ 'x-openreader-test-namespace': value });
|
|
}
|
|
|
|
describe('getOpenReaderTestNamespace gate', () => {
|
|
test('honored in non-production builds', async () => {
|
|
await withEnv({ NODE_ENV: 'development', ENABLE_TEST_NAMESPACE: undefined }, () => {
|
|
expect(getOpenReaderTestNamespace(headers('chromium'))).toBe('chromium');
|
|
});
|
|
});
|
|
|
|
test('ignored on production builds without the explicit flag', async () => {
|
|
await withEnv({ NODE_ENV: 'production', ENABLE_TEST_NAMESPACE: undefined }, () => {
|
|
expect(getOpenReaderTestNamespace(headers('attacker'))).toBeNull();
|
|
});
|
|
});
|
|
|
|
test('honored on production builds when ENABLE_TEST_NAMESPACE=true (CI parity)', async () => {
|
|
await withEnv({ NODE_ENV: 'production', ENABLE_TEST_NAMESPACE: 'true' }, () => {
|
|
expect(getOpenReaderTestNamespace(headers('webkit'))).toBe('webkit');
|
|
});
|
|
});
|
|
});
|