feat(sim): behaviours, session model, engine - #17
Merged
Conversation
Milestone 1c (docs: design/playground-simulation.md) — the sim is now
driveable end to end from a script; no UI yet.
- behavior.ts — the six canned server behaviours as specs (label,
appliesTo, defaultConfig seeded from the function's return / error
types, make): Reply with value, Echo params, Increment field, Delay
then reply, Raise error, Drop. `defaultKindFor` picks Reply, or Drop
for a one-way function.
- model.ts — Session { shape, instances, connection }. addInstance
(auto-named `<proto>-N`, server instances get a seeded behaviour map),
removeInstance (drops the connection if it referenced the instance),
setConnection (same protocol + opposite roles, replaces any existing),
setBehavior, and rebuild — re-point at a fresh shape, keeping a
surviving instance and the configs of functions that remain.
- engine.ts — connect(session, connection): a GenericDispatch server
bound to the instance's behaviours and a GenericClient, over a tapped
duplex(), handshake run. `setBehavior` swaps a live entry; takes effect
on the next call.
- engine.test.ts — the 1c acceptance: Reply returns the value; Echo
returns params and a live swap takes effect next call; Increment bumps
once per call; Raise comes back as a mapped SimRemoteError; Drop leaves
the call pending; and the model ops (naming, removal, rebuild).
12/12 sim tests pass. No app-bundle change.
This was referenced Sep 3, 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.
Milestone 1c of playground simulation. The sim is now driveable end to end from a script — no UI yet (that's 1d).
behavior.ts— six canned behavioursEach is a spec (
label,appliesTo,defaultConfigseeded from the function's return / error types,make):reply.err(ordinal, data)for one of the fn'sthrowscallstays pending (default for a one-way fn)model.ts— the sessionSession { shape, instances, connection }.addInstance(auto-named<proto>-N; server instances get a seeded behaviour map),removeInstance(drops the connection if it referenced the instance),setConnection(same protocol + opposite roles, replaces any existing),setBehavior, andrebuild— re-point at a freshly compiled shape, keeping surviving instances and the configs of functions that remain.engine.ts— bring a connection liveconnect(session, connection)→ aGenericDispatchserver bound to the instance's behaviours + aGenericClient, over a tappedduplex(), handshake run.setBehavior(fnName, setting)swaps a live entry (mutates theBehaviorMapGenericDispatchreads per dispatch) — takes effect on the next call.Tests
12/12 sim tests pass (7 new + 5 from 1b).
npm run buildgreen; no app-bundle change (nothing importssim/behavior|model|enginefrom an entry yet).