Skip to content

fix(cli): load the event store, and wire replay to a real emulator (#855, #879) - #882

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/855-879-cli-loads-the-event-store
Sep 15, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/855-879-cli-loads-the-event-store

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

NewEventStore builds a file backend eagerly "so Load can be called right away". Nothing in cmd/ ever called it, so three commands read the in-memory slice and reported nothing from a persistent backend:

  • substrate replay <stream> failed at no events in stream for every stream that has ever been recorded. The command could not succeed.
  • substrate export wrote a valid, empty NDJSON or CSV document with exit status 0 — and on the default --output -, printed nothing at all to say so. A user exporting a recorded run as a regression fixture, one of the documented reasons the event log exists, got an empty file and no indication anything was wrong.
  • substrate debug <stream> loaded the config, discarded it (_ = cfg // used for future persistence options), hardcoded a memory backend, and therefore always printed stream %q contains no events — under help text promising to list them. No configuration and no argument made it print an event.

All three now go through one newLoadedEventStore, so they cannot drift apart again. A command that finds nothing names the backend and the path it looked in and says what the store does hold: the bare no events in stream was true and useless, because the two overwhelmingly likely causes are a memory backend — which cannot hold anything across two processes, and is the shipped default — and a persist path that is not the one the recording was written to, and neither is visible without naming them.

replay was wired to nothing

Even with a loaded stream, the engine would have verified nothing. The registry was NewPluginRegistry() with no RegisterDefaultPlugins, so every event would have routed to ServiceNotAvailable and been reported as failed. The state manager was nil, which made resetState a no-op and computeStateHash return "" — so StateValid was vacuously true, a passing verdict produced by no comparison.

newReplayEngineWiring builds both, in the order newServerCmd fixes. The one real ordering constraint: the auth controller is constructed before the plugins, because CloudFormation takes it — a stack's resource calls are dispatched in process rather than through the server, so they are authorized by the controller the plugin holds. It is a function rather than inline in RunE for the same reason as newFaultController and newCredentialWiring, and that reason is exactly why none of this was caught: a RunE closure cannot be called from a test, and the one existing replay test asserts the command is non-nil and never invokes RunE.

The plugins get a recording-disabled store, not the one being replayed. Wiring a real registry introduces a hazard the empty one did not have: the CloudFormation deployer records its in-process resource calls, so replaying one CreateStack against the loaded store would append events that never happened in the recorded run — and with a file backend the automatic flush would write them into the recording, so the next replay of the same stream would read a longer stream. A replay must not write to the log it is reading. A disabled store is what the CloudFormation plugin itself falls back to when none is supplied. The cost, recorded rather than traded away: the one plugin that reads the log — Cost Explorer — sees an empty store on replay, so a ce operation replays against no cost history. That is a fidelity gap in one service, against corrupting the event log in every stack replay.

The summary reports the verdict

Skipped, StateValid and StateErrors are printed; the last two are what ReplayResults' own doc comment names as the verdict, and all three were omitted. It also says explicitly when every event was skipped for want of a recorded request — a stream recorded without event_store.include_bodies cannot be replayed at all, and Success: 0, Skipped: N left the reader to work that out.

State is reported as "not checked" rather than "valid" when validation never ran, which is the only setting reachable until a replay: config section exists (#880). StateValid starts true and is only ever falsified by a comparison ValidateState gates, so printing it as "valid" would be this release's own defect in the release's own output: a value that did not come from where it appears to.

Two of #855's criteria were reversed with citations, not implemented

Recorded on the issue before this PR:

Compatibility

replay, export and debug now report what a persistent backend holds instead of nothing, so a script that treated an empty export as "no events recorded" will start seeing data. replay against a stream recorded without event_store.include_bodies now says every event was skipped rather than reporting a success count; that was always the truth of the run. The replay summary gained three lines, so anything parsing its stdout by line position should be checked.

Tests

New cmd/substrate/replay_wiring_test.go — eight tests, all through a file backend, because with the memory backend none of these defects is visible. Each was mutation-verified by removing the Load and confirming it fails for the intended reason, rather than trusted because it passes:

  • newLoadedEventStore loads what the backend holds, with the defect kept as a precondition assertion — a store built the way the three commands built it reports zero events for a stream sitting on disk.
  • newReplayEngineWiring re-executes a non-zero number of events from a file-backed stream (substrate replay wires an empty registry, a nil state manager, and never loads the events #855's central criterion), and does not write to the stream it replays — asserted both in the store and against the NDJSON on disk.
  • replay, export and debug are driven through run(), so the assertions are on the output a user actually sees: the summary's Skipped/State lines, the not checked verdict, an error naming the backend and path, a three-record export, and debug listing sts/GetCallerIdentity.
  • export's two empties are distinguished — a filter that matched nothing versus a store that holds nothing.
  • Table tests for eventStoreLocation and replayStateSummary.

cmd/substrate coverage goes 23.2% → 45.0%; total 83.3% → 83.4%.

Closes #855
Closes #879

, #879)

Nothing in cmd/ ever called EventStore.Load. NewEventStore builds a file backend
eagerly "so Load can be called right away", and three commands read the
in-memory slice instead: replay failed at "no events in stream" for every stream
ever recorded, export wrote an empty document with exit status 0 and — on the
default --output - — no stderr line at all, and debug hardcoded a memory backend
next to a discarded config, so it always printed "contains no events" under help
text promising to list them.

The three now share newLoadedEventStore, so they cannot drift apart again, and a
command that finds nothing names the backend and the path it looked in rather
than answering with a bare stream ID.

replay was additionally wired to nothing: an empty PluginRegistry, so every
event would route to ServiceNotAvailable, and a nil StateManager, which made
resetState a no-op and computeStateHash return "" — so StateValid was vacuously
true. newReplayEngineWiring builds a populated registry and a real state manager
in the order newServerCmd fixes, with authCtrl before the plugins because
CloudFormation takes it.

The plugins get a recording-disabled store rather than the one being replayed. A
replay must not write to the log it is reading: the CloudFormation deployer
records its in-process resource calls, so replaying one CreateStack would append
events that never happened in the recorded run, and the automatic flush would put
them in the recording.

The summary now prints Skipped, StateValid and StateErrors — the two fields
ReplayResults' own doc comment names as the verdict — and says so explicitly when
every event was skipped for want of a recorded request. State is reported as "not
checked" rather than "valid" when validation never ran, since StateValid starts
true and is only ever falsified by a comparison ValidateState gates.

Closes #855
Closes #879
@scttfrdmn scttfrdmn added this to the v0.116.0 milestone Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.13043% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/substrate/main.go 89.13% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit bd1dca7 into main Sep 15, 2026
14 checks passed
@scttfrdmn
scttfrdmn deleted the feat/855-879-cli-loads-the-event-store branch September 15, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant