thoughtworks/pacto — pull request #132 by maxlinc (2014-07-03 19:35:30+00:00)
Title: Stenographer logging and playback

Details from the WIP README for upcoming v0.4.0

### The Stenographer

The stenographer keeps a short-hand record of everything that happens in the courtroom. These logs can be used for troubleshooting, creating reports, or re-enacting the courtroom activities at a later date (and with different [actors](#actors).

The stenographer's logs are similar to HTTP access logs in this respect, but in a format that's more compact and suited to Pacto. A typical HTTP access log might look like this:

```
#Fields: date time c-ip cs-username s-ip s-port cs-method cs-uri-stem cs-uri-query sc-status cs(User-Agent)
2014-07-01 17:42:15 127.0.0.1 - 127.0.0.1 80 PUT /store/album/123/cover_art - 201 curl/7.30.0
2014-07-01 17:42:18 127.0.0.1 - 127.0.0.1 80 GET /store/album/123/cover_art size=small 200 curl/7.30.0
```

If Pacto has the following services registered:
![routes.png](https://draftin.com:443/images/16800?token=8Z2bmsbxOQ74ogeeWTXBwyvVaJ0YBfNJCfQTHa08L3AnvQXsnIf40htwMVudSIugAmpeJp8MD53mN7FPzfgqG9o)

Then it can match those requests to request and generate a stenographer log that looks like this:
```ruby
request 'Upload Album Art', values: {album_id: '123'}, response: {status: 201} # no contract violations
request 'Download Album Art', values: {album_id: '123', size: 'small'}, response: {status: 200} # no contract violations
```

This log file is designed so Pacto it can be used by Pacto to simulate the requests:
```ruby
Pacto.simulate_consumer :my_client do
request 'Upload Album Art', values: {album_id: '123'}, response: {status: 201} # no contract violations
request 'Download Album Art', values: {album_id: '123', size: 'small'}, response: {status: 200} # no contract violations
end
```

Since Pacto has added a layer of abstraction you can experiment with changes to the contracts (including routing) without needing to re-record the interactions with the stenographer. For example Pacto will adjust if you change the route from:
![original_put.png](https://draftin.com:443/images/16801?token=6yI7VugUqaLJAMpMvf4oAlPucfQBnfdrdcGpcCuUFET_FH5E0ZreFIrL1C7U2GwRuNndntc9OTIXLD-B2wbkiyg)
to
![new_put.png](https://draftin.com:443/images/16802?token=IagQX2ggHIaaCfRGhR5q85cK9oNN6OgFX2yc9aT0CTZkGzxUMXB1nR40mwIYRat7dUeWPOmLebNOHWXOKlpe-iU)