test-extract.jsโข2.81 kB
/**
* Simple test script to validate the extraction function
*/
import { execFile } from "child_process";
import { promisify } from "util";
import { readFile, access, mkdir } from "fs/promises";
import { join } from "path";
import { constants } from "fs";
const execFileAsync = promisify(execFile);
const DEFAULT_MX_PATH = "D:\\Program Files\\Mendix\\11.3.0.80734\\modeler\\mx.exe";
const TEST_MPR = "d:\\kelly.seale\\CodeBase\\OneTech-main\\OneTech.mpr";
const TEST_MODULE = "RequestHub";
const TEST_OUTPUT = "D:\\kelly.seale\\CodeBase\\onetech-mcp-server\\test-output";
async function runTest() {
console.log("๐งช Testing OneTech MCP Server extraction...\n");
// Ensure output directory exists
await mkdir(TEST_OUTPUT, { recursive: true });
const commands = [
{
name: "DomainModel",
unitType: "DomainModels$DomainModel",
outputFile: join(TEST_OUTPUT, `${TEST_MODULE}-DomainModel.json`),
},
{
name: "Pages",
unitType: "Pages$Page",
outputFile: join(TEST_OUTPUT, `${TEST_MODULE}-Pages.json`),
},
{
name: "Microflows",
unitType: "Microflows$Microflow",
outputFile: join(TEST_OUTPUT, `${TEST_MODULE}-Microflows.json`),
},
{
name: "Enumerations",
unitType: "Enumerations$Enumeration",
outputFile: join(TEST_OUTPUT, `${TEST_MODULE}-Enumerations.json`),
},
];
const results = [];
for (const cmd of commands) {
try {
console.log(`Extracting ${cmd.name}...`);
const args = ["dump-mpr", "--unit-type", cmd.unitType, "--module-names", TEST_MODULE, "--output-file", cmd.outputFile, TEST_MPR];
const startTime = Date.now();
await execFileAsync(DEFAULT_MX_PATH, args, { maxBuffer: 50 * 1024 * 1024 });
const duration = Date.now() - startTime;
const fileContent = await readFile(cmd.outputFile, "utf-8");
const size = Buffer.byteLength(fileContent, "utf-8");
results.push({
name: cmd.name,
success: true,
size: size,
duration: duration,
});
console.log(`โ
${cmd.name}: ${(size / 1024).toFixed(1)}KB in ${duration}ms`);
} catch (error) {
results.push({
name: cmd.name,
success: false,
error: error.message,
});
console.log(`โ ${cmd.name}: ${error.message}`);
}
}
console.log("\n๐ Test Results:");
console.log(`Success: ${results.filter((r) => r.success).length}/4`);
console.log(`Total size: ${(results.reduce((sum, r) => sum + (r.size || 0), 0) / 1024).toFixed(1)}KB`);
console.log(`Total time: ${results.reduce((sum, r) => sum + (r.duration || 0), 0)}ms`);
const allSuccess = results.every((r) => r.success);
console.log(allSuccess ? "\nโ
All tests passed!" : "\nโ Some tests failed");
return allSuccess;
}
runTest()
.then((success) => process.exit(success ? 0 : 1))
.catch((error) => {
console.error("Fatal error:", error);
process.exit(1);
});