Artifact bb04f5c09e429b9df3c3a446fcec12e23a63a5ed07b0483622b3c2fe50dfaf36:
- File
leaf/telemetry/ctxslog_test.go
— part of check-in
[b53032d01f]
at
2026-04-24 16:02:07
on branch trunk
— notify: extract shared natshdr.Carrier to kill duplicate header-carrier
Two copies of natsHeaderCarrier existed (leaf/agent/nats.go and leaf/agent/notify/pubsub.go), both carrying the same latent case-sensitive Get bug that was fixed in Task 6. Extract the type to leaf/agent/internal/natshdr so the next bug can be fixed once.
While consolidating, drop the 4-tier fallback in Get in favor of a single EqualFold scan. Header maps are tiny (typically 3 entries) and tiers 1-3 were subsumed by tier 4 anyway. The new implementation is demonstrably correct and easier to read. (user: [email protected], size: 782) [annotate] [blame] [check-ins using] [more...]
package telemetry import ( "bytes" "context" "log/slog" "strings" "testing" ) func TestCtxHandler_AddsAgentIDFromContext(t *testing.T) { var buf bytes.Buffer inner := slog.NewTextHandler(&buf, nil) h := NewCtxHandler(inner) ctx := WithAgentID(context.Background(), "agent-42") logger := slog.New(h) logger.InfoContext(ctx, "hello") if !strings.Contains(buf.String(), "agent_id=agent-42") { t.Fatalf("expected agent_id in output, got: %q", buf.String()) } } func TestCtxHandler_NoAgentIDNoAttribute(t *testing.T) { var buf bytes.Buffer h := NewCtxHandler(slog.NewTextHandler(&buf, nil)) slog.New(h).InfoContext(context.Background(), "hello") if strings.Contains(buf.String(), "agent_id") { t.Fatalf("agent_id should be absent, got: %q", buf.String()) } }