Files
jcoffey-dev 13cf9a30cb Rebrand: Sentry -> Cairn OBS
Full rebrand across cosmetic branding, code identifiers, and
infrastructure/data-plane naming, using the supplied Cairn OBS logo
package. Cosmetic: favicon/logo swap (also closes a stale license-audit
finding -- the old favicon was SvelteKit's unreplaced scaffold logo),
new centered welcome landing page, larger/legible sidebar logo, page
titles, CLAUDE.md/README/docs prose.

Code identifiers: Go module path github.com/sentry/sentry ->
github.com/cairnobs/cairnobs across all 13 modules and ~91 files (protoc
regenerated); Rust crates sentry-agent/sentry-parser/sentry-search ->
cairnobs-*; CLI sentryctl -> cairnobsctl; Terraform provider fully
renamed (sentry_dashboard etc. -> cairnobs_dashboard, provider type,
env vars); every session/auth cookie name; agent config paths and
Windows service identity.

Deliberately preserved: the gRPC wire protocol's protobuf packages
(sentry.logs.v1, sentry.agent.v1) and their Go import directory
(proto/sentry/...) -- renaming the wire-level package would break every
currently-deployed agent binary (confirmed two real hosts, including
mail.inbuxa.com, are actively streaming through this exact contract)
until rebuilt and redeployed in lockstep with an ingest cutover. Only
the Go module path wrapping the generated code changes.

Infrastructure: every docker-compose container name (root and three
component-level compose files); the Helm chart (directory, Chart.yaml,
named-template helpers, all templates, values.yaml image repos);
Kubernetes Operator (CRD group sentry.io -> cairnobs.io, both CRD YAML
files, Go identifiers, RBAC markers); the coupled enterprise/tenantcrd
package. Caught and fixed real path-coupling bugs along the way: the
Helm chart's search/ingest volume mounts and the dev-only-credential
detection constant vs. docker-compose.yml's literal values had to move
together or a security warning would have silently stopped firing.

Data plane: Postgres database sentry_metadata -> cairnobs_metadata and
role sentry -> cairnobs; ClickHouse database sentry -> cairnobs; Kafka
topic sentry.logs.raw -> cairnobs.logs.raw and its consumer groups.
Source-level defaults, docker-compose.yml, and every migrate.sh/
provision script default updated together; already-applied migration
files left untouched per this repo's immutable-migration convention.

Verified at every layer: all 13 Go modules build/vet/test clean, both
Rust workspaces (agent, search) build/clippy/test clean, npm run check/
build clean, docker compose config validates on all four compose files.
Live-verified against a real docker stack multiple times through this
work, including a final fresh-volume run confirming the actual renamed
Postgres database/role, ClickHouse database, and Kafka topic all work
end to end with a real login and query, zero console errors.
2026-08-21 20:53:32 -07:00

146 lines
5.1 KiB
Go

package main
import (
"bytes"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestParseQueryArgsNL(t *testing.T) {
qa := parseQueryArgs([]string{"--nl", "errors in the last hour", "--execute"}, func(string) string { return "" })
if qa.nlQuery != "errors in the last hour" {
t.Errorf("nlQuery = %q", qa.nlQuery)
}
if !qa.execute {
t.Error("execute = false, want true")
}
}
func TestCmdQueryNLLowConfidenceDoesNotRun(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/ai/translate" {
t.Errorf("unexpected request to %s, want only /ai/translate (never /query)", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"query":"","confidence":"low","lowConfidenceReason":"not sure what that means"}`))
}))
defer srv.Close()
var stdout, stderr bytes.Buffer
code := cmdQuery([]string{"--nl", "show me weird stuff", "--execute", "--api", srv.URL}, &stdout, &stderr)
if code != 1 {
t.Errorf("code = %d, want 1 (no confident translation)", code)
}
if !strings.Contains(stdout.String(), "not sure what that means") {
t.Errorf("stdout = %q, want the low-confidence reason", stdout.String())
}
}
func TestCmdQueryNLBlockedIsNotRunEvenWithExecute(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/query" {
t.Error("a blocked translation must never reach /query, even with --execute")
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"query":"severity=ERROR | stats count by service","confidence":"high","compiles":true,"blocked":true,"costWarnings":["no time range filter, and this query aggregates"]}`))
}))
defer srv.Close()
var stdout, stderr bytes.Buffer
code := cmdQuery([]string{"--nl", "errors by service", "--execute", "--api", srv.URL}, &stdout, &stderr)
if code != 1 {
t.Errorf("code = %d, want 1 (blocked)", code)
}
if !strings.Contains(stdout.String(), "Not offered as directly runnable") {
t.Errorf("stdout = %q", stdout.String())
}
}
func TestCmdQueryNLNonCompilingDoesNotRun(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/query" {
t.Error("a non-compiling translation must never reach /query")
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"query":"| stats count","confidence":"high","compiles":false,"compileError":"expected a filter, comparison, or search term, got PIPE"}`))
}))
defer srv.Close()
var stdout, stderr bytes.Buffer
code := cmdQuery([]string{"--nl", "something odd", "--execute", "--api", srv.URL}, &stdout, &stderr)
if code != 1 {
t.Errorf("code = %d, want 1", code)
}
if !strings.Contains(stdout.String(), "does not parse") {
t.Errorf("stdout = %q", stdout.String())
}
}
func TestCmdQueryNLWithExecuteRunsTheQuery(t *testing.T) {
var sawQuery string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.URL.Path {
case "/ai/translate":
w.Write([]byte(`{"query":"earliest=-1h severity=ERROR | stats count by service","confidence":"high","compiles":true,"blocked":false}`))
case "/query":
sawQuery = "called"
w.Write([]byte(`{"columns":["service","count"],"rows":[["api",5]]}`))
default:
t.Errorf("unexpected request to %s", r.URL.Path)
}
}))
defer srv.Close()
var stdout, stderr bytes.Buffer
code := cmdQuery([]string{"--nl", "errors per service in the last hour", "--execute", "--api", srv.URL}, &stdout, &stderr)
if code != 0 {
t.Fatalf("code = %d, want 0; stderr=%s", code, stderr.String())
}
if sawQuery != "called" {
t.Error("expected /query to be called with --execute set")
}
if !strings.Contains(stdout.String(), "api") {
t.Errorf("stdout = %q, want the query results printed", stdout.String())
}
}
func TestCmdQueryNLWithoutExecuteNonInteractiveDoesNotRun(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/query" {
t.Error("must not run without --execute when stdin isn't a terminal")
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"query":"earliest=-1h | stats count","confidence":"high","compiles":true,"blocked":false}`))
}))
defer srv.Close()
var stdout, stderr bytes.Buffer
code := cmdQuery([]string{"--nl", "how many events", "--api", srv.URL}, &stdout, &stderr)
if code != 0 {
t.Errorf("code = %d, want 0 (declining to run isn't a failure)", code)
}
if !strings.Contains(stdout.String(), "Not running") {
t.Errorf("stdout = %q", stdout.String())
}
}
func TestConfirmRunAcceptsY(t *testing.T) {
var stdout bytes.Buffer
if !confirmRun(strings.NewReader("y\n"), &stdout, "Run?") {
t.Error("expected 'y' to confirm")
}
}
func TestConfirmRunRejectsBlankAndOther(t *testing.T) {
var stdout bytes.Buffer
if confirmRun(strings.NewReader("\n"), &stdout, "Run?") {
t.Error("expected a blank line to NOT confirm")
}
if confirmRun(strings.NewReader("sure\n"), &stdout, "Run?") {
t.Error("expected an unrecognized answer to NOT confirm")
}
}