fix(ui): исключить подстановку моковых WAN в live расчёт
This commit is contained in:
1 parent
338335ddc0
commit
6e6558bde9
7 files changed
+35
-41
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* (см. блок `#route-ai` в `/settings` и страницу `/route-optimizer`).
|
||||
*/
|
||||
|
||||
import { servers, type FilterRule } from "@/lib/data"
|
||||
import { type FilterRule } from "@/lib/data"
|
||||
|
||||
// ── Совместимо с app/(main)/route-optimizer/page.tsx ─────────────────────────
|
||||
|
||||
@@ -191,18 +191,6 @@ function confidenceFromProb(prob: number): "HIGH" | "MEDIUM" | "LOW" {
|
||||
return prob >= 55 ? "HIGH" : prob >= 30 ? "MEDIUM" : "LOW"
|
||||
}
|
||||
|
||||
function syntheticWans(home: OptimizerApiServer): WanUplink[] {
|
||||
return [{
|
||||
id: `w-${home.id}-1`,
|
||||
name: "WAN1",
|
||||
isp: "—",
|
||||
iface: "auto",
|
||||
ip: home.host,
|
||||
maxDl: 1000,
|
||||
maxUl: 1000,
|
||||
}]
|
||||
}
|
||||
|
||||
function normalizeApiWanUplinks(list: OptimizerApiServer["wanUplinks"]): WanUplink[] {
|
||||
const src = Array.isArray(list) ? list : []
|
||||
const out = src
|
||||
@@ -219,29 +207,6 @@ function normalizeApiWanUplinks(list: OptimizerApiServer["wanUplinks"]): WanUpli
|
||||
return out
|
||||
}
|
||||
|
||||
function catalogWansForHome(homeId: string, homeHost?: string, homeName?: string): WanUplink[] | null {
|
||||
const hostNorm = (homeHost ?? "").trim().toLowerCase()
|
||||
const nameNorm = (homeName ?? "").trim().toLowerCase()
|
||||
const row = servers.find((s) => {
|
||||
if (s.type !== "home-router") return false
|
||||
if (String(s.id) === homeId) return true
|
||||
if (hostNorm && String(s.host ?? "").trim().toLowerCase() === hostNorm) return true
|
||||
if (nameNorm && String(s.name ?? "").trim().toLowerCase() === nameNorm) return true
|
||||
return false
|
||||
})
|
||||
const list = row?.wanUplinks ?? []
|
||||
if (!list.length) return null
|
||||
return list.map((w, idx) => ({
|
||||
id: w.id || `w-${homeId}-${idx + 1}`,
|
||||
name: w.name || `WAN${idx + 1}`,
|
||||
isp: w.isp || "—",
|
||||
iface: w.iface || "",
|
||||
ip: w.ip || "",
|
||||
maxDl: Math.max(1, Math.round(Number(w.maxDl) || 1000)),
|
||||
maxUl: Math.max(1, Math.round(Number(w.maxUl) || 1000)),
|
||||
}))
|
||||
}
|
||||
|
||||
function legPing(
|
||||
a: number | null,
|
||||
b: number | null,
|
||||
@@ -285,9 +250,7 @@ export function mapApiServersToTopology(rows: OptimizerApiServer[]): {
|
||||
model: s.model ?? "—",
|
||||
ip: s.host,
|
||||
wans:
|
||||
normalizeApiWanUplinks(s.wanUplinks).length > 0
|
||||
? normalizeApiWanUplinks(s.wanUplinks)
|
||||
: (catalogWansForHome(String(s.id), s.host, s.name) ?? syntheticWans(s)),
|
||||
normalizeApiWanUplinks(s.wanUplinks),
|
||||
}))
|
||||
|
||||
const jumpHosts: JumpHost[] = rows
|
||||
|
||||
@@ -21,3 +21,14 @@ test("missing and disabled probe leave observed values unknown while model stays
|
||||
assert.equal(result.homes[0].fullRoutes[0].je.observed?.probeId,null)
|
||||
}
|
||||
})
|
||||
|
||||
import {servers} from "./data"
|
||||
test("live topology never imports mock WAN or creates a synthetic uplink",()=>{
|
||||
const mock=servers.find(server=>server.type==="home-router")!
|
||||
for(const wanUplinks of [undefined,[]]){
|
||||
const inventory=rows.map((row,i)=>i===0?{...row,name:mock.name,host:mock.host,wanUplinks}:row)
|
||||
const result=buildLiveOptimizerData(inventory,[],DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS)
|
||||
assert.equal(result.homes[0].home.wans.length,0);assert.equal(result.homes[0].fullRoutes.length,0)
|
||||
assert.equal(result.homes[0].bestRoute,null)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user