← Belső rendszer fejlesztők adatlapja
Nézd meg, miben segít
Állapottartó modellalapú tesztek
Egyszerű referenciamodellhez generál műveletsorokat az egyedi példákból kimaradó hibák megtalálására.
stateful-model-based-testing
Ezt a skillt használó csapattagok
Mikor hasznos?
Akkor használd, ha helyesség több művelet sorrendjétől függ.
Miben segít neked?
- Modellállapotot és érvényes előfeltételű parancsokat határoz meg.
- Minden lépés után összeveti az eredményt és állandó szabályokat.
- Érthető minimális reprodukcióvá szűkíti a hibás sorozatot.
Például ezt kérheted
Modellezz számlanyitást, befizetést és kivétet; keress hibás egyenleget elutasított kivét után. Generálj befizetésből, sikeres és elutasított kifizetésből sorozatot. Minden parancs után vess össze modell- és valódi egyenleget, helyes elutasításnál is.
Részletes dokumentáció
Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.
Összecsukás
Stateful & Model-Based Testing
Use this skill when bugs depend on the ordering, repetition, or interleaving of operations across stateful entities (credit wallets, subscriptions, orders, approvals, inventory reservations, or cache/DB synchronization).
State-Machine Command Architecture (Lamport & Hughes)
Model the system as an explicit state machine driven by generated sequences of Commands (fc.commands / fc.asyncModelRun in fast-check, RuleBasedStateMachine in Hypothesis):
- Shadow Model State ($M$):
- Maintain a minimal, transparent in-memory representation of the expected domain state (e.g.,
Map<AccountId, { balance: bigint, reserved: bigint, seenKeys: Set<string> }>). - Keep $M$ simple and free of production infrastructure concerns (no SQL, no caching, no framework middleware).
- Maintain a minimal, transparent in-memory representation of the expected domain state (e.g.,
- Command Catalog ($C_1, C_2, \dots, C_k$):
- Define a command for each domain action, including adversarial and duplicate actions:
- Normal lifecycle actions (
GrantCredit,Reserve,Capture,Release,Refund,Cancel). - Replay / duplicate actions (
ReplayLastRequestWithSameIdempotencyKey,DuplicateWebhookDelivery). - Invalid / out-of-order actions (
CaptureAlreadyReleasedReservation,OverRefund,ApproveOwnRequest).
- Normal lifecycle actions (
- Define a command for each domain action, including adversarial and duplicate actions:
- Command Contract (
check+run):- Precondition (
check(model)): Determines whether the command is applicable in the current model state. Include commands that specifically test invalid state transitions so rejection behavior is verified too. - Execution (
run(model, realSystem)):- Execute the operation against
realSystem. - If the operation is legal in
model, updatemodeland assert thatrealSystem's return value and observable state matchmodel. - If the operation is illegal in
model(e.g., insufficient funds or terminal state), assert thatrealSystemrejects it with the expected domain error and thatrealSystemstate remains completely unchanged.
- Execute the operation against
- Global Step Invariant: After every command in the sequence, assert global cross-entity invariants (e.g., ledger conservation, no negative available balances, cache matches DB).
- Precondition (
Designing Effective State-Space Exploration
- Pool-Based Entity References: Draw IDs, accounts, and reservations from bounded pools (
Bundlesin Hypothesis or shared model arrays infast-check) so generated commands repeatedly collide on the same entities instead of creating a fresh, isolated entity on every step. - Test State Re-Entry & Loops: Ensure command sequences can cycle through
reserve -> release -> reserve -> partial capture -> refundorsubscribe -> cancel -> reactivate -> upgradeto expose stale flags or leaked locks.
Checklist
- Does the shadow model track the essential business state clearly without copying production code?
- Do generated command sequences include replays, out-of-order calls, and rejected transitions alongside happy-path steps?
- Do commands draw from a shared pool of entities so multiple operations hit the same records?
- Are global state invariants verified after every individual command step, not only at the end of the run?
Csomagban lévő fájlok 1
SKILL.md
