38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { init } from '../src/cli/commands/init.js';
|
|
import { loadConfig, saveConfig } from '../src/core/config.js';
|
|
import { resolveMcpContext } from '../src/mcp/server.js';
|
|
|
|
describe('MCP context resolution', () => {
|
|
let cwd: string;
|
|
const originalEnv = process.env.AGENTHUB_SERVER;
|
|
|
|
beforeEach(() => {
|
|
cwd = mkdtempSync(join(tmpdir(), 'ah-mcp-'));
|
|
init(cwd, { projectName: 'mcp-test', yes: true });
|
|
delete process.env.AGENTHUB_SERVER;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (originalEnv === undefined) delete process.env.AGENTHUB_SERVER;
|
|
else process.env.AGENTHUB_SERVER = originalEnv;
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
});
|
|
|
|
it('self-heals a stale configured server URL before MCP tools call remote APIs', async () => {
|
|
const config = loadConfig(cwd);
|
|
config.serverUrl = 'http://agenthub.local:3377';
|
|
saveConfig(cwd, config);
|
|
|
|
const context = await resolveMcpContext(cwd, {
|
|
probe: async () => false,
|
|
discover: async () => 'http://127.0.0.1:3377',
|
|
});
|
|
|
|
expect(context).toEqual({ root: cwd, serverUrl: 'http://127.0.0.1:3377' });
|
|
});
|
|
});
|