Download src/node-host/invoke-payload.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/node-host/invoke-payload.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/node-host/invoke-payload.test.ts
-
curl -L -o invoke-payload.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/node-host/invoke-payload.test.ts
1.96 kB
| import { describe, expect, it } from "vitest"; | |
| import { coerceNodeInvokeInputPayload, coerceNodeInvokePayload } from "./invoke-payload.js"; | |
| describe("coerceNodeInvokePayload", () => { | |
| it.each([ | |
| ["preserves the exact owning session", "agent:main:managed", "agent:main:managed"], | |
| ["normalizes the owning session", " agent:main:managed ", "agent:main:managed"], | |
| ["omits an absent owning session", undefined, undefined], | |
| ["omits a blank owning session", " ", undefined], | |
| ["omits a non-string owning session", 42, undefined], | |
| ])("%s", (_name, sessionKey, expectedSessionKey) => { | |
| expect( | |
| coerceNodeInvokePayload({ | |
| id: "invoke-1", | |
| nodeId: "node-1", | |
| command: "plugin.workspace", | |
| sessionKey, | |
| }), | |
| ).toEqual({ | |
| id: "invoke-1", | |
| nodeId: "node-1", | |
| command: "plugin.workspace", | |
| paramsJSON: null, | |
| timeoutMs: null, | |
| idempotencyKey: null, | |
| ...(expectedSessionKey ? { sessionKey: expectedSessionKey } : {}), | |
| }); | |
| }); | |
| }); | |
| describe("coerceNodeInvokeInputPayload", () => { | |
| it("accepts a bounded well-formed input payload", () => { | |
| expect( | |
| coerceNodeInvokeInputPayload({ | |
| id: "invoke-1", | |
| nodeId: "node-1", | |
| seq: 0, | |
| payloadJSON: JSON.stringify({ kind: "data", data: "keys" }), | |
| }), | |
| ).toEqual({ | |
| invokeId: "invoke-1", | |
| nodeId: "node-1", | |
| seq: 0, | |
| payloadJSON: JSON.stringify({ kind: "data", data: "keys" }), | |
| }); | |
| }); | |
| it.each([ | |
| [ | |
| "oversized payloadJSON", | |
| { id: "i", nodeId: "n", seq: 0, payloadJSON: "x".repeat(16 * 1024 + 1) }, | |
| ], | |
| ["negative seq", { id: "i", nodeId: "n", seq: -1, payloadJSON: "{}" }], | |
| ["fractional seq", { id: "i", nodeId: "n", seq: 0.5, payloadJSON: "{}" }], | |
| ["array frame", []], | |
| ["string frame", "input"], | |
| ])("rejects %s", (_name, payload) => { | |
| expect(coerceNodeInvokeInputPayload(payload)).toBeNull(); | |
| }); | |
| }); | |