File size: 1,948 Bytes
ece5049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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/);
});