From e5bbb969a15c569cf7d37634234a71783f628390 Mon Sep 17 00:00:00 2001 From: James O'Doherty Date: Fri, 22 May 2026 11:37:57 -0400 Subject: Fix PID lifecycle race and improve CLI routing for diagnostic commands --- tests/e2e/config_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/e2e/config_test.go (limited to 'tests/e2e/config_test.go') diff --git a/tests/e2e/config_test.go b/tests/e2e/config_test.go new file mode 100644 index 0000000..83cfc15 --- /dev/null +++ b/tests/e2e/config_test.go @@ -0,0 +1,58 @@ +package e2e + +import ( + "fmt" + "os" + "os/exec" + "strings" + "testing" +) + +func TestConfigPropagation(t *testing.T) { + binaryPath, err := GetBinaryPath() + if err != nil { + t.Skipf("Skipping test: %v", err) + } + + tmpRuntimeDir := t.TempDir() + profile := "config-test-vpn" + + // Test 1: Non-isolated configuration + cmd := exec.Command(binaryPath, "show-config", "--profile", profile) + cmd.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("show-config failed: %v\nOutput: %s", err, string(out)) + } + + output := string(out) + expectedBase := tmpRuntimeDir + expectedPids := fmt.Sprintf("%s/profiles/%s/pids", tmpRuntimeDir, profile) + + if !strings.Contains(output, fmt.Sprintf("Runtime Base: %s", expectedBase)) { + t.Errorf("Expected Runtime Base %s in output: %s", expectedBase, output) + } + if !strings.Contains(output, fmt.Sprintf("PIDs Path: %s", expectedPids)) { + t.Errorf("Expected PIDs Path %s in output: %s", expectedPids, output) + } + + // Test 2: Configuration after bootstrap (Isolated) + // We use 'test-ns' as a way to run a command that we know is isolated. + // Actually, we can just run 'show-config' but the current 'Route' + // handles 'show-config' BEFORE the bootstrap. + // To test isolated config, we can't use 'show-config' because it's a diagnostic + // command designed to run outside isolation. + + // To verify what an isolated process sees, we can use a target command + // that prints the environment. + cmdIsolated := exec.Command(binaryPath, "--profile", profile, "--", "sh", "-c", "echo $XDG_RUNTIME_DIR") + cmdIsolated.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir)) + outIso, err := cmdIsolated.CombinedOutput() + if err != nil { + t.Fatalf("Isolated command failed: %v\nOutput: %s", err, string(outIso)) + } + + if !strings.Contains(string(outIso), expectedBase) { + t.Errorf("Expected isolated process to see XDG_RUNTIME_DIR=%s, got: %s", expectedBase, string(outIso)) + } +} -- cgit v1.2.3