|
1 | 1 | // Telegram tests cover bot native commands.session meta plugin behavior. |
| 2 | +import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound"; |
2 | 3 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
3 | 4 | import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime"; |
4 | 5 | import { resolveChunkMode } from "openclaw/plugin-sdk/reply-dispatch-runtime"; |
@@ -1445,6 +1446,161 @@ describe("registerTelegramNativeCommands — session metadata", () => { |
1445 | 1446 | ); |
1446 | 1447 | }); |
1447 | 1448 |
|
| 1449 | + it("emits the fallback when a non-final suppression precedes a final failure", async () => { |
| 1450 | + dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
| 1451 | + await plan.delivery.onDelivered?.( |
| 1452 | + { text: "cancelled tool reply" }, |
| 1453 | + { kind: "tool" }, |
| 1454 | + { |
| 1455 | + visibleReplySent: false, |
| 1456 | + suppression: { reason: "cancelled_by_reply_payload_sending_hook" }, |
| 1457 | + }, |
| 1458 | + ); |
| 1459 | + plan.delivery.onError?.(new Error("Telegram final delivery failed"), { |
| 1460 | + kind: "final", |
| 1461 | + }); |
| 1462 | + return { |
| 1463 | + admission: { kind: "dispatch" }, |
| 1464 | + dispatched: true, |
| 1465 | + ctxPayload: plan.ctxPayload, |
| 1466 | + routeSessionKey: plan.route.sessionKey, |
| 1467 | + dispatchResult: { |
| 1468 | + queuedFinal: false, |
| 1469 | + counts: { block: 0, final: 0, tool: 0 }, |
| 1470 | + }, |
| 1471 | + }; |
| 1472 | + }); |
| 1473 | + const { handler } = registerAndResolveStatusHandler({ cfg: {} }); |
| 1474 | + |
| 1475 | + await handler(createTelegramPrivateCommandContext()); |
| 1476 | + |
| 1477 | + expect(deliveryMocks.deliverReplies).toHaveBeenCalledOnce(); |
| 1478 | + expect(deliveryMocks.deliverReplies).toHaveBeenCalledWith( |
| 1479 | + expect.objectContaining({ |
| 1480 | + replies: [{ text: "No response generated. Please try again." }], |
| 1481 | + }), |
| 1482 | + ); |
| 1483 | + }); |
| 1484 | + |
| 1485 | + it("emits the fallback when a suppressed block reply precedes a final failure", async () => { |
| 1486 | + dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
| 1487 | + await plan.delivery.onDelivered?.( |
| 1488 | + { text: "cancelled block reply" }, |
| 1489 | + { kind: "block" }, |
| 1490 | + { |
| 1491 | + visibleReplySent: false, |
| 1492 | + suppression: { reason: "empty_after_reply_payload_sending_hook" }, |
| 1493 | + }, |
| 1494 | + ); |
| 1495 | + plan.delivery.onError?.(new Error("Telegram final delivery failed"), { |
| 1496 | + kind: "final", |
| 1497 | + }); |
| 1498 | + return { |
| 1499 | + admission: { kind: "dispatch" }, |
| 1500 | + dispatched: true, |
| 1501 | + ctxPayload: plan.ctxPayload, |
| 1502 | + routeSessionKey: plan.route.sessionKey, |
| 1503 | + dispatchResult: { |
| 1504 | + queuedFinal: false, |
| 1505 | + counts: { block: 0, final: 0, tool: 0 }, |
| 1506 | + }, |
| 1507 | + }; |
| 1508 | + }); |
| 1509 | + const { handler } = registerAndResolveStatusHandler({ cfg: {} }); |
| 1510 | + |
| 1511 | + await handler(createTelegramPrivateCommandContext()); |
| 1512 | + |
| 1513 | + expect(deliveryMocks.deliverReplies).toHaveBeenCalledOnce(); |
| 1514 | + }); |
| 1515 | + |
| 1516 | + it("emits the fallback when a final failure precedes a later suppressed final", async () => { |
| 1517 | + dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
| 1518 | + plan.delivery.onError?.(new Error("Telegram final delivery failed"), { |
| 1519 | + kind: "final", |
| 1520 | + }); |
| 1521 | + await plan.delivery.onDelivered?.( |
| 1522 | + { text: "cancelled final reply" }, |
| 1523 | + { kind: "final" }, |
| 1524 | + { |
| 1525 | + visibleReplySent: false, |
| 1526 | + suppression: { reason: "cancelled_by_reply_payload_sending_hook" }, |
| 1527 | + }, |
| 1528 | + ); |
| 1529 | + return { |
| 1530 | + admission: { kind: "dispatch" }, |
| 1531 | + dispatched: true, |
| 1532 | + ctxPayload: plan.ctxPayload, |
| 1533 | + routeSessionKey: plan.route.sessionKey, |
| 1534 | + dispatchResult: { |
| 1535 | + queuedFinal: false, |
| 1536 | + counts: { block: 0, final: 0, tool: 0 }, |
| 1537 | + }, |
| 1538 | + }; |
| 1539 | + }); |
| 1540 | + const { handler } = registerAndResolveStatusHandler({ cfg: {} }); |
| 1541 | + |
| 1542 | + await handler(createTelegramPrivateCommandContext()); |
| 1543 | + |
| 1544 | + expect(deliveryMocks.deliverReplies).toHaveBeenCalledOnce(); |
| 1545 | + }); |
| 1546 | + |
| 1547 | + it("preserves a suppressed final after a non-final delivery failure", async () => { |
| 1548 | + dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
| 1549 | + plan.delivery.onError?.(new Error("Telegram tool delivery failed"), { |
| 1550 | + kind: "tool", |
| 1551 | + }); |
| 1552 | + await plan.delivery.onDelivered?.( |
| 1553 | + { text: "cancelled final reply" }, |
| 1554 | + { kind: "final" }, |
| 1555 | + { |
| 1556 | + visibleReplySent: false, |
| 1557 | + suppression: { reason: "cancelled_by_reply_payload_sending_hook" }, |
| 1558 | + }, |
| 1559 | + ); |
| 1560 | + return { |
| 1561 | + admission: { kind: "dispatch" }, |
| 1562 | + dispatched: true, |
| 1563 | + ctxPayload: plan.ctxPayload, |
| 1564 | + routeSessionKey: plan.route.sessionKey, |
| 1565 | + dispatchResult: { |
| 1566 | + queuedFinal: false, |
| 1567 | + counts: { block: 0, final: 0, tool: 0 }, |
| 1568 | + }, |
| 1569 | + }; |
| 1570 | + }); |
| 1571 | + const { handler } = registerAndResolveStatusHandler({ cfg: {} }); |
| 1572 | + |
| 1573 | + await handler(createTelegramPrivateCommandContext()); |
| 1574 | + |
| 1575 | + expect(deliveryMocks.deliverReplies).not.toHaveBeenCalled(); |
| 1576 | + }); |
| 1577 | + |
| 1578 | + it("does not emit the fallback after a partially delivered final", async () => { |
| 1579 | + dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
| 1580 | + plan.delivery.onError?.( |
| 1581 | + createChannelPartialDeliveryError(new Error("Telegram final delivery failed"), { |
| 1582 | + visibleReplySent: true, |
| 1583 | + }), |
| 1584 | + { kind: "final" }, |
| 1585 | + ); |
| 1586 | + return { |
| 1587 | + admission: { kind: "dispatch" }, |
| 1588 | + dispatched: true, |
| 1589 | + ctxPayload: plan.ctxPayload, |
| 1590 | + routeSessionKey: plan.route.sessionKey, |
| 1591 | + dispatchResult: { |
| 1592 | + queuedFinal: false, |
| 1593 | + counts: { block: 0, final: 0, tool: 0 }, |
| 1594 | + }, |
| 1595 | + }; |
| 1596 | + }); |
| 1597 | + const { handler } = registerAndResolveStatusHandler({ cfg: {} }); |
| 1598 | + |
| 1599 | + await handler(createTelegramPrivateCommandContext()); |
| 1600 | + |
| 1601 | + expect(deliveryMocks.deliverReplies).not.toHaveBeenCalled(); |
| 1602 | + }); |
| 1603 | + |
1448 | 1604 | it("retains the empty fallback for a true non-silent metadata-only native reply", async () => { |
1449 | 1605 | dispatchChannelInboundTurnMock.mockImplementationOnce(async (plan) => { |
1450 | 1606 | plan.dispatcherOptions?.onSkip?.({}, { kind: "final", reason: "empty" }); |
|
0 commit comments