Testing of and with AI
Claude wrote all 69 tests for the AI assistant itself, based on the domain model. The first run found two bugs nobody had seen. How a good domain model makes it easy to test AI with AI.
This was my instruction to Claude:
> Make an AI assistant test suite that can be run with a real AI.
Test all the tools for all the roles.
Test domain logic and UI elements.
Test questions and actions.
Test that tools and information that should not be available for a user actually is not.
Measure tokens and give an estimate of token use per question. Estimate cost for my current AI model.
That was enough for Claude to create 60 tests for 4 different user roles. With a little input from me for new tests, we now have a test suite of 69 tests.
How did Claude manage that? Because it had a good specification: a domain model with rules for what the different users are allowed to do. So Claude could write the tests itself, without me having to write tests or read the code.
About the system
The system is a sales system for Happy Made and their subcontractors integrated with Fiken accounting. It has an AI assistant. Not your usual dumb chatbot, but an assistant that actually knows what it is talking about. It can answer questions about your orders, what you can do and so on, but it must not give you information you don’t have access to.
The figure shows how it fits together (hover over the numbers):
Testing
The language model is not deterministic. The goal is to make it as accurate as possible and to do a thorough test before this goes live.
(1) The test starts by building objects in the domain model. (2) Then it sends a question to the assistant as if it were a user with a specific role. The assistant runs the same steps 3-6 as it does in production. Then the test verifies the answer and what the AI assistant did:
- Did it use the right REST method?
- Did the assistant answer as expected?
- Did the assistant reveal anything this user should not know?
The first run found two bugs nobody had seen:
- A producer could read the customer’s price.
- A producer could not see their own deliveries.
One was fixed in the domain model, the other by fixing a REST method. Neither was fixed by changing the prompt.
In the last run, 68 of 69 were approved. Why not 69 of 69? Because this is still a statistical model, and because I use a cheap language model. I could get everything right with a more expensive (and slower) model, but that is a trade-off I choose to make.
Next week I will write about the method I use to create such a domain model: Object Cases.
Where do the rules of your system live: in an old JIRA issue, in a specification (that is actually up to date), in an AI prompt, or in someone’s head?