【架构优化】拆分 runner.collectTaskOutputs 的输出文件读取、补丁目录推导与补丁采集

Abierto
#431 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fx-kurumi ya está trabajando en esto.

Desde el 13/11/2026.

  • #432 de @fx-kurumi — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
22/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
git, go
Área
devtools

Línea de trabajo

Work is confined to internal/runner/outputs.go, where collectTaskOutputs mixes file reading, patch-directory derivation and patch collection. The payload names no entry point beyond that function. Done means three helpers are extracted with unchanged behaviour, the existing TestCollectTaskOutputsReportsOnlyRegularFilesInsideWorkspace still passes, and new tests cover the extracted pieces. However, a linked pull request (#432) is already open, so the work is likely claimed.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

现状问题

internal/runner/outputs.go 的 collectTaskOutputs 约 50 行,在一个函数里串行做了三件互不相关的事:

  1. 逐个读取 OutputFiles(路径安全校验、Lstat 只认普通文件、超过 maxArtifactUploadBytes 记入 TooLarge、读入 Files);
  2. 推导需要采集补丁清单的仓库目录(无仓库时为工作区根 "",否则为各仓库的 safeRunnerRepoDir(WorkspaceDir)),并逐个调用 gitwork.PatchInventory 填 Patches;
  3. 检测前端工作区事实 Facts。

其中「仓库目录推导」是纯逻辑却埋在 I/O 循环里,无法单独测试;现有测试也只覆盖了第 1 步。

重构方案

仅在 internal/runner/outputs.go 内拆函数,不改逻辑:

  • readOutputFiles(workspace, rels) (files map[string]string, tooLarge []string):原第 1 段循环原样搬入;
  • patchInventoryDirs(inv) []string:原目录推导原样搬入;
  • collectPatchInventories(workspace, dirs) map[string]string:原补丁采集循环原样搬入;
  • collectTaskOutputs 只负责编排:恢复缺失输出 → 读文件 → 采补丁 → 采事实。

nil map / nil slice 的语义保持不变(没有文件时 Files/Patches 仍为 nil,JSON omitempty 输出不变)。

影响范围

仅 internal/runner/outputs.go(及新增测试文件),collectTaskOutputs 签名与三个调用方(daemon.go)不变,对外接口与行为不变。

验证方式

  • 新增测试覆盖 patchInventoryDirs(无仓库 / 多仓库)、collectPatchInventories(真实 git 仓库有改动 / 无改动 / 非仓库目录)与 readOutputFiles 的 nil 语义;
  • 原有 TestCollectTaskOutputsReportsOnlyRegularFilesInsideWorkspace 不改动且通过;
  • gofmt、go vet ./internal/runner/、go test ./internal/runner/。
Lenguaje dominante
Go
Estrellas
141
Forks
28
Merge medio
1 d 15 h
PR fusionados (30 d)
113

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Tencent/LoopForge

Todos los issues de Tencent/LoopForge

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.