fix(evolution): проверять каталог и сохранять неизвестные счётчики

This commit is contained in:
Denozordec committed 2026-10-03 13:51:07 +07:00
1 parent 9db1471b2c
commit 7e3cb754b0
16 files changed
+140 -82

No files matched your search

+1 -1
View File
@@ -134,7 +134,7 @@ export interface Asn {
asn: string
org: string
country: string
prefixes: number
prefixes: number | null
filter: string
updated: string
enabled: boolean
+14
View File
@@ -15,3 +15,17 @@ test("ASN and community zero counts are preserved, invalid counts rejected", ()
assert.equal(parseEvoBgpCatalog({ ...empty, asns: [asn] }).asns[0].prefixes, 0)
assert.throws(() => parseEvoBgpCatalog({ ...empty, asns: [{ ...asn, prefixes: -1 }] }))
})
test("unknown counts stay nullable and differ from confirmed zero", () => {
const asn = { id: "asn-unknown", asn: "AS64512", org: "", country: "", prefixes: null, filter: "", updated: "—", enabled: true }
const community = { id: "c", value: "64512:1", name: "c", description: "", type: "custom", filterIds: [], serverCount: 0, prefixCount: null, action: "permit", enabled: true }
const result = parseEvoBgpCatalog({...empty, asns:[asn], communities:[community]})
assert.equal(result.asns[0].prefixes,null)
assert.equal(result.communities[0].prefixCount,null)
assert.equal(result.communities[0].serverCount,0)
for(const value of [undefined,-1,1.5,Number.MAX_SAFE_INTEGER+1]) {
assert.throws(()=>parseEvoBgpCatalog({...empty,asns:[{...asn,prefixes:value}]}))
assert.throws(()=>parseEvoBgpCatalog({...empty,communities:[{...community,prefixCount:value}]}))
}
})
+2 -2
View File
@@ -12,8 +12,8 @@ const schema = z.object({
modules: unique(z.object({ id, name: text, type: text })),
domains: unique(z.object({ ...base, domain: text, resolvedIp: text })),
ipRanges: unique(z.object({ ...base, cidr: text, country: text })),
asns: unique(z.object({ id, asn: text, org: text, country: text, prefixes: count, filter: text, updated: text, enabled: z.boolean() })),
communities: unique(z.object({ id, value: text, name: text, description: text, type: z.enum(["standard", "no-export", "no-advertise", "local-as", "custom"]), filterIds: z.array(text), serverCount: count, prefixCount: count, action: z.enum(["permit", "deny", "local-pref", "metric"]), actionValue: z.number().finite().optional(), enabled: z.boolean() })),
asns: unique(z.object({ id, asn: text, org: text, country: text, prefixes: count.nullable(), filter: text, updated: text, enabled: z.boolean() })),
communities: unique(z.object({ id, value: text, name: text, description: text, type: z.enum(["standard", "no-export", "no-advertise", "local-as", "custom"]), filterIds: z.array(text), serverCount: count, prefixCount: count.nullable(), action: z.enum(["permit", "deny", "local-pref", "metric"]), actionValue: z.number().finite().optional(), enabled: z.boolean() })),
})
export function parseEvoBgpCatalog(raw: unknown): EvoBgpCatalogSnapshot {
const parsed = schema.safeParse(raw)
+1 -1
View File
@@ -16,7 +16,7 @@ export interface EvoBgpCommunityRow {
type: "standard" | "no-export" | "no-advertise" | "local-as" | "custom"
filterIds: string[]
serverCount: number
prefixCount: number
prefixCount: number | null
action: "permit" | "deny" | "local-pref" | "metric"
actionValue?: number
enabled: boolean