playground

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package playground serves the Modeler's Playground area: a caller opens a session on a model, feeds it cases, and drives it — free-running, or one occurrence at a time with a person answering the human tasks.

The engine work is in github.com/pblumer/atlas/playground; this package is the HTTP half. It is a per-area service (ADR-0147) with an unusual property: it holds no run loop of its own, because it touches no state the server's loop owns. Every sandbox carries its own single-writer goroutine, and the only way into one is playground.Session.With — the boundary travels with the session rather than with this service.

Nothing here reaches the durable engine, the deployment registry or any design-time store. Resolving *which* model a session runs is the one thing that does, and that is injected as ModelSource so the server keeps its own authorization rules over drafts and deployments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModelSource

type ModelSource func(r *http.Request, kind, ref string) (xml []byte, status int, message string)

ModelSource resolves the model a session is asked to run and decides whether this request may read it.

It returns the BPMN XML on success, or an HTTP status and message to answer with. Both halves belong to the server: it owns the draft store, the deployment registry, and the per-artifact authorization rules that say who may open a draft (ADR-0071). Putting them behind one function keeps this service free of design-time state and of policy alike.

type Scenario

type Scenario struct {
	// Open is the body of POST /playground/sessions: the model source, the seed,
	// and the stub and pool policy.
	Open json.RawMessage `json:"open"`
	// Run is the body of POST /playground/sessions/{id}/runs: the dataset and the
	// arrival profile.
	Run json.RawMessage `json:"run"`
	// Expect is the body of POST /playground/sessions/{id}/verdict: what the run
	// has to show. Omitted means the scenario runs but judges nothing.
	Expect json.RawMessage `json:"expect,omitempty"`
}

Scenario is a saved run: everything needed to run it again and get the same answer, plus what it must show for that answer to count as a pass.

It is literally the three requests that make a run — open a session, start a batch, judge the report — kept as the bodies those endpoints already take. The alternative was a parallel set of structs describing a stub policy, an arrival profile and a set of expectations a second time; this cannot drift from the endpoints, because it *is* them. A client that can run a scenario is a client that can replay three requests, which is what the CI runner does.

The design-time store that holds these keeps them opaque for the same reason a form's schema is opaque to it: storage has no business understanding a stub policy, and a second copy of these shapes would be a second place to keep in step.

func (Scenario) Validate

func (s Scenario) Validate() error

Validate reports what is wrong with a scenario's shape. It is a syntactic check only — that each part is a JSON object the matching endpoint could be handed — because the endpoints are the authority on their own bodies and re-deciding here is how the two answers start disagreeing.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service serves the Playground area. Build it with New.

func New

func New(sessions *playground.Registry, source ModelSource, vars VarsFromMap) *Service

New builds the Playground service over a session registry.

func (*Service) HandleAdvanceClock

func (s *Service) HandleAdvanceClock(w http.ResponseWriter, r *http.Request)

HandleAdvanceClock jumps simulated time and fires whatever came due.

func (*Service) HandleArrivalProfile

func (s *Service) HandleArrivalProfile(w http.ResponseWriter, r *http.Request)

HandleArrivalProfile reports the shape of a stream before it is run.

It exists so a panel can draw the timing somebody just typed. The arithmetic is the planner's own — the same call the run makes — because a profile drawn from a second implementation of it in a browser is a picture of a stream nobody is going to get.

func (*Service) HandleCancelRun

func (s *Service) HandleCancelRun(w http.ResponseWriter, r *http.Request)

HandleCancelRun stops a batch at the end of its current slice, leaving what it did readable.

func (*Service) HandleCase

func (s *Service) HandleCase(w http.ResponseWriter, r *http.Request)

HandleCase reports what became of one case.

func (*Service) HandleClose

func (s *Service) HandleClose(w http.ResponseWriter, r *http.Request)

HandleClose ends a session and discards its sandbox.

func (*Service) HandleCompare

func (s *Service) HandleCompare(w http.ResponseWriter, r *http.Request)

HandleCompare sets this run beside a report sent in the body — a stored baseline, normally.

The baseline travels in the request rather than being looked up here on purpose: this service holds no design-time state (ADR-0147), and a session that could read the scenario store would be the first thing to break that. The client already holds both halves.

func (*Service) HandleCompleteTask

func (s *Service) HandleCompleteTask(w http.ResponseWriter, r *http.Request)

HandleCompleteTask completes a parked job the way the person would have.

