puerto 0.31.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.
use crate::commands::list::{require_puerto_project, run_list};
use crate::commands::new::extract_template;
use crate::commands::validate;
use crate::generators::conflict::OverwritePolicy;
use crate::puerto_toml::ValueObjectDefinition;
use crate::{puerto_toml, scaffold, snippets};
use cargo_generate::{GenerateArgs, TemplatePath, Vcs, generate};
use std::fs;
use std::path::{Path, PathBuf};

fn temp_dir(name: &str) -> PathBuf {
    std::env::temp_dir().join(format!("puerto_test_{name}"))
}

fn cleanup(path: &Path) {
    let _ = fs::remove_dir_all(path);
}

fn generate_project(name: &str, destination: &Path) -> Result<PathBuf, Box<dyn std::error::Error>> {
    let tmp = extract_template()?;

    let args = GenerateArgs {
        template_path: TemplatePath {
            path: Some(tmp.path().to_string_lossy().into_owned()),
            ..Default::default()
        },
        name: Some(name.to_string()),
        destination: Some(destination.to_path_buf()),
        vcs: Some(Vcs::None),
        no_workspace: true,
        ..Default::default()
    };

    let output_dir = generate(args)?;
    drop(tmp);
    Ok(output_dir)
}

/// Task in `output`. Arch and Fedora package it as `go-task` (`task` is Taskwarrior there);
/// devenv and the rest, as `task`.
fn task_command(output: &Path) -> std::process::Command {
    let bin = ["go-task", "task"]
        .into_iter()
        .find(|bin| {
            std::process::Command::new(bin)
                .arg("--version")
                .output()
                .is_ok_and(|o| o.status.success())
        })
        .expect("Task (go-task or task) is not on the PATH");
    let mut command = std::process::Command::new(bin);
    // Task colours its output when `CI` is set (GitHub Actions sets it): the tests read plain text.
    command
        .current_dir(output)
        .env("NO_COLOR", "1")
        .stdin(std::process::Stdio::null());
    command
}

/// (exit success, stdout + stderr).
fn output_of(mut command: std::process::Command) -> (bool, String) {
    let out = command.output().unwrap();
    let text = format!(
        "{}{}",
        String::from_utf8_lossy(&out.stdout),
        String::from_utf8_lossy(&out.stderr)
    );
    (out.status.success(), text)
}

/// The generated wiring of a project: `presentacion/cableado/src/lib.rs` (repositories), each
/// context's `casos.rs` (its use cases, Fase 33.2), then `presentacion/api/src/generado/bootstrap.rs`
/// (the APIs on them).
fn wiring(base: &Path) -> String {
    let read = |rel: &str| fs::read_to_string(base.join(rel)).unwrap_or_default();
    let mut contexts: Vec<PathBuf> = fs::read_dir(base.join("presentacion/cableado/src"))
        .into_iter()
        .flatten()
        .flatten()
        .map(|e| e.path().join("casos.rs"))
        .filter(|p| p.exists())
        .collect();
    contexts.sort();
    let casos: String = contexts
        .iter()
        .map(|p| fs::read_to_string(p).unwrap_or_default())
        .collect();
    format!(
        "{}\n{casos}\n{}",
        read("presentacion/cableado/src/lib.rs"),
        read("presentacion/api/src/generado/bootstrap.rs")
    )
}

mod aforo_gaps;
mod auth;
mod auth_e2e;
mod bootstrap_gen;
mod canasta_gaps;
mod cli_surface;
mod compile_matrix;
mod composite_value_objects;
mod conventions;
mod domain_events;
mod extension;
mod field_args;
mod generated_output;
mod ide_snippets;
mod inmemory_repository;
mod layered_generators;
mod mail;
mod mail_e2e;
mod manifest_validation;
mod migrations;
mod new_project;
mod owner;
mod paged_lists;
mod patchers;
mod references;
mod repository_errors;
mod runtime_crates;
mod scaffolding;
mod server_fields;
mod startup_errors;
mod taskfile;
mod transitions;
mod tui;
mod typed_fields;
mod typed_ids;
mod use_cases;
mod user_references;
mod value_objects;
mod walkthrough_fixes;
mod web_blocks;
mod web_slice;
mod worker;
mod worker_e2e;

// Helpers shared across the test modules. Each lives next to the tests that introduced it.
use compile_matrix::{assert_generated_project_is_clean, scenario_workspace, test_database_server};
use new_project::new_project_non_interactive;
use scaffolding::{scaffold_test_field, setup_puerto_stubs, setup_puerto_stubs_with_project_db};
use use_cases::setup_use_case_stubs;