feat: support MCP elicitation and rebuild release
This commit is contained in:
86
scripts/gitea-mcp-probe-unit.js
Normal file
86
scripts/gitea-mcp-probe-unit.js
Normal file
@@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
|
||||
/** gitea-mcp stdio 预检离线回归。 */
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const process = require('node:process');
|
||||
const {
|
||||
DEFAULT_TIMEOUT_MS,
|
||||
MAX_TIMEOUT_MS,
|
||||
probeGiteaMcp,
|
||||
} = require('../lib/gitea-mcp-probe');
|
||||
|
||||
const fixture = path.join(__dirname, '..', 'fixtures', 'gitea-workflow', 'mock-gitea-mcp.js');
|
||||
|
||||
async function expectCode(promise, code) {
|
||||
await assert.rejects(promise, (error) => {
|
||||
assert.equal(error.code, code);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
assert.equal(DEFAULT_TIMEOUT_MS, 8000);
|
||||
assert.equal(MAX_TIMEOUT_MS, 30000);
|
||||
|
||||
const success = await probeGiteaMcp({
|
||||
command: process.execPath,
|
||||
args: [fixture],
|
||||
env: { GITEA_MCP_FIXTURE_MODE: 'success', GITEA_ACCESS_TOKEN: 'fixture-token' },
|
||||
timeoutMs: 1000,
|
||||
});
|
||||
assert.equal(success.ok, true);
|
||||
assert.equal(success.protocolVersion, '2024-11-05');
|
||||
|
||||
await expectCode(probeGiteaMcp({
|
||||
command: process.execPath,
|
||||
args: [fixture],
|
||||
env: { GITEA_MCP_FIXTURE_MODE: 'error' },
|
||||
timeoutMs: 1000,
|
||||
}), 'gitea_mcp_handshake_failed');
|
||||
|
||||
await expectCode(probeGiteaMcp({
|
||||
command: process.execPath,
|
||||
args: [fixture],
|
||||
env: { GITEA_MCP_FIXTURE_MODE: 'exit' },
|
||||
timeoutMs: 1000,
|
||||
}), 'gitea_mcp_start_failed');
|
||||
|
||||
await expectCode(probeGiteaMcp({
|
||||
command: process.execPath,
|
||||
args: [fixture],
|
||||
env: { GITEA_MCP_FIXTURE_MODE: 'timeout' },
|
||||
timeoutMs: 250,
|
||||
}), 'gitea_mcp_handshake_timeout');
|
||||
|
||||
await expectCode(probeGiteaMcp({
|
||||
command: '/definitely/missing/gitea-mcp',
|
||||
timeoutMs: 1000,
|
||||
}), 'gitea_mcp_spawn_failed');
|
||||
|
||||
// 协议守门:失败仍交给统一的队列终态回执,线程级注入和“禁止自动安装”不回退。
|
||||
const serverSource = fs.readFileSync(path.join(__dirname, '..', 'server.js'), 'utf8');
|
||||
const probeSource = fs.readFileSync(path.join(__dirname, '..', 'lib', 'gitea-mcp-probe.js'), 'utf8');
|
||||
const buildSource = fs.readFileSync(path.join(__dirname, '..', 'scripts', 'build-single-exe.js'), 'utf8');
|
||||
assert.match(serverSource, /await probeGiteaMcp\(\{/);
|
||||
assert.match(serverSource, /code: 'gitea_mcp_not_found'/);
|
||||
assert.match(serverSource, /path\.join\(APP_DIR, 'bin', bundledName\)/);
|
||||
assert.match(probeSource, /gitea_mcp_start_failed/);
|
||||
assert.match(probeSource, /gitea_mcp_handshake_failed/);
|
||||
assert.match(probeSource, /gitea_mcp_handshake_timeout/);
|
||||
assert.match(serverSource, /failed: \(task\) => `任务失败:/);
|
||||
assert.match(serverSource, /failed_reply: \(task\) => `回帖失败:/);
|
||||
assert.match(serverSource, /statusComments/);
|
||||
assert.match(serverSource, /config\['mcp_servers\.gitea'\]/);
|
||||
assert.match(buildSource, /copyDirIfExists\(path\.join\(projectRoot, 'bin'\), path\.join\(releaseDir, 'bin'\)\)/);
|
||||
assert.doesNotMatch(serverSource, /npm\s+(?:install| i)\b|curl\s+[^\n]*(?:gitea-mcp|github)/i);
|
||||
|
||||
console.log('Gitea MCP probe unit checks passed.');
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error.stack || error.message || error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user