<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Manuel Andree dongo Palza</title>
    <description>The latest articles on DEV Community by Manuel Andree dongo Palza (@manuel_dong00).</description>
    <link>https://dev.to/manuel_dong00</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4018051%2F21556e6c-d826-4ade-9843-9d34cdd5ce4f.jpg</url>
      <title>DEV Community: Manuel Andree dongo Palza</title>
      <link>https://dev.to/manuel_dong00</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manuel_dong00"/>
    <language>en</language>
    <item>
      <title>Cazar el error 500 antes de que exista: SAST con Semgrep y GitHub Actions</title>
      <dc:creator>Manuel Andree dongo Palza</dc:creator>
      <pubDate>Mon, 16 Nov 2026 15:37:04 +0000</pubDate>
      <link>https://dev.to/manuel_dong00/cazar-el-error-500-antes-de-que-exista-sast-con-semgrep-y-github-actions-d03</link>
      <guid>https://dev.to/manuel_dong00/cazar-el-error-500-antes-de-que-exista-sast-con-semgrep-y-github-actions-d03</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Actividad Grupal 1 — Vulnerability Scanning Tools&lt;/strong&gt;&lt;br&gt;
Calidad y Pruebas de Software (SI-784) · Universidad Privada de Tacna&lt;br&gt;
&lt;strong&gt;Equipo:&lt;/strong&gt; Manuel Andre Dongo Palza y Milton H. Flores Chino&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Enlaces del proyecto
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;📦 &lt;strong&gt;Repositorio&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/manuelandredp-gif/abrigando-corazones" rel="noopener noreferrer"&gt;https://github.com/manuelandredp-gif/abrigando-corazones&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🌐 &lt;strong&gt;Aplicación pública&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://abrigandocorazones.site.je" rel="noopener noreferrer"&gt;https://abrigandocorazones.site.je&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ &lt;strong&gt;Workflow (escaneo + despliegue)&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/manuelandredp-gif/abrigando-corazones/actions" rel="noopener noreferrer"&gt;https://github.com/manuelandredp-gif/abrigando-corazones/actions&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📝 &lt;strong&gt;Artículo del equipo (Nuclei)&lt;/strong&gt; · Milton H. Flores Chino&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/milton_hfloreschino_123/reproducir-un-error-500-en-php-con-nuclei-y-github-actions-1bnb"&gt;https://dev.to/milton_hfloreschino_123/reproducir-un-error-500-en-php-con-nuclei-y-github-actions-1bnb&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Dos formas de encontrar la misma falla
&lt;/h2&gt;

&lt;p&gt;Mi compañero Milton reprodujo un error 500 en nuestra app atacándola &lt;strong&gt;desde afuera&lt;/strong&gt;: con Nuclei lanzó peticiones contra la aplicación corriendo y confirmó que &lt;code&gt;/?url[]=contacto&lt;/code&gt; devolvía HTTP 500. Eso es &lt;strong&gt;DAST&lt;/strong&gt; (pruebas dinámicas): sabes &lt;em&gt;que&lt;/em&gt; algo falla, porque lo ves fallar.&lt;/p&gt;

&lt;p&gt;Este artículo toma el camino opuesto y complementario: encontrar esa misma falla &lt;strong&gt;desde adentro&lt;/strong&gt;, leyendo el código, &lt;strong&gt;antes de desplegar y sin levantar el servidor&lt;/strong&gt;. Eso es &lt;strong&gt;SAST&lt;/strong&gt; (análisis estático), y la herramienta es &lt;a href="https://semgrep.dev" rel="noopener noreferrer"&gt;Semgrep&lt;/a&gt;. La idea de fondo: si una herramienta puede señalar la línea culpable en cada push, el bug no necesita llegar a producción para que alguien lo note.&lt;/p&gt;

&lt;h2&gt;
  
  
  La app bajo análisis
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Abrigando Corazones&lt;/strong&gt; es una web PHP (MVC propio, sin framework) de una campaña solidaria en Tacna, desplegada en InfinityFree. Todo el enrutamiento pasa por un archivo: &lt;code&gt;app/core/Router.php&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  El bug, visto desde el código
&lt;/h2&gt;

&lt;p&gt;La primera línea del enrutador toma el parámetro &lt;code&gt;url&lt;/code&gt; y lo recorta:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$rawUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;trim()&lt;/code&gt; espera un &lt;strong&gt;string&lt;/strong&gt;. En PHP 8, si el parámetro llega como arreglo —&lt;code&gt;?url[]=contacto&lt;/code&gt;— &lt;code&gt;$_GET['url']&lt;/code&gt; es un &lt;code&gt;array&lt;/code&gt;, y la función lanza un &lt;code&gt;TypeError&lt;/code&gt; que termina en &lt;strong&gt;HTTP 500&lt;/strong&gt;. La raíz no es &lt;code&gt;trim()&lt;/code&gt;: es que &lt;strong&gt;la entrada del usuario se usa sin validar su tipo&lt;/strong&gt;. Nuclei ve el 500; Semgrep ve la línea que lo produce.&lt;/p&gt;

&lt;h2&gt;
  
  
  Qué es Semgrep (y por qué encaja en CI)
&lt;/h2&gt;

