Files
myclaude/codeagent-wrapper/wrapper_name.go
swe-agent[bot] c6cd20d2fd fix(parallel): 修复并行执行启动横幅重复打印问题
修复 GitHub Actions 失败的测试 TestRunParallelStartupLogsPrinted。

问题根源:
- 在 main.go 中有重复的启动横幅和日志路径打印逻辑
- executeConcurrent 内部也添加了相同的打印逻辑
- 导致横幅和任务日志被打印两次

修复内容:
1. 删除 main.go 中 --parallel 处理中的重复打印代码(行 184-194)
2. 保留 executeConcurrent 中的 printTaskStart 函数,实现:
   - 在任务启动时立即打印日志路径
   - 使用 mutex 保护并发打印,确保横幅只打印一次
   - 按实际执行顺序打印任务信息

测试结果:
- TestRunParallelStartupLogsPrinted: PASS
- TestRunNonParallelOutputsIncludeLogPathsIntegration: PASS
- TestRunStartupCleanupRemovesOrphansEndToEnd: PASS

影响范围:
- 修复了 --parallel 模式下的日志输出格式
- 不影响非并行模式的执行

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 17:02:59 +08:00

61 lines
1.4 KiB
Go

package main
import (
"os"
"path/filepath"
"strings"
)
const (
defaultWrapperName = "codeagent-wrapper"
legacyWrapperName = "codex-wrapper"
)
// currentWrapperName resolves the wrapper name based on the invoked binary.
// Only known names are honored to avoid leaking build/test binary names into logs.
func currentWrapperName() string {
if len(os.Args) == 0 {
return defaultWrapperName
}
base := filepath.Base(os.Args[0])
base = strings.TrimSuffix(base, ".exe") // tolerate Windows executables
switch base {
case defaultWrapperName, legacyWrapperName:
return base
default:
return defaultWrapperName
}
}
// logPrefixes returns the set of accepted log name prefixes, including the
// current wrapper name and legacy aliases.
func logPrefixes() []string {
prefixes := []string{currentWrapperName(), defaultWrapperName, legacyWrapperName}
seen := make(map[string]struct{}, len(prefixes))
var unique []string
for _, prefix := range prefixes {
if prefix == "" {
continue
}
if _, ok := seen[prefix]; ok {
continue
}
seen[prefix] = struct{}{}
unique = append(unique, prefix)
}
return unique
}
// primaryLogPrefix returns the preferred filename prefix for log files.
// Defaults to the current wrapper name when available, otherwise falls back
// to the canonical default name.
func primaryLogPrefix() string {
prefixes := logPrefixes()
if len(prefixes) == 0 {
return defaultWrapperName
}
return prefixes[0]
}