Skip to content

Conversation

cidrblock
Copy link
Contributor

@cidrblock cidrblock commented Aug 2, 2025

image

Summary

Introduces a new "Scenario recap" section to Molecule's report output that matches Ansible's play recap format. This enhancement provides users with a consolidated view of scenario execution results, displaying action counts and completion state statistics per scenario with conditional ANSI coloring.

Motivation

  • Improve user experience by providing familiar Ansible-style output formatting
  • Offer quick visual summary of test execution across multiple scenarios
  • Maintain consistency with Ansible tooling that users already know

Changes by File

src/molecule/reporting.py

  • Add scenario recap section to main report() function
  • Update headers to "DETAILS" and "SCENARIO RECAP" with 79-character padding
  • Integrate format_scenario_recap() call in report flow
  • Use original_stderr for proper stream handling

src/molecule/ansi_output.py

  • Add format_scenario_recap() method to AnsiOutput class
  • Implement Ansible-style formatting with 26-character scenario name padding
  • Apply conditional ANSI coloring (only when count > 0)
  • Generate state counts dynamically from SCENARIO_RECAP_STATE_ORDER constant
  • Support actions count display (actions=X) before completion states

src/molecule/constants.py

  • Add SCENARIO_RECAP_STATE_ORDER tuple for display order
  • Add COMPLETION_STATE_PRIORITY_ORDER tuple for state ranking
  • Add COMPLETION_STATE_COLORS mapping for consistent color application

tests/unit/test_reporting.py

  • Add comprehensive test coverage for format_scenario_recap() method
  • Test empty results, single/multiple scenarios, mixed states, and alignment
  • Verify conditional coloring behavior and proper state counting
  • Update existing report tests for new header format

tests/integration/test_command.py

  • Add normalize_report_whitespace() helper for robust test comparisons
  • Update test expectations for new "DETAILS" and "SCENARIO RECAP" headers
  • Improve error output with unified diff and character count reporting
  • Handle 79-character header padding in assertions

Output Example

DETAILS                                                                        
default ➜ create: Completed: Successful
test-scenario ➜ dependency: Completed: 2 missing (Remove from test_sequence to suppress)
test-scenario ➜ converge: Completed: Successful

SCENARIO RECAP                                                                 
default                   : actions=1  successful=1  disabled=0  skipped=0  missing=0  failed=0
test-scenario             : actions=9  successful=3  disabled=0  skipped=0  missing=7  failed=0

Testing

  • All unit tests pass with comprehensive coverage of new functionality
  • Integration tests pass in tox environment
  • Maintains backward compatibility with existing report output
  • No breaking changes to public APIs

- Add scenario recap section matching Ansible play recap format
- Include action counts and completion state statistics per scenario
- Apply conditional ANSI coloring following Molecule's theme
- Use 79-character padded headers for consistency
- Dynamically build state counts from SCENARIO_RECAP_STATE_ORDER constant
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new Ansible-style "Scenario Recap" section to Molecule's report output. The enhancement provides users with a consolidated summary of scenario execution results, displaying action counts and completion state statistics per scenario with conditional ANSI coloring.

  • Adds scenario recap functionality with Ansible-style formatting and coloring
  • Updates report headers from "Summary" to "DETAILS" and adds "SCENARIO RECAP" section
  • Refactors completion state constants for consistency and reusability

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/molecule/reporting.py Updates main report function with new header format and integrates scenario recap
src/molecule/ansi_output.py Implements format_scenario_recap() method with Ansible-style formatting and conditional coloring
src/molecule/constants.py Adds new constants for scenario recap state ordering and completion state colors
tests/unit/test_reporting.py Adds comprehensive test coverage for scenario recap functionality
tests/integration/test_command.py Updates integration tests for new report format with helper functions
.config/dictionary.txt Updates spell check dictionary with new test-related terms

@cidrblock
Copy link
Contributor Author

I'm going to merge this, it just an addition to the UI. The next PR is gonna change the output again and assert against it.

Reporting is still an opt in experimental feature so there should no impact to the logic and flow.

If concerned LMK

@cidrblock cidrblock merged commit 183fb36 into ansible:main Aug 2, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant