Make SCUM logs live relay only
This commit is contained in:
@@ -102,6 +102,61 @@ func TestSCUMSQLStoreWritesTrajectorySamplesWithoutCoordinateConversion(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestSCUMSQLStoreWritesConsoleAndSemanticEventsToPluginTables(t *testing.T) {
|
||||
db, recorder := newRecordingSQLDB(t, "console-db")
|
||||
store, err := NewSCUMSQLStore(db)
|
||||
if err != nil {
|
||||
t.Fatalf("create SCUM SQL store: %v", err)
|
||||
}
|
||||
stamp := time.Date(2026, 8, 31, 3, 0, 0, 0, time.UTC)
|
||||
records := []ConsoleRecord{{ServerID: "server-1", Stream: "stdout", Sequence: 9, OccurredAt: stamp, Text: "SCUM LOGIN 76561198000000001 10.0.0.1"}}
|
||||
written, err := store.StoreConsoleRecords(context.Background(), records)
|
||||
if err != nil || written != 1 {
|
||||
t.Fatalf("store console records: written=%d err=%v", written, err)
|
||||
}
|
||||
batch := ParseConsoleRecords("server-1", records, "correlation-secret")
|
||||
if len(batch.Events) != 1 || batch.Events[0].NetworkCorrelation == "" {
|
||||
t.Fatalf("expected one correlated semantic event: %#v", batch)
|
||||
}
|
||||
semanticWritten, err := store.StoreSemanticEventBatch(context.Background(), batch)
|
||||
if err != nil || semanticWritten != 1 {
|
||||
t.Fatalf("store semantic events: written=%d err=%v", semanticWritten, err)
|
||||
}
|
||||
if recorder.commits != 2 {
|
||||
t.Fatalf("console and semantic writes did not commit once each: %d", recorder.commits)
|
||||
}
|
||||
|
||||
consoleIndex := findStatement(recorder.statements, "INSERT INTO scum_console_logs")
|
||||
if consoleIndex < 0 {
|
||||
t.Fatalf("missing console insert statement: %v", recorder.statements)
|
||||
}
|
||||
consoleInsert := recorder.statements[consoleIndex]
|
||||
if !strings.Contains(consoleInsert, "line_text") || strings.Contains(consoleInsert, "platform_logs") {
|
||||
t.Fatalf("console SQL must write the SCUM plugin table only: %s", consoleInsert)
|
||||
}
|
||||
consoleArgs := recorder.args[consoleIndex]
|
||||
if consoleArgs[1].Value != "server-1" || consoleArgs[2].Value != "stdout" || !driverNumberEquals(consoleArgs[3].Value, 9) || consoleArgs[5].Value != records[0].Text {
|
||||
t.Fatalf("unexpected console insert args: %+v", consoleArgs)
|
||||
}
|
||||
|
||||
semanticIndex := findStatement(recorder.statements, "INSERT INTO scum_semantic_events")
|
||||
if semanticIndex < 0 {
|
||||
t.Fatalf("missing semantic event insert statement: %v", recorder.statements)
|
||||
}
|
||||
semanticInsert := recorder.statements[semanticIndex]
|
||||
if strings.Contains(semanticInsert, "platform_logs") || strings.Contains(semanticInsert, "run_logs") {
|
||||
t.Fatalf("semantic SQL must write the SCUM plugin table only: %s", semanticInsert)
|
||||
}
|
||||
semanticArgs := recorder.args[semanticIndex]
|
||||
if semanticArgs[1].Value != "server-1" || !driverNumberEquals(semanticArgs[2].Value, 9) || semanticArgs[3].Value != "scum.login" || semanticArgs[4].Value != "76561198000000001" {
|
||||
t.Fatalf("unexpected semantic insert args: %+v", semanticArgs)
|
||||
}
|
||||
correlation, ok := semanticArgs[7].Value.(string)
|
||||
if !ok || correlation == "10.0.0.1" || len(correlation) != 64 {
|
||||
t.Fatalf("semantic event stored raw or missing network correlation: %+v", semanticArgs[7])
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrajectorySamplesFromSCUMRowsKeepWorldCoordinates(t *testing.T) {
|
||||
sampledAt := time.Date(2026, 8, 28, 8, 0, 0, 0, time.UTC)
|
||||
positionSamples, err := TrajectorySamplesFromPositionRows("server-1", []map[string]any{
|
||||
@@ -168,3 +223,16 @@ func findStatement(statements []string, prefix string) int {
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func driverNumberEquals(value any, want int64) bool {
|
||||
switch typed := value.(type) {
|
||||
case int:
|
||||
return int64(typed) == want
|
||||
case int64:
|
||||
return typed == want
|
||||
case uint64:
|
||||
return typed == uint64(want)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user