feat: add stateful/sequential mocks - #129
Open
MaxMichel2 wants to merge 1 commit into
Open
MaxMichel2 wants to merge 1 commit into
MaxMichel2 wants to merge 1 commit into
Conversation
Adds a Sequence operation state that advances through an ordered list of responses one step per matched request, sticking on the last step once exhausted. Fills the most common manual-testing gap static mocks can't: polling flows (order status, upload progress, async job completion) where the interesting behavior is the transition across repeated calls, not any single response. - OperationMockState.Sequence(responses: List<Mock>, currentIndex: Int): the position is persisted as part of this same state rather than a separate DataStore key/counter - simpler than the originally-proposed design, and it means resetting an operation to Network (or resetting all mocks) already discards the position along with everything else, with zero special-casing in the existing reset paths. - NetworkMockPlugin: a new Sequence branch that serves the current step, then persists the advanced (or exhaustion-clamped) index back through the state repository before returning. Shares response-loading logic with the Mock branch via a new buildMockCall helper. The probabilistic x-devview.failureRate roll (see #95) applies to Sequence the same way it does to Mock. - UI: a "SEQUENCE" section in the operation picker page. Building one is a page-level mode (not a new icon on every response row): "Build a Sequence" toggles tapping responses to append-to-sequence instead of select-immediately; "Save Sequence" commits (2+ steps required), "Cancel" discards. An active sequence shows its current step and a "Reset Position" action. Reordering is by clearing and rebuilding rather than drag handles - a deliberate v1 scope cut, not a gap in what's needed yet. Breaking (fine during 0.2.0 alphas): OperationMockState gains another new sealed subtype - the same exhaustive-when sites touched for Failure (EndpointCard, EndpointStateChip, the operation sheet, ModelUtils, the Mocked/Network list filter) needed a Sequence branch too. Closes #96. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MaxMichel2
force-pushed
the
feat/networkmock-sequential-mocks
branch
from
September 22, 2026 12:51
88775d1 to
a9e2d10
Compare
This branch has not been deployed
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.
Summary
Closes #96.
Stacked on #128 (PR chain: #123 → #124 → #127 → #128 → this) — merge in order.
Adds sequential/stateful mocks: an operation can advance through an ordered list of responses one step per matched request, sticking on the last step once exhausted. Fills the most common manual-testing gap static mocks can't — polling flows (order status, upload progress, async job completion) where the interesting behavior is the transition across repeated calls.
Design deviation from the issue's proposed shape
The issue suggested persisting the sequence position as a separate DataStore counter, keyed by
OperationKey, alongside the existingSequencestate. I went with a simpler design:currentIndexlives insideOperationMockState.Sequenceitself (matching the issue's own alternate suggestion,Sequence(responses, currentIndex)), not a second persisted key.This is strictly simpler and gets the reset requirement for free:
MockStateRepository.resetKnownOperationsToNetwork()andNetworkMockState.resetAllToNetwork()already replace the entireOperationMockStatevalue withNetwork— with position embedded in the same object, it's discarded automatically. A separate counter key would need explicit clearing in both reset paths, which is exactly the trap the issue itself calls out.What changed
OperationMockState.Sequence(responses: List<Mock>, currentIndex: Int = 0): a new sealed-interface variant.currentResponse: Mock?safely indexes the current step.NetworkMockPlugin: a newSequencebranch — serves the current step, then persists the advanced (exhaustion-clamped) index viastateRepository.setOperationMockStatebefore returning. Shares response-loading with theMockbranch via a newbuildMockCallhelper (reduces duplication rather than copy-pasting the try/catch). Thex-devview.failureRateprobabilistic roll from feat: probabilistic failure-rate injection #95 applies toSequencethe same way it does toMock."200 - default (2/3)") and offers "Reset Position".NetworkMockViewModelgainssetOperationSequenceState(key, responses)andresetOperationSequencePosition(key).Public API (breaking, per your call on 0.2.0 alphas)
OperationMockStategains another sealed subtype — the same exhaustive-whensites touched forFailurein #128 (EndpointCard,EndpointStateChip, the operation sheet's selected-response lookup,ModelUtils' icon/color extensions,NetworkMockScreen's Mocked/Network filter) needed aSequencebranch too (folded into "Mocked", same reasoning asFailure).api.txtregenerated fordevview-networkmock-coreanddevview-networkmock.Tests
MockStateRepositoryTest:Sequenceround-trips through the real DataStore JSON path with its position intact; resetting toNetworkdiscards a previous sequence position.NetworkMockPluginTest: a sequence advances across successive requests and sticks on the last step once exhausted (via a smallmutableStateRepositoryMockbacked by a realMutableStateFlow, so the plugin's own write-then-reread round-trips like it would against real DataStore); the probabilistic failure roll applies toSequencestates too.Docs:
networkmock-workflows.md(new workflow),networkmock-core.md(DataStore schema entry).Verification
All green (combined run, including a full repo-wide
testAndroidHostTest).🤖 Generated with Claude Code