puerto 0.33.0

Puerto: la CLI de un framework full-stack DDD en Rust. Genera proyectos con Clean Architecture, la inyección de dependencias cableada sola y soporte de SQLx, sin cablear nada a mano. Antes, puerto-framework.
//! Fase 37.7: `puerto actualizar` prepares the upgrade for the agent — the steps and, in order, the
//! breaking changes and migration guides between the project's version and the CLI's — and the
//! generated project carries the skill that tells the agent how.
use super::*;
use crate::commands::update;

const CHANGELOG: &str = "## [0.32.0] - 2026-11-28

### Added

- Algo nuevo.

### Breaking

- `listar` cambia.

### Migration Guide

1. Sube los crates a la 0.32.

## [0.31.1] - 2026-11-27

### Fixed

- Un arreglo.

## [0.31.0] - 2026-11-27

### Breaking

- Taskfile.

### Migration Guide

1. Cambia el Taskfile.

## [0.30.0] - 2026-11-26

### Migration Guide

1. Lo de la 0.30.
";

fn manifest(version: &str) -> String {
    format!(
        "[workspace]\nmembers = [\"presentacion/*\"]\n\n[workspace.dependencies]\npuerto-nucleo = \"{version}\"\npuerto-web = {{ version = \"{version}\" }}\n"
    )
}

#[test]
fn the_guides_after_the_projects_version_come_in_order_up_to_the_clis() {
    let report = update::report(&manifest("0.30"), "0.32.0", CHANGELOG).unwrap();

    assert!(report.contains("0.30"), "{report}");
    assert!(report.contains("0.32.0"), "{report}");
    assert!(report.contains("actualizar-puerto"), "{report}");
    let at = |needle: &str| {
        report
            .find(needle)
            .unwrap_or_else(|| panic!("{needle}\n{report}"))
    };
    assert!(at("## [0.31.0]") < at("## [0.31.1]"), "{report}");
    assert!(at("## [0.31.1]") < at("## [0.32.0]"), "{report}");
    assert!(report.contains("1. Cambia el Taskfile."), "{report}");
    assert!(report.contains("- `listar` cambia."), "{report}");
    assert!(!report.contains("Lo de la 0.30"), "{report}");
    assert!(!report.contains("Algo nuevo"), "only what breaks: {report}");
    let patch = &report[at("## [0.31.1]")..at("## [0.32.0]")];
    assert!(patch.contains("sin cambios incompatibles"), "{patch}");
}

#[test]
fn a_project_on_the_clis_version_has_nothing_to_update() {
    let report = update::report(&manifest("0.32"), "0.32.0", CHANGELOG).unwrap();

    assert!(report.contains("no hay nada que actualizar"), "{report}");
    assert!(!report.contains("## ["), "{report}");
}

#[test]
fn a_project_newer_than_the_cli_asks_to_update_the_cli_first() {
    let err = update::report(&manifest("0.33"), "0.32.0", CHANGELOG).unwrap_err();

    assert!(err.contains("actualiza antes la CLI"), "{err}");
}

#[test]
fn a_manifest_without_the_runtime_is_an_error() {
    let err = update::report("[workspace]\n", "0.32.0", CHANGELOG).unwrap_err();

    assert!(err.contains("puerto-nucleo"), "{err}");
}

#[test]
fn the_cli_carries_its_own_changelog() {
    assert!(
        update::CHANGELOG.contains(&format!("## [{}]", env!("CARGO_PKG_VERSION"))),
        "the CHANGELOG embedded in the CLI has no section for its version"
    );
}

#[test]
fn a_new_project_carries_the_skill_that_updates_it_and_its_agents_md_names_it() {
    let dir = temp_dir("update_skill");
    cleanup(&dir);
    fs::create_dir_all(&dir).unwrap();
    let output = generate_project("actualizar", &dir).unwrap();

    let skill =
        fs::read_to_string(output.join(".claude/skills/actualizar-puerto/SKILL.md")).unwrap();
    assert!(
        skill.starts_with("---\nname: actualizar-puerto\n"),
        "{skill}"
    );
    for step in [
        "puerto actualizar",
        "puerto generar bootstrap",
        "puerto validar",
        "task test",
        "task lint",
        "git diff",
    ] {
        assert!(skill.contains(step), "{step}\n{skill}");
    }
    let agents = fs::read_to_string(output.join("AGENTS.md")).unwrap();
    for command in [
        ".claude/skills/actualizar-puerto/SKILL.md",
        "puerto deshacer",
        "puerto generar --simular",
        "puerto validar --json",
    ] {
        assert!(agents.contains(command), "{command}");
    }
    cleanup(&dir);
}