feat(browser): auto-commit con 3 cambios

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-26 23:30:35 +02:00
parent d7387d9d2c
commit 2ff111bae4
3 changed files with 74 additions and 34 deletions
@@ -7,9 +7,10 @@ modulo `browser.whatsapp_send_image` (donde quedan ligados los nombres por el
`from browser.X import Y`), de modo que NO hace falta Chrome.
El fake de cdp_eval distingue cada expresion por un marcador de comentario JS embebido en
ella (`/*ADJUNTAR*/`, `/*PREVIEW*/`, `/*SEND*/`, `/*LABEL*/`). El estado `after_send` (que
/*SEND*/ activa) hace que /*PREVIEW*/ devuelva 0 adjuntos tras el envio de la imagen,
simulando el cierre de la bandeja.
ella (`/*ADJUNTAR*/`, `/*ADJEXP*/`, `/*PREVIEW*/`, `/*SEND*/`, `/*LASTIMG*/`, `/*LABEL*/`).
El estado simula el ciclo real: el menu Adjuntar arranca cerrado y se abre tras un click;
tras pulsar enviar (/*SEND*/) la bandeja se vacia (/*PREVIEW*/ -> 0) y la ultima fila pasa a
ser una imagen (/*LASTIMG*/ -> True).
"""
import json
@@ -41,11 +42,17 @@ def _make_eval(label="Escribir un mensaje para el grupo NOTAS WASAP", state=None
def fake(expr, *, port=9222, target_url_substr=""):
if "/*ADJUNTAR*/" in expr:
return {"ok": True, "value": json.dumps({"x": 575, "y": 589}), "error": ""}
if "/*ADJEXP*/" in expr:
n = state.get("adjexp_n", 0)
state["adjexp_n"] = n + 1
return {"ok": True, "value": ("false" if n == 0 else "true"), "error": ""}
if "/*SEND*/" in expr:
state["after_send"] = True
return {"ok": True, "value": json.dumps({"x": 1136, "y": 578}), "error": ""}
if "/*PREVIEW*/" in expr:
return {"ok": True, "value": 0 if state.get("after_send") else 1, "error": ""}
if "/*LASTIMG*/" in expr:
return {"ok": True, "value": bool(state.get("after_send")), "error": ""}
if "/*LABEL*/" in expr:
return {"ok": True, "value": label, "error": ""}
return {"ok": True, "value": None, "error": ""}
@@ -83,10 +90,11 @@ def test_golden_envia_imagen_y_caption_de_seguimiento(monkeypatch):
assert res["image"] == _IMG
assert res["caption"] == cap
assert res["error"] == ""
# Se adjunto la imagen (ruta absoluta) por setFileInputFiles.
assert set_spy.calls[0][0][0] == 'input[type="file"][multiple]'
# Se adjunto la imagen (ruta absoluta) por setFileInputFiles, una sola vez.
assert len(set_spy.calls) == 1
assert set_spy.calls[0][0][0] == 'input[type="file"]'
assert set_spy.calls[0][0][1] == _IMG
# Dos clicks reales: Adjuntar y Enviar (bandeja).
# Dos clicks reales: abrir Adjuntar (menu cerrado al inicio) y Enviar.
assert len(click_spy.calls) == 2
# El caption viaja como mensaje de texto de seguimiento, open_first=False.
assert len(sendmsg_spy.calls) == 1
@@ -107,7 +115,7 @@ def test_envia_sin_caption_no_manda_texto(monkeypatch):
assert res["caption_sent"] is False
# Sin caption: NO se manda mensaje de texto de seguimiento.
assert len(sendmsg_spy.calls) == 0
assert len(click_spy.calls) == 2
assert len(set_spy.calls) == 1
def test_edge_imagen_no_existe_error_sin_abrir(monkeypatch):
@@ -167,7 +175,7 @@ def test_error_set_file_input_falla_no_envia(monkeypatch):
assert res["sent"] is False
assert "no se pudo adjuntar" in res["error"]
# Se intento adjuntar (dos selectores) pero no se llego a enviar (solo el click de Adjuntar).
assert len(set_spy.calls) == 2
# Se abrio Adjuntar (1 click) e intento adjuntar (1 set), pero NO se envio nada.
assert len(set_spy.calls) == 1
assert len(click_spy.calls) == 1
assert len(sendmsg_spy.calls) == 0