- Add await ctx.cache.subscribe() to addSymbol mutation so symbols added via the sidebar get registered in symbol_demand and yfinance jobs are queued immediately - Backfill PEP, WYNN, STZ, CELH into symbol_demand + adapter_queue - Upgrade yahoo-finance2 3.15.3 -> 3.15.4 and pass validateResult:false to quoteSummary() to handle Yahoo schema drift - Add error detail logging for analyst ratings schema failures - Update .gitignore with common ignores
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import {
|
|
isRateLimitError,
|
|
jobBackoffMs,
|
|
parseCooldownUntil,
|
|
rateLimitCooldownMs,
|
|
RATE_LIMIT_COOLDOWN_MS,
|
|
} from '../sourceRatePolicy.ts';
|
|
|
|
test('isRateLimitError detects Yahoo Edge / 429 / bird HTTP 429', () => {
|
|
assert.equal(isRateLimitError('Edge: Too Many Requests'), true);
|
|
assert.equal(isRateLimitError('HTTP 429: Rate limit exceeded'), true);
|
|
assert.equal(isRateLimitError('XCookieAdapter: bird CLI failed — HTTP 429: Rate limit exceeded'), true);
|
|
assert.equal(isRateLimitError('rate limit'), true);
|
|
assert.equal(isRateLimitError('quota exceeded for this key'), true);
|
|
assert.equal(isRateLimitError('symbol not found'), false);
|
|
assert.equal(isRateLimitError(null), false);
|
|
assert.equal(isRateLimitError(''), false);
|
|
});
|
|
|
|
test('rateLimitCooldownMs escalates across ladder', () => {
|
|
assert.equal(rateLimitCooldownMs(1), RATE_LIMIT_COOLDOWN_MS[0]);
|
|
assert.equal(rateLimitCooldownMs(2), RATE_LIMIT_COOLDOWN_MS[1]);
|
|
assert.equal(rateLimitCooldownMs(5), RATE_LIMIT_COOLDOWN_MS[4]);
|
|
assert.equal(rateLimitCooldownMs(99), RATE_LIMIT_COOLDOWN_MS[4]);
|
|
assert.ok(rateLimitCooldownMs(1) >= 60_000, 'cool-down is at least one minute');
|
|
});
|
|
|
|
test('jobBackoffMs stays in short window for ordinary errors', () => {
|
|
assert.equal(jobBackoffMs(1), 2000);
|
|
assert.equal(jobBackoffMs(5), 60_000);
|
|
assert.ok(jobBackoffMs(1) < rateLimitCooldownMs(1));
|
|
});
|
|
|
|
test('parseCooldownUntil reports active remaining window', () => {
|
|
const now = Date.UTC(2026, 0, 1, 12, 0, 0);
|
|
const until = new Date(now + 30_000).toISOString();
|
|
const a = parseCooldownUntil(until, now);
|
|
assert.equal(a.active, true);
|
|
assert.equal(a.remainingMs, 30_000);
|
|
const b = parseCooldownUntil(until, now + 60_000);
|
|
assert.equal(b.active, false);
|
|
assert.equal(b.remainingMs, 0);
|
|
});
|