package services import ( "strings" "testing" ) // Registrar una factura dictando los datos no era posible: la única // herramienta de venta era adjuntar_factura, que exige un archivo pendiente. // Sin una alternativa, el modelo no tenía con qué guardar y el usuario recibía // un "guardado exitosamente" sobre algo que nunca se creó. func TestExisteHerramientaParaFacturaSinAdjunto(t *testing.T) { tools := agentTools() nombres := map[string]agentTool{} for _, tl := range tools { nombres[tl.Function.Name] = tl } crear, ok := nombres["crear_factura"] if !ok { t.Fatal("falta crear_factura: no habría forma de registrar una factura de venta sin archivo adjunto") } if _, ok := nombres["adjuntar_factura"]; !ok { t.Error("adjuntar_factura debe seguir existiendo para el caso con documento") } // La descripción tiene que distinguirlas, o el modelo elige la equivocada // y falla por falta de adjunto — que es justo el problema original. d := strings.ToLower(crear.Function.Description) if !strings.Contains(d, "sin archivo adjunto") { t.Error("la descripción debe dejar claro que no necesita adjunto") } if !strings.Contains(d, "adjuntar_factura") { t.Error("la descripción debe remitir a adjuntar_factura cuando sí hay documento") } // cliente_id y monto son obligatorios: sin ellos la factura no sirve. req := strings.Join(crear.Function.Parameters.Required, ",") for _, campo := range []string{"cliente_id", "monto"} { if !strings.Contains(req, campo) { t.Errorf("%q debería ser obligatorio en crear_factura", campo) } } }