Open ntfy notifications in the app and notify chats that need the operator
Run notifications now always click through to pipelines://run/<id>; a valid PIPELINES_WEB_PUBLIC_URL adds an "Open in browser" ntfy view action instead of replacing the click. Queued rows derive links from the run id at delivery, so legacy rows holding a web URL still open the app. Unresolved chat questions/forms and permission requests publish one async, bounded notification to the system destination (pipelines://chat/<id> plus the browser action), deduplicated per form/request id across reconnects and replays. stage.PublishNtfy gains optional, strictly validated view actions. Server tests now clear the operator's real ntfy environment.
This commit is contained in:
@@ -37,8 +37,8 @@ func TestStageNotificationEventsAndArtifactAudit(t *testing.T) {
|
||||
var calls atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
count := calls.Add(1)
|
||||
if click := r.Header.Get("Click"); !strings.HasPrefix(click, "https://pipelines.example.com/runs/") {
|
||||
t.Errorf("stage notification lacks web run link: %q", click)
|
||||
if click, actions := r.Header.Get("Click"), r.Header.Get("Actions"); !strings.HasPrefix(click, "pipelines://run/") || actions != "view, Open in browser, https://pipelines.example.com/runs/"+strings.TrimPrefix(click, "pipelines://run/") {
|
||||
t.Errorf("stage notification lacks app click/web action: %q %q", click, actions)
|
||||
}
|
||||
filename, _ := new(mime.WordDecoder).DecodeHeader(r.Header.Get("Filename"))
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
@@ -300,14 +300,14 @@ func TestRunAttentionNotificationDelivery(t *testing.T) {
|
||||
}
|
||||
defer store.Close()
|
||||
type delivered struct {
|
||||
method, path, title, message, click, authorization string
|
||||
method, path, title, message, click, authorization, actions string
|
||||
}
|
||||
deliveries := make(chan delivered, 8)
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
decoder := new(mime.WordDecoder)
|
||||
title, _ := decoder.DecodeHeader(r.Header.Get("Title"))
|
||||
message, _ := decoder.DecodeHeader(r.Header.Get("Message"))
|
||||
deliveries <- delivered{r.Method, r.URL.Path, title, message, r.Header.Get("Click"), r.Header.Get("Authorization")}
|
||||
deliveries <- delivered{r.Method, r.URL.Path, title, message, r.Header.Get("Click"), r.Header.Get("Authorization"), r.Header.Get("Actions")}
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"id": "attention-receipt", "event": "message"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
@@ -341,7 +341,7 @@ func TestRunAttentionNotificationDelivery(t *testing.T) {
|
||||
if first.title != "Run needs your decision" || !strings.Contains(first.message, "Run #7") || !strings.Contains(first.message, "release") || !strings.Contains(first.message, "decision") || !strings.Contains(first.message, "approve") {
|
||||
t.Fatalf("waiting notification does not identify the run/pipeline/need: %+v", first)
|
||||
}
|
||||
if first.click != "https://pipelines.example.com/runs/7" {
|
||||
if first.click != "pipelines://run/7" || first.actions != "view, Open in browser, https://pipelines.example.com/runs/7" {
|
||||
t.Fatalf("waiting notification click does not open the run: %q", first.click)
|
||||
}
|
||||
if first.authorization != "" {
|
||||
@@ -351,7 +351,7 @@ func TestRunAttentionNotificationDelivery(t *testing.T) {
|
||||
if second.title != "Run failed" || !strings.Contains(second.message, "Run #7") || !strings.Contains(second.message, "release") || !strings.Contains(second.message, "deploy") || !strings.Contains(second.message, "provider returned 500") {
|
||||
t.Fatalf("failed notification is not actionable: %+v", second)
|
||||
}
|
||||
if second.click != "https://pipelines.example.com/runs/7" {
|
||||
if second.click != "pipelines://run/7" || second.actions != "view, Open in browser, https://pipelines.example.com/runs/7" {
|
||||
t.Fatalf("failed notification click does not open the run: %q", second.click)
|
||||
}
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user