mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:50:43 +00:00
test(telegram): dedupe exec approval resolver cases
This commit is contained in:
@@ -10,6 +10,38 @@ vi.mock("openclaw/plugin-sdk/approval-gateway-runtime", () => ({
|
||||
}));
|
||||
|
||||
describe("resolveTelegramExecApproval", () => {
|
||||
async function invokeResolver(params: {
|
||||
approvalId: string;
|
||||
decision: string;
|
||||
senderId: string;
|
||||
allowPluginFallback?: boolean;
|
||||
}) {
|
||||
const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js");
|
||||
|
||||
await resolveTelegramExecApproval({
|
||||
cfg: {} as never,
|
||||
gatewayUrl: undefined,
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
function expectApprovalGatewayCall(params: {
|
||||
approvalId: string;
|
||||
decision: string;
|
||||
senderId: string;
|
||||
allowPluginFallback?: boolean;
|
||||
}) {
|
||||
expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({
|
||||
cfg: {} as never,
|
||||
approvalId: params.approvalId,
|
||||
decision: params.decision,
|
||||
senderId: params.senderId,
|
||||
gatewayUrl: undefined,
|
||||
allowPluginFallback: params.allowPluginFallback,
|
||||
clientDisplayName: `Telegram approval (${params.senderId})`,
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy
|
||||
.mockReset()
|
||||
@@ -17,88 +49,49 @@ describe("resolveTelegramExecApproval", () => {
|
||||
});
|
||||
|
||||
it("routes plugin approval ids through plugin.approval.resolve", async () => {
|
||||
const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js");
|
||||
|
||||
await resolveTelegramExecApproval({
|
||||
cfg: {} as never,
|
||||
await invokeResolver({
|
||||
approvalId: "plugin:abc123",
|
||||
decision: "allow-once",
|
||||
senderId: "9",
|
||||
});
|
||||
|
||||
expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({
|
||||
cfg: {} as never,
|
||||
expectApprovalGatewayCall({
|
||||
approvalId: "plugin:abc123",
|
||||
decision: "allow-once",
|
||||
senderId: "9",
|
||||
gatewayUrl: undefined,
|
||||
allowPluginFallback: undefined,
|
||||
clientDisplayName: "Telegram approval (9)",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to plugin.approval.resolve when exec approval ids are unknown", async () => {
|
||||
const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js");
|
||||
|
||||
await resolveTelegramExecApproval({
|
||||
cfg: {} as never,
|
||||
it.each([
|
||||
"falls back to plugin.approval.resolve when exec approval ids are unknown",
|
||||
"falls back to plugin.approval.resolve for structured approval-not-found errors",
|
||||
])("%s", async () => {
|
||||
await invokeResolver({
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
allowPluginFallback: true,
|
||||
});
|
||||
|
||||
expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({
|
||||
cfg: {} as never,
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
gatewayUrl: undefined,
|
||||
allowPluginFallback: true,
|
||||
clientDisplayName: "Telegram approval (9)",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to plugin.approval.resolve for structured approval-not-found errors", async () => {
|
||||
const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js");
|
||||
|
||||
await resolveTelegramExecApproval({
|
||||
cfg: {} as never,
|
||||
expectApprovalGatewayCall({
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
allowPluginFallback: true,
|
||||
});
|
||||
|
||||
expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({
|
||||
cfg: {} as never,
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
gatewayUrl: undefined,
|
||||
allowPluginFallback: true,
|
||||
clientDisplayName: "Telegram approval (9)",
|
||||
});
|
||||
});
|
||||
|
||||
it("passes fallback disablement through unchanged", async () => {
|
||||
const { resolveTelegramExecApproval } = await import("./exec-approval-resolver.js");
|
||||
|
||||
await resolveTelegramExecApproval({
|
||||
cfg: {} as never,
|
||||
await invokeResolver({
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
});
|
||||
|
||||
expect(approvalGatewayRuntimeHoisted.resolveApprovalOverGatewaySpy).toHaveBeenCalledWith({
|
||||
cfg: {} as never,
|
||||
expectApprovalGatewayCall({
|
||||
approvalId: "legacy-plugin-123",
|
||||
decision: "allow-always",
|
||||
senderId: "9",
|
||||
gatewayUrl: undefined,
|
||||
allowPluginFallback: undefined,
|
||||
clientDisplayName: "Telegram approval (9)",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user