Skip to content

Commit ee0b2da

Browse files
committed
fix(test): narrow Canvas node invocation frames
1 parent f85ea4f commit ee0b2da

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

‎test/e2e/qa-lab/plugins/canvas-agent-node.e2e.test.ts‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ const CANVAS_NODE_COMMANDS = [
5757
] as const;
5858

5959
type NodeInvokeFrame = {
60-
id?: unknown;
61-
nodeId?: unknown;
62-
command?: unknown;
63-
paramsJSON?: unknown;
64-
timeoutMs?: unknown;
65-
idempotencyKey?: unknown;
60+
id: string;
61+
nodeId: string;
62+
command: string;
63+
paramsJSON: string | null;
64+
timeoutMs: number;
65+
idempotencyKey: string;
6666
};
6767

6868
type CapturedInvocation = {
@@ -337,13 +337,13 @@ describe("Canvas agent tool over a paired Linux node", () => {
337337
expect(invocation.timeoutMs).toBeGreaterThan(0);
338338
expect(invocation.timeoutMs).toBeLessThanOrEqual(actions[index]?.args.timeoutMs ?? 0);
339339
}
340-
expect(invocations.map((invocation) => invocation.idempotencyKey)).toEqual(
341-
invocations.map((invocation) =>
342-
expect.stringMatching(
343-
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u,
340+
expect(
341+
invocations.every((invocation) =>
342+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u.test(
343+
invocation.idempotencyKey,
344344
),
345345
),
346-
);
346+
).toBe(true);
347347
expect(new Set(invocations.map((invocation) => invocation.idempotencyKey)).size).toBe(
348348
actions.length,
349349
);
@@ -400,7 +400,7 @@ async function respondToCanvasInvocation(params: {
400400
frame: unknown;
401401
invocations: CapturedInvocation[];
402402
}): Promise<void> {
403-
const frame = params.frame as NodeInvokeFrame;
403+
const frame = params.frame as Partial<NodeInvokeFrame>;
404404
const invalidFields = [
405405
!params.client ? "client" : "",
406406
typeof frame.id !== "string" ? "id" : "",
@@ -415,6 +415,18 @@ async function respondToCanvasInvocation(params: {
415415
`Gateway sent invalid Canvas node fields: ${invalidFields.join(", ")}; payload=${JSON.stringify(frame)}`,
416416
);
417417
}
418+
const client = params.client;
419+
if (
420+
!client ||
421+
typeof frame.id !== "string" ||
422+
frame.nodeId !== params.expectedNodeId ||
423+
typeof frame.command !== "string" ||
424+
typeof frame.timeoutMs !== "number" ||
425+
typeof frame.idempotencyKey !== "string" ||
426+
!(frame.paramsJSON === null || typeof frame.paramsJSON === "string")
427+
) {
428+
throw new Error(`invalid Canvas node invocation: ${JSON.stringify(frame)}`);
429+
}
418430
const invocation: CapturedInvocation = {
419431
nodeId: frame.nodeId,
420432
command: frame.command,
@@ -436,7 +448,7 @@ async function respondToCanvasInvocation(params: {
436448
if (!Object.hasOwn(responseByCommand, frame.command)) {
437449
throw new Error(`unexpected Canvas node command: ${frame.command}`);
438450
}
439-
await params.client.request("node.invoke.result", {
451+
await client.request("node.invoke.result", {
440452
id: frame.id,
441453
nodeId: frame.nodeId,
442454
ok: true,

0 commit comments

Comments
 (0)