# Score a test run

> Checks what a test run made against what its test case expects, and gives each check a pass or a fail with the reason.

Source: https://docs.go-lumen.ai/es/reference/steps/score

## De un vistazo

| Propiedad | Valor |
| --- | --- |
| **Nombre del paso** | `score` |
| **Recurso** | ClusterStep (`lumen.ai/v1alpha1`) |
| **Grupo de la paleta, categoría** | control, logic |
| **Créditos** | **0** créditos cada vez que tiene éxito |
| **Efectos externos** | no |
| **La instalación debe aportar** | nada |

## Entradas

| Propiedad | Valor |
| --- | --- |
| **Necesita** | nada |
| **Produce** | `fields` |
| **Trabaja sobre** | item: un documento cada vez |

Necesita y Produce son tipos de datos (file, text, fields, email). El editor ofrece un paso solo donde lo que necesita ya está en el camino. Consulta [Documentos y datos](https://docs.go-lumen.ai/es/concepts/how-flows-run.md#documents-and-data).

## Salidas

Un nodo posterior se refiere a una salida como `{nodeId.field}` en un texto, o `nodeId.field` en una condición.

| Salida | Tipo |
| --- | --- |
| `passed` | boolean |
| `score` | number |
| `checks` | array |
| `failed` | number |

## Ajustes

Se definen bajo `config:` en el nodo del flujo. Los ajustes de texto pueden contener marcadores de posición como `{nodeId.field}`.

| Ajuste | Tipo | Valor por defecto | Descripción |
| --- | --- | --- | --- |
| `checks` (obligatorio) | list of object |  | Checks (minItems 1; maxItems 50) |
| `checks[].name` (obligatorio) | string |  | Name is the metric, as results show it. (minLength 1; maxLength 63) |
| `checks[].actual` (obligatorio) | string |  | Actual is the field checked, as a condition names it: <node>.<field>, walking into a JSON answer (extract.reply.source). It is read from that node's own output. (minLength 1; maxLength 200) |
| `checks[].op` (obligatorio) | string |  | Op is how: equals, contains, matches (a regular expression), json (the expected JSON is part of the value), changes (a change list against the expected list), count (a list's length or a number), exists. (one of equals, contains, matches, json, changes, count, exists) |
| `checks[].expected` | string |  | Expected is the value to check against, written here. (maxLength 4000) |
| `checks[].expectedColumn` | string |  | ExpectedColumn takes the expected value from the test case's column instead (run.case.<column>). (maxLength 63) |
| `checks[].mode` | string | `"equal"` | Mode is a changes check's: equal (exactly these changes, a change not expected is a wrong write and fails) or include (at least these). (one of equal, include) |
| `minScore` | number |  | MinScore is the share of checks that must pass for the run to pass, from 0 to 1. Unset is 1: every check. (minimum 0; maximum 1) |

El JSON Schema completo de estos ajustes: [score.schema.json](https://docs.go-lumen.ai/schemas/steps/score.schema.json).

## Ejemplo

```yaml title="config"
checks:
- actual: read.total
  expected: "1170"
  name: total
  op: equals
```

## Úsalo en un flujo

Un nodo que ejecuta `score` va bajo `spec.nodes` de un [Flow](https://docs.go-lumen.ai/es/concepts/how-flows-run.md#the-flow-as-yaml). Dale cualquier id y enumera en next los ids de los nodos siguientes.

```yaml title="flow.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: score-example
  namespace: tenant-acme
spec:
  displayName: "Score a test run"
  triggers:
    - id: start
      ref: {name: manual-run}
      next: [score]
  nodes:
    - id: score
      stepRef: {name: score}
      config:
        checks:
        - actual: read.total
          expected: "1170"
          name: total
          op: equals
```