&lt;p&gt;Semgrep busca &lt;strong&gt;patrones en el código&lt;/strong&gt; (no texto plano: entiende la estructura del lenguaje) y se maneja con reglas en YAML versionadas junto al proyecto. Lo decisivo para un pipeline: puede terminar con código de salida distinto de cero cuando encuentra algo, así que &lt;strong&gt;un hallazgo rompe el build&lt;/strong&gt; y bloquea el despliegue. Es el equivalente estático de los umbrales que ya usamos en otras pruebas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Una regla a la medida del bug
&lt;/h2&gt;

&lt;p&gt;Igual que Milton escribió una plantilla de Nuclei propia, escribí una regla de Semgrep para este patrón exacto: entrada de usuario (&lt;code&gt;$_GET&lt;/code&gt;/&lt;code&gt;$_POST&lt;/code&gt;/&lt;code&gt;$_REQUEST&lt;/code&gt;) pasada directo a una función de cadena.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;entrada-sin-validar-en-funcion-de-cadena&lt;/span&gt;
    &lt;span class="na"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;php&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;WARNING&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;Entrada de usuario pasada directamente a una funcion de cadena.&lt;/span&gt;
      &lt;span class="s"&gt;Si el parametro llega como arreglo (?x[]=a), PHP lanza TypeError y&lt;/span&gt;
      &lt;span class="s"&gt;responde HTTP 500. Validar el tipo antes de usarla.&lt;/span&gt;
    &lt;span class="na"&gt;patterns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern-either&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trim($SRC[...], ...)&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trim($SRC[...])&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;strlen($SRC[...])&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;str_replace(..., ..., $SRC[...])&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;explode(..., $SRC[...])&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;metavariable-pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;metavariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$SRC&lt;/span&gt;
          &lt;span class="na"&gt;patterns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern-either&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$_GET&lt;/span&gt;
                &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$_POST&lt;/span&gt;
                &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$_REQUEST&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No busca la palabra &lt;code&gt;trim&lt;/code&gt;: busca &lt;em&gt;la forma&lt;/em&gt; "función de cadena aplicada a un índice de &lt;code&gt;$_GET&lt;/code&gt;", así que también atraparía &lt;code&gt;explode($_GET[...])&lt;/code&gt; o &lt;code&gt;strlen($_POST[...])&lt;/code&gt; el día que aparezcan.&lt;/p&gt;

&lt;h2&gt;
  
  
  El escaneo, con evidencia real
&lt;/h2&gt;

&lt;p&gt;Corriendo la regla sobre &lt;code&gt;app/&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;❯❱ &lt;span class="n"&gt;entrada&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;validar&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;en&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;funcion&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;de&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cadena&lt;/span&gt;
   &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
      &lt;span class="mi"&gt;9&lt;/span&gt;┆ &lt;span class="nv"&gt;$rawUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nc"&gt;Code&lt;/span&gt; &lt;span class="nc"&gt;Finding&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Un hallazgo, en la línea 9 de &lt;code&gt;Router.php&lt;/code&gt; — la misma que produce el 500 que Milton reprodujo desde afuera. Sin servidor, sin peticiones, sin esperar a que alguien mande un arreglo en producción.&lt;/p&gt;

&lt;h2&gt;
  
  
  La prueba de que sirve como compuerta
&lt;/h2&gt;

&lt;p&gt;Una alerta solo vale si pasa a verde cuando el bug se corrige. Validé el tipo antes de usar la entrada:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$entrada&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'url'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$entrada&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;     &lt;span class="c1"&gt;// rechaza arreglos&lt;/span&gt;
    &lt;span class="nf"&gt;http_response_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// 400, no 500&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Solicitud invalida'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$rawUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$entrada&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Volviendo a correr la misma regla:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Original  app/core/Router.php  → 1 hallazgo
Corregido Router.php           → 0 hallazgos
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;De 1 a 0. Eso convierte la regla en una &lt;strong&gt;prueba de regresión&lt;/strong&gt;: si alguien vuelve a meter una entrada sin validar, el escaneo lo marca y el build falla.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dónde entra en el pipeline
&lt;/h2&gt;

&lt;p&gt;El workflow del repo (&lt;code&gt;deploy-infinityfree.yml&lt;/code&gt;) ya empaqueta el commit, valida la sintaxis con &lt;code&gt;php -l&lt;/code&gt;, corre Nuclei contra la copia local y publica por FTP solo si se pide. Semgrep entra &lt;strong&gt;antes de desplegar&lt;/strong&gt;, como primera compuerta estática:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Analisis estatico con Semgrep (SAST)&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;python -m pip install --quiet semgrep&lt;/span&gt;
    &lt;span class="s"&gt;semgrep --config ./seguridad/reglas --error app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;El &lt;code&gt;--error&lt;/code&gt; es lo que hace que un hallazgo tumbe el job. Así quedan dos capas sobre el mismo riesgo: &lt;strong&gt;Semgrep lo bloquea en el código, y Nuclei lo confirma en ejecución.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    A[git push] --&amp;gt; B[SAST: Semgrep lee el codigo]
    B --&amp;gt;|hallazgo| X[Build en rojo: no se despliega]
    B --&amp;gt;|limpio| C[php -l + levantar copia local]
    C --&amp;gt; D[DAST: Nuclei ataca la app corriendo]
    D --&amp;gt;|match 500| X
    D --&amp;gt;|limpio| E[Publicar por FTP a InfinityFree]&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Severidad
&lt;/h2&gt;

