fix(api): подтверждать полный сбор пути без скрытых ошибок

This commit is contained in:
Denozordec committed 2026-10-04 00:11:17 +07:00
1 parent 5fdd6ef58c
commit d4ae1c3127
10 files changed
+102 -46

No files matched your search

+2 -2
View File
@@ -3,10 +3,10 @@ import {test} from "node:test"
import {parseDashboardPath,parseDashboardSpeedProbes,parseDashboardWanRuntime,parseDashboardFilters} from "./dashboard-path-response"
import {resolveDefaultRouteLookup,buildDashboardInternetPath} from "./dashboard-internet-path"
import {servers} from "./data"
const snapshot={sampledAt:"2026-10-03T00:00:00Z",servers:[],greTunnels:[],filtersRulesets:[],speedProbes:[],routeLookupByServerId:{},wanRuntimeByHomeId:{}}
const snapshot={collectionComplete:true,sampledAt:"2026-10-03T00:00:00Z",servers:[],greTunnels:[],filtersRulesets:[],speedProbes:[],routeLookupByServerId:{},wanRuntimeByHomeId:{}}
test("path validates explicit empty snapshot and rejects missing fields, foreign IDs and mismatched time",()=>{
assert.deepEqual(parseDashboardPath({snapshot:null}),{snapshot:null});assert.ok(parseDashboardPath({snapshot}))
for(const raw of [{},{snapshot:{}},{snapshot:null,sampledAt:snapshot.sampledAt},{snapshot:{...snapshot,speedProbes:undefined}},{snapshot:{...snapshot,routeLookupByServerId:{"99":null}}},{snapshot,sampledAt:"2026-10-03T01:00:00Z"}])assert.throws(()=>parseDashboardPath(raw))
for(const raw of [{snapshot:{...snapshot,collectionComplete:undefined}},{snapshot:{}},{snapshot:null,sampledAt:snapshot.sampledAt},{snapshot:{...snapshot,speedProbes:undefined}},{snapshot:{...snapshot,routeLookupByServerId:{"99":null}}},{snapshot,sampledAt:"2026-10-03T01:00:00Z"}])assert.throws(()=>parseDashboardPath(raw))
})
test("path fallback validates rules, speed probes and WAN rather than silently using empty data",()=>{
assert.ok(parseDashboardSpeedProbes({probes:[]}));assert.ok(parseDashboardFilters({rulesets:[]}));assert.ok(parseDashboardWanRuntime({defaultGateway:null,defaultInterface:null,uplinks:[]}))