AI写代码已经快得让人眼花,真正卡脖子的是另一件事:它写出来的东西,到底对不对,合不合需求?没有验证器,人就得一行行盯着看,AI再快也白搭。下面从为什么需要验证器讲起,再给出一条能快速起步的路线,最后梳理几种常见的落地方案。
🧭 为什么验证器是AI编码的地基
编码智能体生成代码很快,但如果它没法检查自己的成果,错误就会一路累积,最后全压到人身上。业内的共识越来越清晰,自我验证、测试和反馈回路是AI生成软件可靠的前提。
有开发者分享过一套验证层级的做法。AI负责直接输出,人负责设计和掌控验证系统。人的精力从逐行审查转到设计规则,让机器自己去跑、去判、去返工。
还有一个容易踩的坑。通过现有测试,不等于代码正确。已有测试只覆盖了过去想到的场景,对新需求可能完全没有约束力。所以验证器要回答的问题是产品是否符合需求,光看代码有没有跑通不够。
🔍 验证器的分层结构
验证器越便宜、越确定,就越应该放在前面。慢而贵的检查留给后面,只处理前面筛不掉的问题。
每一层各管什么
- 静态检查,包括类型检查、代码风格和安全扫描,几秒钟就能出结果,用来挡住低级错误。
- 单元与契约测试,检查函数、接口的输入输出是否符合约定,是需求落地的主战场。
- 端到端行为测试,模拟真实用户操作,验证整条链路能否走通。
- AI评审与人工抽检,处理难以量化的部分,比如交互是否顺手、文案是否得体。
这套层级的意义在于让失败信息可以自动回流。AI收到明确的报错,就能自己改,改完再跑,形成闭环。
🛠️ 快速构建的四步路线
第一步,把需求翻译成可执行的验收条件
模糊的需求没法验证。把一句话需求拆成输入、操作和预期结果三段,每条都能用代码判定真假。
比如需求是用户可以用邮箱注册,重复邮箱要被拒绝。它可以改写成下面的测试。
import pytest
def test_register_with_new_email_succeeds(client):
resp = client.post("/register", json={"email": "a@x.com", "password": "Passw0rd!"})
assert resp.status_code == 201
def test_register_with_duplicate_email_is_rejected(client):
payload = {"email": "dup@x.com", "password": "Passw0rd!"}
client.post("/register", json=payload)
resp = client.post("/register", json=payload)
assert resp.status_code == 409
这些测试最好在AI动手写实现之前就备好。AI拿到的是一把尺子,不是一个开放题。
第二步,把所有检查收拢到一个入口
AI最怕入口分散。一条命令跑完全部检查,输出统一格式,AI才容易读懂。
#!/usr/bin/env bash
set -e
ruff check .
mypy src
pytest tests/unit -q
pytest tests/e2e -q
echo VERIFY_OK
第三步,让失败信息说人话
报错要带上哪条需求没满足、期望什么、实际得到什么。信息越具体,AI一轮修对的概率越高。
第四步,设置回路上限与通过率指标
给自动返工设一个最大轮数,避免AI陷入死循环。同时用一个简单指标衡量验证覆盖的程度。
覆盖率偏低,说明验证器还有盲区,回头补测试就是了。
📊 常见落地方案对比
不同团队的基础不同,下面几种方案可以按成本和收益组合着用。
选型时可以参考这个顺序。已有测试的团队直接接入持续集成。需求经常变的团队,行为驱动规格更省心。要让AI长时间自主开发,就得上分层验证加自动返工。
评估AI编码工具时的参照
挑选编码智能体本身,也可以用验证器来反推。有评测思路建议,用仓库级别的真实测试去考察自主性、上下文理解、验证能力、集成度和成本这几个维度。验证能力是其中一项硬指标。
💡 避坑与收尾
几个反复出现的坑,提前知道能省不少力气。
- 让AI自己写测试再自己验自己,容易出现测试迁就代码的情况,需求侧的测试最好由人把关。
- 只盯通过率,忽略测试质量,会得到一个看上去很美的绿灯。
- 验证太慢,AI每轮等得太久,整体效率反而下降,所以要把快检查放前面。
- 只验功能不验约束,性能、安全和兼容性同样要写进验收条件。
回头看,快速构建验证器的核心就是三件事。把需求写成能跑的检查,把检查收进一个入口,把失败信息送回给AI。先用一两个核心需求跑通闭环,再逐步加层,比一开始就追求大而全靠谱得多。AI负责写,验证器负责把关,人则回到更值钱的位置,去定义什么叫做对。
参考资料
How to choose an AI coding agent for real work | Octomind octomind.run/blog/ai-cod…
I built a verification hierarchy that lets AI write production code 24/7 www.reddit.com/r/SideProje…
Why AI Coding Agents Need a Way to Verify Their Own Work
How to verify correctness of AI-generated code beyond passing existing tests
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
AAI's writing code is fast enough for people to see, and the real thing that's stuck in their neck is another thing: it's writing something, right? Without a certifier, people have to keep an eye on it, and it's a waste of time. From the point of view of why a certifier is needed, a fast-start route is given and several common landing programmes are finally combed.
Why is the certifier an AI code foundation?
Encoding AI agent is quick to generate the code, but if it cannot check its own results, the error accumulates all the way to the human body. Consensus within industry is becoming clearer, and self-certification, testing and feedback loops are prerequisites for the reliability of AI-generated software.
A system of certification levels has been shared by developers. AI is responsible for direct output, and people are responsible for designing and controlling the certification system. The human energy shifted from line-by-line review to design rules that allowed the machine to run, judge and return to work.
There's a pit that's easy to step on. Using existing tests, this does not mean that the code is correct. Tests already exist only to cover past scenarios and may not be binding on new needs at all. So the question to be answered by the certifier is whether the product is in demand and whether the code is running.
The stratification of the certifier
The cheaper and more certain the certifier, the more it should be placed ahead. Slow and expensive inspections are left behind to deal only with issues that cannot be screened in the front.
What do you care on every level?
- Static checks, including type checks, code styles and security scans, produce results in a few seconds and are used to block low-level errors.
- Modules and contract tests to check whether functions, interface inputs and outputs are in accordance with the agreement and are the main battleground for demand.
- End-to-end behavioural tests, simulation of real user operations, verification of the passage of the entire link.
- AI reviews and manual check-ups to deal with those parts of quantization that are difficult, such as whether the interaction has been successful and whether the case has been properly written.
The point of this hierarchy is that information about failure is automatically returned. If AI receives a clear report of the error, it can change it itself, change it and run again, and form a closed ring.
A fast-build four-step course.
First step, translate demand into enforceable acceptance check conditions
The fuzzy need cannot be verified. Dismantling a sentence into three paragraphs of input, operation and expected outcome, each of which can be determined by a code.
For example, the demand is that users can register in mailboxes and repeat mailboxes are rejected. It can be rewritten as a test below.
import pytest
def test_register_with_new_email_succeeds(client):
resp = client.post("/register", json={"email": "a@x.com", "password": "Passw0rd!"})
assert resp.status_code == 201
def test_register_with_duplicate_email_is_rejected(client):
payload = {"email": "dup@x.com", "password": "Passw0rd!"}
client.post("/register", json=payload)
resp = client.post("/register", json=payload)
assert resp.status_code == 409
These tests should be ready before AI does it. AI got a ruler, not an open question.
Step two, close all checks to one entrance.
I'm afraid the entrance is scattered. It's easy for AI to read a single command running through a full-scale inspection and output uniform format.
#!/usr/bin/env bash
set -e
ruff check .
mypy src
pytest tests/unit -q
pytest tests/e2e -q
echo VERIFY_OK
Step three, let the failed information speak.
What needs are not met, what is expected, and what is actually obtained by making mistakes. The more specific the information, the more likely the AI round is.
Step four, set return limit and pass rate targets
Sets a maximum number of rotations for automatic return to work to avoid AI falling into a dead cycle. At the same time, the degree of validation coverage is measured by a simple indicator.
The low coverage means that the certifier still has a blind zone, and the back-to-back test.
• Common landing programme comparison
The basis of the different teams is different, and the following options can be combined by cost and benefit.
You can refer to this order in the selection. The teams that have been tested have direct access to ongoing integration. Frequently changing teams with behaviour-driven specifications. To allow AI to develop on its own for long periods of time, it will have to go up and verify and return to work.
References in the assessment of the AI coding tool
Selecting the code AI agent itself can also be inverted with a certifier. It was suggested that the dimensions of autonomy, context understanding, certification capacity, integration and cost should be examined using real tests at the warehouse level. Certification capacity is one of the hard indicators.
Scrambling and closing.
Several recurrent pits were known in advance to save strength.
- Allowing AI to write its own tests and test its own, which can easily be changed to code, is best handled by a person.
- Just focus on pass rates, ignore the quality of tests, and get a green light that looks beautiful.
- Verification is too slow, AI waits too long each round, and overall efficiency is reduced, so fast checking should be in front.
- Functionality is not limited, and performance, safety and compatibility are also included in the acceptance check conditions.
Turning back, there's three things at the heart of fast-build certification. Write the requirement as a running check, put the check in an entry and send the failed information back to AI. One or two core requirements will be used to close the loop and then gradually add to the layer, much larger and more broadly than the original pursuit. AI is responsible for writing, the certifier is responsible for closing, and the person is returned to a more valuable position to define what is called right.
References
How to choose an AI coding agent for real work | Octomind octomind.run/blog/ai-cod…
I built a verification hierarchy that lets AI write production code 24/7 www.reddit.com/r/SideProje…
Why AI Coding Agents Need a Way to Verify Their Own Work
How to verify correctness of AI-generated code beyond passing existing tests
Auto-fetched and translated by AI Atlas. All rights belong to the original author.