func (*Service) HandleGeneratePreview

func (s *Service) HandleGeneratePreview(w http.ResponseWriter, r *http.Request)

HandleGeneratePreview shows the first cases a description would produce.

They are the first cases the run will produce, not a sample of what one might look like: the preview draws on the same seed and the same simulated start, and every case draws on its own position, so nothing here depends on the rows that would follow. A preview that showed something other than what runs would be worse than showing nothing.

func (*Service) HandleHeatMap

func (s *Service) HandleHeatMap(w http.ResponseWriter, r *http.Request)

HandleHeatMap returns the per-element and per-sequence-flow token counts of the run, including the parts of the model it never reached.

func (*Service) HandleOpen

func (s *Service) HandleOpen(w http.ResponseWriter, r *http.Request)

HandleOpen opens a session on a draft, a deployed definition, or an inline model.

func (*Service) HandleOverlay

func (s *Service) HandleOverlay(w http.ResponseWriter, r *http.Request)

HandleOverlay reports how many tokens have passed through each element — the heat map's raw material, in the shape the runtime overlay already uses.

func (*Service) HandlePause

func (s *Service) HandlePause(w http.ResponseWriter, r *http.Request)

HandlePause holds a run in flight at its next occurrence.

func (*Service) HandlePublishMessage

func (s *Service) HandlePublishMessage(w http.ResponseWriter, r *http.Request)

HandlePublishMessage delivers a message into the sandbox — the author standing in for the outside world.

func (*Service) HandleReport

func (s *Service) HandleReport(w http.ResponseWriter, r *http.Request)

HandleReport returns the run's summary.

func (*Service) HandleResults

func (s *Service) HandleResults(w http.ResponseWriter, r *http.Request)

HandleResults returns one page of the results table.

func (*Service) HandleResultsCSV

func (s *Service) HandleResultsCSV(w http.ResponseWriter, r *http.Request)

HandleResultsCSV streams the whole results table as CSV, a page at a time, so the response is bounded however many cases there are.

func (*Service) HandleResume

func (s *Service) HandleResume(w http.ResponseWriter, r *http.Request)

HandleResume lets a paused session run again.

func (*Service) HandleRun

func (s *Service) HandleRun(w http.ResponseWriter, r *http.Request)

HandleRun runs the session until the model comes to rest, the service's budget stops it, or somebody pauses it.

func (*Service) HandleRunStatus

func (s *Service) HandleRunStatus(w http.ResponseWriter, r *http.Request)

HandleRunStatus reports how far a batch has got.

func (*Service) HandleStartCase

func (s *Service) HandleStartCase(w http.ResponseWriter, r *http.Request)

HandleStartCase starts one case, seeded with the given variables.

func (*Service) HandleStartRun

func (s *Service) HandleStartRun(w http.ResponseWriter, r *http.Request)

HandleStartRun starts a batch over a dataset sent inline — listed, or described and drawn here.

func (*Service) HandleStartRunFromCSV

func (s *Service) HandleStartRunFromCSV(w http.ResponseWriter, r *http.Request)

HandleStartRunFromCSV starts a batch over an uploaded CSV, one case per row.

The file is parsed by the same code the CSV start path uses (ADR-0084/0139), against a layout derived from its own header: every column becomes a start variable under its header's name. A playground dataset is somebody's export, not a configured integration, so asking them to describe the columns they just exported would be asking twice.

func (*Service) HandleStatus

func (s *Service) HandleStatus(w http.ResponseWriter, r *http.Request)

HandleStatus reports a session's state.

func (*Service) HandleStep

func (s *Service) HandleStep(w http.ResponseWriter, r *http.Request)

HandleStep carries out exactly one occurrence.

func (*Service) HandleTasks

func (s *Service) HandleTasks(w http.ResponseWriter, r *http.Request)

HandleTasks lists the jobs waiting for a person.

func (*Service) HandleVerdict

func (s *Service) HandleVerdict(w http.ResponseWriter, r *http.Request)

HandleVerdict judges the run against the expectations in the body.

It is a POST rather than a field of the report because the expectations belong to the scenario, not to the session: the same run can be judged against a stricter target without being run again, which is what makes a scenario editable after the fact.

type VarsFromMap

type VarsFromMap func(map[string]any) ([]model.VariableValue, error)

VarsFromMap converts a name→value map in encoding/json shape into engine variables. Injected rather than reimplemented so a playground case is seeded exactly as a real start is.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL