fix(design): bound requests and prevent mutation replay

This commit is contained in:
2026-08-19 12:51:46 +08:00
parent 1ba68a9e41
commit 87e4140f8a
7 changed files with 447 additions and 55 deletions

View File

@@ -35,6 +35,36 @@ describe('proxyAwareFetch', () => {
expect(net.fetch).toHaveBeenCalledWith('https://example.test', undefined);
});
it('does not replay a mutation through global fetch after Electron net.fetch fails', async () => {
setElectronVersion('43.4.0');
const transportError = new Error('response transport failed');
const fetchMock = vi.fn();
vi.mocked(net.fetch).mockRejectedValue(transportError);
vi.stubGlobal('fetch', fetchMock);
await expect(proxyAwareFetch('https://example.test/quote', {
method: 'PATCH',
body: JSON.stringify({ aspect_ratio: '16:9' }),
})).rejects.toBe(transportError);
expect(net.fetch).toHaveBeenCalledOnce();
expect(fetchMock).not.toHaveBeenCalled();
});
it('retains the global fallback for safe reads after Electron net.fetch fails', async () => {
setElectronVersion('43.4.0');
const response = new Response('node fallback');
const fetchMock = vi.fn().mockResolvedValue(response);
vi.mocked(net.fetch).mockRejectedValue(new Error('electron transport failed'));
vi.stubGlobal('fetch', fetchMock);
await expect(proxyAwareFetch('https://example.test/read', {
method: 'GET',
})).resolves.toBe(response);
expect(fetchMock).toHaveBeenCalledWith('https://example.test/read', { method: 'GET' });
});
it('uses the global fetch outside Electron', async () => {
setElectronVersion(undefined);
const response = new Response('node');