Skip to content

Commit e26b4d1

Browse files
Sayan-claude
andcommitted
Surface stop_timeout on the Instance response
stop_timeout was settable at create but not returned on the Instance object, so clients couldn't read back what they configured. Add it to the Instance schema and map it in instanceToOAPI, emitting the configured value when set and omitting it when unset (server default applies) — symmetric with the request-side semantics. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 39655ca commit e26b4d1

4 files changed

Lines changed: 217 additions & 168 deletions

File tree

cmd/api/api/instances.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,10 @@ func instanceToOAPI(inst instances.Instance) oapi.Instance {
11831183
oapiInst.ExitMessage = lo.ToPtr(inst.ExitMessage)
11841184
}
11851185

1186+
if inst.StopTimeout > 0 {
1187+
oapiInst.StopTimeout = lo.ToPtr(inst.StopTimeout)
1188+
}
1189+
11861190
if len(inst.Env) > 0 {
11871191
oapiInst.Env = &inst.Env
11881192
}

cmd/api/api/instances_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,44 @@ func TestInstanceToOAPI_OmitsPlatformWhenUnset(t *testing.T) {
635635
assert.Nil(t, oapiInst.Platform)
636636
}
637637

638+
func TestInstanceToOAPI_EchoesStopTimeout(t *testing.T) {
639+
t.Parallel()
640+
641+
inst := instances.Instance{
642+
StoredMetadata: instances.StoredMetadata{
643+
Id: "inst-stop-timeout",
644+
Name: "inst-stop-timeout",
645+
Image: "docker.io/library/alpine:latest",
646+
CreatedAt: time.Now(),
647+
HypervisorType: hypervisor.TypeCloudHypervisor,
648+
StopTimeout: 30,
649+
},
650+
State: instances.StateRunning,
651+
}
652+
653+
oapiInst := instanceToOAPI(inst)
654+
require.NotNil(t, oapiInst.StopTimeout)
655+
assert.Equal(t, 30, *oapiInst.StopTimeout)
656+
}
657+
658+
func TestInstanceToOAPI_OmitsStopTimeoutWhenUnset(t *testing.T) {
659+
t.Parallel()
660+
661+
inst := instances.Instance{
662+
StoredMetadata: instances.StoredMetadata{
663+
Id: "inst-no-stop-timeout",
664+
Name: "inst-no-stop-timeout",
665+
Image: "docker.io/library/alpine:latest",
666+
CreatedAt: time.Now(),
667+
HypervisorType: hypervisor.TypeCloudHypervisor,
668+
},
669+
State: instances.StateStopped,
670+
}
671+
672+
oapiInst := instanceToOAPI(inst)
673+
assert.Nil(t, oapiInst.StopTimeout)
674+
}
675+
638676
// errCreateInstanceManager is a fake whose CreateInstance always fails with a
639677
// preset error, used to assert the handler maps typed image errors to statuses.
640678
type errCreateInstanceManager struct {

0 commit comments

Comments
 (0)