2.4 KiB
2.4 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(...).tui(...)now accepts an injectedCliRenderer, test mode, and anonReadycallback. Production still creates the real renderer.