import { test, expect, handleElementDialogs } from "../fixtures/persistent-context"; import { goToRoom, sendMessage, waitForBotReply, assertNoDecryptionErrors, startThreadOnLastMessage, sendThreadMessage, waitForThreadReply, } from "../fixtures/matrix-room"; test.describe("asistente-2", () => { test.beforeEach(async ({ page }) => { await page.goto("/"); await handleElementDialogs(page); await goToRoom(page, "Asistente 2"); }); test("responde a un saludo", async ({ page }) => { await sendMessage(page, "Hola, que tal?"); const reply = await waitForBotReply(page, { timeout: 60_000, sender: "Asistente 2", }); expect(reply).toBeTruthy(); expect(reply.length).toBeGreaterThan(10); }); test("!tools muestra herramientas disponibles", async ({ page }) => { await sendMessage(page, "!tools"); const reply = await waitForBotReply(page, { timeout: 10_000, sender: "Asistente 2", }); expect(reply).toBeTruthy(); // asistente-2 tiene al menos current_time expect(reply.toLowerCase()).toMatch(/current_time|hora|herramienta|tool/); }); test("pregunta que activa tool use (que hora es?)", async ({ page }) => { await sendMessage(page, "Que hora es ahora mismo?"); const reply = await waitForBotReply(page, { timeout: 60_000, sender: "Asistente 2", }); expect(reply).toBeTruthy(); // La respuesta debe contener algo relacionado con tiempo/hora expect(reply.length).toBeGreaterThan(5); }); test("!help muestra comandos", async ({ page }) => { await sendMessage(page, "!help"); const reply = await waitForBotReply(page, { timeout: 10_000, sender: "Asistente 2", }); expect(reply).toBeTruthy(); expect(reply.toLowerCase()).toContain("help"); expect(reply.toLowerCase()).toContain("ping"); }); test("responde dentro del thread cuando se le habla por thread", async ({ page, }) => { // 1. Enviar un mensaje normal (sera el thread root) await sendMessage(page, "Mensaje para iniciar thread"); // Esperar a que el bot responda al mensaje original await waitForBotReply(page, { timeout: 60_000, sender: "Asistente 2", }); // 2. Iniciar thread sobre el mensaje del usuario await startThreadOnLastMessage(page); // 3. Enviar mensaje dentro del thread await sendThreadMessage( page, "Hola desde el thread, respondeme aqui por favor" ); // 4. Esperar que el bot responda DENTRO del thread const threadReply = await waitForThreadReply(page, { timeout: 60_000, sender: "Asistente 2", }); expect(threadReply).toBeTruthy(); expect(threadReply.length).toBeGreaterThan(5); }); test("no hay errores de E2EE en el timeline", async ({ page }) => { await assertNoDecryptionErrors(page); }); });