From 6f52ef49a516587c1bbd99ac22069232b371fa89 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 24 Mar 2026 02:21:55 +0100 Subject: [PATCH] test(mcp): add OCPP schema mapping consistency tests Verify that every broadcast channel OCPP command has a corresponding MCP tool schema and OCPP schema mapping entry. Ensures schema coverage stays in sync with supported commands as a single source of truth guard. --- .../ui-server/UIMCPServer.test.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/charging-station/ui-server/UIMCPServer.test.ts b/tests/charging-station/ui-server/UIMCPServer.test.ts index 54567ed3..1145c86f 100644 --- a/tests/charging-station/ui-server/UIMCPServer.test.ts +++ b/tests/charging-station/ui-server/UIMCPServer.test.ts @@ -14,7 +14,11 @@ import { fileURLToPath } from 'node:url' import type { ProtocolResponse, RequestPayload, ResponsePayload } from '../../../src/types/index.js' -import { mcpToolSchemas } from '../../../src/charging-station/ui-server/mcp/index.js' +import { + mcpToolSchemas, + ocppSchemaMapping, +} from '../../../src/charging-station/ui-server/mcp/index.js' +import { AbstractUIService } from '../../../src/charging-station/ui-server/ui-services/AbstractUIService.js' import { UIMCPServer } from '../../../src/charging-station/ui-server/UIMCPServer.js' import { DEFAULT_MAX_PAYLOAD_SIZE } from '../../../src/charging-station/ui-server/UIServerSecurity.js' import { BaseError } from '../../../src/exception/index.js' @@ -179,6 +183,39 @@ await describe('UIMCPServer', async () => { await it('should have a tool schema for every ProcedureName', () => { assert.strictEqual(mcpToolSchemas.size, Object.keys(ProcedureName).length) }) + + await it('should have an OCPP schema mapping for every broadcast channel OCPP command', () => { + const broadcastMapping = Reflect.get( + AbstractUIService, + 'ProcedureNameToBroadCastChannelProcedureNameMapping' + ) as Map + for (const procedureName of broadcastMapping.keys()) { + const toolSchema = mcpToolSchemas.get(procedureName) + assert.ok( + toolSchema != null, + `Missing MCP tool schema for broadcast command '${procedureName}'` + ) + const schema = ocppSchemaMapping.get(procedureName) + if ( + 'ocpp16Payload' in toolSchema.inputSchema.shape || + 'ocpp20Payload' in toolSchema.inputSchema.shape + ) { + assert.ok( + schema != null, + `Missing OCPP schema mapping for OCPP command '${procedureName}'` + ) + } + } + }) + + await it('should have ocpp16 or ocpp20 schema file reference for every mapped command', () => { + for (const [procedureName, mapping] of ocppSchemaMapping) { + assert.ok( + mapping.ocpp16 != null || mapping.ocpp20 != null, + `OCPP schema mapping for '${procedureName}' has neither ocpp16 nor ocpp20 schema` + ) + } + }) }) await describe('hasResponseHandler override', async () => { -- 2.43.0