Connect_Ionos_With_Claude/test/smoke.js
Tony AVERTY 16702f3d56 feat: serveur MCP pour une boîte mail IONOS
Lecture (dossiers, liste, recherche, lecture), brouillons, envoi en deux
temps (prepare_send puis confirm_send), déplacement et corbeille, sans
suppression définitive. Assistant de configuration qui teste réellement
la connexion IMAP et SMTP avant d'enregistrer quoi que ce soit.
Identifiants séparés du code (chiffrement Windows DPAPI ou variable
d'environnement), README, licence MIT et test de fumée.
2026-10-16 09:23:15 +02:00

59 lines
2.8 KiB
JavaScript

// Test de fumée sans identifiants : le serveur démarre, expose ses outils, et refuse proprement
// de se déclarer opérationnel quand aucune configuration n'existe.
import { spawn } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const emptyDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ionos-mail-test-'));
const EXPECTED = [
'test_connection', 'list_folders', 'list_messages', 'search_messages', 'get_message',
'create_draft', 'prepare_send', 'confirm_send', 'mark_messages', 'move_message', 'trash_message',
];
const child = spawn(process.execPath, [path.join(root, 'index.js')], {
env: { ...process.env, IONOS_MAIL_CONFIG_DIR: emptyDir, MAIL_PASSWORD: '' },
stdio: ['pipe', 'pipe', 'inherit'],
});
const send = (o) => child.stdin.write(JSON.stringify(o) + '\n');
const replies = new Map();
let buffer = '';
child.stdout.on('data', (d) => {
buffer += d;
const lines = buffer.split('\n');
buffer = lines.pop();
for (const l of lines.filter(Boolean)) { const j = JSON.parse(l); if (j.id) replies.set(j.id, j); }
});
const wait = async (id) => {
for (let i = 0; i < 100 && !replies.has(id); i++) await new Promise((r) => setTimeout(r, 100));
if (!replies.has(id)) throw new Error(`Pas de réponse pour la requête ${id}`);
return replies.get(id);
};
const check = (cond, msg) => { if (!cond) { console.error(`✘ ${msg}`); process.exitCode = 1; } else console.log(`✔ ${msg}`); };
try {
send({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'smoke', version: '0' } } });
await wait(1);
send({ jsonrpc: '2.0', method: 'notifications/initialized' });
send({ jsonrpc: '2.0', id: 2, method: 'tools/list' });
const tools = (await wait(2)).result.tools.map((t) => t.name);
check(EXPECTED.every((n) => tools.includes(n)), `${tools.length} outils exposés`);
check(!tools.some((n) => /delete|expunge|purge/i.test(n)), 'aucun outil de suppression définitive');
send({ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name: 'test_connection', arguments: {} } });
const r = (await wait(3)).result;
check(r.isError === true && /setup|Configuration absente/.test(r.content[0].text), 'sans configuration, test_connection échoue explicitement');
send({ jsonrpc: '2.0', id: 4, method: 'tools/call', params: { name: 'prepare_send', arguments: { to: 'a@example.org', subject: 's', body: 'b' } } });
const p = (await wait(4)).result;
check(/NON ENVOYÉ/.test(p.content[0].text), 'prepare_send n\'envoie rien');
} catch (e) {
console.error(`✘ ${e.message}`);
process.exitCode = 1;
} finally {
child.kill();
fs.rmSync(emptyDir, { recursive: true, force: true });
}