feat(server): say at startup when alerting is unconfigured (#107) WARN once at startup when BRAIN_NTFY_URL is unset, naming what will not fire (brain_edit_root governance rewrites, capture audit degradation). Rebase of PR #108 (never CI-tested) onto current main, no functional change to alertingWarnings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Mathias <mthbqv@gmail.com>
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
// ingestion/cmd/server/main_test.go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/claudewatcher"
|
|
)
|
|
|
|
func TestClaudeSink_IngestWritesToNonIndexedArchiveNotWiki(t *testing.T) {
|
|
dir := t.TempDir()
|
|
sink := &claudeSink{brainDir: dir, logger: slog.New(slog.NewTextHandler(os.Stderr, nil))}
|
|
|
|
err := sink.Ingest(context.Background(), claudewatcher.Batch{
|
|
Host: "koala",
|
|
FilePath: "/host-home-claude/projects/-home-mathias-dev/abc.jsonl",
|
|
SessionID: "abc",
|
|
ProjectID: "-home-mathias-dev",
|
|
Turns: []claudewatcher.Turn{
|
|
{Type: "assistant", Content: "did a thing"},
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
got, err := os.ReadFile(filepath.Join(dir, "archive", "claude-sessions", "koala", "session-koala-abc.md"))
|
|
require.NoError(t, err, "raw session dump must land in the non-indexed archive")
|
|
assert.Contains(t, string(got), "did a thing")
|
|
|
|
_, err = os.Stat(filepath.Join(dir, "wiki", "claude-sessions"))
|
|
assert.True(t, os.IsNotExist(err), "raw transcripts must never land under wiki/ (ai-sessions#10 — BM25 pollution)")
|
|
}
|
|
|
|
// --- #107: an unconfigured alert must announce itself ----------------------
|
|
|
|
func TestAlertingWarnings(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
env map[string]string
|
|
want []string // substrings that must appear across the warnings
|
|
none bool // true = expect no warnings at all
|
|
}{
|
|
{
|
|
// The failure this exists to prevent: two alerts dark in
|
|
// production, discovered only by firing a real event and watching
|
|
// nothing arrive (#100).
|
|
name: "notifier unconfigured names what will not fire",
|
|
env: map[string]string{},
|
|
want: []string{"BRAIN_NTFY_URL", "brain_edit_root", "audit"},
|
|
},
|
|
{
|
|
name: "configured notifier is silent",
|
|
env: map[string]string{"BRAIN_NTFY_URL": "http://ntfy/brain-alerts"},
|
|
none: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := alertingWarnings(func(k string) string { return tt.env[k] })
|
|
if tt.none {
|
|
assert.Empty(t, got)
|
|
return
|
|
}
|
|
joined := strings.Join(got, " ")
|
|
for _, w := range tt.want {
|
|
assert.Contains(t, joined, w)
|
|
}
|
|
})
|
|
}
|
|
}
|