PropertyDamage.Diagram (PropertyDamage v0.2.0)

View Source

Generate visual sequence diagrams from test executions.

Transforms command sequences and event logs into sequence diagrams in multiple formats for documentation, debugging, and visualization.

Supported Formats

  • :mermaid - Mermaid sequence diagrams (GitHub, GitLab, Notion compatible)
  • :plantuml - PlantUML sequence diagrams
  • :websequence - sequencediagram.org format

Usage

From a Failure Report

report = PropertyDamage.run(...) |> elem(1)
diagram = PropertyDamage.Diagram.from_failure_report(report, :mermaid)
IO.puts(diagram)

From a Sequence and Event Log

diagram = PropertyDamage.Diagram.generate(
  sequence,
  event_log,
  format: :plantuml,
  title: "Account Creation Flow",
  show_state: true
)

Example Output (Mermaid)

```mermaid
sequenceDiagram
    participant Test
    participant SUT
    participant State

    Test->>SUT: CreateAccount(name: "Alice")
    SUT-->>Test: AccountCreated(id: "acc_123")
    Test->>State: balance: 0

    Test->>SUT: Deposit(amount: 100)
    SUT-->>Test: DepositSucceeded(new_balance: 100)
    Test->>State: balance: 100

    Note over Test,SUT:  FAILURE at command 2
    Test-xSUT: Withdraw(amount: 200)
    Note right of SUT: NonNegativeBalance violated
```

Options

  • :title - Diagram title (default: "PropertyDamage Sequence")
  • :show_state - Include state changes (default: false)
  • :show_timestamps - Include timestamps (default: false)
  • :max_value_length - Truncate long values (default: 50)
  • :highlight_failure - Highlight failure point (default: true)
  • :show_branches - Show parallel branches (default: true)

Summary

Functions

Generate a sequence diagram from a failure report.

Generate a sequence diagram from a sequence and event log.

Generate diagrams in all supported formats.

Save a diagram to a file.

Types

format()

@type format() :: :mermaid | :plantuml | :websequence

options()

@type options() :: [
  title: String.t(),
  show_state: boolean(),
  show_timestamps: boolean(),
  max_value_length: pos_integer(),
  highlight_failure: boolean(),
  show_branches: boolean()
]

Functions

from_failure_report(report, format, opts \\ [])

@spec from_failure_report(PropertyDamage.FailureReport.t(), format(), options()) ::
  String.t()

Generate a sequence diagram from a failure report.

Parameters

  • report - A PropertyDamage.FailureReport struct
  • format - Output format (:mermaid, :plantuml, :websequence)
  • opts - Options (see module docs)

Returns

A string containing the diagram in the specified format.

generate(sequence, event_log, format, opts \\ [])

Generate a sequence diagram from a sequence and event log.

Parameters

  • sequence - A PropertyDamage.Sequence struct
  • event_log - List of PropertyDamage.EventLog.Entry structs
  • format - Output format (:mermaid, :plantuml, :websequence)
  • opts - Options (see module docs)

Returns

A string containing the diagram in the specified format.

generate_all(sequence, event_log, opts \\ [])

@spec generate_all(
  PropertyDamage.Sequence.t(),
  [PropertyDamage.EventLog.Entry.t()],
  options()
) :: %{
  required(format()) => String.t()
}

Generate diagrams in all supported formats.

Returns a map with format keys and diagram strings as values.

save(diagram, path, format)

@spec save(String.t(), Path.t(), format()) :: :ok | {:error, term()}

Save a diagram to a file.

Automatically adds the appropriate file extension if not present.