Files
MikrotikManager/packages/contracts/src/mcp-routing.test.ts
T

17 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict"
import { routeAiControllerBlockReason, routeAiProfileSchema } from "./mcp-routing.js"
const raw = { name: "context", serverId: 1, community: "65000:10", family: "ipv4", table: "policy-only", candidates: [{ id: "a", wanInterface: "wan", downstreamInterface: "down", jumpHostId: 2, exitNodeId: 3, gateway: "192.0.2.1", gatewayRef: { resource: "ipv4_route", id: "*a" } }] }
assert.equal(routeAiProfileSchema.parse(raw).probeVrf, "main")
assert.deepEqual(routeAiProfileSchema.parse({ ...raw, probeVrf: "tenant-vrf", bgpContext: { connectionId: "*c", instance: "tenant-bgp", inputChain: "tenant-in" } }).bgpContext, { connectionId: "*c", instance: "tenant-bgp", inputChain: "tenant-in", vrf: "main" })
assert.equal(routeAiProfileSchema.parse({ ...raw, probeVrf: "probe-vrf", bgpContext: { connectionId: "*c", instance: "tenant-bgp", inputChain: "tenant-in", vrf: "bgp-vrf" } }).bgpContext?.vrf, "bgp-vrf")
for (const bgpContext of [{ connectionId: "name", instance: "i", inputChain: "in" }, { connectionId: "*c", instance: "i", inputChain: "in", direction: "output" }, { connectionId: "*c", instance: "i\n", inputChain: "in\u0000" }]) assert.equal(routeAiProfileSchema.safeParse({ ...raw, bgpContext }).success, false)
console.log("Route AI profile: installation table/probe VRF/input binding remain separate; strict native identity and control-character rejection")
const scoped = routeAiProfileSchema.parse({ ...raw, bgpContext: { connectionId: "*c", instance: "tenant-bgp", inputChain: "tenant-in" } })
assert.match(routeAiControllerBlockReason(routeAiProfileSchema.parse(raw))!, /BGP-привязку/)
assert.match(routeAiControllerBlockReason(scoped)!, /исходным адресом/)
const withProbe = { ...scoped, candidates: [{ ...scoped.candidates[0], controlProbe: { sourceAddress: "192.0.2.2", targetInterface: "down", expectedHops: [{ serverId: 2, interface: "wan" }] } }] }
assert.equal(routeAiControllerBlockReason(withProbe), null)
assert.match(routeAiControllerBlockReason({ ...withProbe, autoRecovery: true })!, /ROUTE_RECOVERY_EXECUTOR_UNAVAILABLE.*непрерывность событий RouterOS.*REST \/log/)
assert.equal(routeAiControllerBlockReason(routeAiProfileSchema.parse({ ...raw, table: "main" })), null)