3.5 KiB
3.5 KiB
Property-Based TUI Testing Working Notes
Mock LLM Provider
SessionPromptgets model metadata throughProvider.Service.getModel(...).- Actual generation is routed through
LLM.Service/streamText(...), so the first mock should return an AI SDKLanguageModelV3from the provider service. - The normal
Provider.layerbuilds providers from config/models.dev/plugin state. For first pass, the simulated graph can replaceProvider.Servicewith a smaller simulation provider service instead of trying to flow through provider config. - Control state should own an ordered LLM script queue. The provider/model should consume from that queue when the AI SDK calls the language model.
- First version can support text-only output. Tool calls and stream chunk fidelity can come next.
- Missing script should fail loudly with a typed simulation error, not silently return an empty assistant message.
- Implemented
SimulationProvider.layer, replacingProvider.ServiceincreateSimulatedRoutes. - The provider exposes provider
simulationand modelmock. doGenerateanddoStreamboth consume one queued script throughSimulation.Service.nextLLM().- Current script support:
text,thinking(treated as text for now), anderror. - Snapshot currently records
llmQueuedandllmConsumed, not per-step details yet.
OpenTUI Fake Renderer
- OpenTUI Solid exposes
testRender(...)from@opentui/solid. - The lower-level core API is
createTestRenderer(...)from@opentui/core/testing. createTestRenderer(...)returnsrenderer,mockInput,mockMouse,renderOnce,captureCharFrame,captureSpans, andresize.captureCharFrame()is the simple screen-buffer string API used heavily in OpenTUI snapshots.captureSpans()returns structured lines/spans plus cursor position, which is a better starting point for visible element discovery than parsing raw characters.mockInputsupports interactions liketypeText,pressEnter, andpressArrow.- Implemented
TuiSimulation.createSimulationRenderer(...)besidethread.ts. It creates a test renderer and exposesrenderOnce,screen,spans, anddestroy. thread.tschecksOPENCODE_SIMULATION, creates the fake renderer there, starts the normal worker/backend, and passes the renderer intotui(...).- Backend route assembly checks
OPENCODE_SIMULATION_BACKEND;OPENCODE_SIMULATIONimplies this flag. OPENCODE_SIMULATION_BACKEND=1can run a real frontend against a simulated backend.tui(...)now accepts an injectedCliRenderer, test mode, and anonReadycallback. Production still creates the real renderer.
OpenTUI Action APIs
- Interactable discovery can walk
renderer.root.getChildren()recursively. Renderable.focusableandRenderable.focusedare public and enough to discover focus targets.renderer.currentFocusedEditoridentifies active text input/edit-buffer targets for typing/submission.renderer.hitTest(x, y)maps terminal coordinates through the hit grid to a renderable id.- Renderables have public geometry:
screenX,screenY,width,height, andnum. - Mouse listener metadata is stored internally on renderables; first pass checks
_mouseListener/_mouseListenersat runtime to identify clickable targets. This is pragmatic but not a stable public API. - Test execution uses
mockInput.typeText,mockInput.pressEnter,mockInput.pressArrow, andmockMouse.clickfrom OpenTUI testing. - Implemented
SimulationActionswithelements(...),actions(...), andexecute(...).