diff --git a/servicios/nexxa/organismo/VERSION b/servicios/nexxa/organismo/VERSION index 88c5fb89..347f5833 100644 --- a/servicios/nexxa/organismo/VERSION +++ b/servicios/nexxa/organismo/VERSION @@ -1 +1 @@ -1.4.0 +1.4.1 diff --git a/servicios/nexxa/organismo/server.rb b/servicios/nexxa/organismo/server.rb index 83b4e555..73fa156f 100644 --- a/servicios/nexxa/organismo/server.rb +++ b/servicios/nexxa/organismo/server.rb @@ -137,10 +137,20 @@ LOGIN_FILE = File.expand_path('login.html', WEB_DIR).freeze # GET / — sirve login.html o index.html según la sesión (P201/Fase4). Se lee # del disco en cada request (mismo criterio que docs_web/server.rb, P164). +# +# Cache busting (P335, 2026-10-04): los .js/.css los sirve un FileHandler estático y el navegador se quedaba con el +# app.js viejo tras un deploy (el Operador veía el menú Pools nuevo pero la sección vacía). Al servir el HTML se le +# agrega ?v= a cada /js/ y /css/: cada versión nueva obliga a bajar los archivos nuevos. El HTML en sí no se +# cachea (no-cache), así siempre trae la versión vigente. +def html_con_version(ruta) + File.read(ruta).gsub(%r{(["'])(/(?:js|css)/[^"'?]+\.(?:js|css))\1}) { "#{$1}#{$2}?v=#{version_actual}#{$1}" } +end + server.mount_proc '/' do |req, res| res.status = 200 res.content_type = 'text/html; charset=utf-8' - res.body = File.read(operador_autenticado?(req) ? NEXXA_APP_FILE : LOGIN_FILE) + res['Cache-Control'] = 'no-cache' + res.body = html_con_version(operador_autenticado?(req) ? NEXXA_APP_FILE : LOGIN_FILE) end # Estáticos (css/js) — públicos a propósito: login.html los necesita antes de diff --git a/servicios/nexxa/test/humo_http_test.rb b/servicios/nexxa/test/humo_http_test.rb index 041eca39..b5dac16b 100644 --- a/servicios/nexxa/test/humo_http_test.rb +++ b/servicios/nexxa/test/humo_http_test.rb @@ -13,6 +13,7 @@ PRUEBA = ServidorPrueba.armar(individuos: %w[gemma-humo liberar-humo]) PUERTO = PRUEBA[:puerto] TOKEN_IND = PRUEBA[:tokens]['gemma-humo'] TOKEN_LIB = PRUEBA[:tokens]['liberar-humo'] # individuo propio del test de liberar: no comparte estado +BASE_NEXXA_ORG = File.join(ServidorPrueba::BASE, 'organismo') PID = ServidorPrueba.arrancar(PRUEBA) Minitest.after_run { ServidorPrueba.detener(PID, PRUEBA) } @@ -124,6 +125,20 @@ class HumoHttpTest < Minitest::Test assert_nil pedir('get', '/pools', sesion: SES_OPER)[1].dig('individuos', 'revocar-humo') end + # Cache busting: el HTML referencia js/css con ?v= y no se cachea (P335: app.js viejo dejaba Pools vacío) + def test_html_trae_estaticos_con_version_y_no_se_cachea + version = File.read(File.join(BASE_NEXXA_ORG, 'VERSION')).strip + r = Net::HTTP.start('127.0.0.1', PUERTO) { |h| h.get('/') } # sin sesión: login.html + assert_includes r.body, "/css/estilos.css?v=#{version}" + assert_includes r.body, "/js/login.js?v=#{version}" + assert_equal 'no-cache', r['Cache-Control'] + req = Net::HTTP::Get.new('/') + req['Cookie'] = "nexxa_session=#{SES_OPER}" + r = Net::HTTP.start('127.0.0.1', PUERTO) { |h| h.request(req) } # con sesión: index.html + assert_includes r.body, "/js/app.js?v=#{version}" + assert_equal 200, Net::HTTP.start('127.0.0.1', PUERTO) { |h| h.get("/js/app.js?v=#{version}") }.code.to_i + end + def test_sin_token_ni_sesion assert_equal 401, pedir('get', '/disponible/mente')[0] assert_equal 401, pedir('get', '/pools')[0]