feat(process): add running-only process listing

This commit is contained in:
Virgil 2026-04-04 07:48:31 +00:00
parent f9537fb24d
commit 56bc171add
2 changed files with 36 additions and 1 deletions

View file

@ -181,7 +181,7 @@ func (p *ProcessProvider) Describe() []api.RouteDescription {
Method: "GET",
Path: "/processes",
Summary: "List managed processes",
Description: "Returns the current process service snapshot as serialisable process info entries.",
Description: "Returns the current process service snapshot as serialisable process info entries. Pass runningOnly=true to limit results to active processes.",
Tags: []string{"process"},
Response: map[string]any{
"type": "array",
@ -459,6 +459,9 @@ func (p *ProcessProvider) listProcesses(c *gin.Context) {
}
procs := p.service.List()
if runningOnly, _ := strconv.ParseBool(c.Query("runningOnly")); runningOnly {
procs = p.service.Running()
}
infos := make([]process.Info, 0, len(procs))
for _, proc := range procs {
infos = append(infos, proc.Info())

View file

@ -277,6 +277,38 @@ func TestProcessProvider_ListProcesses_Good(t *testing.T) {
assert.Equal(t, "echo", resp.Data[0].Command)
}
func TestProcessProvider_ListProcesses_RunningOnly_Good(t *testing.T) {
svc := newTestProcessService(t)
runningProc, err := svc.Start(context.Background(), "sleep", "60")
require.NoError(t, err)
exitedProc, err := svc.Start(context.Background(), "echo", "done")
require.NoError(t, err)
<-exitedProc.Done()
p := processapi.NewProvider(nil, svc, nil)
r := setupRouter(p)
w := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/api/process/processes?runningOnly=true", nil)
require.NoError(t, err)
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var resp goapi.Response[[]process.Info]
err = json.Unmarshal(w.Body.Bytes(), &resp)
require.NoError(t, err)
require.True(t, resp.Success)
require.Len(t, resp.Data, 1)
assert.Equal(t, runningProc.ID, resp.Data[0].ID)
assert.Equal(t, process.StatusRunning, resp.Data[0].Status)
require.NoError(t, svc.Kill(runningProc.ID))
<-runningProc.Done()
}
func TestProcessProvider_GetProcess_Good(t *testing.T) {
svc := newTestProcessService(t)
proc, err := svc.Start(context.Background(), "echo", "single")