fix(mcp): включить проверяемый контроллер маршрутизации
This commit is contained in:
1 parent
6569dbfc60
commit
1f0704add0
25 files changed
+1041
-291
No files matched your search
@@ -1,8 +1,16 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { routeAiProfileSchema } from "./mcp-routing.js"
|
||||
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/)
|
||||
assert.equal(routeAiControllerBlockReason(routeAiProfileSchema.parse({ ...raw, table: "main" })), null)
|
||||
@@ -36,6 +36,22 @@ export const routeMeasurementSchema = z.object({
|
||||
bandwidth: z.boolean().default(false), durationSec: z.number().int().min(3).max(30).default(5), maxMbps: z.number().positive().max(10000).optional(),
|
||||
}).strict().refine(input => !input.bandwidth || input.maxMbps !== undefined, "Bandwidth-тест требует ограничения скорости")
|
||||
export type RouteAiProfile = z.infer<typeof routeAiProfileSchema>
|
||||
type RouteAiContext = Pick<RouteAiProfile, "table" | "probeVrf" | "bgpContext">
|
||||
|
||||
export function usesScopedRouteAiContext({ table, probeVrf, bgpContext }: RouteAiContext): boolean {
|
||||
return table.trim() !== "main" || probeVrf.trim() !== "main" ||
|
||||
!!bgpContext && (bgpContext.inputChain.trim() !== "bgp-in" || bgpContext.vrf.trim() !== "main")
|
||||
}
|
||||
|
||||
export function routeAiControllerBlockReason(profile: RouteAiContext & Pick<RouteAiProfile, "autoRecovery"> & {
|
||||
candidates: readonly { controlProbe?: { sourceAddress?: string } }[]
|
||||
}): string | null {
|
||||
if (profile.autoRecovery) return "ROUTE_RECOVERY_EXECUTOR_UNAVAILABLE: автоматическое восстановление требует отдельного подтверждения состояния после переключения"
|
||||
if (!usesScopedRouteAiContext(profile)) return null
|
||||
if (!profile.bgpContext) return "Укажите явную BGP-привязку для контроллера отдельной таблицы или VRF"
|
||||
if (profile.candidates.some(candidate => !candidate.controlProbe?.sourceAddress?.trim())) return "Укажите контрольную пробу с исходным адресом для каждого пути"
|
||||
return null
|
||||
}
|
||||
export interface RouteObservation {
|
||||
id: string; srcServerId: number; dstServerId: number; srcInterface: string; dstInterface: string;
|
||||
family: "ipv4" | "ipv6"; table: string; pingMs: number | null; lossPct: number | null; dlMbps: number | null; ulMbps: number | null;
|
||||
|
||||
Reference in new issue
Block a user