feat: add optional asset gateway control plane

This commit is contained in:
john
2026-07-12 09:51:13 +08:00
parent 03a79322e4
commit f4d9897072
8 changed files with 449 additions and 1 deletions
+42
View File
@@ -90,6 +90,48 @@ test('admin memory-v2 config routes expose config and runtime state', async () =
}
});
test('admin asset gateway routes preserve an explicit, admin-only control plane', async () => {
const calls = [];
const router = createAdminApi({
jsonBody: express.json(),
getToken() { return 'token-admin'; },
userAuth: { async getMe() { return { id: 'admin-1', role: 'admin' }; } },
llmProviderService: null,
memoryV2ConfigService: null,
assetGatewayConfigService: {
async getConfig() { return { enabled: false, plugins: [] }; },
async updateGlobalConfig(payload, context) { calls.push({ type: 'global', payload, context }); return { enabled: true }; },
async updatePluginConfig(pluginId, payload, context) {
calls.push({ type: 'plugin', pluginId, payload, context });
return { ok: true, config: { enabled: true, plugins: [] } };
},
},
plazaPosts: null,
plazaOps: null,
wechatAdmin: null,
subscriptionService: null,
});
const server = await startTestServer(router);
try {
const read = await fetch(`${server.baseUrl}/admin-api/asset-gateway/config`, {
headers: { cookie: 'h5_user_session=token-admin' },
});
assert.equal(read.status, 200);
assert.deepEqual(await read.json(), { enabled: false, plugins: [] });
const update = await fetch(`${server.baseUrl}/admin-api/asset-gateway/plugins/asset-generate`, {
method: 'PUT',
headers: { 'content-type': 'application/json', cookie: 'h5_user_session=token-admin' },
body: JSON.stringify({ enabled: true, provider: 'flux-schnell' }),
});
assert.equal(update.status, 200);
assert.equal(calls[0].pluginId, 'asset-generate');
assert.equal(calls[0].context.updatedBy, 'admin-1');
} finally {
await server.close();
}
});
test('admin system test route executes shared validation service', async () => {
const calls = [];
const router = createAdminApi({