---
name: vault_diff
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: pure
signature: "func VaultDiff(prev, curr []VaultFile) VaultDiffReport"
description: "Computes the diff between two vault snapshots (slices of VaultFile). Returns Added, Removed, Changed and Unchanged counts. Pure and deterministic — no I/O."
tags: [vault, diff, comparison, pure, pendiente-usar]
uses_functions: []
uses_types: ["vault_file_go_infra"]
returns: []
returns_optional: false
error_type: ""
imports: ["sort"]
tested: true
tests:
  - "TestVaultDiff_NoChanges"
  - "TestVaultDiff_AllAdded"
  - "TestVaultDiff_AllRemoved"
  - "TestVaultDiff_ContentChanged"
  - "TestVaultDiff_Mixed"
test_file_path: "functions/infra/vault_diff_test.go"
file_path: "functions/infra/vault_diff.go"
params:
  - name: prev
    desc: "Snapshot anterior — slice de VaultFile del estado previo del vault (puede ser nil para diff desde cero)."
  - name: curr
    desc: "Snapshot actual — slice de VaultFile del estado corriente del vault (puede ser nil para diff de borrado total)."
output: "VaultDiffReport con Added (nuevos), Removed (eliminados), Changed (mismo rel_path, sha256 distinto) y Unchanged (identicos). Todos los slices ordenados por RelPath ASC."
---

## Ejemplo

```go
prev, _ := infra.VaultInventoryScan(oldPath, "my_vault_proj", "my_vault")
curr, _ := infra.VaultInventoryScan(newPath, "my_vault_proj", "my_vault")
report := infra.VaultDiff(prev, curr)
fmt.Printf("Added: %d, Removed: %d, Changed: %d, Unchanged: %d\n",
    len(report.Added), len(report.Removed), len(report.Changed), report.Unchanged)
```

## Notas

- Usa `RelPath` como clave de identidad de archivo (no nombre, no sha256).
- Dos archivos con mismo `RelPath` pero diferente `Sha256` se consideran Changed.
- Los slices del report se ordenan por `RelPath` ASC para salida deterministica.
- Función pura: no toca disco ni BD.
