feat(server): load mocks from a file at startup (--init-mocks)#331
Merged
Conversation
Add --init-mocks / SMOCKER_INIT_MOCKS: a YAML file of mocks (the exact POST /mocks format) loaded into a fresh "init-mocks" session when the mocks service is constructed. Useful for declarative, ephemeral setups (e.g. a Kubernetes ConfigMap) where mocks should be present on boot without an API call. It's read-only (never written back) and mutually exclusive with --persistence-directory: seeding a fixed set and resuming/rewriting persisted state are opposite intents, so setting both fails fast at startup. Addresses #217 / #222. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The --init-mocks flag usage string and the mutual-exclusivity error message each exceeded the 150-char limit; split them across lines. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 19, 2026
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.
What
Add
--init-mocks/SMOCKER_INIT_MOCKS: a YAML file of mocks — the exactPOST /mocksformat — loaded into a freshinit-mockssession when the mocks service is constructed.This gives a declarative, dependency-free way to have mocks present on boot, without an init container or a post-start API call — handy in Kubernetes (mount a ConfigMap and point
--init-mocksat it).Design
--persistence-directory: seeding a fixed set and resuming/rewriting persisted state are opposite intents (both define the boot state → ambiguous on restart, and a read-only ConfigMap mount can't be written to anyway). Setting both fails fast at startup with a clear message.services.NewMocksalongside how persisted sessions are loaded.Verified
go build/go vet/go test ./server/...green; new unit tests cover the happy path (session name + count), a missing file, and an invalid mock.--init-mocksseeds aninit-mockssession and the mock server serves the loaded mocks;--init-mocks+--persistence-directoryrefuses to start; a missing/invalid file exits with a clear error.Follow-ups (not in this PR)
Addresses #217 and #222.
🤖 Generated with Claude Code