&lt;p&gt;La marco &lt;strong&gt;baja&lt;/strong&gt;, igual que el equipo calificó el 500: es un error de servidor acotado a esa petición, no una fuga de datos ni una ejecución de código. Pero es exactamente el tipo de bug barato de atrapar en el código y molesto de descubrir en producción.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lecciones
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SAST y DAST no compiten, se complementan.&lt;/strong&gt; Uno lee el código antes de desplegar; el otro ataca la app corriendo. Juntos cubren el mismo riesgo desde dos lados.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Las reglas propias valen.&lt;/strong&gt; Una regla de cinco líneas atrapó un bug real y seguirá atrapando toda su familia (&lt;code&gt;explode&lt;/code&gt;, &lt;code&gt;strlen&lt;/code&gt;, &lt;code&gt;str_replace&lt;/code&gt; sobre &lt;code&gt;$_GET&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Una alerta sin verde no es una compuerta.&lt;/strong&gt; Comprobar que el hallazgo baja a cero tras el fix es lo que la vuelve una prueba de regresión y no solo un reporte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correr barato, correr siempre.&lt;/strong&gt; El análisis estático no necesita servidor ni base de datos, así que puede correr en cada push sin costo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;¿Y la confirmación en ejecución —reproducir el 500 de verdad contra la app corriendo? Eso lo cubre Nuclei, y lo explica Milton en &lt;a href="https://dev.to/milton_hfloreschino_123/reproducir-un-error-500-en-php-con-nuclei-y-github-actions-1bnb"&gt;su artículo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>sast</category>
      <category>php</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>A 200 can lie: load testing with k6 that guards the money, not just the status</title>
      <dc:creator>Manuel Andree dongo Palza</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:54:50 +0000</pubDate>
      <link>https://dev.to/manuel_dong00/un-200-puede-mentir-pruebas-de-carga-con-k6-que-vigilan-el-dinero-no-solo-el-status-3k5m</link>
      <guid>https://dev.to/manuel_dong00/un-200-puede-mentir-pruebas-de-carga-con-k6-que-vigilan-el-dinero-no-solo-el-status-3k5m</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Group Activity 2 — API Testing&lt;/strong&gt;&lt;br&gt;
Software Quality and Testing (SI-784) · Universidad Privada de Tacna&lt;br&gt;
&lt;strong&gt;Team:&lt;/strong&gt; Manuel Andre Dongo Palza &amp;amp; Milton H. Flores Chino&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Project links
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;📦 &lt;strong&gt;Repository&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/miltom123/si784-grupal2-api-testing" rel="noopener noreferrer"&gt;https://github.com/miltom123/si784-grupal2-api-testing&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🚀 &lt;strong&gt;Live API&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="https://si784-api-envios.vercel.app" rel="noopener noreferrer"&gt;https://si784-api-envios.vercel.app&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ &lt;strong&gt;CI/CD runs&lt;/strong&gt; (tests → Vercel → Newman &amp;amp; k6 in prod)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://github.com/miltom123/si784-grupal2-api-testing/actions" rel="noopener noreferrer"&gt;https://github.com/miltom123/si784-grupal2-api-testing/actions&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;📝 &lt;strong&gt;Companion article&lt;/strong&gt; (Newman, by Milton)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://dev.to/milton_hfloreschino_123/pruebas-de-api-con-newman-de-0-a-121-aserciones-en-un-pipeline-que-despliega-en-vercel-2ke2"&gt;https://dev.to/milton_hfloreschino_123/pruebas-de-api-con-newman-de-0-a-121-aserciones-en-un-pipeline-que-despliega-en-vercel-2ke2&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🎬 &lt;strong&gt;Video&lt;/strong&gt; (≤ 5 min)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://youtu.be/XAjGJB6H0Fw" rel="noopener noreferrer"&gt;https://youtu.be/XAjGJB6H0Fw&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  A &lt;code&gt;200 OK&lt;/code&gt; doesn't mean the result is correct
&lt;/h2&gt;

&lt;p&gt;Picture an API that charges money. It returns &lt;code&gt;200&lt;/code&gt;, the JSON looks fine, the customer pays. But the &lt;code&gt;total&lt;/code&gt; was off by a cent because, with twenty requests hitting at once, a rounding step ran on a half-written value. Single-threaded functional tests would never catch it: each one, on its own, returns &lt;code&gt;200&lt;/code&gt;. The bug only shows up &lt;strong&gt;under load&lt;/strong&gt; — and in any system that moves money, a bug that only appears under load is the most expensive kind.&lt;/p&gt;

&lt;p&gt;That's the gap neither unit nor functional tests cover, and it's what this article is about. In our project we split the testing of the same API into two fronts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Newman&lt;/strong&gt; checks that each response is correct — schemas, contract, 121 assertions. Milton covers it in &lt;a href="https://dev.to/milton_hfloreschino_123/pruebas-de-api-con-newman-de-0-a-121-aserciones-en-un-pipeline-que-despliega-en-vercel-2ke2"&gt;his article&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;k6&lt;/strong&gt; checks that the API stays &lt;strong&gt;correct and fast when everyone shows up at once&lt;/strong&gt;. That's what follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One rule held across the whole project: nothing reaches production without passing, and the same tests run again against the public URL after deploying.&lt;/p&gt;

&lt;h2&gt;
  
  
  The API under test
&lt;/h2&gt;

&lt;p&gt;A stateless REST API that quotes shipping prices between Peru's 25 departments (Node.js 20 + Hono, deployed on Vercel as a serverless function). The endpoint that matters isn't a &lt;code&gt;health&lt;/code&gt; check that returns a constant — it's the one that &lt;strong&gt;does money math&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;total = ((zone_base + S/2.50 × each_0.5kg + jungle_surcharge) × express_factor) + insurance_1%
igv   = 18% of the subtotal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Base by zone, S/ 2.50 per started 0.5 kg, jungle surcharge, express factor ×1.6, 1% insurance on the declared value, and 18% VAT (IGV). Several chained roundings. Exactly the kind of logic worth stressing, because that's where a concurrency bug turns into real money.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: a threshold is a contract, not decoration
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://k6.io" rel="noopener noreferrer"&gt;k6&lt;/a&gt; is Grafana Labs' load-testing tool. Scenarios written in JavaScript (versioned next to the code), a Go engine (hundreds of requests per second without choking the machine), and — the part that makes it fit CI — &lt;strong&gt;thresholds&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A threshold is an &lt;strong&gt;SLO written as code&lt;/strong&gt;: "95% of quotes respond in under 800 ms", "fewer than 1% of responses carry an inconsistent amount". If it isn't met, k6 exits non-zero and &lt;strong&gt;the pipeline stops&lt;/strong&gt;. The test stops being "numbers someone glances at" and becomes a quality gate that decides whether the change deserves production. It's the same logic as any serious quality control: it either meets the agreed limit, or it doesn't pass.&lt;/p&gt;

&lt;p&gt;The whole scenario lives in one file: &lt;a href="https://github.com/miltom123/si784-grupal2-api-testing/blob/main/tests/k6/carga.js" rel="noopener noreferrer"&gt;&lt;code&gt;tests/k6/carga.js&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The full flow
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    A[git push to main] --&amp;gt; B[Local tests: unit + Newman + k6 smoke]
    B --&amp;gt;|green| C[vercel deploy --prod]
    C --&amp;gt; D[Production tests: Newman + k6 load]
    D --&amp;gt;|any threshold fails| E[Pipeline red: the change is not left deployed]
    D --&amp;gt;|all green| F[Trusted change in production]&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Scenario design: ramp up, hold, ramp down
&lt;/h2&gt;

&lt;p&gt;Instead of dropping a fixed number of users all at once, the load climbs in stages. That way you see both the serverless &lt;strong&gt;cold start&lt;/strong&gt; and the steady state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;scenarios&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;rampa&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ramping-vus'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;startVUs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'15s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// warm-up&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'30s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// sustained load&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'10s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c1"&gt;// ramp down&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;gracefulRampDown&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'5s'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;thresholds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http_req_failed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'rate&amp;lt;0.01'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// &amp;lt; 1% HTTP errors&lt;/span&gt;
    &lt;span class="n"&gt;http_req_duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'p(95)&amp;lt;800'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// 95% respond in &amp;lt; 800 ms&lt;/span&gt;
    &lt;span class="n"&gt;tiempo_cotizacion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'p(95)&amp;lt;800'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'avg&amp;lt;400'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// quote latency&lt;/span&gt;
    &lt;span class="n"&gt;errores_de_negocio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'rate&amp;lt;0.01'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// business errors&lt;/span&gt;
    &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;             &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'rate&amp;gt;0.99'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Twenty virtual users isn't a big number; it's an &lt;strong&gt;honest&lt;/strong&gt; one for this API. The goal wasn't to knock it over, but to set a realistic service level and confirm it holds, repeatably, on every push. And we measure by the &lt;strong&gt;95th percentile&lt;/strong&gt;, not the average: the average hides the users who waited too long; p(95) puts them front and center.&lt;/p&gt;

&lt;h2&gt;
  
  
  The star: a metric that watches the money
&lt;/h2&gt;

&lt;p&gt;Here's what makes this test more than a plain "does it hold or not". k6 ships with network metrics out of the box (&lt;code&gt;http_req_failed&lt;/code&gt;, &lt;code&gt;http_req_duration&lt;/code&gt;). We added a &lt;strong&gt;business&lt;/strong&gt; metric:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;erroresNegocio&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Rate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'errores_de_negocio'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;tiempoCotizacion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Trend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'tiempo_cotizacion'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="n"&gt;tiempoCotizacion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s1"&gt;'quote 200'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'total = subtotal + IGV'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;desglose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;desglose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;igv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.011&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;erroresNegocio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// a 200 with a wrong total DOES count as a failure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;errores_de_negocio&lt;/code&gt; counts the responses that arrive with &lt;code&gt;200&lt;/code&gt; &lt;strong&gt;but with amounts that don't add up&lt;/strong&gt;. To the network that's a success; to whoever charges the customer, it's a failure. It's the only metric that catches the bug from the start of this article, and its threshold (&lt;code&gt;rate&amp;lt;0.01&lt;/code&gt;) is as strict as the one for HTTP errors. We use &lt;code&gt;closeTo&lt;/code&gt; with a one-cent tolerance because the total is born of roundings over decimals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two details that separate a serious test from a toy one
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Random traffic, not the same case a thousand times.&lt;/strong&gt; If you always repeat &lt;code&gt;Tacna → Lima, 2 kg&lt;/code&gt;, the platform caches and you measure a lie. Each iteration builds a different shipment — weights from 0.1 to 50 kg, varied origins and destinations (including the jungle, which adds a surcharge), 30% express — so every branch of the calculation runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expected errors aren't failures.&lt;/strong&gt; One request sends a weight of 999 kg on purpose, to confirm validation still returns &lt;code&gt;422&lt;/code&gt; under load. The catch: k6 counts any &lt;code&gt;4xx&lt;/code&gt; as a failure by default, which would push &lt;code&gt;http_req_failed&lt;/code&gt; to 33%. So we declare it explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invalidBody&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;responseCallback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expectedStatuses&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;422&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a bonus, &lt;code&gt;setup()&lt;/code&gt; does a &lt;code&gt;GET /v1/health&lt;/code&gt; before starting: if the API doesn't answer, the test aborts with a clear message instead of generating thousands of meaningless errors. And &lt;code&gt;handleSummary()&lt;/code&gt; writes &lt;code&gt;reports/k6-resumen.md&lt;/code&gt;, which GitHub Actions shows directly in the run summary.&lt;/p&gt;

&lt;h2&gt;
  
  
  k6 inside the pipeline
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://github.com/miltom123/si784-grupal2-api-testing/blob/main/.github/workflows/ci-cd.yml" rel="noopener noreferrer"&gt;&lt;code&gt;ci-cd.yml&lt;/code&gt;&lt;/a&gt;, k6 runs twice, with different intents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;grafana/setup-k6-action@v1&lt;/span&gt;

&lt;span class="c1"&gt;# Before deploying: a quick smoke so we don't burn minutes if something is already broken
&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;k6 run --vus 5 --duration 10s -e BASE_URL=http://localhost:3000 tests/k6/carga.js&lt;/span&gt;

&lt;span class="c1"&gt;# After deploying: the full ramp scenario against production
&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;k6 run -e BASE_URL="$BASE_URL" tests/k6/carga.js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The short smoke cuts the obvious errors early; the full test, now against Vercel, validates the real service level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results against production (Vercel)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requests&lt;/td&gt;
&lt;td&gt;3148&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Requests per second&lt;/td&gt;
&lt;td&gt;56.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTTP errors&lt;/td&gt;
&lt;td&gt;0.00%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p(95) duration&lt;/td&gt;
&lt;td&gt;45 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Average quote&lt;/td&gt;
&lt;td&gt;26 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Checks passed&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All five thresholds green: &lt;code&gt;http_req_failed&lt;/code&gt; &amp;lt; 1%, &lt;code&gt;http_req_duration&lt;/code&gt; p(95) &amp;lt; 800 ms, &lt;code&gt;tiempo_cotizacion&lt;/code&gt; p(95) &amp;lt; 800 ms and average &amp;lt; 400 ms, &lt;code&gt;errores_de_negocio&lt;/code&gt; &amp;lt; 1%, and &lt;code&gt;checks&lt;/code&gt; &amp;gt; 99%.&lt;/p&gt;

&lt;p&gt;The number that made us think most: locally the p(95) sat around &lt;strong&gt;2 ms&lt;/strong&gt;; in production, &lt;strong&gt;45 ms&lt;/strong&gt;. The code didn't get worse — that's the network plus the serverless layer. That 20× gap is exactly why &lt;strong&gt;you have to measure where the code runs, not where it's written&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters more, not less
&lt;/h2&gt;

&lt;p&gt;Today a growing share of code — and soon much of the &lt;em&gt;tests&lt;/em&gt; themselves — is written by AI. That speeds everything up, but it shifts the question from "did I write it right?" to "how do I know what got generated behaves well in production?". The answer isn't reading more lines: it's having an &lt;strong&gt;executable quality gate&lt;/strong&gt; that runs on its own with every change and says yes or no with data. A k6 threshold isn't impressed by elegant code; it only measures whether, under real load, responses arrive on time and the amounts add up. The faster we produce, the more that gate is worth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The threshold is the test.&lt;/strong&gt; Without &lt;code&gt;thresholds&lt;/code&gt;, k6 just prints numbers; with them, load becomes a gate that blocks deploys, like any SLO.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance and correctness are measured together.&lt;/strong&gt; A fast &lt;code&gt;200&lt;/code&gt; with a wrong total is still a bug — and only a business metric catches it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Declare your expected errors&lt;/strong&gt;, or your failure metrics will lie.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure where it runs, not where it's written.&lt;/strong&gt; The jump from 2 ms to 45 ms between local and production shows up in no test that doesn't hit the public URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try it yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k6 run -e &lt;span class="nv"&gt;BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://si784-api-envios.vercel.app tests/k6/carga.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the correctness of each response one by one — schemas, contract, edge cases? That's Newman's job, and Milton explains it in &lt;a href="https://dev.to/milton_hfloreschino_123/pruebas-de-api-con-newman-de-0-a-121-aserciones-en-un-pipeline-que-despliega-en-vercel-2ke2"&gt;his article&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>k6</category>
      <category>performance</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Manuel Andree dongo Palza</dc:creator>
      <pubDate>Mon, 06 Jul 2026 15:44:39 +0000</pubDate>
      <link>https://dev.to/manuel_dong00/-540n</link>
      <guid>https://dev.to/manuel_dong00/-540n</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3" class="crayons-story__hidden-navigation-link"&gt;Cómo hablar con tu base de datos usando IA y construir un extractor SQL seguro con Streamlit&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/manuel_dong00" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4018051%2F21556e6c-d826-4ade-9843-9d34cdd5ce4f.jpg" alt="manuel_dong00 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/manuel_dong00" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Manuel Andree dongo Palza
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Manuel Andree dongo Palza
                
              
              &lt;div id="story-author-preview-content-4081100" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/manuel_dong00" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4018051%2F21556e6c-d826-4ade-9843-9d34cdd5ce4f.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Manuel Andree dongo Palza&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 6&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3" id="article-link-4081100"&gt;
          Cómo hablar con tu base de datos usando IA y construir un extractor SQL seguro con Streamlit
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/sql"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;sql&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Cómo hablar con tu base de datos usando IA y construir un extractor SQL seguro con Streamlit</title>
      <dc:creator>Manuel Andree dongo Palza</dc:creator>
      <pubDate>Mon, 06 Jul 2026 15:44:03 +0000</pubDate>
      <link>https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3</link>
      <guid>https://dev.to/manuel_dong00/como-hablar-con-tu-base-de-datos-usando-ia-y-construir-un-extractor-sql-seguro-con-streamlit-3hi3</guid>
      <description>&lt;p&gt;Abstract&lt;/p&gt;

&lt;p&gt;Cada vez más equipos quieren consultar datos sin escribir SQL a mano. El problema es que un sistema Text-to-SQL no solo debe “traducir preguntas”, sino también entender el esquema, restringir permisos, validar consultas y explicar por qué una consulta es rápida o lenta. Ese enfoque coincide con la ruta propuesta por el tutorial oficial de LangChain para agentes SQL: listar tablas, inspeccionar esquemas, generar la consulta, revisarla, ejecutarla y corregir errores hasta obtener una respuesta; y el propio tutorial advierte que ejecutar SQL generado por modelos tiene riesgos y exige permisos mínimos. En paralelo, la documentación oficial de Python recomienda usar placeholders en sqlite3 para enlazar parámetros y evitar inyección SQL, mientras que la documentación de SQLite explica que EXPLAIN QUERY PLAN permite inspeccionar si una consulta hace SCAN, SEARCH y si usa índices. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/manueldongo23" rel="noopener noreferrer"&gt;
        manueldongo23
      &lt;/a&gt; / &lt;a href="https://github.com/manueldongo23/sql_ai_sales_assistant_demo" rel="noopener noreferrer"&gt;
        sql_ai_sales_assistant_demo
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;SQL AI Sales Assistant&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A safe &lt;strong&gt;Text-to-SQL&lt;/strong&gt; demo that converts natural language business questions into SQL queries, executes them on a local SQLite retail database, and shows the generated SQL plus &lt;code&gt;EXPLAIN QUERY PLAN&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This project was created as evidence for an article about &lt;strong&gt;SQL AI Database Solutions&lt;/strong&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Topic&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Talk to your database with AI: build a safe SQL query extractor with Streamlit and SQLite.&lt;/strong&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Natural language prompts such as &lt;code&gt;sales by month&lt;/code&gt;, &lt;code&gt;top customers&lt;/code&gt;, &lt;code&gt;sales in Lima&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Rule-assisted NL→SQL generation, designed to be transparent and auditable.&lt;/li&gt;
&lt;li&gt;SQLite demo database with customers, products, orders and order items.&lt;/li&gt;
&lt;li&gt;Read-only SQL validator that blocks destructive commands.&lt;/li&gt;
&lt;li&gt;Parameterized queries for user-provided filters.&lt;/li&gt;
&lt;li&gt;Streamlit interface.&lt;/li&gt;
&lt;li&gt;CLI demo for quick testing.&lt;/li&gt;
&lt;li&gt;Query plan inspection with &lt;code&gt;EXPLAIN QUERY PLAN&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;User question
   ↓
NL → SQL interpreter
   ↓
Read-only SQL validator
   ↓
SQLite execution
   ↓
Results + EXPLAIN QUERY&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/manueldongo23/sql_ai_sales_assistant_demo" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
Cuerpo del artículo

&lt;p&gt;La promesa de SQL + IA suena sencilla: le haces una pregunta al sistema y este devuelve una tabla, un indicador o una respuesta de negocio. Pero en la práctica, los sistemas serios no viven solo de “adivinar SQL”. Los benchmarks más influyentes lo dejan claro. Spider fue diseñado precisamente para medir si un modelo puede generalizar a bases de datos no vistas, y los resultados iniciales mostraron que el problema seguía siendo difícil incluso para consultas complejas. CoSQL, por su parte, añadió turnos conversacionales, aclaraciones y reformulaciones, algo mucho más parecido a lo que pasa en equipos reales cuando un analista pregunta, corrige y vuelve a preguntar. &lt;/p&gt;

&lt;p&gt;Por eso, en vez de hacer un demo “mágico” y opaco, este proyecto usa una arquitectura híbrida y segura. El flujo es: el usuario escribe una pregunta en lenguaje natural, una capa de interpretación identifica la intención, se genera SQL, un validador bloquea sentencias peligrosas, SQLite ejecuta solo lecturas y la interfaz muestra tanto el resultado como el plan de ejecución. Esta decisión no es casual: LangChain documenta exactamente esa secuencia conceptual para un agente SQL y subraya que las credenciales del motor deben estar limitadas al mínimo necesario. &lt;/p&gt;

&lt;p&gt;El caso de uso que elegí fue analítica de ventas retail, porque permite mostrar ejemplos de negocio que cualquiera entiende y, al mismo tiempo, obliga a tocar varios patrones SQL reales: agregaciones, JOIN, GROUP BY, filtros por ciudad, filtros temporales, rankings y cálculo de ticket promedio. También funciona muy bien con SQLite, que la documentación oficial de Python describe como una biblioteca ligera, basada en disco y sin proceso servidor separado, ideal para prototipos y aplicaciones pequeñas antes de migrar a motores mayores. &lt;/p&gt;

&lt;p&gt;La base de datos del demo tiene cuatro tablas: customers, products, orders y order_items. Con ese esquema, ya puedes responder preguntas como estas:&lt;/p&gt;

&lt;p&gt;¿Cuáles fueron las ventas por mes?&lt;br&gt;
¿Quiénes son mis mejores clientes?&lt;br&gt;
¿Qué productos son los más vendidos?&lt;br&gt;
¿Qué artículos tienen stock bajo?&lt;br&gt;
¿Cuánto vendí en Lima?&lt;br&gt;
¿Cuál es el ticket promedio?&lt;br&gt;
¿Cuánto se vendió en una categoría concreta?&lt;br&gt;
¿Cuánto se vendió entre dos fechas?&lt;br&gt;
Un ejemplo clásico es “Muéstrame las ventas por mes”. En ese caso, la capa NL2SQL detecta una intención temporal y genera esta consulta:&lt;/p&gt;

&lt;p&gt;sql&lt;br&gt;
Copiar&lt;br&gt;
SELECT substr(o.order_date, 1, 7) AS month,&lt;br&gt;
       ROUND(SUM(oi.quantity * oi.unit_price), 2) AS revenue,&lt;br&gt;
       COUNT(DISTINCT o.order_id) AS total_orders&lt;br&gt;
FROM orders o&lt;br&gt;
JOIN order_items oi ON oi.order_id = o.order_id&lt;br&gt;
GROUP BY substr(o.order_date, 1, 7)&lt;br&gt;
ORDER BY month;&lt;br&gt;
Ese ejemplo es importante porque muestra dos cosas. Primero, la IA no responde “en abstracto”, sino que aterriza en un SQL ejecutable. Segundo, el sistema puede explicar rendimiento. La documentación oficial de SQLite indica que EXPLAIN QUERY PLAN muestra si el motor realiza un SCAN completo o un SEARCH usando índices, y esa diferencia sirve para enseñar optimización de consultas con un caso real. &lt;/p&gt;

&lt;p&gt;Otro ejemplo muy útil para negocio es el ranking de mejores clientes. Ahí usamos JOIN entre clientes, pedidos y detalle de pedido para sumar ingresos y contar órdenes. Esa es la consulta:&lt;/p&gt;

&lt;p&gt;sql&lt;br&gt;
Copiar&lt;br&gt;
SELECT c.full_name,&lt;br&gt;
       c.city,&lt;br&gt;
       ROUND(SUM(oi.quantity * oi.unit_price), 2) AS total_sales,&lt;br&gt;
       COUNT(DISTINCT o.order_id) AS total_orders&lt;br&gt;
FROM customers c&lt;br&gt;
JOIN orders o ON o.customer_id = c.customer_id&lt;br&gt;
JOIN order_items oi ON oi.order_id = o.order_id&lt;br&gt;
GROUP BY c.customer_id, c.full_name, c.city&lt;br&gt;
ORDER BY total_sales DESC&lt;br&gt;
LIMIT 5;&lt;br&gt;
Este tipo de ejemplo es “real” porque responde una pregunta clásica de gerencia comercial: quién compra más, desde qué ciudad y con cuántos pedidos. En otras palabras, el sistema no es un juguete para seleccionar una sola tabla; trabaja con relaciones, agregaciones y límites, que son exactamente los componentes que un sistema Text-to-SQL serio debe manejar. Los trabajos sobre KaggleDBQA y sobre evaluación de ChatGPT en Text-to-SQL justamente remarcan que el salto desde datasets controlados a bases más reales sigue siendo un desafío, sobre todo cuando cambia el dominio, el formato y la forma en que los usuarios formulan sus preguntas. &lt;/p&gt;

&lt;p&gt;La parte más importante del proyecto no está en la interfaz, sino en la seguridad. Si alguien te vende un “chat con tu base de datos” sin hablar de permisos, validación o inyección SQL, te está mostrando solo la mitad del sistema. La documentación de sqlite3 en Python recomienda expresamente usar placeholders como ? en vez de interpolar cadenas, para evitar ataques de inyección SQL. Mi demo sigue esa recomendación para filtros por ciudad, categoría o intervalos de fechas. Además, el motor bloquea cualquier consulta que no empiece por SELECT o WITH, y rechaza instrucciones como DROP, DELETE, UPDATE, ALTER, PRAGMA o múltiples sentencias encadenadas. &lt;/p&gt;

&lt;p&gt;Aquí tienes el núcleo de esa validación:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
Copiar&lt;br&gt;
FORBIDDEN_SQL = {&lt;br&gt;
    "insert", "update", "delete", "drop", "alter", "attach", "detach",&lt;br&gt;
    "replace", "truncate", "create", "pragma", "vacuum", "reindex"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;def validate_sql(sql: str) -&amp;gt; None:&lt;br&gt;
    normalized = re.sub(r"\s+", " ", sql.strip().lower())&lt;br&gt;
    if not (normalized.startswith("select") or normalized.startswith("with")):&lt;br&gt;
        raise ValueError("Solo se permiten consultas SELECT o WITH.")&lt;br&gt;
    for keyword in FORBIDDEN_SQL:&lt;br&gt;
        if re.search(rf"\b{re.escape(keyword)}\b", normalized):&lt;br&gt;
            raise ValueError(f"Consulta bloqueada por seguridad: contiene '{keyword}'.")&lt;br&gt;
La interfaz la construí con Streamlit porque su guía oficial de inicio rápido está pensada precisamente para levantar una app de datos con muy poca fricción, instalando el entorno y creando una primera aplicación de forma directa. Para un demo académico, eso es ideal porque te deja concentrarte en el flujo NL2SQL y no en el frontend complejo. &lt;/p&gt;

&lt;p&gt;La capa de interpretación también está diseñada para ser útil en clase o en una publicación técnica. En vez de esconder todo detrás de un LLM remoto, el sistema expone qué regla identificó, qué SQL generó, qué parámetros usó y qué plan de ejecución devolvió SQLite. Eso vuelve el comportamiento del demo auditado y explicable, que es justo lo que falta en muchos ejemplos de “IA para bases de datos”.&lt;/p&gt;

&lt;p&gt;Este enfoque además se alinea con proyectos públicos del ecosistema. DB-GPT-Hub se presenta como un repositorio orientado a Text-to-SQL parsing with LLMs, con código, documentación, requisitos y experimentos para mejorar desempeño de modelos en Text-to-SQL. Vanna, por su parte, define su propuesta como “Natural language → SQL → Answers” y la documentación de Vanna 2.0 describe un framework de agente que conecta LLMs con bases de datos, aprendiendo de interacciones exitosas y aplicando controles de acceso. Para fines de artículo, eso permite mostrar que tu demo no sale de la nada: está alineado con líneas públicas y reconocibles del ecosistema. &lt;/p&gt;

&lt;p&gt;La gran lección es esta: el verdadero valor de SQL + IA no está en reemplazar SQL, sino en encapsularlo de forma segura, comprensible y útil para el negocio. Un buen sistema Text-to-SQL no debe ser solo generativo; debe ser verificable. Si puede mostrar el SQL, justificar la consulta, enlazar parámetros, restringir permisos y enseñar el plan de ejecución, entonces deja de ser una demo vistosa y se convierte en una solución de ingeniería que sí puede escalar. Esa misma tensión entre potencia y fiabilidad es visible en la bibliografía reciente: los trabajos más sólidos siguen invirtiendo en schema linking, recuperación de ejemplos, validación y evaluación fuera de distribución, no solo en “usar un modelo más grande”. &lt;/p&gt;

&lt;p&gt;Conclusión&lt;/p&gt;

&lt;p&gt;Si quieres construir una solución de bases de datos con IA que de verdad sirva, empieza por un dominio concreto, un esquema pequeño pero real, una capa de validación estricta y una interfaz clara. Después de eso, puedes sustituir el motor híbrido por un LLM o por un framework especializado. Pero la base correcta sigue siendo la misma: esquema, seguridad, SQL verificable y observabilidad. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/manueldongo23" rel="noopener noreferrer"&gt;
        manueldongo23
      &lt;/a&gt; / &lt;a href="https://github.com/manueldongo23/sql_ai_sales_assistant_demo" rel="noopener noreferrer"&gt;
        sql_ai_sales_assistant_demo
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;SQL AI Sales Assistant&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A safe &lt;strong&gt;Text-to-SQL&lt;/strong&gt; demo that converts natural language business questions into SQL queries, executes them on a local SQLite retail database, and shows the generated SQL plus &lt;code&gt;EXPLAIN QUERY PLAN&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This project was created as evidence for an article about &lt;strong&gt;SQL AI Database Solutions&lt;/strong&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Topic&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Talk to your database with AI: build a safe SQL query extractor with Streamlit and SQLite.&lt;/strong&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Natural language prompts such as &lt;code&gt;sales by month&lt;/code&gt;, &lt;code&gt;top customers&lt;/code&gt;, &lt;code&gt;sales in Lima&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Rule-assisted NL→SQL generation, designed to be transparent and auditable.&lt;/li&gt;
&lt;li&gt;SQLite demo database with customers, products, orders and order items.&lt;/li&gt;
&lt;li&gt;Read-only SQL validator that blocks destructive commands.&lt;/li&gt;
&lt;li&gt;Parameterized queries for user-provided filters.&lt;/li&gt;
&lt;li&gt;Streamlit interface.&lt;/li&gt;
&lt;li&gt;CLI demo for quick testing.&lt;/li&gt;
&lt;li&gt;Query plan inspection with &lt;code&gt;EXPLAIN QUERY PLAN&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;User question
   ↓
NL → SQL interpreter
   ↓
Read-only SQL validator
   ↓
SQLite execution
   ↓
Results + EXPLAIN QUERY&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/manueldongo23/sql_ai_sales_assistant_demo" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>ai</category>
      <category>python</category>
      <category>security</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
