// Each tenant keeps its own resident process across turns. The real child, cat, echoes each line. // The Lab scripts distinct replies and checks that closing one session leaves the other open. type Turn = struct { tenant: string, prompt: string } type Message = struct { tenant: string, text: string } type Reply = struct { tenant: string, answer: string } graph dialogues : App { input in: Turn | string input close: Turn output out: Reply output invalid: string output exit: ProcessExit operator turn { input in: Turn | string output out: Turn on in match { data is Turn => out = data as Turn data is string => out = { tenant = "local"; prompt = data } _ => nothing } } graph conversation { input in: Turn input close: Turn output out: Reply output invalid: string output exit: ProcessExit instance = { key = data.tenant } lifetime = { kind = persistent } operator request { input in: Turn output out: Message on in { out = { tenant = data.tenant; text = data.prompt } } } connector model : Process { mode = service command = "cat" codec = jsonl max_frame = "1MiB" behavior = probabilistic closing = { drain_for = duration("1s"); settle_for = duration("1s") } } operator decode { input in: variant output out: Reply output invalid: string on in { val message = data as? Message match { message is Message => out = { tenant = message.tenant; answer = message.text } _ => invalid = "valid JSON, but not a Message" } } } operator finish { input in: Turn output out: Turn on in { out = data } } in -> request -> model model.out -> decode decode.out -> out decode.invalid -> invalid model.err -> nothing model.exit -> exit close -> finish finish.out -> model.instance.stop } in -> turn -> conversation close -> conversation.close conversation.out -> out conversation.invalid -> invalid conversation.exit -> exit } lab scripted_model { mock conversation.model { on in where data is Message match { data.text == "quit" => exit = Exited { exit_code = 0; signal = null } data.text == "garden" => out = { tenant = data.tenant; text = "Plant tomatoes." } data.text == "water?" => out = { tenant = data.tenant; text = "Water the tomatoes in the morning." } data.text == "trip" => out = { tenant = data.tenant; text = "Visit Kyoto." } data.text == "how long?" => out = { tenant = data.tenant; text = "Three days in Kyoto." } _ => out = { tenant = data.tenant; text = "I am still here." } } } scenario alice_and_bob { app.in = { tenant = "alice"; prompt = "garden" } expect app.out where data.tenant == "alice" && data.answer == "Plant tomatoes." expect app.exit == nothing app.in = { tenant = "bob"; prompt = "trip" } expect app.out where data.tenant == "bob" app.in = { tenant = "alice"; prompt = "water?" } expect app.out where data.answer == "Water the tomatoes in the morning." app.in = { tenant = "bob"; prompt = "how long?" } expect app.out where data.answer == "Three days in Kyoto." app.close = { tenant = "alice"; prompt = "stop this child" } advance duration("2s") expect app.exit where data is OutcomeUnknown app.in = { tenant = "bob"; prompt = "still there?" } expect app.out where data.tenant == "bob" && data.answer == "I am still here." app.in = { tenant = "bob"; prompt = "quit" } expect app.exit where data is Exited } scenario fresh_child { app.in = { tenant = "alice"; prompt = "garden" } expect app.out app.in = { tenant = "alice"; prompt = "quit" } expect app.exit where data is Exited advance duration("10s") expect app.out == nothing app.in = { tenant = "alice"; prompt = "trip" } expect app.out where data.answer == "Visit Kyoto." app.in = { tenant = "alice"; prompt = "quit" } expect app.exit } }