Skip to content

chore: Go 升级到 1.27.4、golangci-lint 升级到 2.15.0,lint 改为全量检查并清理失效的测试与 CI 配置 - #1831

Merged
chen-ran merged 1 commit into
felinics:mainfrom
chen-ran:chore/go-1.27-golangci-2.15
Nov 22, 2026
Merged

chen-ran merged 1 commit into
felinics:mainfrom
chen-ran:chore/go-1.27-golangci-2.15

Conversation

@chen-ran

@chen-ran chen-ran commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

把 Go 从 1.26.10 升到 1.27.4、golangci-lint 从 2.10.1 升到 2.15.0,并处理升级暴露出来的问题。golangci-lint 2.10.1 用 Go 1.26 构建,加载不了 Go 1.27 的模块(直接 panic),所以两者必须一起升。

版本

  • go.mod、mise.toml、三个 Go 基础镜像(docker/Dockerfile.server、docker/Dockerfile.workspace、devenv/Dockerfile.server):1.26.10 → 1.27.4。CI 的 setup-go 读 go.mod。
  • mise.toml、go-ci.yml:golangci-lint 2.10.1 → 2.15.0。
  • 依赖版本和 go.sum 不变。

随 Go 1.27 来的行为变化(需要审查者留意)

Go 1.27 的 encoding/json 改由 v2 实现支撑,UnmarshalTypeError.Field 变成完整路径:数组元素带下标,map 的值带键。本仓库有两处把这个字段原样传出去:

位置 Go 1.26.10 Go 1.27.4
httpx.Binder → request.field_invalid 的 args.field items.count、meta.count items.1.count、meta.k.count
工具参数解码失败时返回给模型的文案 ids must be an integer ids.2 must be an integer

顶层字段和嵌套对象字段不变。新值能指出是哪一个元素错了,所以没有做兼容处理;docs/errors.md 补了说明,两处各加一个测试钉住(在 Go 1.26.10 下失败)。前端只把 field 填进 {field} is invalid. 这句文案,没有按字段值分支。

逐项核对了 Go 1.27 其余的默认值变化(移除的 GODEBUG 开关、tracebacklabels、x509sslcertoverrideplatform、html/template 的 meta URL 转义),本仓库都没有用到。

新版 lint 报出的存量问题

未改动的 main 在 2.10.1 下是 0 条,在 2.15.0 下是 205 条,其中 193 条在测试文件里:

  • noctx(166):httptest.NewRequest 改为 NewRequestWithContext。原本紧接着 .WithContext(ctx) 的 8 处直接用那个 context。
  • errcheck(19):从 channel 收到 error 后丢弃。18 处在测试里,改为记日志或断言;cmd/bridge 在 kill Xvnc 后回收进程的那一处保留丢弃并加 nolint 说明原因。
  • gosec G602(7):循环里每个元素都重新求值 turns[i].Messages 再索引,改为先取成局部切片;两个测试辅助函数改用 slices.Equal。
  • govet nilness、staticcheck SA4023:case existingReady 之后的 case !existingReady 就是 default;剪贴板读循环只在失败时返回,调用方不再判断 err != nil。
  • gofumpt(4)、predeclared(1)。另有 5 处带原因保留为 nolint(gosec 4 处:G115 两处、G407、G703;staticcheck SA1019 一处,是仍在兼容期的 message_id 入参)。

Lint 任务改为全量检查

go-ci.yml 的 lint 任务原先带 only-new-issues: true,只报相对合并基点新增的问题,PR 没碰到的代码里的问题永远不会出现。上面 205 条就是这样在绿色检查后面积累起来的。本 PR 去掉这个选项(以及只为它服务的 fetch-depth: 0),任务改为检查整个模块。当前全量为 0 条。

这是 CI 策略的改变,不是清理。 以后升级 lint 版本时,存量问题会让所有 PR 变红,直到修完。如果不想在这个 PR 里做,可以单独拿掉这一项,其余改动不依赖它。

提交钩子在符号链接路径下静默跳过全部检查

