chore: agents update

This commit is contained in:
xiaojunnuo
2026-05-05 22:17:09 +08:00
parent 91a1b97550
commit 72b6597817
3 changed files with 47 additions and 3 deletions
@@ -80,4 +80,47 @@ describe("TldClient", () => {
(TldClient as any).rdapSsRequestTimes = originalRequestTimes;
}
});
it("clears rdapSsRequestTimes entries older than 24 hours", async () => {
const now = Date.now();
const originalRequestTimes = (TldClient as any).rdapSsRequestTimes;
try {
const recentTime = now - 1000 * 60 * 60;
const oldTime = now - 25 * 60 * 60 * 1000;
(TldClient as any).rdapSsRequestTimes = [oldTime, recentTime];
const client = new TldClient() as any;
await client.waitRdapSsRateLimit();
const times = (TldClient as any).rdapSsRequestTimes;
assert.equal(times.length, 2);
assert.ok(times.every((t: number) => now - t < 24 * 60 * 60 * 1000));
} finally {
(TldClient as any).rdapSsRequestTimes = originalRequestTimes;
}
});
it("keeps rdapSsRequestTimes entries within 24 hours and removes those exactly at boundary", async () => {
const now = Date.now();
const originalRequestTimes = (TldClient as any).rdapSsRequestTimes;
try {
const boundaryTime = now - 24 * 60 * 60 * 1000;
const withinTime = now - 23 * 60 * 60 * 1000;
(TldClient as any).rdapSsRequestTimes = [boundaryTime, withinTime];
const client = new TldClient() as any;
await client.waitRdapSsRateLimit();
const times = (TldClient as any).rdapSsRequestTimes as number[];
assert.equal(times.length, 2);
assert.ok(times.every((t: number) => now - t < 24 * 60 * 60 * 1000));
assert.ok(times.includes(withinTime));
} finally {
(TldClient as any).rdapSsRequestTimes = originalRequestTimes;
}
});
});
@@ -18,6 +18,7 @@ export class TldClient {
{ windowMs: 24 * 60 * 60 * 1000, max: 12000 },
];
private static readonly RDAP_SS_MAX_WAIT_MS = 3 * 60 * 1000;
private static readonly RDAP_SS_DATA_RETENTION_MS = 24 * 60 * 60 * 1000;
private static rdapSsRequestTimes: number[] = [];
private rdapMap: Record<string, string> = {};
@@ -177,8 +178,7 @@ export class TldClient {
private async waitRdapSsRateLimit() {
while (true) {
const now = Date.now();
const maxWindowMs = Math.max(...TldClient.RDAP_SS_RATE_LIMITS.map(item => item.windowMs));
TldClient.rdapSsRequestTimes = TldClient.rdapSsRequestTimes.filter(time => now - time < maxWindowMs);
TldClient.rdapSsRequestTimes = TldClient.rdapSsRequestTimes.filter(time => now - time < TldClient.RDAP_SS_DATA_RETENTION_MS);
const waitMs = TldClient.RDAP_SS_RATE_LIMITS.reduce((maxWaitMs, limit) => {
const times = TldClient.rdapSsRequestTimes.filter(time => now - time < limit.windowMs);