Skip to content

Add JSON output to validate command (12.10) #390

Closed

Description

@josecelano

Overview

Add JSON output format support to the validate command (roadmap task 12.10). This is part of Phase 2 of the JSON output epic (#348), which aims to implement JSON output for all remaining commands so that JSON can eventually become the default output format.

The validate command currently only outputs human-readable text progress messages and a validation summary. This task adds a machine-readable JSON alternative that automation workflows, CI/CD pipelines, and AI agents can parse programmatically.

Key characteristic: The validate command takes an --env-file <PATH> argument and performs validation without creating any deployment state. Its output reflects configuration properties extracted from the file — environment name, provider, and enabled feature flags (Prometheus, Grafana, HTTPS, backup). There is no domain Environment state object involved — the DTO is built directly from ValidationResult.

Specification

See detailed specification: docs/issues/390-add-json-output-to-validate-command.md

🏗️ Architecture Requirements

DDD Layer: Presentation
Module Path: src/presentation/cli/views/commands/validate/
Pattern: Strategy Pattern for rendering (same as provision, create, show, run, list, configure, release, test, destroy)

Module Structure Requirements

  • Follow the existing view module structure established in destroy/ (has view_data/)
  • ValidateDetailsData is a plain presentation DTO deriving Serialize, PartialEq (not Deserialize) with a named constructor from_result(&Path, &ValidationResult)
  • JsonView::render() returns String — serialization errors handled inline via unwrap_or_else
  • TextView::render() formats the same data as human-readable text and also returns String

Architectural Constraints

  • No business logic in presentation layer — only rendering
  • Error handling follows project conventions
  • Output must go through UserOutput methods — never println! or eprintln! directly
  • The ValidateDetailsData DTO must derive serde::Serialize (output-only — no Deserialize needed)

Anti-Patterns to Avoid

  • ❌ Mixing rendering concerns in the controller
  • ❌ Adding business logic to view structs
  • ❌ Using println!/eprintln! instead of UserOutput

Implementation Plan

Phase 1: View Module

  • Create src/presentation/cli/views/commands/validate/mod.rs
  • Implement ValidateDetailsData DTO with from_result() constructor in view_data/validate_details.rs
  • Implement JsonView::render() in views/json_view.rs
  • Implement TextView::render() in views/text_view.rs
  • Register validate in src/presentation/cli/views/commands/mod.rs

Phase 2: Controller + Router

  • Add output_format: OutputFormat parameter to ValidateCommandController::execute()
  • Refactor complete_workflow() to accept and dispatch on output_format
  • Update router to pass output_format from context to controller

Phase 3: Tests + Manual Verification + Docs

  • Unit tests for JsonView::render()
  • Unit tests for TextView::render()
  • Manual verification: run cargo run -- validate --env-file envs/lxd-local-example.json and confirm text output is unchanged
  • Manual verification: run cargo run -- validate --env-file envs/lxd-local-example.json --output-format json 2>/dev/null and confirm JSON output matches spec
  • Update docs/user-guide/commands/validate.md with JSON output examples

Acceptance Criteria

Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.

Quality Checks:

  • Pre-commit checks pass: ./scripts/pre-commit.sh

Task-Specific Criteria:

  • validate --output-format json outputs valid JSON with all expected fields
  • validate --output-format text (default) produces human-readable output identical to current output
  • Unit tests cover both view renderers
  • Documentation updated with JSON output examples

Related

  • Parent: EPIC: Add JSON output format support #348 (EPIC: Add JSON output format support)
  • Roadmap: section 12.10
  • Reference implementation (destroy): src/presentation/cli/views/commands/destroy/
  • Reference implementation (test): src/presentation/cli/views/commands/test/

Activity

  1. self-assigned this
    on Feb 26, 2026
  2. added 2 commits that reference this issue on Feb 26, 2026
    fd60f63
    192b5ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions