Add internal/logging.Feed, a logging-owned bounded replay buffer separate from the persisted task-lifecycle event stream, with a live SSE endpoint. Expose the executable workflow registry (skillbuild.Catalog) including zero-run definitions and their origin (builtin vs. installed skill), not just historical run statistics. Route() now returns an explicit failure workflow for an unknown pre-assigned workflow name instead of silently falling through to label-based routing. Fixes #54
35 lines
956 B
Go
35 lines
956 B
Go
package logging
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"testing"
|
|
)
|
|
|
|
func TestFeedCapturesStructuredSlogEntriesInOrder(t *testing.T) {
|
|
feed := NewFeed(2)
|
|
logger := slog.New(NewFeedHandler(slog.NewJSONHandler(testWriter{}, nil), feed))
|
|
logger.Info("started", "component", "daemon")
|
|
logger.Warn("slow", "component", "worker")
|
|
|
|
entries := feed.Snapshot()
|
|
if len(entries) != 2 || entries[0].ID == 0 || entries[1].ID <= entries[0].ID {
|
|
t.Fatalf("entries = %#v", entries)
|
|
}
|
|
if entries[0].Message != "started" || entries[0].Fields["component"] != "daemon" {
|
|
t.Fatalf("first entry = %#v", entries[0])
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(t.Context())
|
|
defer cancel()
|
|
updates := feed.Subscribe(ctx)
|
|
logger.Error("failed", "component", "worker")
|
|
if got := <-updates; got.Message != "failed" || got.Level != "ERROR" {
|
|
t.Fatalf("live entry = %#v", got)
|
|
}
|
|
}
|
|
|
|
type testWriter struct{}
|
|
|
|
func (testWriter) Write(p []byte) (int, error) { return len(p), nil }
|