Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: add coverage for pre-aborted signal in AbortSignal.any fallback path

Adam Eivy8cfcdf7546bb
diff --git a/server/lib/fetchWithTimeout.test.js b/server/lib/fetchWithTimeout.test.js
index bccd2a3e46..aed38f4f3a 100644
--- a/server/lib/fetchWithTimeout.test.js
+++ b/server/lib/fetchWithTimeout.test.js
@@ -62,4 +62,28 @@ describe('fetchWithTimeout', () => {
await expect(promise).rejects.toThrow('aborted');
});
+
+ it('aborts immediately when caller signal is already aborted (fallback path)', async () => {
+ // Force fallback path by making AbortSignal.any non-function
+ const origAny = AbortSignal.any;
+ Object.defineProperty(AbortSignal, 'any', { value: undefined, configurable: true });
+
+ try {
+ vi.stubGlobal('fetch', vi.fn().mockImplementation((_url, opts) =>
+ new Promise((_resolve, reject) => {
+ // Handle already-aborted signal (event won't fire if already aborted)
+ if (opts.signal.aborted) return reject(new DOMException('aborted', 'AbortError'));
+ opts.signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')));
+ })
+ ));
+
+ const callerController = new AbortController();
+ callerController.abort(); // Pre-abort before calling fetchWithTimeout
+
+ await expect(fetchWithTimeout('http://example.com', { signal: callerController.signal }, 60000))
+ .rejects.toThrow('aborted');
+ } finally {
+ Object.defineProperty(AbortSignal, 'any', { value: origAny, configurable: true });
+ }
+ });
});