mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-26 16:29:34 +00:00
fix(nodes): preserve falsy event payloads
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { parseWindowsCodePage } from "../infra/windows-encoding.js";
|
||||
import { withEnv } from "../test-utils/env.js";
|
||||
import { decodeCapturedOutputBuffer, sanitizeEnv } from "./invoke.js";
|
||||
import { buildNodeInvokeResultParams } from "./runner.js";
|
||||
import { buildNodeEventParams, buildNodeInvokeResultParams } from "./runner.js";
|
||||
|
||||
describe("node-host sanitizeEnv", () => {
|
||||
it("ignores PATH overrides", () => {
|
||||
@@ -121,3 +121,28 @@ describe("buildNodeInvokeResultParams", () => {
|
||||
expect(params.payload).toEqual({ reason: "bad" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildNodeEventParams", () => {
|
||||
it("serializes explicit falsy event payloads", () => {
|
||||
expect(buildNodeEventParams("node.test", undefined)).toEqual({
|
||||
event: "node.test",
|
||||
payloadJSON: null,
|
||||
});
|
||||
expect(buildNodeEventParams("node.test", null)).toEqual({
|
||||
event: "node.test",
|
||||
payloadJSON: "null",
|
||||
});
|
||||
expect(buildNodeEventParams("node.test", false)).toEqual({
|
||||
event: "node.test",
|
||||
payloadJSON: "false",
|
||||
});
|
||||
expect(buildNodeEventParams("node.test", 0)).toEqual({
|
||||
event: "node.test",
|
||||
payloadJSON: "0",
|
||||
});
|
||||
expect(buildNodeEventParams("node.test", "")).toEqual({
|
||||
event: "node.test",
|
||||
payloadJSON: '""',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -618,12 +618,20 @@ export function buildNodeInvokeResultParams(
|
||||
return params;
|
||||
}
|
||||
|
||||
export function buildNodeEventParams(
|
||||
event: string,
|
||||
payload: unknown,
|
||||
): { event: string; payloadJSON: string | null } {
|
||||
const payloadJSON = payload === undefined ? undefined : JSON.stringify(payload);
|
||||
return {
|
||||
event,
|
||||
payloadJSON: typeof payloadJSON === "string" ? payloadJSON : null,
|
||||
};
|
||||
}
|
||||
|
||||
async function sendNodeEvent(client: GatewayClient, event: string, payload: unknown) {
|
||||
try {
|
||||
await client.request("node.event", {
|
||||
event,
|
||||
payloadJSON: payload ? JSON.stringify(payload) : null,
|
||||
});
|
||||
await client.request("node.event", buildNodeEventParams(event, payload));
|
||||
} catch {
|
||||
// ignore: node events are best-effort
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
} from "./plugin-node-host.js";
|
||||
|
||||
export { buildNodeInvokeResultParams };
|
||||
export { buildNodeEventParams } from "./invoke.js";
|
||||
|
||||
type NodeHostRunOptions = {
|
||||
gatewayHost: string;
|
||||
|
||||
Reference in New Issue
Block a user