BREAKING: every shell operation now requires a shellId. The Manager
previously keyed by workspaceID alone (one bash per workspace). It now
keys by (workspaceID, shellID) where shellID is a UUID returned by
Start.
Fixes the long-standing bug where the WS handler's closeAll called
stdin.Close() and killed bash when a WS client disconnected. The
Session owns the pty file; the WS handler no longer closes it. The
pty is only closed by Manager.Stop (explicit) or by captureOutput
when the process naturally exits (EOF).
- internal/shell/manager.go: Manager interface gains List and every
method takes shellID; storage becomes
map[workspaceID]map[shellID]*Session; Start returns (shellID, err)
via uuid.NewString; Resize/Status/ExitStatus/Subscribe/Stdin/Stop
route by shellID; new List(workspaceID) returns ShellInfo[] in
creation order.
- internal/shell/session.go: Session gains ShellID + CreatedAt; Status
type gains ShellID.
- internal/shell/manager_test.go: updated existing tests for new
signatures; added TestShellMultiInstance (two shells in one
workspace, no output cross-talk, independent stop, List behavior).
- internal/service/shell_service.go: wrappers carry shellID; new
List method.
- internal/service/workspace_service.go: auto-start captures/logs
shellID; Delete iterates and stops all workspace shells.
- internal/api/shell_handler.go: WS closeAll drops stdin.Close();
start/restart return 201 with {shellId, pid, ...}; new list handler;
stop/resize take shellId in body.
- internal/api/router.go: GET /api/workspaces/:id/shell (list).
- internal/model/shell.go: new ShellStartResponse, ShellInfo,
ShellListResponse, ShellStopRequest, ShellRestartRequest; updated
ShellStatusResponse + ShellResizeRequest to carry shellId.
- go.mod/go.sum: github.com/google/uuid.
E2E:
- workspace create -> 1 auto shell
- start 2 more -> 3 shells in list
- stop 1 -> 2 shells in list
- WS connect -> send cmd -> disconnect -> WS reconnect -> send cmd ->
response OK, no [process exited] banner
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package model
|
|
|
|
// ShellStatusResponse is the API response for shell status.
|
|
type ShellStatusResponse struct {
|
|
WorkspaceID string `json:"workspaceId"`
|
|
ShellID string `json:"shellId,omitempty"`
|
|
Running bool `json:"running"`
|
|
PID int `json:"pid,omitempty"`
|
|
}
|
|
|
|
// ShellStartResponse is the API response for POST /shell/start.
|
|
type ShellStartResponse struct {
|
|
WorkspaceID string `json:"workspaceId"`
|
|
ShellID string `json:"shellId"`
|
|
Running bool `json:"running"`
|
|
PID int `json:"pid,omitempty"`
|
|
}
|
|
|
|
// ShellInfo is a single shell entry in a list response.
|
|
type ShellInfo struct {
|
|
WorkspaceID string `json:"workspaceId"`
|
|
ShellID string `json:"shellId"`
|
|
Running bool `json:"running"`
|
|
PID int `json:"pid,omitempty"`
|
|
CreatedAt string `json:"createdAt,omitempty"`
|
|
}
|
|
|
|
// ShellListResponse is the API response for GET /shell.
|
|
type ShellListResponse struct {
|
|
WorkspaceID string `json:"workspaceId"`
|
|
Shells []ShellInfo `json:"shells"`
|
|
}
|
|
|
|
// ShellStopRequest is the body for POST /shell/stop.
|
|
type ShellStopRequest struct {
|
|
ShellID string `json:"shellId"`
|
|
}
|
|
|
|
// ShellResizeRequest is the body for POST /shell/resize.
|
|
type ShellResizeRequest struct {
|
|
ShellID string `json:"shellId"`
|
|
Cols int `json:"cols"`
|
|
Rows int `json:"rows"`
|
|
}
|
|
|
|
// ShellRestartRequest is the body for POST /shell/restart.
|
|
type ShellRestartRequest struct {
|
|
ShellID string `json:"shellId"`
|
|
}
|