Repository navigation
Description
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
- Follow DDD layer separation (see docs/codebase-architecture.md)
- Respect dependency flow rules (dependencies flow toward domain)
- Use appropriate module organization (see docs/contributing/module-organization.md)
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 ofUserOutput
Implementation Plan
Step 1: Create View Module Structure
- Create
src/presentation/views/commands/test/withmod.rs,view_data/,views/
Step 2: Extend TestResult (Application Layer)
- Add
instance_ip: IpAddrfield toTestResult - Update constructors and existing tests
Step 3: Implement DTO
- Implement
TestResultDataandDnsWarningDatastructs - 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: OutputFormatparameter toexecute() - Update
fixture_infrastructure()to returnTestResult - Implement Strategy Pattern in
complete_workflow()
Step 6: Update Router
- Pass
output_formatfrom context to controller
Step 7: Add Tests
- Unit tests for DTO, JsonView, and TextView
Step 8: Documentation
- Update
docs/user-guide/commands/test.mdwith 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:
-
testcommand accepts--output-format jsonflag - JSON output includes
environment_name,instance_ip,result, anddns_warningsfields -
dns_warningsarray 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
- Parent: EPIC: Add JSON output format support #348 (EPIC: Add JSON output format support)
- Roadmap: Roadmap #1 (Project Roadmap)
- Specification: docs/issues/380-add-json-output-to-test-command.md
Activity
docs: add issue specification for #380
feat: [#380] add JSON output support to test command
docs: [#380] update spec progress and rewrite test command user docs
feat: [#380] add JSON output support to test command
docs: [#380] update spec progress and rewrite test command user docs
docs: mark 12.8 and 12.9 as completed in roadmap
docs: mark roadmap 12.14 completed and remove closed issue docs