MEGAINFRA-WEBAPP/scripts/migrations/2026-10-05-add-mcp-operations.test.mjs

14 lines
1 KiB
JavaScript

import {test} from 'node:test';
import {strict as assert} from 'node:assert';
import {mcpSchemas,validateExistingSchema} from './2026-10-05-add-mcp-operations.mjs';
test('private schema and operation/resource exclusion indexes',()=>{
assert.equal(mcpSchemas.length,3);
for(const schema of mcpSchemas)for(const key of ['listRule','viewRule','createRule','updateRule','deleteRule'])assert.equal(schema[key],null);
assert.match(mcpSchemas.find(s=>s.name==='mcp_operations').indexes[0],/UNIQUE.*credential.*tool.*operation_id/);
assert.match(mcpSchemas.find(s=>s.name==='mcp_resource_locks').indexes[0],/UNIQUE.*resource_key/);
});
test('repeat application accepts matching schema and rejects incompatible fields/rules',()=>{
for(const schema of mcpSchemas)assert.doesNotThrow(()=>validateExistingSchema(schema,schema));
const schema=mcpSchemas[0];assert.throws(()=>validateExistingSchema({...schema,listRule:''},schema));
assert.throws(()=>validateExistingSchema({...schema,fields:schema.fields.map((f,i)=>i?f:{...f,type:'number'})},schema));
});