test(mcp): use Promise.withResolvers in hanging-fetch helper per AGENTS.md

This commit is contained in:
can1357
2026-07-23 22:05:15 +02:00
parent e8502806ff
commit 3e445dccd9
@@ -646,16 +646,14 @@ describe("RFC 8414 §3.3 issuer validation", () => {
describe("bounded discovery fetches", () => { describe("bounded discovery fetches", () => {
// A fetch that never resolves on its own; it settles only when its // A fetch that never resolves on its own; it settles only when its
// AbortSignal fires. Pre-fix, discovery passed no signal, so this hung forever. // AbortSignal fires. Pre-fix, discovery passed no signal, so this hung forever.
const hangingFetch: FetchImpl = (_input, init) => const hangingFetch: FetchImpl = (_input, init) => {
new Promise<Response>((_resolve, reject) => { const { promise, reject } = Promise.withResolvers<Response>();
const signal = init?.signal; const signal = init?.signal;
const abort = () => reject(new DOMException("aborted", "AbortError")); const abort = () => reject(new DOMException("aborted", "AbortError"));
if (signal?.aborted) { if (signal?.aborted) abort();
abort(); else signal?.addEventListener("abort", abort, { once: true });
return; return promise;
} };
signal?.addEventListener("abort", abort, { once: true });
});
it("aborts hanging well-known discovery fetches instead of stalling", async () => { it("aborts hanging well-known discovery fetches instead of stalling", async () => {
const oauth = await discoverOAuthEndpoints("https://mcp.example.test/mcp", undefined, undefined, { const oauth = await discoverOAuthEndpoints("https://mcp.example.test/mcp", undefined, undefined, {