mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-24 03:15:46 -06:00
test: tolerate stale mcp pairing approvals
(cherry picked from commitc3b3101890) (cherry picked from commitb73232a594)
This commit is contained in:
@@ -307,6 +307,13 @@ export async function maybeApprovePendingBridgePairing(
|
||||
if (!pendingRequest?.requestId) {
|
||||
return false;
|
||||
}
|
||||
await gateway.request("device.pair.approve", { requestId: pendingRequest.requestId });
|
||||
try {
|
||||
await gateway.request("device.pair.approve", { requestId: pendingRequest.requestId });
|
||||
} catch (error) {
|
||||
if (formatErrorMessage(error).includes("unknown requestId")) {
|
||||
return false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,24 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, statSync } from "node:fs
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
maybeApprovePendingBridgePairing,
|
||||
type GatewayRpcClient,
|
||||
} from "../../scripts/e2e/mcp-channels-harness.ts";
|
||||
import {
|
||||
connectMcpClientWithPairingReconnect,
|
||||
createMcpClientTempState,
|
||||
type McpClientTempState,
|
||||
} from "../../scripts/e2e/mcp-client-temp-state.js";
|
||||
|
||||
function createGateway(request: GatewayRpcClient["request"]): GatewayRpcClient {
|
||||
return {
|
||||
request,
|
||||
events: [],
|
||||
close: async () => {},
|
||||
};
|
||||
}
|
||||
|
||||
describe("mcp-channels harness", () => {
|
||||
it("creates unique client temp state and removes token files on cleanup", () => {
|
||||
const tempRoot = mkdtempSync(path.join(tmpdir(), "openclaw-mcp-harness-test-"));
|
||||
@@ -97,4 +109,23 @@ describe("mcp-channels harness", () => {
|
||||
tempState.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("treats stale pairing request approvals as already handled", async () => {
|
||||
const request = vi.fn<GatewayRpcClient["request"]>(async (method) => {
|
||||
if (method === "device.pair.list") {
|
||||
return {
|
||||
pending: [{ requestId: "stale-request", role: "operator" }],
|
||||
};
|
||||
}
|
||||
if (method === "device.pair.approve") {
|
||||
throw new Error("unknown requestId");
|
||||
}
|
||||
throw new Error(`unexpected method: ${method}`);
|
||||
});
|
||||
|
||||
await expect(maybeApprovePendingBridgePairing(createGateway(request))).resolves.toBe(false);
|
||||
expect(request).toHaveBeenCalledWith("device.pair.approve", {
|
||||
requestId: "stale-request",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user