// Driver for tests/orch_mplex_e2e.py: opens N panels on the multiplexer named by TAI_PLEXER_* and // streams scripted events through the real OrchBoard and OrchMplexTransport. // orch_live N TOKENS HOLD_MS [fail] prints "id label" per panel, finishes them, flushes. #include #include #include #include #include #include "orch_board.h" using namespace detz::orch; int main(int argc, char** argv) { int n = argc > 1 ? std::atoi(argv[1]) : 1; int tokens = argc > 2 ? std::atoi(argv[2]) : 50; int hold_ms = argc > 3 ? std::atoi(argv[3]) : 0; bool fail_last = argc > 4; OrchBoard& board = OrchBoard::instance(); std::vector> panels; for (int i = 0; i < n; ++i) { auto p = board.open("agent #" + std::to_string(i + 1), "scripted task number " + std::to_string(i + 1)); std::printf("%d %s %s\n", p->remote_id(), p->label().c_str(), p->shown() ? "shown" : board.last_error().c_str()); panels.push_back(p); } std::fflush(stdout); std::vector workers; for (int i = 0; i < n; ++i) { workers.emplace_back([&, i] { auto& p = panels[static_cast(i)]; p->emit(OrchEvent::tool_start("shell", "{\"command\":\"echo " + std::to_string(i) + "\"}")); p->emit(OrchEvent::tool_end("shell", "line one\nline two\nline three\nline four", false, 12)); for (int t = 0; t < tokens; ++t) { p->emit(OrchEvent::text_of("word" + std::to_string(i) + "_" + std::to_string(t) + " ")); p->emit(OrchEvent::usage_of(t * 10)); std::this_thread::sleep_for(std::chrono::milliseconds(2)); } p->emit(OrchEvent::text_of("\nTHE END " + std::to_string(i) + "\n")); std::this_thread::sleep_for(std::chrono::milliseconds(hold_ms)); bool bad = fail_last && i == n - 1; p->finish(bad ? OrchPanel::State::Failed : OrchPanel::State::Done, bad ? "scripted failure" : "all good"); }); } for (auto& w : workers) w.join(); board.flush(3.0); return 0; }