Skip to content

feat(sim): behaviours, session model, engine - #17

Merged
Kinflou merged 1 commit into
masterfrom
feat/sim-1c-engine
Sep 2, 2026
Merged

feat(sim): behaviours, session model, engine#17
Kinflou merged 1 commit into
masterfrom
feat/sim-1c-engine

Conversation

@Kinflou

@Kinflou Kinflou commented Sep 2, 2026

Copy link
Copy Markdown
Member

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 behaviours

Each is a spec (label, appliesTo, defaultConfig seeded from the function's return / error types, make):

kind does
Reply with value returns the configured value (default for a normal fn)
Echo params returns the decoded params
Increment field returns a base with one numeric field bumped per call
Delay then reply waits N ms, then replies
Raise error reply.err(ordinal, data) for one of the fn's throws
Drop never settles — the client's call stays pending (default for a one-way fn)

model.ts — the session

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 freshly compiled shape, keeping surviving instances and the configs of functions that remain.

engine.ts — bring a connection live

connect(session, connection) → a GenericDispatch server bound to the instance's behaviours + a GenericClient, over a tapped duplex(), handshake run. setBehavior(fnName, setting) swaps a live entry (mutates the BehaviorMap GenericDispatch reads per dispatch) — takes effect on the next call.

Tests

✔ model — instance naming, seeded behaviours, removal drops the connection
✔ Reply with value returns the configured value
✔ Echo returns the params; a live behaviour swap takes effect on the next call
✔ Increment field bumps once per call
✔ Raise error comes back as SimRemoteError mapped to the ordinal's name
✔ Drop leaves the call pending
✔ rebuild keeps a surviving instance's behaviour config

12/12 sim tests pass (7 new + 5 from 1b). npm run build green; no app-bundle change (nothing imports sim/behavior|model|engine from an entry yet).

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.
@Kinflou
Kinflou merged commit 240b86b into master Sep 2, 2026
2 checks passed
@Kinflou
Kinflou deleted the feat/sim-1c-engine branch September 2, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant