Skip to content

Commit df1704f

Browse files
committed
why can't ai lint
1 parent 07110e2 commit df1704f

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

ai/worker/docker.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -780,26 +780,26 @@ tickerLoop:
780780
return err
781781
}
782782

783-
// If the container is running, we're done.
784-
if json.State.Running {
783+
// If the container is running, we're done.
784+
if json.State.Running {
785785
break tickerLoop
786786
}
787787

788-
// Fail fast on states that won't become running after startup.
789-
if json.State != nil {
790-
status := strings.ToLower(json.State.Status)
791-
// Consider exited/dead as terminal. "removing" will surface via
792-
// inspect error or transition to exited/dead shortly.
793-
if status == "exited" || status == "dead" {
794-
return fmt.Errorf("container entered terminal state before running: %s (exitCode=%d)", json.State.Status, json.State.ExitCode)
795-
}
796-
if !json.State.Restarting && json.State.ExitCode != 0 {
797-
return fmt.Errorf("container exited before running (status=%s, exitCode=%d)", json.State.Status, json.State.ExitCode)
798-
}
799-
if !json.State.Restarting && json.State.Error != "" {
800-
return fmt.Errorf("container error before running: %s", json.State.Error)
801-
}
802-
}
788+
// Fail fast on states that won't become running after startup.
789+
if json.State != nil {
790+
status := strings.ToLower(json.State.Status)
791+
// Consider exited/dead as terminal. "removing" will surface via
792+
// inspect error or transition to exited/dead shortly.
793+
if status == "exited" || status == "dead" {
794+
return fmt.Errorf("container entered terminal state before running: %s (exitCode=%d)", json.State.Status, json.State.ExitCode)
795+
}
796+
if !json.State.Restarting && json.State.ExitCode != 0 {
797+
return fmt.Errorf("container exited before running (status=%s, exitCode=%d)", json.State.Status, json.State.ExitCode)
798+
}
799+
if !json.State.Restarting && json.State.Error != "" {
800+
return fmt.Errorf("container error before running: %s", json.State.Error)
801+
}
802+
}
803803
}
804804
}
805805

ai/worker/docker_test.go

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,62 +1166,62 @@ func TestDockerWaitUntilRunning(t *testing.T) {
11661166
mockDockerClient.AssertExpectations(t)
11671167
})
11681168

1169-
t.Run("FailFastOnExited", func(t *testing.T) {
1170-
// If the container is immediately exited, we should fail fast instead of waiting.
1171-
mockDockerClient := new(MockDockerClient)
1172-
// Always return non-running, exited state
1173-
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1174-
ContainerJSONBase: &types.ContainerJSONBase{
1175-
State: &types.ContainerState{
1176-
Status: "exited",
1177-
Running: false,
1178-
ExitCode: 137,
1179-
},
1180-
},
1181-
}, nil)
1182-
1183-
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1184-
require.Error(t, err)
1185-
require.Contains(t, err.Error(), "terminal state")
1186-
mockDockerClient.AssertExpectations(t)
1187-
})
1188-
1189-
t.Run("FailFastOnDead", func(t *testing.T) {
1190-
mockDockerClient := new(MockDockerClient)
1191-
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1192-
ContainerJSONBase: &types.ContainerJSONBase{
1193-
State: &types.ContainerState{
1194-
Status: "dead",
1195-
Running: false,
1196-
Error: "killed",
1197-
},
1198-
},
1199-
}, nil)
1200-
1201-
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1202-
require.Error(t, err)
1203-
require.Contains(t, err.Error(), "container entered terminal state")
1204-
mockDockerClient.AssertExpectations(t)
1205-
})
1206-
1207-
t.Run("FailFastOnExitCodeNonZeroWithoutRestarting", func(t *testing.T) {
1208-
mockDockerClient := new(MockDockerClient)
1209-
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1210-
ContainerJSONBase: &types.ContainerJSONBase{
1211-
State: &types.ContainerState{
1212-
Status: "created",
1213-
Running: false,
1214-
Restarting: false,
1215-
ExitCode: 1,
1216-
},
1217-
},
1218-
}, nil)
1219-
1220-
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1221-
require.Error(t, err)
1222-
require.Contains(t, err.Error(), "exited before running")
1223-
mockDockerClient.AssertExpectations(t)
1224-
})
1169+
t.Run("FailFastOnExited", func(t *testing.T) {
1170+
// If the container is immediately exited, we should fail fast instead of waiting.
1171+
mockDockerClient := new(MockDockerClient)
1172+
// Always return non-running, exited state
1173+
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1174+
ContainerJSONBase: &types.ContainerJSONBase{
1175+
State: &types.ContainerState{
1176+
Status: "exited",
1177+
Running: false,
1178+
ExitCode: 137,
1179+
},
1180+
},
1181+
}, nil)
1182+
1183+
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1184+
require.Error(t, err)
1185+
require.Contains(t, err.Error(), "terminal state")
1186+
mockDockerClient.AssertExpectations(t)
1187+
})
1188+
1189+
t.Run("FailFastOnDead", func(t *testing.T) {
1190+
mockDockerClient := new(MockDockerClient)
1191+
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1192+
ContainerJSONBase: &types.ContainerJSONBase{
1193+
State: &types.ContainerState{
1194+
Status: "dead",
1195+
Running: false,
1196+
Error: "killed",
1197+
},
1198+
},
1199+
}, nil)
1200+
1201+
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1202+
require.Error(t, err)
1203+
require.Contains(t, err.Error(), "container entered terminal state")
1204+
mockDockerClient.AssertExpectations(t)
1205+
})
1206+
1207+
t.Run("FailFastOnExitCodeNonZeroWithoutRestarting", func(t *testing.T) {
1208+
mockDockerClient := new(MockDockerClient)
1209+
mockDockerClient.On("ContainerInspect", mock.Anything, containerID).Return(types.ContainerJSON{
1210+
ContainerJSONBase: &types.ContainerJSONBase{
1211+
State: &types.ContainerState{
1212+
Status: "created",
1213+
Running: false,
1214+
Restarting: false,
1215+
ExitCode: 1,
1216+
},
1217+
},
1218+
}, nil)
1219+
1220+
err := dockerWaitUntilRunning(ctx, mockDockerClient, containerID, pollingInterval)
1221+
require.Error(t, err)
1222+
require.Contains(t, err.Error(), "exited before running")
1223+
mockDockerClient.AssertExpectations(t)
1224+
})
12251225
}
12261226

12271227
func TestHwGPU(t *testing.T) {

0 commit comments

Comments
 (0)