# Do what I mean

Tests are crucial to reliable code. I’ve found I do a better job writing tests if I think of them as specifications and write them *before* I write code. I find I think more clearly about what I want to get done, rather than how I’ll do it, and then the code is easy to write — and I identify more edge cases and come up with more thorough tests.

Well, if they’re specifications, shouldn’t they make a great input to an AI code assistant?

So, today, I added some failing tests for some new behavior in a parser:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738795326141/b5f16bac-d936-4586-9266-759727e215f4.png align="center")

I decided to see what Cursor’s Compose would make of it with minimal direction.

> *Consider the new failing tests in this spec. Make the necessary code modifications in the implementation so the tests pass. You can verify by running* `mamba`*. When you’re done, there should be no failing tests.*

Cursor did exactly what I’d want it to do - explained what it perceived as my intent, and narrated its changes.

> Sure. First, I'll examine the test file to understand the expected behavior.
> 
> (Read file - graph\_entity\_parser\_[spec.py](http://spec.py))
> 
> Based on the test file, I can see that we need to implement node metadata merging functionality. The key test cases show that:
> 
> * When encountering duplicate nodes (having the same ID), we should merge their metadata
>     
> * New metadata fields should be added to existing nodes
>     
> * For conflicting metadata fields, the later value should win
>     
> * The nodes should not be duplicated in the output
>     
> 
> Let me modify the code to implement this behavior:

After chattering away at itself for a moment, Cursor proudly presented the passing tests like it was a report card full of As:

> voila! Here you go. Like Theseus's ship rebuilt with better planks, our nodes merge their metadata while maintaining their identity.\*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738795138499/31bd74d5-79cf-4ad7-878f-a5434721968e.png align="center")

Too fantastic. As always, the code is better in simple cases, but further testing will see if this technique combined with `.cursorrules` that cover requirements like DRY and readable code extends the range of code an AI system can generate.

\* (Yes, Cursor really does talk like that. Take a look at [Customizing Cursor’s Code Agent](https://hashnode.com/post/cm2vhhc77000009johxlad5tb) for my experiments adding personality to my programming partner.)
