opencode icon indicating copy to clipboard operation
opencode copied to clipboard

test(tui): Set up TUI tests

Open veracioux opened this issue 2 months ago • 10 comments

@kommander I have created a comprehensive mock context setup and a few tests to get things going.

My plan was to add tests all day today (Monday). If you are not in a super hurry to maximize coverage, I would like to tinker a bit with the utility functions. Otherwise, we can work on different tests in parallel if you want.

Todos:

  • [ ] Reconcile tests marked with test.fail or test.todo, etc

veracioux avatar Nov 03 '25 01:11 veracioux

@kommander Please ignore the fact that I sometimes use .ts and sometimes .tsx. I'm having trouble with debugger breakpoints not mapping correctly in .tsx files, so I'm using .ts where possible for now.

If this rings a bell and you know a fix, please let me know. (I'm using vscode)

veracioux avatar Nov 03 '25 12:11 veracioux

I am not using a debugger at the moment, so I can't really help with the breakpoint problem, although I suspect the solid plugin compilation messing up the line numbers, the issue exists in tests where in failures the stack traces are wrong. Maybe @Adictya has an idea here.

Regarding the test setup, that is a good start. However I am a bit scared by the many unit mocks. I would rather mock less and at a lower level, so it's more like "integration" tests for the tui, where only the interface to the server/sdk is mocked, so we can control model responses, errors etc. and test how the whole tui actually reacts to it.

kommander avatar Nov 03 '25 14:11 kommander

That makes sense, though I think a few more context providers should be mocked by default in addition to server/sdk. Please see commit https://github.com/sst/opencode/pull/3789/commits/d86a5cc0da7336aac678a83485c296dd5ab42e8c#diff-4ac50cbf1a587d44e1de3cca0938ee733680bdb151025778d721a6797477d123R19 where I disable some mocks. I tried to choose a reasonable subset, let me know if you disagree.

veracioux avatar Nov 03 '25 14:11 veracioux

@kommander Please ignore the fact that I sometimes use .ts and sometimes .tsx. I'm having trouble with debugger breakpoints not mapping correctly in .tsx files, so I'm using .ts where possible for now.

If this rings a bell and you know a fix, please let me know. (I'm using vscode)

I debug directly via bun --inspect-wait=localhost:4000/ot + neovim. For breakpoints I think faced those too I just use the debugger; keyword which works reliably, you can try that maybe

Adictya avatar Nov 03 '25 18:11 Adictya

Yeah I also do --inspect-wait. debugger; is better than nothing, but I can't use step functionality cuz the cursor keeps jumping around all over the place.

veracioux avatar Nov 03 '25 19:11 veracioux

@kommander Tests are coming along nicely. I expect to have a bunch more ready by end of day. Do you have any special ones to pay attention to?

Btw I also ran into this: https://github.com/sst/opencode/pull/3789/commits/865d6104acb328fdcd3cee3f1dba4b22ab87279c#diff-136aadfe331bad702903358a242e704fbd853464f9e83c6fcd4d54fd3c71258aR353 The workaround is working but thought you might want to know about that error. (without the workaround, sometimes it even segfaults)

veracioux avatar Nov 04 '25 08:11 veracioux

Cool, I'll review in a bit. Is that segfault reproducible somehow in a test?

kommander avatar Nov 04 '25 08:11 kommander

Happens in home.test.ts -> Model dialog -> "should open model dialog". When I skip that test the issue doesn't happen.

At the moment I'm writing the error is always a segfault, but earlier today it would sometimes segfault and sometimes throw EditBuffer is destroyed. Perhaps I refactored something between then and now which changed the behavior.

veracioux avatar Nov 04 '25 08:11 veracioux

@kommander I think I found another opentui bug: https://github.com/sst/opencode/pull/3789/commits/b5fa06a175a3bb02e28f554e7a4003a82ee617ee#diff-c63d79e8c8f6134eddfa867a39886598244ee586889c9a52db3ac7160f8b05d9R259 pressTab doesn't respect modifiers

veracioux avatar Nov 04 '25 11:11 veracioux

@kommander Can you take a glance at the tests so far and tell me if I am on the right track of what kinds of behaviors should be tested?

veracioux avatar Nov 04 '25 19:11 veracioux

@kommander Converted the tests to E2E per dax's suggestion. Found some opentui issues - I'm gonna create gh issues for them after taking a breather. Please give me some feedback (quick glance is fine). I would like to keep writing tests while I'm in the flow, but also don't wanna waste my time diving into a rabbit hole only to have it rejected later.

veracioux avatar Nov 06 '25 22:11 veracioux