Skip to content

Commit ab33fe3

Browse files
committed
fix(e2e): invoke kitchen sink image job
1 parent 0543126 commit ab33fe3

2 files changed

Lines changed: 158 additions & 26 deletions

File tree

‎scripts/e2e/kitchen-sink-rpc-walk.mjs‎

Lines changed: 98 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Walks the kitchen-sink gateway RPC scenario for E2E smoke coverage.
22
import childProcess from "node:child_process";
3+
import { createHash } from "node:crypto";
34
import fs from "node:fs";
45
import os from "node:os";
56
import path from "node:path";
@@ -1270,6 +1271,89 @@ export function assertKitchenSinkTextInvokeResult(payload) {
12701271
}
12711272
}
12721273

1274+
export function assertKitchenSinkImageJobInvokeResult(payload) {
1275+
if (payload?.ok !== true || payload?.source !== "plugin") {
1276+
throw new Error(`Kitchen Sink image job tool invoke failed: ${boundedJsonPreview(payload)}`);
1277+
}
1278+
const output = assertObjectPayload(payload.output, "Kitchen Sink image job tool output");
1279+
const image = assertObjectPayload(output.image, "Kitchen Sink image job image");
1280+
const imageMetadata = assertObjectPayload(
1281+
image.metadata,
1282+
"Kitchen Sink image job image metadata",
1283+
);
1284+
const mediaBytes = decodePngDataUrl(output.mediaUrl);
1285+
const mediaSha256 = mediaBytes ? createHash("sha256").update(mediaBytes).digest("hex") : "";
1286+
if (
1287+
output.ok !== true ||
1288+
output.route !== "tool:kitchen_sink_image_job" ||
1289+
output.job?.status !== "completed" ||
1290+
output.job?.route !== "tool:kitchen_sink_image_job" ||
1291+
!mediaBytes ||
1292+
!hasPngSignature(mediaBytes) ||
1293+
image.mimeType !== "image/png" ||
1294+
imageMetadata.assetName !== "kitchen_sink_office.png" ||
1295+
imageMetadata.width !== 1024 ||
1296+
imageMetadata.height !== 1024 ||
1297+
typeof imageMetadata.sha256 !== "string" ||
1298+
!/^[a-f0-9]{64}$/u.test(imageMetadata.sha256) ||
1299+
mediaSha256 !== imageMetadata.sha256
1300+
) {
1301+
throw new Error(
1302+
`Kitchen Sink image job tool output missed expected fixture: ${boundedJsonPreview(output)}`,
1303+
);
1304+
}
1305+
}
1306+
1307+
function decodePngDataUrl(value) {
1308+
if (typeof value !== "string") {
1309+
return undefined;
1310+
}
1311+
const match = /^data:image\/png;base64,([A-Za-z0-9+/]+={0,2})$/u.exec(value);
1312+
if (!match || match[1].length === 0 || match[1].length % 4 !== 0) {
1313+
return undefined;
1314+
}
1315+
return Buffer.from(match[1], "base64");
1316+
}
1317+
1318+
function hasPngSignature(buffer) {
1319+
return (
1320+
buffer.length >= 8 &&
1321+
buffer[0] === 0x89 &&
1322+
buffer[1] === 0x50 &&
1323+
buffer[2] === 0x4e &&
1324+
buffer[3] === 0x47 &&
1325+
buffer[4] === 0x0d &&
1326+
buffer[5] === 0x0a &&
1327+
buffer[6] === 0x1a &&
1328+
buffer[7] === 0x0a
1329+
);
1330+
}
1331+
1332+
const KITCHEN_SINK_TOOL_INVOKES = [
1333+
{
1334+
name: "kitchen_sink_search",
1335+
args: { query: "kitchen sink rpc walk" },
1336+
idempotencyKey: "kitchen-sink-rpc-search",
1337+
assertResult: assertKitchenSinkSearchInvokeResult,
1338+
},
1339+
{
1340+
name: "kitchen_sink_text",
1341+
args: { prompt: "explain kitchen sink rpc walk" },
1342+
idempotencyKey: "kitchen-sink-rpc-text",
1343+
assertResult: assertKitchenSinkTextInvokeResult,
1344+
},
1345+
{
1346+
name: "kitchen_sink_image_job",
1347+
args: { prompt: "generate a kitchen sink rpc walk image" },
1348+
idempotencyKey: "kitchen-sink-rpc-image-job",
1349+
assertResult: assertKitchenSinkImageJobInvokeResult,
1350+
},
1351+
];
1352+
1353+
export function listKitchenSinkToolInvokeNames() {
1354+
return KITCHEN_SINK_TOOL_INVOKES.map((entry) => entry.name);
1355+
}
1356+
12731357
export function assertCreatedKitchenSinkSession(payload, expectedKey = SESSION_KEY) {
12741358
const created = assertObjectPayload(payload, "sessions.create");
12751359
if (created.ok !== true || created.key !== expectedKey || !isNonEmptyString(created.sessionId)) {
@@ -2066,31 +2150,20 @@ export async function main() {
20662150
{ requirePluginProvenance: true },
20672151
);
20682152

2069-
const searchInvoked = await retryRpcCall(
2070-
"tools.invoke",
2071-
{
2072-
name: "kitchen_sink_search",
2073-
args: { query: "kitchen sink rpc walk" },
2074-
sessionKey: createdSession.key,
2075-
agentId: "main",
2076-
idempotencyKey: "kitchen-sink-rpc-search",
2077-
},
2078-
rpcOptions,
2079-
);
2080-
assertKitchenSinkSearchInvokeResult(searchInvoked);
2081-
2082-
const textInvoked = await retryRpcCall(
2083-
"tools.invoke",
2084-
{
2085-
name: "kitchen_sink_text",
2086-
args: { prompt: "explain kitchen sink rpc walk" },
2087-
sessionKey: createdSession.key,
2088-
agentId: "main",
2089-
idempotencyKey: "kitchen-sink-rpc-text",
2090-
},
2091-
rpcOptions,
2092-
);
2093-
assertKitchenSinkTextInvokeResult(textInvoked);
2153+
for (const toolInvoke of KITCHEN_SINK_TOOL_INVOKES) {
2154+
const invoked = await retryRpcCall(
2155+
"tools.invoke",
2156+
{
2157+
name: toolInvoke.name,
2158+
args: toolInvoke.args,
2159+
sessionKey: createdSession.key,
2160+
agentId: "main",
2161+
idempotencyKey: toolInvoke.idempotencyKey,
2162+
},
2163+
rpcOptions,
2164+
);
2165+
toolInvoke.assertResult(invoked);
2166+
}
20942167

20952168
const ttsProviders = await retryRpcCall("tts.providers", {}, rpcOptions);
20962169
const ttsStatus = await retryRpcCall("tts.status", {}, rpcOptions);

‎test/scripts/kitchen-sink-rpc-walk.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Kitchen Sink Rpc Walk tests cover kitchen sink rpc walk script behavior.
2+
import { createHash } from "node:crypto";
23
import { EventEmitter } from "node:events";
34
import fs, {
45
existsSync,
@@ -21,6 +22,7 @@ import {
2122
assertExpectedKitchenSinkToolEntries,
2223
assertGatewayHealthPayload,
2324
assertGatewayStatusPayload,
25+
assertKitchenSinkImageJobInvokeResult,
2426
assertKitchenSinkUiDescriptors,
2527
assertKitchenSinkSearchInvokeResult,
2628
assertKitchenSinkTextInvokeResult,
@@ -35,6 +37,7 @@ import {
3537
findErrorLogFindings,
3638
findDistCallGatewayModuleFiles,
3739
hasChildExited,
40+
listKitchenSinkToolInvokeNames,
3841
makeEnv,
3942
readPositiveInt,
4043
readBoundedResponseText,
@@ -792,6 +795,14 @@ describe("kitchen-sink RPC command catalog assertions", () => {
792795
).toEqual(["kitchen_sink_text", "kitchen_sink_search", "kitchen_sink_image_job"]);
793796
});
794797

798+
it("invokes every advertised Kitchen Sink tool during the RPC walk", () => {
799+
expect(listKitchenSinkToolInvokeNames().toSorted()).toEqual([
800+
"kitchen_sink_image_job",
801+
"kitchen_sink_search",
802+
"kitchen_sink_text",
803+
]);
804+
});
805+
795806
it("requires provenance for effective Kitchen Sink plugin tools too", () => {
796807
expect(() =>
797808
assertExpectedKitchenSinkToolEntries(
@@ -873,7 +884,12 @@ describe("kitchen-sink RPC command catalog assertions", () => {
873884
).toThrow("did not report a configured Kitchen Sink speech provider");
874885
});
875886

876-
it("checks search and text tool invocation fixtures separately", () => {
887+
it("checks search, text, and image job tool invocation fixtures separately", () => {
888+
const pngBytes = Buffer.from(
889+
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",
890+
"base64",
891+
);
892+
const pngSha256 = createHash("sha256").update(pngBytes).digest("hex");
877893
expect(() =>
878894
assertKitchenSinkSearchInvokeResult({
879895
ok: true,
@@ -891,6 +907,27 @@ describe("kitchen-sink RPC command catalog assertions", () => {
891907
},
892908
}),
893909
).not.toThrow();
910+
expect(() =>
911+
assertKitchenSinkImageJobInvokeResult({
912+
ok: true,
913+
source: "plugin",
914+
output: {
915+
ok: true,
916+
route: "tool:kitchen_sink_image_job",
917+
job: { status: "completed", route: "tool:kitchen_sink_image_job" },
918+
mediaUrl: `data:image/png;base64,${pngBytes.toString("base64")}`,
919+
image: {
920+
mimeType: "image/png",
921+
metadata: {
922+
assetName: "kitchen_sink_office.png",
923+
height: 1024,
924+
sha256: pngSha256,
925+
width: 1024,
926+
},
927+
},
928+
},
929+
}),
930+
).not.toThrow();
894931
expect(() =>
895932
assertKitchenSinkTextInvokeResult({
896933
ok: true,
@@ -916,6 +953,28 @@ describe("kitchen-sink RPC command catalog assertions", () => {
916953
output: { text: "Kitchen Sink prompt echoed tool:kitchen_sink_text" },
917954
}),
918955
).toThrow("Kitchen Sink text tool output missed expected fixture");
956+
957+
expect(() =>
958+
assertKitchenSinkImageJobInvokeResult({
959+
ok: true,
960+
source: "plugin",
961+
output: {
962+
ok: true,
963+
route: "tool:kitchen_sink_image_job",
964+
job: { status: "completed", route: "tool:kitchen_sink_image_job" },
965+
mediaUrl: "data:image/png;base64,fixture",
966+
image: {
967+
mimeType: "image/png",
968+
metadata: {
969+
assetName: "kitchen_sink_office.png",
970+
height: 1024,
971+
sha256: "not-a-real-hash",
972+
width: 1024,
973+
},
974+
},
975+
},
976+
}),
977+
).toThrow("Kitchen Sink image job tool output missed expected fixture");
919978
});
920979

921980
it("bounds failed tool invocation diagnostics", () => {

0 commit comments

Comments
 (0)