Cursor terminal access for auto-fixing unit tests

Basically I want Cursor to automatically look at the terminal (integrated inside Cursor) that’s running my unit tests and fix them automatically without me having to copy paste them from the terminal back and forth and telling it to fix it. It should make changes, look at the tests, if any failures, then fix them, and reiterate until all tests are fixed.

How can I automate this whole process? Can I use an MCP for this? Anyone have ideas?

Hi, you could use the YOLO/Auto-run mode. See following thread where i just answered almost the same as you ask.

You can do testing with the auto-run mode, you wont need MCP for that unless your test tool only runs in MCP.

Not sure which programming language you use but most of them have a test runner. That can run likely locally and can likely be launched from commandline.

I’m using Angular and Jasmine as the test runner. Does Cursor AI have access to the terminals automatically? Or do I need to give it access? I understand the auto-run mode (previously YOLO mode?), but what I want is for it to read the test failures and fix them automatically. Will the auto-run mode do all that automatically?

Yes Cursor editor (there is no Cursor AI as such) has access to the terminal.

Default: Agent has terminal access and executes the test runner. if the test runner reports issues in CLI then AI in Agent mode can see the result and adjust code.

Im using this for various languages which do not need any additional configurations apart of a properly setup test runner. (in my case its not a plugin for the editor but a CLI command to run the tests)

You might need to tell it how to run the test runner. and ask it to test and fix the code.

I think I understand what you mean. So I have to tell it to run the test and then it will know which tests are failing, correct?

I usually have a dedicated terminal for my tests with the --watch flag such that the tests auto-run on any code change. Wondering if it’s easy to make it look at that dedicated terminal?

Well Agent runs its own terminal so you wouldnt use --watch.

Yes it would be nicer if its fully automated but in terms of context, test results and necessary changes it helps to limit the run.

For examples i can run my test runner on certain tests only (either by test name, group or folder,…) which ensures that it doesnt try too much at one time.

You may also need to start a new chat after some changes as tests often output a lot of text which pollutes the context and may confuse AI.

I would run the first runs manually and if you narrow down the scope then tell Agent to run certain tests/groups so it doesnt get confused.

Do it first in smaller steps and as you gain insight what the limits are you can run longer tests.

I configured my tests to run ‘changed’ code only or full test runs, as two separate runners which i explained to AI in a rule file.

You can really start simple and expand.

Ah okay. Yeah in my case I have a suite of 1600 unit tests in my app that execute very quickly (<20s) and I just wanted to see if I can automate it. I’ll try having the agent run its own terminal and check the output. You’re right about the context window getting polluted with all the nonsense that the test runners spit out - that could become a problem easily

It would be nice if I could just tell it like, route output from this terminal directly into your input and then auto fix the test failures etc.. Maybe that type of feature will be added at some point

Thanks for your help

Yeah MCP sse server could do that but im not sure how well supported that is and if MCP test runners exist yet that widely or how stable that would be or how AI would know when it got enough data to start testing.

in my case when coding i ask AI to write a test, test changes and then to run full test suite to ensure nothing else is broken.

my ‘changes’ test runner config is verbose and the full test is errors only so it doesnt list all tests.

Yeah the changes only thing sounds interesting. I would like to figure out how to do that for my angular/jasmine testing. What stack are you using? Any idea how I can implement that with my angular/jasmine testing?

Ah yes, Jasmine/Karma doent support running changes only though you can filter certain tests so if AI creates/edits a test, guide it to test first just that test.

Jest has ⁠–onlyChanged flag which is how i do it.

1 Like

Oh that’s awesome, I’ll give Jest a try. I’ve heard a lot of good things about it