cc-libs/tools/mcp-bridge/test-integration/exec-lua-real-program.test.ts

28 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { callExecLua, formatFailure, startBridge, startCraftos, waitForComputers } from "./harness.js";
test("exec-lua runs code through the real TrapOS mcp-computer program", async () => {
const bridge = await startBridge();
const craftos = startCraftos("/programs/mcp-computer.lua", {
mountRepo: true,
shellArgs: [bridge.linkUrl],
timeoutMs: 15_000,
});
try {
await waitForComputers(bridge.registry, 1, 12_000);
const text = await callExecLua(bridge.mcpUrl, 0, "print('hello from exec'); return 2 + 3");
assert.match(text, /^computer: 0 \(Label: null\)\nok: true\nreturns: \[\{.*\}\]\noutput:\nhello from exec$/);
assert.match(text, /"type":"number"/);
assert.match(text, /"value":5/);
} catch (error) {
craftos.abort();
const result = await craftos.done;
throw new Error(formatFailure(error instanceof Error ? error.message : String(error), result.output), { cause: error });
} finally {
craftos.abort();
await craftos.done;
await bridge.close();
}
});