Repository navigation
Conversation
…ng metrics M11 假成功:DELETE /routes/<不存在>、/platforms、/instances、/adapters 和 POST /messages/<不存在>/ack 都回 200,因为 repository 的 Delete/UpdateStatus 不看 RowsAffected。改成返回 gorm.ErrRecordNotFound,handler 统一映射 404。 M12 错误码语义:新增 service 层哨兵错误(ErrNotFound/ErrConflict/ErrInvalid/ ErrUnauthorized)和 handler.respondError 单点映射(404/409/400/401/500, 其余仍 500)。Get/Update/Delete 的 not-found 分支不再回 400,重名 (platform code、username)走 409,`record not found` 原文不再当 400 文案。 M10 恒为 0 的监控页:AdapterInstance 补 last_heartbeat / message_count / error_count,迁移 003 与 AutoMigrate 双重覆盖;心跳、入站消息、失败投递在 WebSocket 热路径上维护,状态翻 running,指标不再恒为 0。 M13 测试:internal/handler 新增 httptest 表驱动用例,覆盖 404/409 两端与 500/400 边界;在基线提交上先红后绿。 文档:api-reference.md 的状态码表补规则并补实例指标字段。 Co-authored-by: multica-agent <github@multica.ai>
TyperBody
force-pushed
the
agent/sxy/e371b29c7b9a
branch
from
November 7, 2026 14:16
17547cd to
44c9029
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes ESPL-21
Base:
feat/project-review-and-pr-qa(PR #3)。不改 M5。清 M10 / M11 / M12 / M13:假成功、错误码语义、恒为 0 的监控指标,以及钉住这些行为的状态码测试。
改前 → 改后(本机起真实服务实测,非 mock)
改前跑基线提交
a0d5148的二进制,改后跑本分支,同一套 curl:DELETE /api/v1/routes/nope{"message":"route deleted"}{"error":"resource not found"}DELETE /api/v1/platforms/nopeDELETE /api/v1/instances/nopeDELETE /api/v1/adapters/nopePOST /api/v1/messages/nope/ack{"message":"message acknowledged"}PUT /api/v1/instances/nope{"error":"record not found"}{"error":"resource not found"}PUT /api/v1/routes/nope{"error":"record not found"}PUT /api/v1/platforms/nope{"error":"record not found"}POST /api/v1/adapters/nope/start{"error":"record not found"}POST /api/v1/platforms(重复 code)platform code already existsPOST /api/v1/auth/register(重复用户)username already existsGET /api/v1/instances的监控字段last_heartbeat/message_count/error_count有真实值监控页实测:连上
/ws/adapter?instance_id=…发 3 条消息 + 1 帧error后改前同样的库/动作下三个指标恒为
0、status恒为stopped。改动要点
Delete/UpdateStatus判RowsAffected,为 0 返回gorm.ErrRecordNotFound(10 个 repository 方法,含 route/platform/instance/adapter/message/user)。internal/service/errors.go新增ErrNotFound/ErrConflict/ErrInvalid/ErrUnauthorized哨兵;internal/handler/errors.go的respondError单点映射 404/409/401/400,其余 500。所有 handler 的err.Error()+ 写死状态码改成走它,record not found不再作为 400 文案回吐。重名(platform code、username)走 409;已在运行再 start 走 409。models.AdapterInstance补last_heartbeat/message_count/error_count;迁移migrations/003_instance_metrics.sql(IF NOT EXISTS+ 回滚注释)与AutoMigrate双重覆盖,migrations/README.md补索引。WebSocket 热路径维护三个值:连上/任意帧刷新心跳并置running,入站消息 +1,桥报错/落库失败 +1;error帧不再当消息入库,两类计数不重叠。internal/handler/errors_test.go表驱动httptest,覆盖 404 全资源面、409 两类、400 坏 body、500 内部错误,以及“删除真实资源仍 200”的正向用例。api-reference.md状态码表补规则(DELETE无行必须 404、重名 409、已在运行 409、404 不回数据库原文),实例表示补三个指标字段。测试先红后绿
新测试在基线
a0d5148上跑(只拷入测试文件):本分支全绿。
本地校验
CGO_ENABLED=1 make testokgolangci-lint run0 issues.gofmt -l .npx tsc --noEmit(改了前端)npm run lint约束:未引入新依赖;全程离线(只在本机起服务打 curl/WS,不碰上游平台);
CGO_ENABLED=1。范围外
message_count当窗口速率算的 “messages per minute” 仍是累计均值,只在变量名上写明,未改成时间窗统计。gh仍不可用,PR 由 API 创建。