Skip to content

refactor(engine): ports 的上游复制段归零 - #282

Merged
SheathedSharp merged 5 commits into
mainfrom
refactor/engine-ports-upstream-zero
Nov 12, 2026
Merged

SheathedSharp merged 5 commits into
mainfrom
refactor/engine-ports-upstream-zero

Conversation

@SheathedSharp

Copy link
Copy Markdown
Owner

这次做了什么

internal/ports 按本项目的对象模型重写,审计(对照 26dbcae)里这一包从 677 行降到 0:

范围 之前 之后
ports 生产 288 0
ports 测试 389 0

引擎总量 9,610 → 8,933 行 / 664 段 / 135 文件(生产 3,564,测试 5,369)。

怎么重写的

  • Windows 当前目录(PEB 读取):32/64 位偏移不再由本机镜像结构体的 unsafe.Offsetof 推导,改成按目标字长选择的两张 ABI 表;UNICODE_STRING 头、UTF-16 解码与路径规范化一起重写。失败语义不变:短读、空/奇数长度、空缓冲区都拒绝,读不到的 pid 仍然缺省。
  • 进程采样与容器统计:ProcSample、DockerStatsEntry 按「启动身份 / 负载 / 状态」重新分组,Apply 合并同来源字段。
  • 测试:PEB 几何、指针解码、UNICODE_STRING、UTF-16、路径规范化和合成进程镜像的用例按同一行为重述;ps 进程表、tasklist、启动时间与显示名的用例按运行器/语言分组重述,覆盖不减少。

Windows ABI 的常量属于事实,保留;改的是表达与结构,不是把同一份代码改个名字。文件路径未动,审计仍按同一相对路径对照上游。

验证

  • go vet ./...
  • go test -count=1 -timeout=8m ./...(全绿)
  • go test -race -count=1 ./internal/ports/
  • GOOS=windows go vet ./internal/ports/、GOOS=windows GOARCH=arm64 go build ./...
  • python3 scripts/audit-upstream-origin.py --upstream /tmp/sonar:ports 无输出,总量 8,933

本机是 macOS,Windows 只做了交叉编译与 vet,没有原生运行 PEB 读取。

🤖 Generated with Claude Code

SheathedSharp and others added 5 commits November 12, 2026 11:05
PEB 跨进程读取的偏移改由 32/64 位两张表按目标字长选择,不再用本机
镜像结构体的 unsafe.Offsetof 推导;UNICODE_STRING 头按目标字长解出长度
与缓冲区,UTF-16 解码与路径规范化同步重写。

行为不变:拒绝短读、空/奇数长度、空缓冲区与越界偏移的用例保留。

Co-Authored-By: Claude Code <noreply@anthropic.com>
ProcSample 按「启动身份 / 负载 / 状态」分组,DockerStatsEntry 按「容器
状态 / 负载」分组;Apply 把同一来源的字段合并赋值,行为不变。

Co-Authored-By: Claude Code <noreply@anthropic.com>
三项覆盖不变:ps 行里带空格的命令行只丢坏行、lstart 按本机时区解释、
显示名按运行器与语言分组取命令里真正标识服务的那一段。

Co-Authored-By: Claude Code <noreply@anthropic.com>
对照 26dbcae:总量 9,610 → 8,933 行 / 664 段、135 个文件(生产 3,564、
测试 5,369),internal/ports 整包归零。

Co-Authored-By: Claude Code <noreply@anthropic.com>
@SheathedSharp
SheathedSharp merged commit e292462 into main Nov 12, 2026
13 checks passed
@SheathedSharp
SheathedSharp deleted the refactor/engine-ports-upstream-zero branch November 12, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant