26 lines
1.8 KiB
TypeScript
26 lines
1.8 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { test } from "node:test"
|
|
import { mcpOperationDescriptorSchema } from "@mmapp/contracts/mcp"
|
|
import type { add } from "./actions.js"
|
|
import { registerServerPollAction } from "./server-poll-registration.js"
|
|
import { findMcpService } from "./service-registry.js"
|
|
|
|
test("registration exposes one actual global write plan and fixed nondiagnostic service", async () => {
|
|
const calls: Parameters<typeof add>[] = []
|
|
registerServerPollAction(((...args: Parameters<typeof add>) => { calls.push(args) }) as typeof add)
|
|
assert.equal(calls.length, 1)
|
|
const [id, tool, description, section, permission, effect, scope, schema, handlers] = calls[0]
|
|
assert.match(description, /8 на владельца, 128 на приложение/)
|
|
assert.match(description, /Архивирование сохраняет аудит/)
|
|
assert.match(description, /pollStorageCapacity/)
|
|
assert.equal(mcpOperationDescriptorSchema.shape.title.safeParse(description).success, true)
|
|
assert.equal(id, "servers.poll"); assert.equal(tool, "mm_server_poll_plan"); assert.equal(section, "servers")
|
|
assert.equal(permission, "mm:servers:write"); assert.equal(effect, "write"); assert.equal(scope, "global"); assert.equal(handlers.version, 1)
|
|
assert(handlers.prepare); assert(handlers.target); assert.equal(handlers.read, undefined)
|
|
assert(schema.safeParse({ serverId: 1 }).success)
|
|
for (const input of [{ serverId: 1, identity: {} }, { serverId: 1, sql: "SELECT 1" }, { serverId: 1, receiptId: "forged" }, { serverId: 0 }]) assert(!schema.safeParse(input).success)
|
|
const service = findMcpService(id); assert(service); assert.equal(service.cancellableDiagnostic, undefined)
|
|
for (const method of ["current", "execute", "verify", "reconcile"] as const) assert.equal(typeof service[method], "function")
|
|
assert.equal(await service.verify!({}, {}), false)
|
|
})
|