chore: update molt.bot domains
This commit is contained in:
@@ -83,6 +83,26 @@ describe("lobster plugin tool", () => {
|
||||
expect(res.details).toMatchObject({ ok: true, status: "ok" });
|
||||
});
|
||||
|
||||
it("tolerates noisy stdout before the JSON envelope", async () => {
|
||||
const payload = { ok: true, status: "ok", output: [], requiresApproval: null };
|
||||
const { binPath } = await writeFakeLobsterScript(
|
||||
`const payload = ${JSON.stringify(payload)};\n` +
|
||||
`console.log("noise before json");\n` +
|
||||
`process.stdout.write(JSON.stringify(payload));\n`,
|
||||
"clawdbot-lobster-plugin-noisy-",
|
||||
);
|
||||
|
||||
const tool = createLobsterTool(fakeApi());
|
||||
const res = await tool.execute("call-noisy", {
|
||||
action: "run",
|
||||
pipeline: "noop",
|
||||
lobsterPath: binPath,
|
||||
timeoutMs: 1000,
|
||||
});
|
||||
|
||||
expect(res.details).toMatchObject({ ok: true, status: "ok" });
|
||||
});
|
||||
|
||||
it("requires absolute lobsterPath when provided", async () => {
|
||||
const tool = createLobsterTool(fakeApi());
|
||||
await expect(
|
||||
|
||||
@@ -131,10 +131,28 @@ async function runLobsterSubprocess(params: {
|
||||
}
|
||||
|
||||
function parseEnvelope(stdout: string): LobsterEnvelope {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(stdout);
|
||||
} catch {
|
||||
const trimmed = stdout.trim();
|
||||
|
||||
const tryParse = (input: string) => {
|
||||
try {
|
||||
return JSON.parse(input) as unknown;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
let parsed: unknown = tryParse(trimmed);
|
||||
|
||||
// Some environments can leak extra stdout (e.g. warnings/logs) before the
|
||||
// final JSON envelope. Be tolerant and parse the last JSON-looking suffix.
|
||||
if (parsed === undefined) {
|
||||
const suffixMatch = trimmed.match(/({[\s\S]*}|\[[\s\S]*])\s*$/);
|
||||
if (suffixMatch?.[1]) {
|
||||
parsed = tryParse(suffixMatch[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (parsed === undefined) {
|
||||
throw new Error("lobster returned invalid JSON");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user