import { spawn } from "child_process";
import path from "path";
const serverPath = path.join(__dirname, "dist", "src", "server.js");
const serverProcess = spawn("node", [serverPath], {
stdio: ["pipe", "pipe", "inherit"]
});
// We will just test that the tool accepts the new argument and returns a result (even if empty/error about empty DB)
// This confirms the schema update and that the function is reachable.
const requests = [
{
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2024-11-05",
capabilities: {},
clientInfo: { name: "test-client", version: "1.0.0" }
}
},
{
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "query_knowledge_base",
arguments: {
query: "test query",
document_id: "non-existent-id"
}
}
}
];
let buffer = "";
serverProcess.stdout.on("data", (data) => {
buffer += data.toString();
const lines = buffer.split("\n");
buffer = lines.pop() || "";
for (const line of lines) {
if (!line.trim()) continue;
try {
const response = JSON.parse(line);
console.log("Received response:", JSON.stringify(response, null, 2));
if (response.id === 2) {
console.log("Verification complete.");
serverProcess.kill();
process.exit(0);
}
} catch (e) {
console.error("Error parsing JSON:", e);
}
}
});
// Send requests
requests.forEach((req) => {
const msg = JSON.stringify(req) + "\n";
serverProcess.stdin.write(msg);
});
setTimeout(() => {
console.error("Timeout waiting for response");
serverProcess.kill();
process.exit(1);
}, 5000);