Download patch-pi-rpc.test.mjs from Mike0021/chat-ui-agent-runtime: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-runtime/resolve/main/patch-pi-rpc.test.mjs
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-runtime/patch-pi-rpc.test.mjs
-
curl -L -o patch-pi-rpc.test.mjs https://huggingface.co/spaces/Mike0021/chat-ui-agent-runtime/resolve/main/patch-pi-rpc.test.mjs
1.95 kB
| import assert from "node:assert/strict"; | |
| import test from "node:test"; | |
| import { patchPiRpcSource } from "./patch-pi-rpc.mjs"; | |
| const fixture = `async function handle(command) { | |
| const id = command.id; | |
| switch (command.type) { | |
| case "follow_up": { | |
| await session.followUp(command.message, command.images); | |
| return success(id, "follow_up"); | |
| } | |
| case "abort": { | |
| await session.abort(); | |
| } | |
| } | |
| } | |
| async function handleInputLine(parsed) { | |
| // Handle extension UI responses | |
| if (typeof parsed === "object" && | |
| parsed !== null && | |
| "type" in parsed && | |
| parsed.type === "extension_ui_response") { | |
| const response = parsed; | |
| const pending = pendingExtensionRequests.get(response.id); | |
| if (pending) { | |
| pendingExtensionRequests.delete(response.id); | |
| pending.resolve(response); | |
| } | |
| return; | |
| } | |
| }`; | |
| test("adds queue CAS and correlated semantic extension responses to pinned Pi RPC", () => { | |
| const patched = patchPiRpcSource(fixture); | |
| assert.match(patched, /case "replace_queue"/); | |
| assert.match(patched, /session\.getSteeringMessages\(\)/); | |
| assert.match(patched, /Pending queue changed; refresh and try again/); | |
| assert.match(patched, /session\.clearQueue\(\)/); | |
| assert.ok(patched.indexOf("session.clearQueue()") < patched.indexOf("session._queueSteer")); | |
| assert.match(patched, /const requestId = response\.requestId \?\? response\.id/); | |
| assert.match(patched, /Extension UI request is no longer pending/); | |
| assert.match(patched, /output\(success\(correlationId, "extension_ui_response"\)\)/); | |
| assert.equal(patchPiRpcSource(patched), patched); | |
| }); | |
| test("fails closed when the pinned upstream handler changes", () => { | |
| assert.throws(() => patchPiRpcSource("export const changed = true;"), /Expected one pinned Pi/); | |
| }); | |