Files
hose-use/src/cli/commands/workflow/mvel-eval.test.ts
T

19 lines
892 B
TypeScript

import { expect, test } from "bun:test";
import { parseArgs } from "../../parser.js";
import { handleWorkflowEvalScript } from "./script.js";
test("MVEL CLI JSON returns the terminal expression and preserves failure exit codes", async () => {
for (const [code, success] of [
['Map result = new java.util.HashMap(); result.put("value", 7); result;', true],
['new java.util.Date();', false],
['if (true) { 7; }', false],
] as const) {
const result = await handleWorkflowEvalScript(parseArgs(["workflow", "eval-script", "--type", "code", "--code", code, "--json"]), { jsonMode: true } as any);
const report = JSON.parse(result.stdout);
expect(result.exitCode).toBe(success ? 0 : 1);
expect(report.success).toBe(success);
if (success) expect(report.returnValue).toEqual({ value: 7 });
else expect(report.error.name).toBe("UnsupportedMvelSyntax");
}
});