#!/usr/bin/env bash # Beyond test suite, on a throwaway database. # # WHY A CLEAN DATABASE. beyond_dev accumulates state that has nothing to do # with the code: uninstalled modules, leftover demo companies, taxes edited by # hand. Six tests failed there for reasons none of us caused, and a baseline # that is not zero stops being a signal — nobody reads "6 failed" twice. # The suite now runs against a database created from scratch on every run, so # a failure means the code, always. # # beyond_dev is for looking at screens; this is for knowing whether it works. # # The database is dropped at the end, including when a test fails. Keep it for # a post mortem with: ./scripts/pruebas.sh --conservar # # Uso: # ./scripts/pruebas.sh # los seis módulos # ./scripts/pruebas.sh beyond_base # solo uno (y sus dependencias) # ./scripts/pruebas.sh --conservar # no borra la base al terminar set -euo pipefail DB="${BEYOND_TEST_DB:-beyond_test}" MODULOS="beyond_base,beyond_branch,beyond_customer,beyond_product_capture,beyond_attendance_qr,beyond_pos_theme" CONSERVAR=0 for arg in "$@"; do case "$arg" in --conservar) CONSERVAR=1 ;; --*) echo "Opción desconocida: $arg" >&2; exit 2 ;; *) MODULOS="$arg" ;; esac done # Ports of their own: the dev server holds 8069 and the HttpCase tests need to # bind something. Without this the whole run dies with "Address already in use" # before a single test starts. PUERTO="${BEYOND_TEST_PORT:-8169}" PUERTO_GEVENT="${BEYOND_TEST_GEVENT_PORT:-8172}" limpiar() { if [ "$CONSERVAR" -eq 1 ]; then echo "[*] La base $DB se conserva (--conservar)." return fi echo "[*] Borrando la base de pruebas $DB..." # --force: Odoo leaves its connection pool open for a moment after # --stop-after-init and plain dropdb refuses while anyone is attached. docker compose exec -T db dropdb -U odoo --if-exists --force "$DB" || true } trap limpiar EXIT echo "[*] Creando la base de pruebas $DB desde cero..." docker compose exec -T db dropdb -U odoo --if-exists --force "$DB" docker compose exec -T db createdb -U odoo -O odoo "$DB" # Only OUR tests. --test-enable alone runs every installed module's suite, # which here means ~3700 core tests, many of them browser tours that cannot # pass without chromium in the container. Their noise is exactly what this # script exists to remove. ETIQUETAS="$(echo "$MODULOS" | tr ',' '\n' | sed 's|^|/|' | paste -sd, -)" echo "[*] Instalando $MODULOS con datos demo y corriendo su suite..." # -i and not -u: the point is a fresh install. # # --with-demo is REQUIRED, not decoration: in Odoo 19 demo data is off by # default for new databases ("--without-demo ... (default)"), and beyond_dev # only has it because it was created through the database manager with the box # ticked. Without this flag there are no demo branches and the tests that look # one up fail on an empty search. The demo data is also part of what has to # keep working (CLAUDE.md, "demostrarlo en 2 minutos"). docker compose exec -T odoo odoo \ -d "$DB" -i "$MODULOS" --with-demo \ --test-enable --test-tags="$ETIQUETAS" --stop-after-init \ --http-port="$PUERTO" --gevent-port="$PUERTO_GEVENT" \ 2>&1 | tee /tmp/beyond_pruebas.log | grep -E \ "(FAIL|ERROR): Test|Traceback|tests\.stats|failed, .* error|Modules loaded" || true # ── Fallos esperados ────────────────────────────────────────────────────── # Known-failing tests, with the ticket that owns each one. They are NOT # silenced: they are counted and listed on every run, so the baseline stays # honest and a NEW failure stands out immediately. A test that stops failing # is also reported, so this list does not rot. # # ADR-014 (docs/adr/ADR-014-impuesto-propio.md): a clean install has no 16% # tax at all, because l10n_mx only auto-installs when a company's country is # Mexico and ours is set to the United States. The guarantee of ADR-010 —the # displayed price is the total to pay— has nothing to stand on. These five # tests are right and the product is wrong; they stay red until ADR-014 is # decided. ESPERADOS="TestBeyondIvaIncluido.test_el_iva_de_venta_esta_incluido_en_el_precio TestBeyondIvaIncluido.test_la_aritmetica_es_de_extraccion_no_de_suma TestBeyondIvaIncluido.test_repara_una_base_donde_el_iva_se_suma TestBeyondIvaConCajaAbierta.test_al_cerrar_la_caja_entra_solo TestBeyondIvaConCajaAbierta.test_con_una_venta_viva_se_difiere_en_vez_de_reventar" REALES="$(grep -oE '(FAIL|ERROR): [A-Za-z0-9_]+\.[A-Za-z0-9_]+' /tmp/beyond_pruebas.log \ | sed -E 's/^(FAIL|ERROR): //' | sort -u)" ESPERADOS_ORD="$(echo "$ESPERADOS" | sort -u)" INESPERADOS="$(comm -23 <(echo "$REALES") <(echo "$ESPERADOS_ORD") | sed '/^$/d')" ARREGLADOS="$(comm -13 <(echo "$REALES") <(echo "$ESPERADOS_ORD") | sed '/^$/d')" echo if [ -n "$ARREGLADOS" ]; then echo "[!] Estos tests estaban en la lista de esperados y ya PASAN." echo " Quítalos de ESPERADOS en este script:" echo "$ARREGLADOS" | sed 's/^/ /' echo fi ESPERADOS_VIVOS="$(comm -12 <(echo "$REALES") <(echo "$ESPERADOS_ORD") | sed '/^$/d')" if [ -n "$ESPERADOS_VIVOS" ]; then echo "[i] Fallos esperados (ADR-014, siguen rojos a propósito): $(echo "$ESPERADOS_VIVOS" | wc -l | tr -d ' ')" echo "$ESPERADOS_VIVOS" | sed 's/^/ /' echo fi if [ -n "$INESPERADOS" ]; then echo "[X] Fallos NUEVOS, no esperados:" echo "$INESPERADOS" | sed 's/^/ /' echo " Registro completo: /tmp/beyond_pruebas.log" exit 1 fi echo "[OK] Sin fallos nuevos sobre base limpia."