From 078ad9b2f3b82aaa50e60632ff112b233cb340fd Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 28 Aug 2026 16:21:34 +0800 Subject: [PATCH] chore(autoresearch): init cordis-quality session files --- .auto/checks.sh | 11 +++++++++++ .auto/ideas.md | 11 +++++++++++ .auto/measure.sh | 18 ++++++++++++++++++ .auto/prompt.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100755 .auto/checks.sh create mode 100644 .auto/ideas.md create mode 100755 .auto/measure.sh create mode 100644 .auto/prompt.md diff --git a/.auto/checks.sh b/.auto/checks.sh new file mode 100755 index 00000000..72631f79 --- /dev/null +++ b/.auto/checks.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Correctness gate: build + full tests + Cordis architecture checker (errors only) +set -euo pipefail +cd "$(dirname "$0")/../backend" + +go build ./... 2>&1 | head -20 +go test ./... 2>&1 | grep -vE '^(ok|---|\?|PASS)' | grep -v 'no test files' | head -40 || true +FAILS=$(go test ./... 2>&1 | grep -cE '^(FAIL|--- FAIL)' || true) +if [ "${FAILS}" != "0" ]; then echo "TESTS FAILED (${FAILS})"; exit 1; fi +"$(dirname "$0")/../scripts/check_cordis_architecture.sh" >/dev/null 2>&1 || { echo "CORDIS ARCH CHECK FAILED"; exit 1; } +echo "CHECKS OK" diff --git a/.auto/ideas.md b/.auto/ideas.md new file mode 100644 index 00000000..192abce5 --- /dev/null +++ b/.auto/ideas.md @@ -0,0 +1,11 @@ +# Ideas Backlog +- extpoints 四处同构 Register 代码用泛型 helper 收敛(migration/setting/schedule/task) +- message_gateway admin_handlers/push_handlers/push_channels 三文件互为重复 → 提取共享构建函数 +- message_gateway/repository.go 222-240 ↔ 332-350 重复查询块 +- driver_asynq_worker/plugin.go 371-390 ↔ 420-439 重复 +- admin/repository.go:507 nilerr 真 bug → 读代码确认 + 回归测试 +- inproc 驱动 contextcheck 两处 → 传 ctx +- gosec 权限修复(test_helpers.go 0755→0750/0600, postgres.go 49) +- nestif 四处拆函数 +- 全库性能巡查:N+1 查询、循环内 compile/alloc、锁粒度、LIKE 无 EscapeLike、缺失索引 +- 包结构优化(upload/shared、message_gateway 文件命名混乱) diff --git a/.auto/measure.sh b/.auto/measure.sh new file mode 100755 index 00000000..ccf47e4d --- /dev/null +++ b/.auto/measure.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Autoresearch measure: golangci-lint issue count (primary) + dupl subset + test packages +set -euo pipefail +cd "$(dirname "$0")/../backend" + +# Primary metric: total golangci-lint issues (non-test code) +golangci-lint run > /tmp/ar_lint.txt 2>&1 || true +LINT_ISSUES=$(grep -cE '(^|[/\\])[^/\\:]+\.go:[0-9]+:' /tmp/ar_lint.txt || true) + +# Secondary: dupl-specific issues +DUP_ISSUES=$(grep -cE '\(dupl\)$' /tmp/ar_lint.txt || true) + +# Secondary: passing test packages (regression guard) +TESTS_PASSED=$(go test ./... 2>&1 | grep -c '^ok' || true) + +echo "METRIC lint_issues=${LINT_ISSUES}" +echo "METRIC dup_issues=${DUP_ISSUES}" +echo "METRIC tests_passed=${TESTS_PASSED}" diff --git a/.auto/prompt.md b/.auto/prompt.md new file mode 100644 index 00000000..bd38118b --- /dev/null +++ b/.auto/prompt.md @@ -0,0 +1,48 @@ +# Autoresearch: Cordis 架构合规 + Bug 修复 + 性能 + 代码质量 + +## Objective +Wavelet 后端(Go, Cordis 插件化微内核架构)全面质量提升:修复违反 Cordis 设计原则的地方、修复 bug、消除潜在性能问题、减少代码重复(dupl)、提升可维护性。主指标为 golangci-lint 问题总数,逐实验递减,且不得以作弊手段(nolint / 弱化配置 / 删测试)达成。 + +## Metrics +- **Primary**: lint_issues (count, lower is better) — `golangci-lint run` 报告的问题总数(基线 45) +- **Secondary**: dup_issues (dupl 专项计数), tests_passed (go test 通过包数,不得下降) + +## How to Run +`./.auto/measure.sh` — 输出 `METRIC lint_issues=N` / `METRIC dup_issues=N` / `METRIC tests_passed=N`。 + +## Files in Scope +- `backend/core/` 微内核(context.go/container.go/events.go/app.go/extpoints/contracts)— 只允许更纯粹,禁止引入框架依赖 +- `backend/plugins/{domain,infra,drivers}/` 所有插件 — 重复代码消除、bug 修复 +- `backend/pkg/` 基础库 +- `scripts/check_cordis_architecture.sh` 架构守门脚本(只可增强、不可弱化) +- `.auto/*` 会话文件 + +## Off Limits(作弊红线) +- ❌ 禁止修改 `.golangci.yml` 弱化 lint(禁阈值调高、禁关 linter、禁 excludes) +- ❌ 禁止 `//nolint` 注释压制问题 +- ❌ 禁止删除测试或功能来消除告警(删除死代码需先证明确实无人引用) +- ❌ 禁止违反 `backend/pkg/util/` 纯净性、`backend/core/` 微内核纯净性、contracts 纯抽象 +- ❌ 修复行为 bug 必须带回归测试或明确论证;tests_passed 不得下降 +- ✅ 允许:重构提取共享 helper(插件内)、加注释、常量化字符串、拆复杂嵌套、修 gosec 权限、优化 SQL/锁/分配 + +## Constraints +- `.auto/checks.sh` 必须通过:`go build` + `go test ./...` + Cordis 架构检查全绿 +- 插件间严禁跨包 import,只能走 `core/contracts` + EventBus +- 裸 `go func()` 禁止,统一 `util.Go`;SQL LIKE 必须 `util.EscapeLike` + `ESCAPE '\\'` +- API Handler 改动后跑 `make swagger`(若改了 handler 签名/路由) + +## What's Been Tried +### 基线状态(2026-08-28, 45 lint issues) +- **nilerr 真 bug 候选**: `backend/plugins/domain/admin/repository.go:507` err!=nil 却 return nil +- **contextcheck**: `driver_inproc_cron/plugin.go:70`、`driver_inproc_worker/plugin.go:133` 未传 context +- **dupl 重复块**: core/extpoints{migration,setting,schedule,task} 四处同构注册代码;message_gateway{admin_handlers:55-67,115-130,143-158 ↔ push_handlers:61-74,77-93 ↔ push_channels:218-231,270-286}; message_gateway/repository.go:222-240↔332-350; driver_asynq_worker/plugin.go:371-390↔420-439 +- **nestif 深嵌套**: admin/handlers_config.go:442(complexity 6), upload/filesrv/file_server.go:330(6), driver_asynq_cron/plugin.go:142(9), driver_asynq_cron/scheduler.go:119(5) +- **gosec**: upload/shared/test_helpers.go:133(G301),134(G306),152(G304); infra/database/postgres.go:49(G301) +- **goconst**: "sqlite"(admin/handlers_db.go:150,handlers_status.go:179), "upload"/"default"(upload/task/*) +- **revive**: storage.go:53 缺注释, db_helper.go{admin:118,125; message_gateway:25; upload/storage/migration.go:40} 未用参数, handlers_config.go:510 未用参数 +- **mnd**: pkg/cache/disk/cache.go:100 魔法数 10 +- **gofumpt**: upload/stats/{category,stats_counter}.go, driver_http/db_helper.go 格式错误 +- 前端 eslint/tsc 已全绿;架构检查脚本 0 违规 + +### 教训 +- (空 — 随实验更新)