package companion import ( "testing" "time" ) func TestConsoleSemanticEventProducerParsesOnlyBoundedKnownOutput(t *testing.T) { availability := VerifiedSemanticEventProducer() if !availability.Available || availability.Reason == "" { t.Fatalf("console event producer should be available: %+v", availability) } batch := ParseConsoleRecords("server-1", []ConsoleRecord{{ServerID: "server-1", Stream: "stdout", Sequence: 1, OccurredAt: time.Now(), Text: "SCUM LOGIN 76561198000000001 10.0.0.1"}, {ServerID: "server-1", Stream: "stderr", Sequence: 2, OccurredAt: time.Now(), Text: "unrecognised output"}}, "fixture-secret") if len(batch.Events) != 1 || batch.Events[0].Type != "scum.login" || batch.Events[0].NetworkCorrelation == "" || len(batch.Diagnostics) != 1 || batch.Diagnostics[0].Code != "unknown-console-format" { t.Fatalf("unsafe console parsing result: %+v", batch) } if batch.Events[0].NetworkCorrelation == "10.0.0.1" { t.Fatal("raw network value leaked") } if len(batch.Events[0].NetworkCorrelation) != 64 { t.Fatalf("network correlation must be full sha256 hex, got %q", batch.Events[0].NetworkCorrelation) } } func TestConsoleSemanticEventProducerParsesScumLoginLog(t *testing.T) { observedAt := time.Date(2026, 8, 27, 12, 0, 0, 0, time.UTC) batch := ParseConsoleRecords("server-1", []ConsoleRecord{ {ServerID: "server-1", Stream: "stdout", Sequence: 1, OccurredAt: observedAt, Text: "2026.08.27-12.00.00: '10.0.0.2 76561198000000002:Ada(42)' logged in at: X=1 Y=2 Z=3"}, {ServerID: "server-1", Stream: "stdout", Sequence: 2, OccurredAt: observedAt.Add(time.Second), Text: "2026.08.27-12.00.01: '10.0.0.2 76561198000000002:Ada(42)' logged out"}, }, "fixture-secret") if len(batch.Events) != 2 || batch.Events[0].Type != "scum.login" || batch.Events[1].Type != "scum.logout" { t.Fatalf("login log events not parsed: %+v", batch) } if batch.Events[0].PlayerID != "76561198000000002" || batch.Events[0].DisplayName != "Ada" || len(batch.Events[0].NetworkCorrelation) != 64 { t.Fatalf("login event fields are incomplete: %+v", batch.Events[0]) } if batch.Events[0].NetworkCorrelation == "10.0.0.2" { t.Fatal("raw login log IP leaked") } }