]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(mcp): add OCPP schema mapping consistency tests
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 24 Mar 2026 01:21:55 +0000 (02:21 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 24 Mar 2026 01:21:55 +0000 (02:21 +0100)
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.

tests/charging-station/ui-server/UIMCPServer.test.ts

index 54567ed3775be80d65d24131c077283c8c1c00e2..1145c86fc82521e846422a0c6e4ac7ca90cff7f4 100644 (file)
@@ -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<ProcedureName, unknown>
+      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 () => {