Files
memind/skill-runtime-admin-config.test.mjs
T
john a867592367 feat(skill-runtime): restore admin config and manifest keyword routing
Recover skill runtime policy/admin services and Skill Router v2 helpers so
admins can toggle manifest routing and inspect the platform skill catalog.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 13:59:59 +08:00

75 lines
2.7 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
createSkillRuntimeAdminConfigService,
skillRuntimeAdminConfigInternals,
} from './skill-runtime-admin-config.mjs';
function createPool(seedRow = null) {
const state = { row: seedRow };
return {
state,
async query(sql, params) {
if (sql.includes('CREATE TABLE')) return [[], []];
if (sql.includes('SELECT config_json')) {
return [state.row ? [state.row] : [], []];
}
if (sql.includes('INSERT INTO h5_skill_runtime_config')) {
state.row = {
config_json: params[1],
updated_by: params[2],
updated_at: params[3],
};
return [[], []];
}
throw new Error(`Unexpected query: ${sql}`);
},
};
}
test('skill runtime admin config defaults to disabled router', async () => {
const service = createSkillRuntimeAdminConfigService(createPool(), { env: {} });
const result = await service.getAdminConfig();
assert.equal(result.config.router.v2Enabled, false);
assert.equal(result.config.router.manifestRoutingEnabled, false);
});
test('skill runtime admin config falls back to env when db row is absent', async () => {
const service = createSkillRuntimeAdminConfigService(createPool(), {
env: { TKMIND_SKILL_ROUTER_V2: '1' },
});
const result = await service.getAdminConfig();
assert.equal(result.config.router.v2Enabled, true);
assert.equal(result.config.router.manifestRoutingEnabled, true);
assert.equal(result.source, 'env');
});
test('skill runtime admin config persists router toggles', async () => {
const pool = createPool();
const service = createSkillRuntimeAdminConfigService(pool, { env: {} });
const updated = await service.updateAdminConfig(
{ router: { v2Enabled: true, manifestRoutingEnabled: true } },
{ updatedBy: 'admin-1' },
);
assert.equal(updated.config.router.v2Enabled, true);
assert.equal(updated.config.router.manifestRoutingEnabled, true);
const runtime = await service.getPublicRuntimeConfig();
assert.equal(runtime.routerV2Enabled, true);
assert.equal(runtime.manifestRoutingEnabled, true);
assert.ok(Array.isArray(runtime.manifestRoutes));
});
test('skill runtime admin config keeps db authoritative over env', async () => {
const pool = createPool({
config_json: JSON.stringify(skillRuntimeAdminConfigInternals.defaultConfigShape()),
updated_by: 'admin-1',
updated_at: 123,
});
const service = createSkillRuntimeAdminConfigService(pool, {
env: { TKMIND_SKILL_ROUTER_V2: '1' },
});
const result = await service.getAdminConfig();
assert.equal(result.config.router.v2Enabled, false);
assert.equal(result.source, 'admin-db');
});