452932b291
Moved RPC dialog request lifecycle into a reusable helper that emits a cancel frame targeting the original request before settling an aborted local promise. Added coverage for remote confirmation cancellation and pending-request cleanup.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from "bun:test";
|
|
import { type PendingExtensionRequest, requestRpcDialog } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-mode";
|
|
|
|
describe("RPC extension UI", () => {
|
|
it("cancels the remote dialog when its signal aborts", async () => {
|
|
const pendingRequests = new Map<string, PendingExtensionRequest>();
|
|
const output = vi.fn<(frame: object) => void>();
|
|
const controller = new AbortController();
|
|
const result = requestRpcDialog(
|
|
pendingRequests,
|
|
output,
|
|
{ signal: controller.signal },
|
|
false,
|
|
{ method: "confirm", title: "High-risk command", message: "Allow this command?" },
|
|
response => ("confirmed" in response ? response.confirmed : false),
|
|
);
|
|
const request = output.mock.calls[0]?.[0];
|
|
if (!request || !("id" in request) || typeof request.id !== "string") {
|
|
throw new Error("Expected the RPC dialog request to carry an id");
|
|
}
|
|
|
|
controller.abort();
|
|
|
|
expect(await result).toBe(false);
|
|
expect(output).toHaveBeenNthCalledWith(1, {
|
|
type: "extension_ui_request",
|
|
id: request.id,
|
|
method: "confirm",
|
|
title: "High-risk command",
|
|
message: "Allow this command?",
|
|
});
|
|
expect(output).toHaveBeenNthCalledWith(2, {
|
|
type: "extension_ui_request",
|
|
id: expect.any(String),
|
|
method: "cancel",
|
|
targetId: request.id,
|
|
});
|
|
expect(pendingRequests.size).toBe(0);
|
|
});
|
|
});
|