Files
pipelines/internal/tui/schedule_test.go
T

99 lines
3.6 KiB
Go

package tui
import (
"git.a-wan.net/alan/pipelines/internal/protocol"
"strings"
"testing"
)
func TestScheduleToolbar(t *testing.T) {
m := panelModel(t)
m.detail.Graph.Settings = &protocol.Settings{Schedules: []protocol.Schedule{{Every: "15m", Days: []string{"mon", "fri"}}, {Times: []string{"09:00"}, Timezone: "Europe/London"}}}
view := strings.Join(m.pipelineToolbar(), "\n")
for _, text := range []string{"Schedule:", "mon,fri every 15m (server local)", "everyday at 09:00 (Europe/London)"} {
if !strings.Contains(view, text) {
t.Fatal("missing schedule", text, view)
}
}
m.detail.LatestVersion = m.detail.Version + 1
if !strings.Contains(strings.Join(m.pipelineToolbar(), "\n"), "historical, inactive") {
t.Fatal("historical schedule appears active")
}
}
func TestStageToolsVisible(t *testing.T) {
m := panelModel(t)
m.detail.Graph.Stages[0].Blocks["tools"] = "websearch\nwebfetch"
header, lines := m.stageColumns(116)
view := header + "\n" + strings.Join(lines, "\n")
for _, text := range []string{"TOOLS", "websearch", "webfetch"} {
if !strings.Contains(view, text) {
t.Fatal("missing tools in detail", text, view)
}
}
}
func TestRunComposerShowsStageScopedTools(t *testing.T) {
m := panelModel(t)
m.runForm = 1
m.runInput = newInput()
m.detail.Graph.Stages[0].Blocks["tools"] = "websearch\nwebfetch"
if m.runHasMutationTools() {
t.Fatal("web stage requires mutation approval")
}
view := m.runFormView(40)
if !strings.Contains(view, "websearch, webfetch") || strings.Contains(view, "RUN approves") {
t.Fatal("incorrect web confirmation", view)
}
m.detail.Graph.Stages[0].Blocks["tools"] = "shell"
if !m.runHasMutationTools() {
t.Fatal("shell cannot be approved without edits")
}
view = m.runFormView(40)
if !strings.Contains(view, "shell") || strings.Contains(view, "RUN approves") {
t.Fatal("composer should show tools, not demand approval", view)
}
}
func TestNativeNtfyStagePresentation(t *testing.T) {
m := panelModel(t)
s := &m.detail.Graph.Stages[0]
s.Type = "ntfy"
s.Prompt = ""
s.Configs = map[string]string{"destination": "anime"}
s.Blocks = nil
header, lines := m.stageColumns(116)
view := header + "\n" + strings.Join(lines, "\n")
if strings.Contains(header, "PROMPT") || !strings.Contains(view, "ntfy") || !strings.Contains(view, "anime") {
t.Fatal("native stage displayed as model", view)
}
m.runForm = 1
m.runInput = newInput()
view = m.runFormView(40)
if !strings.Contains(view, "publish Markdown to ntfy destination anime") {
t.Fatal("delivery side effect not shown", view)
}
}
func TestNotifyPolicyAndReceiptsVisible(t *testing.T) {
m := panelModel(t)
m.detail.Graph.Stages[0].Notify = &protocol.NotificationPolicy{On: []string{"success", "failure"}, Destination: "anime", Artifacts: []string{"markdown", "files"}}
header, lines := m.stageColumns(116)
view := header + "\n" + strings.Join(lines, "\n")
for _, text := range []string{"NOTIFY", "Connection: global", "success, failure", "Artifacts: markdown,", "files"} {
if !strings.Contains(view, text) {
t.Fatal("missing notify policy", text, view)
}
}
run := runInspectionModel()
run.runStepIndex = 1
run.toggleRunSection(4)
run.runDetail.Steps[0].Notifications = []protocol.NotificationReceipt{{Destination: "anime", Status: "sent", Filename: "report.txt", MessageID: "message123", AttachmentURL: "https://ntfy.example.com/file/report.txt"}, {Destination: "anime", Status: "failed", Diagnostic: "HTTP 401"}}
view = strings.Join(run.runSectionLines(116), "\n")
for _, text := range []string{"Notification: anime", "report.txt", "message123", "HTTP 401"} {
if !strings.Contains(view, text) {
t.Fatal("missing notification receipt", text, view)
}
}
}