@@ -164,3 +164,48 @@ func TestUpdateRunner_TrimmedBodyNameAccepted(t *testing.T) {
164164 t .Errorf ("expected 200 when body name trims to URL name, got %d body=%s" , rec .Code , rec .Body .String ())
165165 }
166166}
167+
168+ func TestStartRunner_ProbeFailureFallsBackToInstalledStatus (t * testing.T ) {
169+ dir := t .TempDir ()
170+ cfgPath := filepath .Join (dir , "config.yaml" )
171+ installDir := filepath .Join (dir , "r1" )
172+ if err := os .MkdirAll (installDir , 0755 ); err != nil {
173+ t .Fatal (err )
174+ }
175+ // 标记为已注册状态
176+ if err := os .WriteFile (filepath .Join (installDir , ".runner" ), []byte ("ok" ), 0644 ); err != nil {
177+ t .Fatal (err )
178+ }
179+
180+ cfg := & config.Config {
181+ Runners : config.RunnersConfig {
182+ BasePath : dir ,
183+ ContainerMode : true ,
184+ Items : []config.RunnerItem {
185+ {Name : "r1" , TargetType : "org" , Target : "o1" },
186+ },
187+ },
188+ }
189+ if err := cfg .Save (cfgPath ); err != nil {
190+ t .Fatal (err )
191+ }
192+
193+ oldConfigPath := ConfigPath
194+ ConfigPath = cfgPath
195+ defer func () { ConfigPath = oldConfigPath }()
196+
197+ // 让容器状态探测失败(docker 命令不可执行)
198+ t .Setenv ("PATH" , "" )
199+ // 启动阶段走容器模式快速失败分支:若到达此处说明没有被 400 提前拦截
200+ t .Setenv ("DOCKER_HOST" , "tcp://runner-dind:2375" )
201+
202+ e := echo .New ()
203+ e .POST ("/api/runners/:name/start" , StartRunner )
204+ req := httptest .NewRequest (http .MethodPost , "/api/runners/r1/start" , nil )
205+ rec := httptest .NewRecorder ()
206+ e .ServeHTTP (rec , req )
207+
208+ if rec .Code != http .StatusInternalServerError {
209+ t .Fatalf ("expected 500 when start is attempted after probe failure, got %d body=%s" , rec .Code , rec .Body .String ())
210+ }
211+ }
0 commit comments