.husky/checks.mjs 用 process.argv[1] === fileURLToPath(import.meta.url) 判断自己是不是入口。argv[1] 是调用时写的路径,后者是真实路径;检出目录经过符号链接时两者不相等(macOS 的 /tmp → /private/tmp,或链接出来的 worktree 目录),于是钩子什么都不跑并以 0 退出,传一个不存在的检查名也是 0。改为比较两边的真实路径,并补了回归测试(未修复时失败)。

顺带修了钩子自己的回归测试:它继承了调用方的 MEMOH_* 环境变量,所以一次改动 .husky/ 并按文档带 MEMOH_CHECK_TIMEOUT_SECONDS 的提交,会让其中 3 个用例失败。在未改动的 main 上 MEMOH_CHECK_TIMEOUT_SECONDS=600 node --test scripts/hook-checks.test.mjs 即可复现。

删除(不是替换)

删除 依据
internal/channel/identities/service_integration_test.go 文件头是 //go:build ignore,从 2 月起如此,任何构建都不包含它
internal/settings/default_agent_concurrency_postgres_integration_test.go #1110 改了 botagents.Service.Delete 的签名后就编译不过;没有 CI 步骤为这个包带 integration 标签构建,所以没人发现
internal/audio/adapter/edge/ws_integration_test.go 没有跳过条件,直连线上的 Edge TTS 服务,并往系统临时目录写 mp3
go-ci.yml 里 -run 的 RedisDecision 分支 #1707 把 TestPostgresRedisDecisionSurvivesGracefulShutdown 改名后,它不再匹配任何测试。删除它不改变 CI 实际运行的内容
eslint.yml 的 4 条路径过滤 被同一列表里的 packages/** 覆盖
eslint.config.mjs 的一条 ignore 指向 #1813 已删除的文件
.golangci.yml 的 go: "1.25" 和两段设置 版本默认读 go.mod;gocyclo、funlen 没有启用

这里有两处删除之外的缺口,本 PR 都没有补,列出来供决定:

  • 第二个文件验证的并发场景(默认 Agent 的指派与停用/删除互斥)因此失去了数据库层面的测试。补上缺的那个参数后它能通过;这里按"坏掉且无人运行"删除,没有修。如果希望保留,改一个参数并把 ./internal/settings 加进 migrations.yml 的集成测试步骤即可。
  • RedisDecision 分支失效的后果:fix(agent): 重启后接管等待中的问题,并正确处理过期回答 #1707 改名后的 TestPostgresDecisionSurvivesGracefulShutdown 和同一提交新增的 TestPostgresShutdownClosesDecisionsOfLostRun 从 11 月 2 日起没有任何 CI 步骤选中,在不带数据库的 go test ./... 里只会跳过。两者在 Go 1.27.4 + -race、fencing 任务的环境下实测通过。要让 CI 重新覆盖,需要在那条 -run 正则里加上 DecisionSurvives|ShutdownCloses。

没有处理的

  • 带 integration 标签做 lint 还有 19 条存量问题。CI 不带这个标签 lint,本 PR 没有动。
  • internal/agentcredential 和 internal/chat/attention 的 Postgres 集成测试同样没有 CI 步骤运行(共 6 个用例),但它们能编译并通过,没有删。
  • go.mod 的 require 分组不整齐(go mod tidy 会重排,1.26.10 下也会改一行),不影响依赖版本,没有夹带。

Related Issues

无。

Validation

以下均为 Agent 验证。

自动检查(Go 1.27.4)

  • go build ./...、go vet ./...、go vet -tags=integration ./... 通过;GOOS=linux|windows|darwin GOARCH=amd64 交叉编译通过。
  • golangci-lint run ./...(2.15.0,全量):0 条;golangci-lint fmt --diff:无差异;golangci-lint config verify 通过。
  • go test -race -count=1 ./...:macOS arm64 上 174 个包通过,无数据竞争。
  • 在 golang:1.27.4(linux/arm64)容器里按 CI 的方式重跑:vet、全量 lint 通过;race 测试 173 个包通过,1 个包失败(见下方"未通过")。
  • 按工作流文件里的命令在一次性 PostgreSQL 18 和 Redis 上跑了 Session Runtime (PostgreSQL fencing) 的全部步骤、Session Runtime (redis)、连接器断开的集成用例:全部通过。
  • migrations.yml:新库上 migrate up → down → up(版本 173,非 dirty),随后的集成测试步骤 6 个包通过。
  • docker/Dockerfile.server 的 server-builder 阶段在 linux/arm64 和 linux/amd64 上用新基础镜像构建成功;开发用的工作区镜像按 scripts/prepare-dev-workspace-image.sh 重新构建成功。
  • 钩子回归测试 36 个通过;ESLint 0 errors。
  • 两个新测试在 Go 1.26.10 下失败、1.27.4 下通过;符号链接用例在未修复的钩子上失败。

未通过 / 未运行

  • 上述容器里 internal/container/docker 的 TestCreateContainerMapsDockerConflictToAlreadyExists 失败。原因是测试进程本身跑在容器里:代码检测到 /.dockerenv 后去查询"自己这个容器",测试的假 Docker API 不认识这个请求。未改动的 main + golang:1.26.10 在同样的容器里同样失败;去掉 /.dockerenv 后在本分支通过。与升级无关,GitHub 的 VM runner 上没有这个标记。本 PR 没有修。
  • Valkey 矩阵、pgvector 任务、linux/amd64 上的测试、Desktop 构建没有在本地运行,交给 CI。
  • actionlint 在本机跑不起来(它依赖的 shellcheck 没有选定版本),工作流文件只确认了能解析为 YAML。

运行环境与真实界面

用 scripts/dev-compose.sh devenv/docker-compose.yml 加一个只改项目名、容器名和端口的覆盖文件,起了一套独立的开发栈(项目 memoh-go127,Web http://127.0.0.1:28082,Server :28080)。确认了:server 和 channel 容器内是 go1.27.4 linux/arm64,go version -m 显示运行中的 memoh-server 由 go1.27.4 构建,容器内挂载的源码与本分支逐文件哈希一致。

模型用一个本地的 OpenAI 兼容探针端点(流式输出固定回复,可按提示词发起一次工具调用),所以以下验证的是 Memoh 自己的链路,不是真实模型的行为。

在 headless Chrome 里操作真实界面:

  1. 登录,走完首次使用向导:添加自定义服务商(服务端向探针端点请求 /v1/models 并导入模型)、创建 Bot(嵌套 containerd 里创建出工作区)。
  2. 发送消息,回复经正常对话链路流式显示。
  3. 让模型调用 exec:命令在工作区容器里执行,结果 go127-exec-ok 回到模型和界面。
  4. 让模型调用 tool_describe,names 的第三个元素故意给成对象:模型收到 invalid arguments for tool_describe: names.2 must be a string, got object。这是上面表格第二行在运行时的样子。
  5. Bot 设置 → MCP → 导入,粘贴一段 JSON,其中 mcpServers.files.args 的第三个元素是对象:服务端返回 400 request.field_invalid,args.field 为 mcpServers.files.args.2,对话框显示 "mcpServers.files.args.2 is invalid."。这是表格第一行。
  6. 重新打开页面,从存储的历史里加载出同一会话,前面的回复、工具结果都在。

四次运行在 context_lifecycles 里各有一行 completed 且带快照(reconcileTerminalContextLifecycle 是本 PR 改过 switch 的地方)。Server 和 Channel 日志里没有 ERROR 或 panic。

没有在界面上验证的:剪贴板读循环的改动(需要一个桌面会话断线)、cmd/bridge 里 Xvnc 的回收、Feishu/LINE/微信等渠道。这些只有单元测试覆盖。

Screenshots / Recordings

Go 1.27.4 构建下的流式回复

流式回复

工具调用:exec 的结果回到界面;tool_describe 的参数错误带上了数组下标 names.2

工具调用与带下标的参数错误

MCP 导入:request.field_invalid 指向 mcpServers.files.args.2

MCP 导入的字段错误

重新加载后从历史里恢复的会话

历史恢复

Human QA

  • Human QA passed

…p dead tests and CI entries

Toolchain
- go.mod, mise.toml and the three Go base images move from 1.26.10 to 1.27.4.
  CI reads the version from go.mod.
- golangci-lint moves from 2.10.1 to 2.15.0 (mise.toml, go-ci.yml). 2.10.1 is
  built with Go 1.26 and cannot load a Go 1.27 module at all.

Behavior change that comes with Go 1.27
- encoding/json is backed by the v2 implementation, and the Field of an
  UnmarshalTypeError is now the full path, with the index of an array element
  and the key of a map value. Two places pass that field on:
  - request.field_invalid from httpx.Binder: "items.1.count" where it was
    "items.count", "meta.k.count" where it was "meta.count".
  - the decode error a tool call returns to the model: "ids.2 must be an
    integer" where it was "ids must be an integer".
  Top-level and nested object fields are unchanged. docs/errors.md describes
  the field, and a test for each place pins it; both fail on Go 1.26.10.

What the new linter reports on the existing code (0 findings on 2.10.1, 205 on
2.15.0, 193 of them in test files)
- noctx (166): httptest.NewRequest becomes NewRequestWithContext. A request
  that was given a context right after takes that context directly.
- errcheck (19): an error received from a channel and dropped. Tests log it or
  assert it; cmd/bridge reaps Xvnc after killing it and says so.
- gosec G602 (7): loops that re-evaluated turns[i].Messages for every element
  index a named slice; two test helpers become slices.Equal.
- govet nilness, staticcheck SA4023: a `case !existingReady` that follows
  `case existingReady` is the default, and a clipboard reader that only
  returns on failure is not checked for a nil error.
- gofumpt (4), predeclared (1), and four findings kept with a stated reason.

Lint job
- golangci-lint ran with only-new-issues, so findings in code a PR did not
  touch were never reported; that is how the above accumulated behind a green
  check. The job lints the whole module now and no longer needs full history.

Commit hook
- .husky/checks.mjs decided whether it was the entry point by comparing
  argv[1] with its own real path. In a checkout reached through a symlink
  (macOS /tmp, a linked worktree directory) the two differ, so the hook ran
  nothing and exited 0, for an unknown check name too. It compares real paths.
- scripts/hook-checks.test.mjs inherited the caller's MEMOH_* settings, so a
  commit that touches .husky/ and uses the documented
  MEMOH_CHECK_TIMEOUT_SECONDS override failed three of its own regression
  tests. The fixture drops them.

Removed, not replaced
- internal/channel/identities/service_integration_test.go: `//go:build ignore`
  since February; no build includes it.
- internal/settings/default_agent_concurrency_postgres_integration_test.go:
  has not compiled since felinics#1110 changed botagents.Service.Delete, and no CI
  step builds the integration tag for that package.
- internal/audio/adapter/edge/ws_integration_test.go: calls the live Edge TTS
  service with no skip condition and writes mp3 files to the temp directory.
- go-ci.yml: the RedisDecision alternative of a -run pattern, which has
  matched no test since felinics#1707 renamed it (the new name is still selected).
- eslint.yml: four path filters shadowed by "packages/**" in the same list.
- eslint.config.mjs: an ignore entry for a file felinics#1813 deleted.
- .golangci.yml: `go: "1.25"` (the default reads go.mod) and settings for two
  linters that are not enabled.
@github-actions github-actions Bot added change:desktop Changes the Electron desktop app or shared desktop configuration change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:M PR size uses the larger of added or deleted lines, excluding generated files labels Nov 22, 2026
@chen-ran
chen-ran marked this pull request as ready for review November 22, 2026 19:38
@chen-ran
chen-ran merged commit 5db320a into felinics:main Nov 22, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:desktop Changes the Electron desktop app or shared desktop configuration change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:M PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant