skillhub/plugins/dsh/test/retry-after.test.ts
XiaoSeS 3560679793
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
feat(dsh): add native SkillHub plugin for DeepSeek Harness (#956)
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits.

Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-16 19:22:26 +08:00

37 lines
2 KiB
TypeScript

import { expect, test } from 'bun:test';
import { setTimeout as delay } from 'node:timers/promises';
import { retryAfterDeadline } from '../src/host/retry-after.js';
import { RegistryAdapter } from '../src/host/registry-adapter.js';
const now = Date.UTC(2026, 9, 15, 0, 0, 0);
test('Retry-After parses seconds and HTTP dates without treating malformed delays as dates', () => {
expect(retryAfterDeadline('120', now)).toBe(now + 120_000);
expect(retryAfterDeadline('0', now)).toBe(now);
expect(retryAfterDeadline(' 2 ', now)).toBe(now + 2000);
expect(retryAfterDeadline('Thu, 15 Oct 2026 00:02:00 GMT', now)).toBe(now + 120_000);
expect(retryAfterDeadline('Wed, 14 Oct 2026 00:00:00 GMT', now)).toBe(now);
for (const input of [null, '', '-1', '1.5', '1e3', 'NaN', '999999999999999999999999999', 'not a date']) {
expect(retryAfterDeadline(input, now)).toBeUndefined();
}
});
test('a real 429 prevents follow-up requests across endpoints until manual retry after expiry', async () => {
let calls = 0;
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch() {
calls++;
return calls === 1 ? new Response('private diagnostics', { status: 429, headers: { 'Retry-After': '1' } })
: Response.json({ data: { items: [], total: 0, limit: 20 } });
} });
try {
const registry = new RegistryAdapter(server.url.href);
await expect(registry.search()).rejects.toMatchObject({ code: 'RATE_LIMITED', status: 429, retryAfterSeconds: 1 });
await expect(registry.documentation('team', 'writer', '1.0.0')).rejects.toMatchObject({ code: 'RATE_LIMITED', retryAfterSeconds: 1 });
await expect(registry.search('retry')).rejects.toMatchObject({ code: 'RATE_LIMITED' });
expect(calls).toBe(1);
await expect(registry.search('', AbortSignal.abort())).rejects.toMatchObject({ code: 'CANCELLED' });
await delay(1100);
expect(calls).toBe(1); // No delayed task automatically resubmits.
expect(await registry.search()).toEqual({ items: [], total: 0, limit: 20 });
expect(calls).toBe(2);
} finally { await server.stop(true); }
});