Files
alan 227c036aa5 Start machine terminals at the su login prompt instead of tmux
A new terminal runs su -l for the server's own account in its PTY, so the
operator types the account password before getting a shell. Opening is
refused when su is missing, the server runs as root, or su opens a shell
without asking. The Pipelines-owned tmux backing, its reattach and its
persisted session names are removed: terminals end with the server and
are listed as ended. A starting server ends leftover pipelines-term_*
sessions on tmux -L pipelines only.
2026-11-10 00:37:11 +00:00

55 lines
1.5 KiB
Go

package pipeline
import (
"context"
"fmt"
"path/filepath"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func TestTerminalsPersistPruneAndDelete(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "terminals.db")
store, err := Open(path)
if err != nil {
t.Fatal(err)
}
live := protocol.TerminalRecord{ID: "term_live", Cwd: "/home/a", Shell: "/bin/zsh", CreatedAt: 1, Status: protocol.TerminalRunning, Cols: 80, Rows: 24}
if err := store.SaveTerminal(ctx, live, 2); err != nil {
t.Fatal(err)
}
code := 0
for i := 0; i < 3; i++ {
ended := protocol.TerminalRecord{ID: fmt.Sprintf("term_%d", i), Cwd: "/home/a", CreatedAt: int64(10 + i), Status: protocol.TerminalExited, EndedAt: int64(20 + i), ExitCode: &code}
if err := store.SaveTerminal(ctx, ended, 2); err != nil {
t.Fatal(err)
}
}
live.Title, live.Cols = "vim", 120
if err := store.SaveTerminal(ctx, live, 2); err != nil {
t.Fatal(err)
}
store.Close()
store, err = Open(path)
if err != nil {
t.Fatal(err)
}
defer store.Close()
list, err := store.Terminals(ctx)
if err != nil {
t.Fatal(err)
}
if len(list) != 3 || list[0].ID != "term_live" || list[0].Title != "vim" || list[0].Cols != 120 ||
list[1].ID != "term_1" || list[2].ID != "term_2" || list[2].ExitCode == nil || *list[2].ExitCode != 0 {
t.Fatalf("terminals = %+v", list)
}
if err := store.DeleteTerminal(ctx, "term_live"); err != nil {
t.Fatal(err)
}
if list, _ := store.Terminals(ctx); len(list) != 2 {
t.Fatalf("after delete = %+v", list)
}
}