mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-05 02:30:26 +08:00
fix: stabilize Windows tests by removing echo-based JSON output
- Replace echo with createFakeCodexScript() or fake command runner - Use PID offsets based on os.Getpid() to avoid collisions in cleanup tests Generated with SWE-Agent.ai Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
@@ -550,10 +550,8 @@ func TestRunNonParallelOutputsIncludeLogPathsIntegration(t *testing.T) {
|
|||||||
os.Args = []string{"codeagent-wrapper", "integration-log-check"}
|
os.Args = []string{"codeagent-wrapper", "integration-log-check"}
|
||||||
stdinReader = strings.NewReader("")
|
stdinReader = strings.NewReader("")
|
||||||
isTerminalFn = func() bool { return true }
|
isTerminalFn = func() bool { return true }
|
||||||
codexCommand = "echo"
|
codexCommand = createFakeCodexScript(t, "integration-session", "done")
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string {
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
return []string{`{"type":"thread.started","thread_id":"integration-session"}` + "\n" + `{"type":"item.completed","item":{"type":"agent_message","text":"done"}}`}
|
|
||||||
}
|
|
||||||
|
|
||||||
var exitCode int
|
var exitCode int
|
||||||
stderr := captureStderr(t, func() {
|
stderr := captureStderr(t, func() {
|
||||||
@@ -828,15 +826,20 @@ func TestRunCleanupFlagEndToEnd_Success(t *testing.T) {
|
|||||||
|
|
||||||
tempDir := setTempDirEnv(t, t.TempDir())
|
tempDir := setTempDirEnv(t, t.TempDir())
|
||||||
|
|
||||||
staleA := createTempLog(t, tempDir, "codeagent-wrapper-2100.log")
|
basePID := os.Getpid()
|
||||||
staleB := createTempLog(t, tempDir, "codeagent-wrapper-2200-extra.log")
|
stalePID1 := basePID + 10000
|
||||||
keeper := createTempLog(t, tempDir, "codeagent-wrapper-2300.log")
|
stalePID2 := basePID + 11000
|
||||||
|
keeperPID := basePID + 12000
|
||||||
|
|
||||||
|
staleA := createTempLog(t, tempDir, fmt.Sprintf("codeagent-wrapper-%d.log", stalePID1))
|
||||||
|
staleB := createTempLog(t, tempDir, fmt.Sprintf("codeagent-wrapper-%d-extra.log", stalePID2))
|
||||||
|
keeper := createTempLog(t, tempDir, fmt.Sprintf("codeagent-wrapper-%d.log", keeperPID))
|
||||||
|
|
||||||
stubProcessRunning(t, func(pid int) bool {
|
stubProcessRunning(t, func(pid int) bool {
|
||||||
return pid == 2300 || pid == os.Getpid()
|
return pid == keeperPID || pid == basePID
|
||||||
})
|
})
|
||||||
stubProcessStartTime(t, func(pid int) time.Time {
|
stubProcessStartTime(t, func(pid int) time.Time {
|
||||||
if pid == 2300 || pid == os.Getpid() {
|
if pid == keeperPID || pid == basePID {
|
||||||
return time.Now().Add(-1 * time.Hour)
|
return time.Now().Add(-1 * time.Hour)
|
||||||
}
|
}
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
@@ -866,10 +869,10 @@ func TestRunCleanupFlagEndToEnd_Success(t *testing.T) {
|
|||||||
if !strings.Contains(output, "Files kept: 1") {
|
if !strings.Contains(output, "Files kept: 1") {
|
||||||
t.Fatalf("missing 'Files kept: 1' in output: %q", output)
|
t.Fatalf("missing 'Files kept: 1' in output: %q", output)
|
||||||
}
|
}
|
||||||
if !strings.Contains(output, "codeagent-wrapper-2100.log") || !strings.Contains(output, "codeagent-wrapper-2200-extra.log") {
|
if !strings.Contains(output, fmt.Sprintf("codeagent-wrapper-%d.log", stalePID1)) || !strings.Contains(output, fmt.Sprintf("codeagent-wrapper-%d-extra.log", stalePID2)) {
|
||||||
t.Fatalf("missing deleted file names in output: %q", output)
|
t.Fatalf("missing deleted file names in output: %q", output)
|
||||||
}
|
}
|
||||||
if !strings.Contains(output, "codeagent-wrapper-2300.log") {
|
if !strings.Contains(output, fmt.Sprintf("codeagent-wrapper-%d.log", keeperPID)) {
|
||||||
t.Fatalf("missing kept file names in output: %q", output)
|
t.Fatalf("missing kept file names in output: %q", output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2953,13 +2953,10 @@ func TestRunCodexTask_StartError(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunCodexTask_WithEcho(t *testing.T) {
|
func TestRunCodexTask_WithEcho(t *testing.T) {
|
||||||
defer resetTestHooks()
|
defer resetTestHooks()
|
||||||
codexCommand = "echo"
|
codexCommand = createFakeCodexScript(t, "test-session", "Test output")
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{targetArg} }
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
|
|
||||||
jsonOutput := `{"type":"thread.started","thread_id":"test-session"}
|
res := runCodexTask(TaskSpec{Task: "ignored"}, false, 10)
|
||||||
{"type":"item.completed","item":{"type":"agent_message","text":"Test output"}}`
|
|
||||||
|
|
||||||
res := runCodexTask(TaskSpec{Task: jsonOutput}, false, 10)
|
|
||||||
if res.ExitCode != 0 || res.Message != "Test output" || res.SessionID != "test-session" {
|
if res.ExitCode != 0 || res.Message != "Test output" || res.SessionID != "test-session" {
|
||||||
t.Fatalf("unexpected result: %+v", res)
|
t.Fatalf("unexpected result: %+v", res)
|
||||||
}
|
}
|
||||||
@@ -3039,13 +3036,10 @@ func TestRunCodexTask_LogPathWithActiveLogger(t *testing.T) {
|
|||||||
}
|
}
|
||||||
setLogger(logger)
|
setLogger(logger)
|
||||||
|
|
||||||
codexCommand = "echo"
|
codexCommand = createFakeCodexScript(t, "fake-thread", "ok")
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{targetArg} }
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
|
|
||||||
jsonOutput := `{"type":"thread.started","thread_id":"fake-thread"}
|
result := runCodexTask(TaskSpec{Task: "ignored"}, false, 5)
|
||||||
{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`
|
|
||||||
|
|
||||||
result := runCodexTask(TaskSpec{Task: jsonOutput}, false, 5)
|
|
||||||
if result.LogPath != logger.Path() {
|
if result.LogPath != logger.Path() {
|
||||||
t.Fatalf("LogPath = %q, want %q", result.LogPath, logger.Path())
|
t.Fatalf("LogPath = %q, want %q", result.LogPath, logger.Path())
|
||||||
}
|
}
|
||||||
@@ -3057,13 +3051,10 @@ func TestRunCodexTask_LogPathWithActiveLogger(t *testing.T) {
|
|||||||
func TestRunCodexTask_LogPathWithTempLogger(t *testing.T) {
|
func TestRunCodexTask_LogPathWithTempLogger(t *testing.T) {
|
||||||
defer resetTestHooks()
|
defer resetTestHooks()
|
||||||
|
|
||||||
codexCommand = "echo"
|
codexCommand = createFakeCodexScript(t, "temp-thread", "temp")
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{targetArg} }
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
|
|
||||||
jsonOutput := `{"type":"thread.started","thread_id":"temp-thread"}
|
result := runCodexTask(TaskSpec{Task: "ignored"}, true, 5)
|
||||||
{"type":"item.completed","item":{"type":"agent_message","text":"temp"}}`
|
|
||||||
|
|
||||||
result := runCodexTask(TaskSpec{Task: jsonOutput}, true, 5)
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
if result.LogPath != "" {
|
if result.LogPath != "" {
|
||||||
os.Remove(result.LogPath)
|
os.Remove(result.LogPath)
|
||||||
@@ -3109,10 +3100,19 @@ func TestRunCodexTask_LogPathOnStartError(t *testing.T) {
|
|||||||
|
|
||||||
func TestRunCodexTask_NoMessage(t *testing.T) {
|
func TestRunCodexTask_NoMessage(t *testing.T) {
|
||||||
defer resetTestHooks()
|
defer resetTestHooks()
|
||||||
codexCommand = "echo"
|
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{targetArg} }
|
fake := newFakeCmd(fakeCmdConfig{
|
||||||
jsonOutput := `{"type":"thread.started","thread_id":"test-session"}`
|
StdoutPlan: []fakeStdoutEvent{
|
||||||
res := runCodexTask(TaskSpec{Task: jsonOutput}, false, 10)
|
{Data: `{"type":"thread.started","thread_id":"test-session"}` + "\n"},
|
||||||
|
},
|
||||||
|
WaitDelay: 5 * time.Millisecond,
|
||||||
|
})
|
||||||
|
restore := executor.SetNewCommandRunner(func(ctx context.Context, name string, args ...string) executor.CommandRunner { return fake })
|
||||||
|
t.Cleanup(restore)
|
||||||
|
|
||||||
|
codexCommand = "fake-cmd"
|
||||||
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
|
res := runCodexTask(TaskSpec{Task: "ignored"}, false, 10)
|
||||||
if res.ExitCode != 1 || res.Error == "" {
|
if res.ExitCode != 1 || res.Error == "" {
|
||||||
t.Fatalf("expected error for missing agent_message, got %+v", res)
|
t.Fatalf("expected error for missing agent_message, got %+v", res)
|
||||||
}
|
}
|
||||||
@@ -4504,10 +4504,8 @@ func TestRun_CleanupHookAlwaysCalled(t *testing.T) {
|
|||||||
called := false
|
called := false
|
||||||
cleanupHook = func() { called = true }
|
cleanupHook = func() { called = true }
|
||||||
// Use a command that goes through normal flow, not --version which returns early
|
// Use a command that goes through normal flow, not --version which returns early
|
||||||
restore := withBackend("echo", func(cfg *Config, targetArg string) []string {
|
scriptPath := createFakeCodexScript(t, "x", "ok")
|
||||||
return []string{`{"type":"thread.started","thread_id":"x"}
|
restore := withBackend(scriptPath, func(cfg *Config, targetArg string) []string { return []string{} })
|
||||||
{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`}
|
|
||||||
})
|
|
||||||
defer restore()
|
defer restore()
|
||||||
os.Args = []string{"codeagent-wrapper", "task"}
|
os.Args = []string{"codeagent-wrapper", "task"}
|
||||||
if exitCode := run(); exitCode != 0 {
|
if exitCode := run(); exitCode != 0 {
|
||||||
@@ -4739,10 +4737,8 @@ func TestParallelLogPathInSerialMode(t *testing.T) {
|
|||||||
os.Args = []string{"codeagent-wrapper", "do-stuff"}
|
os.Args = []string{"codeagent-wrapper", "do-stuff"}
|
||||||
stdinReader = strings.NewReader("")
|
stdinReader = strings.NewReader("")
|
||||||
isTerminalFn = func() bool { return true }
|
isTerminalFn = func() bool { return true }
|
||||||
codexCommand = "echo"
|
codexCommand = createFakeCodexScript(t, "cli-session", "ok")
|
||||||
buildCodexArgsFn = func(cfg *Config, targetArg string) []string {
|
buildCodexArgsFn = func(cfg *Config, targetArg string) []string { return []string{} }
|
||||||
return []string{`{"type":"thread.started","thread_id":"cli-session"}` + "\n" + `{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`}
|
|
||||||
}
|
|
||||||
|
|
||||||
var exitCode int
|
var exitCode int
|
||||||
stderr := captureStderr(t, func() {
|
stderr := captureStderr(t, func() {
|
||||||
@@ -4766,9 +4762,8 @@ func TestRun_CLI_Success(t *testing.T) {
|
|||||||
stdinReader = strings.NewReader("")
|
stdinReader = strings.NewReader("")
|
||||||
isTerminalFn = func() bool { return true }
|
isTerminalFn = func() bool { return true }
|
||||||
|
|
||||||
restore := withBackend("echo", func(cfg *Config, targetArg string) []string {
|
scriptPath := createFakeCodexScript(t, "cli-session", "ok")
|
||||||
return []string{`{"type":"thread.started","thread_id":"cli-session"}` + "\n" + `{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`}
|
restore := withBackend(scriptPath, func(cfg *Config, targetArg string) []string { return []string{} })
|
||||||
})
|
|
||||||
defer restore()
|
defer restore()
|
||||||
|
|
||||||
var exitCode int
|
var exitCode int
|
||||||
|
|||||||
Reference in New Issue
Block a user