|
1 | 1 | // Walks the kitchen-sink gateway RPC scenario for E2E smoke coverage. |
2 | 2 | import childProcess from "node:child_process"; |
| 3 | +import { createHash } from "node:crypto"; |
3 | 4 | import fs from "node:fs"; |
4 | 5 | import os from "node:os"; |
5 | 6 | import path from "node:path"; |
@@ -1270,6 +1271,89 @@ export function assertKitchenSinkTextInvokeResult(payload) { |
1270 | 1271 | } |
1271 | 1272 | } |
1272 | 1273 |
|
| 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 | + |
1273 | 1357 | export function assertCreatedKitchenSinkSession(payload, expectedKey = SESSION_KEY) { |
1274 | 1358 | const created = assertObjectPayload(payload, "sessions.create"); |
1275 | 1359 | if (created.ok !== true || created.key !== expectedKey || !isNonEmptyString(created.sessionId)) { |
@@ -2066,31 +2150,20 @@ export async function main() { |
2066 | 2150 | { requirePluginProvenance: true }, |
2067 | 2151 | ); |
2068 | 2152 |
|
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 | + } |
2094 | 2167 |
|
2095 | 2168 | const ttsProviders = await retryRpcCall("tts.providers", {}, rpcOptions); |
2096 | 2169 | const ttsStatus = await retryRpcCall("tts.status", {}, rpcOptions); |
|
0 commit comments