package runtime import ( "strings" "testing" ) func TestManagedProcessStopEventNameIsStableAndScoped(t *testing.T) { base := ProcessIdentity{Scope: `C:\workspace\instances\server-1\run-local`, RunEndpointID: "run-1", ServerInstanceID: "server-1", LogSessionID: "session-a"} if got, want := managedProcessStopEventName(base), managedProcessStopEventName(base); got != want { t.Fatalf("stop event name is not stable: got=%q want=%q", got, want) } if got := managedProcessStopEventName(base); !strings.HasPrefix(got, `Local\run-managed-stop-`) { t.Fatalf("stop event name is not in the local namespace: %q", got) } if strings.Contains(managedProcessStopEventName(base), "workspace") { t.Fatalf("stop event name leaked the process scope: %q", managedProcessStopEventName(base)) } for _, changed := range []ProcessIdentity{ {Scope: base.Scope, RunEndpointID: "run-2", ServerInstanceID: base.ServerInstanceID, LogSessionID: base.LogSessionID}, {Scope: base.Scope, RunEndpointID: base.RunEndpointID, ServerInstanceID: "server-2", LogSessionID: base.LogSessionID}, {Scope: base.Scope, RunEndpointID: base.RunEndpointID, ServerInstanceID: base.ServerInstanceID, LogSessionID: "session-b"}, } { if got := managedProcessStopEventName(changed); got == managedProcessStopEventName(base) { t.Fatalf("different process generation shared stop event name: base=%q changed=%q", managedProcessStopEventName(base), got) } } } func TestManagedProcessGenerationRejectsOutputFileSwap(t *testing.T) { current := ProcessIdentity{ PID: 100, LogSessionID: "session-a", StdoutLogRef: "stdout-a.log", StderrLogRef: "stderr-a.log", } if !sameManagedProcessGeneration(current, current) { t.Fatal("expected an identical managed process generation to match") } for _, expected := range []ProcessIdentity{ {PID: 100, LogSessionID: "session-a", StdoutLogRef: "stdout-b.log", StderrLogRef: "stderr-a.log"}, {PID: 100, LogSessionID: "session-a", StdoutLogRef: "stdout-a.log", StderrLogRef: "stderr-b.log"}, } { if sameManagedProcessGeneration(current, expected) { t.Fatalf("output file swap was treated as the same generation: current=%+v expected=%+v", current, expected) } } }