Files
bbs/internal/server/sysop_test.go
T
Claude a93a2cf303 Add the sysop's tools: watching nodes, chat, users, statistics, events
A sysop's main menu has * (and custom menus a sysop action), on every
terminal:

- Watch a node: what a text caller is sent, as it is sent (the text
  terminal's connection echoes to bbs.Node.Echo; a slow watcher misses
  some, never slows the caller).  A key stops; the caller leaving ends
  it.  Text terminals only.
- Chat with a node: the caller is told and taken into a private chat
  (their page's room) at their next menu; the sysop waits there.
- Kick a node.
- Users: level, flags, lock, sysop rights, a new password (not one's
  own lock or rights).
- Statistics: totals, and calls, new users, posts and uploads for each
  of the last 14 days as bars.
- The bans (lifted by number) and the hack log.
- Scheduled events ([event NAME]: a program run without a shell, daily
  at a time or every N minutes, with a timeout; internal/events): when
  they run next, the last run's end and output, run now.
- Available: whether pages reach the sysop; when not, a caller who pages
  may leave a message.

The API: GET /admin/events, POST /admin/events/{name}/run, PUT
/admin/available.  Sysop-Tools is the wiki page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-12 17:45:05 +00:00

98 lines
3.5 KiB
Go

package server
import (
"fmt"
"os"
"strings"
"testing"
)
func writeFile(p, s string) error { return os.WriteFile(p, []byte(s), 0600) }
func contains(s, sub string) bool { return strings.Contains(s, sub) }
func containsAny(ss []string, sub string) bool {
return strings.Contains(strings.Join(ss, "\n"), sub)
}
// TestSysopTools: the sysop watches a caller's screen, calls them into
// chat, and is away when they page.
func TestSysopTools(t *testing.T) {
e := start(t, nil, &Listener{Name: "modem", Kind: "raw", Address: "modem.sock", ANSI: "no"})
sysop := login(e, "sysop", "sysoppass1")
alice := login(e, "alice", "alicepass1")
aliceNode := 0
for _, n := range e.b.Nodes() {
if n.User == "alice" {
aliceNode = n.Num
}
}
sysop.send("*")
sysop.expect("[W] Watch a node")
sysop.send("W")
sysop.expect("Watch which node? (its number, Enter for none): ")
sysop.send(fmt.Sprintf("%d\r", aliceNode))
sysop.expect(fmt.Sprintf("Watching node %d", aliceNode))
alice.send("L")
alice.expect("Last callers")
sysop.expect("Last callers") // what alice was sent
sysop.send(" ")
sysop.expect(fmt.Sprintf("Watching node %d no more.", aliceNode))
sysop.send("C")
sysop.expect("Chat with which node?")
sysop.send(fmt.Sprintf("%d\r", aliceNode))
sysop.expect("is called here at their next menu")
sysop.expect("> ")
alice.expect("would like a word with you")
alice.send("\r")
alice.expect("The sysop would like a word.")
alice.expect(fmt.Sprintf("You are in sysop-%d.", aliceNode))
sysop.expect("-> alice came in")
sysop.send("all well?\r")
alice.expect("sysop: all well?")
alice.send("/quit\r")
alice.expect("Command: ")
sysop.send("/quit\r")
sysop.expect("[A] Available: yes")
sysop.send("A")
sysop.expect("[A] Available: no")
alice.send("S")
alice.expect("Page the sysop about (Enter to give up): ")
alice.send("a question\r")
alice.expect("The sysop is not available just now.")
}
func TestEventConfig(t *testing.T) {
dir := t.TempDir()
load := func(body string) (*Config, error) {
p := dir + "/bbs.conf"
if err := writeFile(p, "[listen t]\ntype = telnet\naddress = :2300\n"+body); err != nil {
t.Fatal(err)
}
return Load(p)
}
c, err := load("[event backup]\ncommand = /bin/echo \"nightly backup\"\nat = 03:30\ntimeout = 60\n" +
"[event poll]\ncommand = /bin/true\nevery = 15\n")
if err != nil || len(c.Events) != 2 || c.Events[0].At != "03:30" || c.Events[0].Command[1] != "nightly backup" ||
c.Events[0].Timeout.Seconds() != 60 || c.Events[1].Every.Minutes() != 15 {
t.Fatalf("%+v %v", c.Events, err)
}
c, err = load("[event x]\ncommand = /no/such/program\nevery = 5\n")
if err != nil || !containsAny(c.Warnings, "/no/such/program") {
t.Errorf("a missing program: %v %v", c.Warnings, err)
}
for body, want := range map[string]string{
"[event x]\nevery = 5\n": "command: none given",
"[event x]\ncommand = /bin/true\n": "at = HH:MM",
"[event x]\ncommand = /bin/true\nat = 3:30\n": "not a time of day",
"[event x]\ncommand = /bin/true\nat = 03:30\nevery = 5\n": "not both",
"[event x]\ncommand = \"/bin/true\nevery = 5\n": "quote",
"[event x]\ncommand = /bin/true\nevery = 5\n[event X]\ncommand = /bin/true\nevery = 5\n": "given twice",
} {
if _, err := load(body); err == nil || !contains(err.Error(), want) {
t.Errorf("%q: %v, want %q", body, err, want)
}
}
}