113 lines
3.2 KiB
TypeScript
113 lines
3.2 KiB
TypeScript
// Optional compatibility check. Requires Claude Code and npm registry access.
|
|
// Uses disposable config directories and fixture credentials; never edits user config.
|
|
import assert from 'node:assert/strict';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { readFixture } from './fixture.js';
|
|
|
|
const f = readFixture();
|
|
const directory = await mkdtemp(join(tmpdir(), 'gitza-mcp-clients-'));
|
|
const executable = resolve(import.meta.dirname, '../dist/cli.js');
|
|
const env = {
|
|
...process.env,
|
|
CLAUDE_CONFIG_DIR: directory,
|
|
GITZA_TOKEN: f.readToken,
|
|
GITZA_URL: f.upstream,
|
|
GITZA_REPOSITORIES: 'alice/project',
|
|
GITZA_DEVELOPMENT: 'true',
|
|
MCP_CATALOG_PATH: undefined,
|
|
MCP_CLIENT_CONFIG_PATH: join(directory, 'client.json'),
|
|
};
|
|
function run(command: string, args: string[]) {
|
|
const result = spawnSync(command, args, {
|
|
cwd: directory,
|
|
env,
|
|
encoding: 'utf8',
|
|
timeout: 120000,
|
|
});
|
|
if (result.status !== 0)
|
|
process.stderr.write(result.stderr.replaceAll(f.readToken, '[REDACTED]'));
|
|
assert.equal(
|
|
result.status,
|
|
0,
|
|
command + ' compatibility check failed (output withheld to protect fixture credentials).',
|
|
);
|
|
return result.stdout;
|
|
}
|
|
try {
|
|
const version = run('claude', ['--version']).trim();
|
|
run('claude', [
|
|
'mcp',
|
|
'add',
|
|
'--transport',
|
|
'stdio',
|
|
'--scope',
|
|
'user',
|
|
'gitza',
|
|
'--',
|
|
process.execPath,
|
|
executable,
|
|
'stdio',
|
|
]);
|
|
const list = run('claude', ['mcp', 'list']);
|
|
assert.match(list, /gitza:.*Connected/);
|
|
process.stdout.write(version + ': clean configuration and stdio connection passed.\n');
|
|
const config = join(directory, 'mcp.json');
|
|
await writeFile(
|
|
config,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
gitza: {
|
|
command: process.execPath,
|
|
args: [executable, 'stdio'],
|
|
env: {
|
|
GITZA_TOKEN: f.readToken,
|
|
GITZA_URL: f.upstream,
|
|
GITZA_REPOSITORIES: 'alice/project',
|
|
GITZA_DEVELOPMENT: 'true',
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
{ mode: 0o600 },
|
|
);
|
|
const base = [
|
|
'exec',
|
|
'--yes',
|
|
'--package=@modelcontextprotocol/inspector@2.12.0',
|
|
'--',
|
|
'mcp-inspector',
|
|
'--cli',
|
|
'--config',
|
|
config,
|
|
'--server',
|
|
'gitza',
|
|
];
|
|
const catalogue = JSON.parse(run('npm', [...base, '--method', 'tools/list']));
|
|
assert.equal(catalogue.tools.length, 15);
|
|
for (const [name, args] of [
|
|
['get_file', { repository: 'alice/project', path: 'src/hello.txt' }],
|
|
['get_issue', { repository: 'alice/project', index: 1 }],
|
|
['get_pull_request', { repository: 'alice/project', index: 2 }],
|
|
] as const) {
|
|
const result = JSON.parse(
|
|
run('npm', [
|
|
...base,
|
|
'--method',
|
|
'tools/call',
|
|
'--tool-name',
|
|
name,
|
|
'--tool-args-json',
|
|
JSON.stringify(args),
|
|
]),
|
|
);
|
|
assert.notEqual(result.isError, true);
|
|
}
|
|
process.stdout.write(
|
|
'MCP Inspector 2.12.0: discovery, private file, issue and PR reads passed.\n',
|
|
);
|
|
} finally {
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|