<!-- https://tinyactors.dev/cli/commands/diff/ -->
# tinyactors diff

Kind: reference. For: [Workflow developer who tests](https://tinyactors.dev/audiences/workflow-tester.xml), [Agent-platform engineer](https://tinyactors.dev/audiences/agent-platform.xml).
Voice: [Reference](https://tinyactors.dev/voices/reference.xml).

> Compare two versions and show what changes for running actors.

Compare two versions and show what changes for running actors.

<a id="usage"></a>

## Usage

```shell
tinyactors diff [options] OLD NEW
```

Compares two images chart by chart, matching charts by name. Each version is an image, a system manifest or one chart. Compares data by id, states by id and transitions by source and events. Compares invokes, executable content as decoded instructions and the events each state handles. Marks each change as breaking for actors running the old version, or as a change of behaviour. A state removed, moved or of another kind is breaking. So are data removed, another datamodel and an event a state no longer handles. The answer says what a migration does to running actors.

<a id="options"></a>

## Options

- **`-W, --warnings-as-errors`**: Refuse a chart that compiles with a warning.
- **`-I, --include DIR`**: Search `DIR` for a src that is not beside the file naming it, in the order given. Repeatable.
- **`-c, --chart NAME`**: Look at the chart named `NAME` only. Repeatable.
- **`-s, --segment N`**: Read the image that segment N of a snapshot runs. Default: the newest live segment.
- **`--exit-code`**: Exit with 1 when the two differ, as git diff `--exit-code` does; with `--breaking`, when a change breaks running actors.
- **`--breaking`**: List only the changes that break actors running the old version.
- **`--all`**: List the charts that did not change too.

Configure output formats like `-f json` using the [shared options on the command reference](https://tinyactors.dev/cli/commands/index.md#program-options).

<a id="examples"></a>

## Examples

```shell
tinyactors diff order-v1.tai order-v2.scxml
```

```text title="output"
# Diff

## Old

- **Path**: order-v1.tai
- **Hash**: 7264231f9a5f18b3
- **Charts**: 1

## New

- **Path**: order-v2.scxml
- **Hash**: fbce6399f9cf5b5b
- **Charts**: 1

- **Identical**: no

## Summary

- **Charts added**: 0
- **Charts removed**: 0
- **Charts changed**: 1
- **Charts unchanged**: 0
- **Differences**: 17
- **Breaking**: 0

## Charts

### Chart 1: order

- **Name**: order
- **Change**: changed
- **Datamodel**: ecmascript
- **Binding**: early

#### States

| State | Change | Breaking | Before | After |
| --- | --- | --- | --- | --- |
| paying | onentry changed, onexit changed | no | atomic in /scxml | atomic in /scxml |
| refunded | added | no |  | final in /scxml |
| cancelled | added | no |  | final in /scxml |

#### Transitions

| Source | Events | Change | Breaking | Before | After |
| --- | --- | --- | --- | --- | --- |
| open | checkout | condition changed | no | → paying (external) | cond `total > 0` → paying (external) |
| paying | charge.declined | removed | no | → open (external) |  |
| open | cancel | added | no |  | → cancelled (external) |
| paying | charge.declined error.communication payment.timeout | added | no |  | cond `attempts < 3` → paying (external) |
| paying | charge.declined error.communication payment.timeout | added | no |  | → cancelled (external) |
| paid | refund | added | no |  | → refunded (external) |

#### Data

| ID | Change | Breaking | Before | After |
| --- | --- | --- | --- | --- |
| attempts | added | no |  | `0` in /scxml |
| refund | added | no |  | `null` in /scxml |

#### Actions

| Where | Change | Before | After |
| --- | --- | --- | --- |
| onentry paying | changed | send event charge to charges type payments id pay with amount=`total` | assign `attempts` = `attempts + 1`; send event charge to charges type payments id pay with amount=`total`; send event payment.timeout to itself id deadline after 30s |
| onexit paying | added |  | cancel deadline |

#### Invokes

_none_

#### Events

| State | Event | Change |
| --- | --- | --- |
| open | cancel | newly handled |
| paying | error.communication | newly handled |
| paying | payment.timeout | newly handled |
| paid | refund | newly handled |

## Events added

- cancel
- error.communication
- payment.timeout
- refund

## Events removed

_none_
```

Compare an image with a newer version of its chart.

```shell
tinyactors diff --breaking --exit-code deployed.tai order.scxml
```

```text title="output"
# Diff

## Old

- **Path**: deployed.tai
- **Hash**: 7264231f9a5f18b3
- **Charts**: 1

## New

- **Path**: order.scxml
- **Hash**: 5e66ab57693504aa
- **Charts**: 1

- **Identical**: no

## Summary

- **Charts added**: 0
- **Charts removed**: 0
- **Charts changed**: 1
- **Charts unchanged**: 0
- **Differences**: 13
- **Breaking**: 0

## Charts

_none_

## Events added

- cancel
- error.communication
- payment.timeout

## Events removed

_none_
```

Fail if a change breaks running actors.

```shell
tinyactors diff -f json --chart order old.tai new.tai
```

```text title="output"
{
  "old": {
    "path": "old.tai",
    "hash": "7264231f9a5f18b3",
    "charts": 1
  },
  "new": {
    "path": "new.tai",
    "hash": "5e66ab57693504aa",
    "charts": 1
  },
  "identical": false,
  "summary": {
    "chartsAdded": 0,
    "chartsRemoved": 0,
    "chartsChanged": 1,
    "chartsUnchanged": 0,
    "differences": 13,
    "breaking": 0
  },
  "charts": [
    {
      "name": "order",
      "change": "changed",
      "datamodel": "ecmascript",
      "binding": "early",
      "states": [
        {
          "state": "paying",
          "change": "onentry changed, onexit changed",
          "breaking": false,
          "before": "atomic in /scxml",
          "after": "atomic in /scxml"
        },
        {
          "state": "cancelled",
          "change": "added",
          "breaking": false,
          "before": "",
          "after": "final in /scxml"
        }
      ],
      "transitions": [
        {
          "source": "open",
          "events": "checkout",
          "change": "condition changed",
          "breaking": false,
          "before": "→ paying (external)",
          "after": "cond `total > 0` → paying (external)"
        },
        {
          "source": "paying",
          "events": "charge.declined",
          "change": "removed",
          "breaking": false,
          "before": "→ open (external)",
          "after": ""
        },
        {
          "source": "open",
          "events": "cancel",
          "change": "added",
          "breaking": false,
          "before": "",
          "after": "→ cancelled (external)"
        },
        {
          "source": "paying",
          "events": "charge.declined error.communication payment.timeout",
          "change": "added",
          "breaking": false,
          "before": "",
          "after": "cond `attempts < 3` → paying (external)"
        },
        {
          "source": "paying",
          "events": "charge.declined error.communication payment.timeout",
          "change": "added",
          "breaking": false,
          "before": "",
          "after": "→ cancelled (external)"
        }
      ],
      "data": [
        {
          "id": "attempts",
          "change": "added",
          "breaking": false,
          "before": "",
          "after": "`0` in /scxml"
        }
      ],
      "actions": [
        {
          "where": "onentry paying",
          "change": "changed",
          "before": "send event charge to charges type payments id pay with amount=`total`",
          "after": "assign `attempts` = `attempts + 1`; send event charge to charges type payments id pay with amount=`total`; send event payment.timeout to itself id deadline after 30s"
        },
        {
          "where": "onexit paying",
          "change": "added",
          "before": "",
          "after": "cancel deadline"
        }
      ],
      "invokes": [],
      "events": [
        {
          "state": "open",
          "event": "cancel",
          "change": "newly handled"
        },
        {
          "state": "paying",
          "event": "error.communication",
          "change": "newly handled"
        },
        {
          "state": "paying",
          "event": "payment.timeout",
          "change": "newly handled"
        }
      ]
    }
  ],
  "eventsAdded": [
    "cancel",
    "error.communication",
    "payment.timeout"
  ],
  "eventsRemoved": []
}
```

Compare one chart of two images as JSON.

<a id="exit-status"></a>

## Exit status

- **`1`**: An input is refused: it does not compile or verify, or it is damaged or of an unknown format.
- **`1`**: With `--exit-code`, the two versions differ; with `--breaking` too, a change breaks running actors.
- **`3`**: A file cannot be read or written, or memory runs out.

<a id="see"></a>

## Related pages

- [CI checks](https://tinyactors.dev/cli/guides/ci/index.md)

## Commands

- [tinyactors compile](https://tinyactors.dev/cli/commands/compile/)
- [tinyactors check](https://tinyactors.dev/cli/commands/check/)
- [tinyactors inspect](https://tinyactors.dev/cli/commands/inspect/)
- [tinyactors states](https://tinyactors.dev/cli/commands/states/)
- [tinyactors transitions](https://tinyactors.dev/cli/commands/transitions/)
- [tinyactors events](https://tinyactors.dev/cli/commands/events/)
- [tinyactors data](https://tinyactors.dev/cli/commands/data/)
- [tinyactors expressions](https://tinyactors.dev/cli/commands/expressions/)
- [tinyactors disassemble](https://tinyactors.dev/cli/commands/disassemble/)
- [tinyactors graph](https://tinyactors.dev/cli/commands/graph/)
- [tinyactors diff](https://tinyactors.dev/cli/commands/diff/)
- [tinyactors lint](https://tinyactors.dev/cli/commands/lint/)
- [tinyactors path](https://tinyactors.dev/cli/commands/path/)
- [tinyactors fmt](https://tinyactors.dev/cli/commands/fmt/)
- [tinyactors actors](https://tinyactors.dev/cli/commands/actors/)
- [tinyactors run](https://tinyactors.dev/cli/commands/run/)
- [tinyactors help](https://tinyactors.dev/cli/commands/help/)
- [tinyactors version](https://tinyactors.dev/cli/commands/version/)
