44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { callExecLua, callWriteFile, formatFailure, startBridge, startCraftos, waitForComputers } from "./harness.js";
|
|
|
|
test("write-file writes 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 first = await callWriteFile(bridge.mcpUrl, 0, "mcp-write-test.txt", "hello\nworld");
|
|
assert.equal(first, "computer: 0 (Label: null)\nok: true\npath: mcp-write-test.txt\nbytes: 11");
|
|
|
|
const readFirst = await callExecLua(
|
|
bridge.mcpUrl,
|
|
0,
|
|
"local h = fs.open('mcp-write-test.txt', 'r'); local c = h.readAll(); h.close(); return c",
|
|
);
|
|
assert.match(readFirst, /"value":"hello\\nworld"/);
|
|
|
|
const second = await callWriteFile(bridge.mcpUrl, 0, "mcp-write-test.txt", "overwritten");
|
|
assert.equal(second, "computer: 0 (Label: null)\nok: true\npath: mcp-write-test.txt\nbytes: 11");
|
|
|
|
const readSecond = await callExecLua(
|
|
bridge.mcpUrl,
|
|
0,
|
|
"local h = fs.open('mcp-write-test.txt', 'r'); local c = h.readAll(); h.close(); fs.delete('mcp-write-test.txt'); return c",
|
|
);
|
|
assert.match(readSecond, /"value":"overwritten"/);
|
|
} 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();
|
|
}
|
|
});
|