Repository navigation
fix(cli): load the event store, and wire replay to a real emulator (#855, #879) - #882
Merged
Merged
Conversation
, #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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NewEventStorebuilds a file backend eagerly "soLoadcan be called right away". Nothing incmd/ever called it, so three commands read the in-memory slice and reported nothing from a persistent backend:substrate replay <stream>failed atno events in streamfor every stream that has ever been recorded. The command could not succeed.substrate exportwrote 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 printedstream %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 bareno events in streamwas 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 noRegisterDefaultPlugins, so every event would have routed toServiceNotAvailableand been reported as failed. The state manager wasnil, which maderesetStatea no-op andcomputeStateHashreturn""— soStateValidwas vacuously true, a passing verdict produced by no comparison.newReplayEngineWiringbuilds both, in the ordernewServerCmdfixes. 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 inRunEfor the same reason asnewFaultControllerandnewCredentialWiring, and that reason is exactly why none of this was caught: aRunEclosure cannot be called from a test, and the one existing replay test asserts the command is non-nil and never invokesRunE.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
CreateStackagainst 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 aceoperation 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,StateValidandStateErrorsare printed; the last two are whatReplayResults' 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 withoutevent_store.include_bodiescannot be replayed at all, andSuccess: 0, Skipped: Nleft 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).StateValidstartstrueand is only ever falsified by a comparisonValidateStategates, 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:
StateManager(percfg.State)" — the "real" half ships; "percfg.State" is not implementable.StateCfghasBackend(one working value, since sqlite is deferred to feat: SQLite StateManager #2) andPath, andConfig.Statehas no reader that constructs anything — onlyDefaultConfigandValidatetouch it, and the server itself callsNewMemoryStateManager()unconditionally. Filed as Config.State is validated and then read by nothing; the state manager is hardcoded #881.ReplayConfigis populated from config" — there is noReplayfield onConfigand noReplayCfgtype, so it pulls inDefaultConfig,Validate, the docs and thesubstrate.yamlexample. That is new scope, not wiring. Filed as substrate replay builds a zero-value ReplayConfig and there is no config section to populate it #880.Compatibility
replay,exportanddebugnow 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.replayagainst a stream recorded withoutevent_store.include_bodiesnow 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 theLoadand confirming it fails for the intended reason, rather than trusted because it passes:newLoadedEventStoreloads 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.newReplayEngineWiringre-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,exportanddebugare driven throughrun(), so the assertions are on the output a user actually sees: the summary'sSkipped/Statelines, thenot checkedverdict, an error naming the backend and path, a three-record export, anddebuglistingsts/GetCallerIdentity.export's two empties are distinguished — a filter that matched nothing versus a store that holds nothing.eventStoreLocationandreplayStateSummary.cmd/substratecoverage goes 23.2% → 45.0%; total 83.3% → 83.4%.Closes #855
Closes #879