fix(settings): проверять доступность текущего источника без гонок

This commit is contained in:
Denozordec committed 2026-10-03 14:30:41 +07:00
1 parent b6f1b72500
commit e5842b415b
8 files changed
+72 -17

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
import assert from "node:assert/strict"
import {test} from "node:test"
import {confirmBackendHealth,getBackendHealth} from "./backend-health"
test("health confirms actual status ok and legacy literal ok true only",()=>{for(const value of [{status:"ok",timestamp:"2026-10-03"},{ok:true}])assert.doesNotThrow(()=>confirmBackendHealth(value));for(const value of [null,{},[],{ok:false},{ok:"true"},{status:"error"},"ok"])assert.throws(()=>confirmBackendHealth(value),/не подтверждена/)})
test("HTTP success alone cannot confirm backend, signals and no retries are preserved",async()=>{const original=globalThis.fetch;let calls=0;try{const controller=new AbortController();globalThis.fetch=async(_url,init)=>{calls++;assert.equal(init?.signal instanceof AbortSignal,true);return new Response("<html>proxy</html>",{status:200})};await assert.rejects(()=>getBackendHealth("https://backend.test",controller.signal));assert.equal(calls,1);globalThis.fetch=async()=>{calls++;return Response.json({status:"ok"})};await getBackendHealth("https://backend.test");assert.equal(calls,2)}finally{globalThis.fetch=original}})