Preserve saved schedule run-level write scope

This commit is contained in:
2026-10-21 01:03:39 +01:00
parent 8c3f116190
commit fe02d153f1
8 changed files with 279 additions and 28 deletions
+10 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"net/http/httptest"
"path/filepath"
"slices"
"strings"
"testing"
"time"
@@ -55,12 +56,15 @@ func TestScheduleAPIOverWebSocket(t *testing.T) {
return response
}
// Saving run information is not definition authoring, and works on run-only servers.
spec := protocol.SavedSchedule{Name: "first", PipelineID: items[0].ID, Version: 1, Enabled: true, Workspace: t.TempDir(), Input: map[string]any{"prompt": "first research", "arbitrary": "retained"}, Rule: protocol.Schedule{Every: "15m"}, Model: "openai/gpt", NotifyMode: "off", Title: "Research"}
spec := protocol.SavedSchedule{Name: "first", PipelineID: items[0].ID, Version: 1, Enabled: true, Workspace: t.TempDir(), Input: map[string]any{"prompt": "first research", "arbitrary": "retained"}, WritePaths: []string{"internal/one.go"}, AllowTools: true, Rule: protocol.Schedule{Every: "15m"}, Model: "openai/gpt", NotifyMode: "off", Title: "Research"}
response := rpc(protocol.Message{Type: protocol.SaveSchedule, Schedule: &spec, RequestKey: "editor-first"})
if response.Type != protocol.SavedScheduleReply || response.Schedule == nil || response.Schedule.ID == 0 || response.Schedule.Revision != 1 {
t.Fatal(response)
}
a := *response.Schedule
if !a.AllowTools || !slices.Equal(a.WritePaths, spec.WritePaths) {
t.Fatal("scope omitted from save reply", a)
}
response = rpc(protocol.Message{Type: protocol.SaveSchedule, Schedule: &spec, RequestKey: "editor-first"})
if response.Schedule == nil || response.Schedule.ID != a.ID || response.Schedule.Revision != a.Revision {
t.Fatal("lost reply duplicated timer", response)
@@ -82,6 +86,9 @@ func TestScheduleAPIOverWebSocket(t *testing.T) {
if response.Type != protocol.Schedules || len(response.Schedules) != 2 {
t.Fatal(response)
}
if !response.Schedules[0].AllowTools || !slices.Equal(response.Schedules[0].WritePaths, spec.WritePaths) {
t.Fatal("scope omitted from list reply", response)
}
a.Enabled = false
response = rpc(protocol.Message{Type: protocol.SaveSchedule, Schedule: &a})
if response.Schedule == nil || response.Schedule.Enabled || response.Schedule.Revision != 2 {
@@ -121,6 +128,8 @@ func TestScheduleAPIOverWebSocket(t *testing.T) {
func(s *protocol.SavedSchedule) { s.Model = "invalid" },
func(s *protocol.SavedSchedule) { s.NotifyMode = "invalid" },
func(s *protocol.SavedSchedule) { s.OutputFormat = "invalid" },
func(s *protocol.SavedSchedule) { s.WritePaths = []string{"../outside.go"} },
func(s *protocol.SavedSchedule) { s.WritePaths = []string{"*.go"} },
} {
bad := spec
mutate(&bad)