AI 智能體構建帶登入功能的 Todo API,審查在合併前找出 4 個真實錯誤
AI Agents Built a Todo API With Login. The Review Caught 4 Real Bugs Before Merge.
AI CodeOps 使用 AI 智能體構建帶註冊與登入功能的 Todo REST API,並在合併前的審查中找出及修復 4 個真實錯誤,最終測試達 31/31。合併門檻包括指定提交的團隊測試通過、AI 審查沒有未解決的高或嚴重問題,以及由人員批准。人工以手機畫面檢查時也發現測試未捕捉的登入錯誤顯示及版面問題;修正後測試通過並完成合併。
We asked AI agents to build a todo REST API with sign-up and login: Node.js, no dependencies, passwords hashed with scrypt, session tokens, a login rate limit, and a web page that works on a phone.
Every change went through a release gate before it could merge. The gate needs three things: the team's tests passing on the exact commit, an AI review of the real diff with no open high or critical findings, and a person approving.
The result: 31 of 31 tests, four real bugs caught and fixed before merge, and a page that works on a phone. Here is how it went, including the parts that didn't go right the first time.
The ticket came in parts
Earlier builds taught us that one big ticket fails. So this one came in three parts, and each part named every file to write, the test runner and the assertion library.
- Part 1, the core. A user store with scrypt password hashing and session tokens, and a todo store where each user only ever sees their own todos.
-
Part 2, the server. Every route, Bearer tokens, a 100 KB body limit,
405with anAllowheader, and five failed logins per email before a429. - Part 3, the page. Static files with a strict Content Security Policy, then the HTML, styles and script.
Part 3 started fresh from main once parts 1 and 2 were merged, so each change stayed small enough to review.
Bug 1: sign-up crashed on a non-string email
Part 1 came back at 12 of 13 tests, and the gate held it. The AI review spotted that sign-up would crash if email wasn't a string, for example a number in the JSON body. That's a real bug, and it never reached the server.
The failing test was a different problem. We pulled the code and ran it. The test used assert.rejects on code that isn't async, so its check never ran. One line of the ticket was also wrong. The follow-up named each file, each line and the fix, including the mistake in our own ticket.
Bug 2: a null body crashed the todo store
In part 2 the review flagged two things, and we tested both:
- Updating a todo with a
nullbody crashed the store. Real. - Without a token, a wrong method got a
401before the405. Not a crash, but worth tightening.
Both were fixed in the next round.
The agent said "all tests pass." The gate said 19 of 20.
The agent's own summary said all tests passed. The console showed the actual run: 19 of 20, on the same page. The gate goes by the real result, not the summary.
The last failure traced back to our ticket again, so the follow-up said exactly that.
Bug 3: the rate limiter remembered every email forever
At 21 of 21, the review still had one finding. The login rate limiter kept every email address it had ever seen. Send it a stream of made-up addresses and memory grows without limit. Real, and fixed.
The change got too big, and the platform said so
Stacked follow-ups had grown the change past 60 KB, too big for a meaningful review. Instead of reviewing it anyway, AI CodeOps said so, named the largest files, and asked for a split.
So the fix went into its own small module, with its own tests. Expired entries are pruned and the map is capped: 26 of 26, release ready.
A person runs it before approving
Before approving, a person ran the server by hand:
- Five wrong passwords, then even the right one gets
429 Too Many RequestswithRetry-After. -
PUT /api/todos/:idgets405withAllow: GET, PATCH, DELETE. - A 110 KB body gets
413, and the next request still succeeds. - A due date of February 30 is rejected.
- Logout really revokes the token.
The approval note lists exactly what was checked, and it goes into the audit trail. Approving opened a pull request on our Forgejo server, and parts 1 and 2 were merged.
Bug 4: the page worked in tests, not on a phone
Part 3's static files and Content Security Policy passed 30 of 30 on the first try. Then came the script, and we opened it on a phone-sized screen. The tests passed, but a person could see more:
- Login errors were hidden.
- A wrong password said "session expired".
- There was no viewport tag.
We sent one specific follow-up for the behaviour and one for the styles. Errors now show on the sign-in screen with the right words, the layout fits the phone, and the todo list reads cleanly. 31 of 31, release ready, no findings. Approved and merged, then checked again locally on Node 22.
What made this work
- The AI review found four real problems, and each was fixed before merge.
- The gate went by the real test results, not the agent's summary.
- Changes stayed small enough to review. When one grew too big, the platform asked for a split instead of waving it through.
- A person ran the app before approving. Several of the most useful findings came from using the page on a phone, not from the tests.
The code is on our Forgejo server: https://nforge.dev/aicodeops-dev/todo-api
AI CodeOps works with GitHub, GitLab, Bitbucket, Gitea and Forgejo, including self-hosted. It's free during the open beta, and free forever for non-commercial open-source projects: https://aicodeops.dev
來源:DEV Community · dev.to