AI 智能體知道規則,卻未必照做
The Agent Knows. It Just Doesn’t Always Do It
AI 智能體即使掌握 TDD 流程,執行時仍可能不按先寫測試、再編寫程式碼的次序,或加入未經測試的額外程式碼。要確認智能體是否按預期工作,除了查看日誌及設置測試陷阱,還需追蹤行為趨勢,並調整測試做法。
The more I work with agents, the more I understand how big the task of making sure they work is. Like, Jupiter big.
And how much of our practices need to change in order to at least have some idea of what we ship to production.
Here’s an example straight from my TDD agent. I taught it well. It knows how to generate the tests first, run them, and see them fail. Only then should it move on to generating the code.
Well, it knows. What it does depends on how it’s feeling that day.
So the bug in this case is not working in the right order. Only, it’s hard to see the bug. Because the agent created working software, only not just how I wished it to.
And how do I know there was a bug? I needed to get into the console logs to see what it was actually doing.
The second example came from the same agent. As we all know, in classic TDD (and my agent is really up there with the classics), you implement just enough code to pass the tests. Anything extra is a no-no.
Again, depending on how the genie felt that day, it did what I asked. Or not.
How did I know? I started running a targeted coverage check as a step after the Green phase. It told me if there was some extra untested code added.
These are just two examples of how to make sure the agent “works”. We need to rummage through logs, looking for evidence. Or set traps – like my coverage tool – to see if it gets out of line.
And these have to run constantly, with every run. And even that isn’t enough. Because I can set traps and look for information – if I know what to look for, and where it will appear.
What about the rest?
In classic testing it’s called exploration. We learn what the app does, and how it behaves. And if we find something we like, or something we want to keep out, we put automated tests around it so we’ll know when it comes back.
In our language – set traps based on our exploration.
But wait, that’s not enough either.
Because, as we know, things can change from under us. Models drift, interpretation changes. The equivalent of automation – pass/fail – may not be enough.
So we need to track trends of behavior.
For example – with my coverage trap, I know when extra code is added. The problem is, in reality, sometimes it’s ok to add extra code. So the event is fired – extra code was added – and I decide if it’s ok or not.
But does it happen a lot? Because if it does, then it’s a bug. If not, it’s a tolerated exception.
I track the behavior over time to see if it’s a real problem.
So where a simple pass/fail check was enough, I need more. More checks, more traps and more trackers.
Our testing practices need to change. We can’t continue to test agents the old way.
Originally published at testingil.com.
I'm Gil Zilberfeld. I teach API testing and test automation, and I write about what AI-generated code does to quality.
來源:DEV Community · dev.to