Repository navigation
feat(random)!: remove the integer form of the random action - #392
Merged
Merged
Conversation
The random action now only runs the actions of one weighted outcome. A random value is drawn into a variable by an updateVariable operation with op: random, which runs in list order with the action's other operations and does not continue to the next line. A random action with an integer distribution or a variableId is refused by the schema and at runtime. An integer result that an older engine recorded for a random action is dropped when a save is loaded or the project is updated, like any record whose action no longer matches. random is one entry of the Decision phase, before conditional. Bumps the version to 1.54.0.
1.54.0 was released from main without this change, so the removal ships as 1.55.0 and the docs name that version.
…aves - Replay of a random action nested in a weighted outcome or a conditional branch is asserted from its own record, with the second outcome selected. - The integer distribution rules of the schema are tested through the updateVariable random operation, which is their only user now. - The schema test refuses a random action with no distribution or with a distribution type other than weighted. - The order test places random after the form actions. - The old-save test also covers a project changed to an updateVariable roll, a Back step from a later line and a project update. - An updateVariable roll continues to the next line only with a conditional beside it. The docs say which rollbacks replay a line without a dropped roll, how to keep the continuation of the removed action, and when an integer roll draws no word or fails.
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.
Why
A random value is now drawn into a variable by an
updateVariableoperation withop: random, which runs in list order with the action's other operations, can appear any number of times on a line and does not continue to the next line. That leaves the integer form of therandomaction as a second, more awkward way to do the same thing: one per line, always after everyupdateVariableoperation, and it continues to the next line by itself.Removing it gives each action one job:
updateVariablechanges values, including random ones, andrandomchooses a path.Breaking change
A
randomaction withdistribution.type: integeror avariableIdis no longer accepted.Before:
After:
The operation does not continue to the next line, and its line is an ordinary Back stop. A line or button that relied on the removed action continuing keeps that behaviour with an empty default
conditionalbeside the roll:What changed
randomaction accepts only a weighted distribution. The schema refuses the integer form andvariableId, and the engine refuses them when the action runs. For the integer form the error names theupdateVariablerandom operation.randomis a single entry of the Decision phase, after the form actions and beforeconditional. The separate State-phase entry for the integer form is gone.sampleRandomDistributiondraws only weighted outcomes. Integer sampling stays, used by theupdateVariablerandom operation.Existing data:
randomaction is not migrated. The engine refuses the action when its line runs.randomaction. It is dropped when the save is loaded or the project is updated, like any record whose action no longer matches. The save loads with its variables as they were saved. Any rollback that replays the line of the roll, including one Back step from a later line, then runs it without the roll, so the variable has the value it had before that line and later lines and conditionals that read it are replayed with that value. Nothing is drawn again, and the record is not moved to anupdateVariableroll that replaced the action.updateVariablerandom operations are unaffected.Testing
spec/RouteEngine.randomActions.test.js: the tests that used the integer form now use weighted outcomes that set a variable, and cover the same behaviour: order beforeconditional, transactions, line recording and replay through save, load and rollback, a new draw after rolling back past the line, same-line re-entry, nested paths, project updates, malformed and unsupported ledgers.variableIdare refused before anything is drawn.randomaction nested in a weighted outcome or a conditional branch is replayed from its own record, with the second outcome selected.updateVariableroll. The saved variables are restored, and a Back step from a later line and a rollback to the line both replay it without the roll and without a draw.updateVariableroll stays on its line by itself, and continues once and is skipped by Back with an empty defaultconditionalbeside it.spec/RouteEngine.updateVariableRandom.test.jscovers for the operation.spec/random.test.js: integer sampling is tested through the variable distribution, and the action sampler refuses an integer distribution.spec/projectDataSchema.test.js: the integer distribution rules (required bounds, safe integers, no extra keys) are tested through theupdateVariablerandom operation, and arandomaction with no distribution or a distribution type other than weighted is refused.spec/actionExecutionOrder.test.js:randomis placed after the form actions and beforeconditional.bun run test,bun run lint,bun run check:test-markersandbun run buildpass.random/choice-integer-branchnow rolls with theupdateVariablerandom operation and still matches its two reference images.robustness/variable-random-line-rollbackandrobustness/variable-random-choice-branchpass the CI flow locally with 0 mismatched images. All three were run on the final source.