T-136: tests
This commit is contained in:
parent
30552a661d
commit
d3a5105327
1 changed files with 42 additions and 0 deletions
|
|
@ -200,6 +200,48 @@ describe('read_knowledge QA: port failures and malformed port output', () => {
|
|||
expectSanitized(res);
|
||||
}
|
||||
});
|
||||
|
||||
// Regression: port calls were started eagerly inside the Promise.all array literal, so a
|
||||
// synchronous throw from a later source abandoned an earlier source's rejected promise.
|
||||
// Bun treats that unhandled rejection as fatal: the MCP stdio process exits 1 after replying
|
||||
// and prints the raw error (including any connection string) to stderr. Bun's test runner
|
||||
// also reports it as an error between tests, so the scenario runs in a child process.
|
||||
test('earlier async rejection combined with a later synchronous throw does not crash the process', () => {
|
||||
const indexPath = new URL('../src/mcp/index.ts', import.meta.url).pathname;
|
||||
const script = `
|
||||
import { createMcpServer, createReadKnowledgeTool } from ${JSON.stringify(indexPath)};
|
||||
const secret = ${JSON.stringify(SECRET)};
|
||||
const combos = [
|
||||
{ listLibraryCards: () => Promise.reject(new Error(secret)), listFindings: () => { throw new Error('sync'); }, listProviderCaveats: async () => [] },
|
||||
{ listLibraryCards: () => Promise.reject(new Error(secret)), listFindings: async () => [], listProviderCaveats: () => { throw new Error('sync'); } },
|
||||
{ listLibraryCards: async () => [], listFindings: () => Promise.reject(new Error(secret)), listProviderCaveats: () => { throw new Error('sync'); } },
|
||||
];
|
||||
for (const port of combos) {
|
||||
const server = createMcpServer({ name: 'qa', version: '0.0.0', tools: [createReadKnowledgeTool({ port })] });
|
||||
const raw = await server.handleMessage(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'read_knowledge', arguments: {} } }));
|
||||
console.log(JSON.parse(raw).result.content[0].text);
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 20));
|
||||
console.log('DONE');
|
||||
`;
|
||||
|
||||
const proc = Bun.spawnSync([process.execPath, '-e', script], {
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
timeout: 30_000,
|
||||
});
|
||||
const stdout = proc.stdout.toString();
|
||||
const stderr = proc.stderr.toString();
|
||||
|
||||
expect(stdout.trim().split('\n')).toEqual([
|
||||
'Error: Tool execution failed.',
|
||||
'Error: Tool execution failed.',
|
||||
'Error: Tool execution failed.',
|
||||
'DONE',
|
||||
]);
|
||||
expect(stderr).not.toContain('super-secret');
|
||||
expect(proc.exitCode).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('read_knowledge QA: read-only port usage', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue