Skip to content

Add JSON output to test command #380

Closed

Description

@josecelano

Overview

Add JSON output format support to the test command (roadmap task 12.8). 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 test command currently only outputs human-readable text progress messages and DNS warnings. This task adds a machine-readable JSON alternative that automation workflows, CI/CD pipelines, and AI agents can parse programmatically.

Key difference from other commands: The test command does not transition environment state. It loads the current environment (any state), validates running services, and returns a TestResult containing pass/fail status and advisory DNS warnings. The JSON output schema reflects this test-result nature rather than the environment-state pattern used by other commands.

Specification

See detailed specification: docs/issues/380-add-json-output-to-test-command.md

🏗️ Architecture Requirements

DDD Layer: Presentation
Module Path: src/presentation/views/commands/test/
Pattern: Strategy Pattern for rendering

Module Structure Requirements

Architectural Constraints

  • No business logic in presentation layer
  • Error handling follows project conventions (see docs/contributing/error-handling.md)
  • Testing strategy aligns with layer responsibilities

Anti-Patterns to Avoid

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

Implementation Plan

Step 1: Create View Module Structure

  • Create src/presentation/views/commands/test/ with mod.rs, view_data/, views/

Step 2: Extend TestResult (Application Layer)

  • Add instance_ip: IpAddr field to TestResult
  • Update constructors and existing tests

Step 3: Implement DTO

  • Implement TestResultData and DnsWarningData structs
  • Implement TestResultData::new() constructor

Step 4: Implement Views

  • Implement JsonView::render() with inline error handling
  • Implement TextView::render() with formatted text output

Step 5: Update Controller

  • Add output_format: OutputFormat parameter to execute()
  • Update fixture_infrastructure() to return TestResult
  • Implement Strategy Pattern in complete_workflow()

Step 6: Update Router

  • Pass output_format from context to controller

Step 7: Add Tests

  • Unit tests for DTO, JsonView, and TextView

Step 8: Documentation

  • Update docs/user-guide/commands/test.md with JSON output examples
  • Correct existing inaccuracies in user docs (test categories, state validation, exit codes, execution flow don't match actual implementation)

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:

  • test command accepts --output-format json flag
  • JSON output includes environment_name, instance_ip, result, and dns_warnings fields
  • dns_warnings array correctly serializes warning details (domain, expected_ip, issue)
  • Text output preserves current UX behavior
  • Unit tests cover DTO conversion, JsonView, and TextView (with and without DNS warnings)
  • User documentation updated and corrected

Related

Activity

  1. self-assigned this
    on Feb 23, 2026
  2. added 5 commits that reference this issue on Feb 23, 2026
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