nolint:paralleltest // This test is sensitive to environment variables
(t *testing.T)
| 27 | |
| 28 | //nolint:paralleltest // This test is sensitive to environment variables |
| 29 | func TestCLI(t *testing.T) { |
| 30 | t.Run("OK", func(t *testing.T) { |
| 31 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 32 | cmd, path := cmd(ctx, t, 123, 12) |
| 33 | err := cmd.Start() |
| 34 | require.NoError(t, err) |
| 35 | go cmd.Wait() |
| 36 | |
| 37 | waitForSentinel(ctx, t, cmd, path) |
| 38 | requireOOMScore(t, cmd.Process.Pid, 123) |
| 39 | requireNiceScore(t, cmd.Process.Pid, 12) |
| 40 | }) |
| 41 | |
| 42 | t.Run("FiltersEnv", func(t *testing.T) { |
| 43 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 44 | cmd, path := cmd(ctx, t, 123, 12) |
| 45 | cmd.Env = append(cmd.Env, fmt.Sprintf("%s=true", agentexec.EnvProcPrioMgmt)) |
| 46 | cmd.Env = append(cmd.Env, fmt.Sprintf("%s=123", agentexec.EnvProcOOMScore)) |
| 47 | cmd.Env = append(cmd.Env, fmt.Sprintf("%s=12", agentexec.EnvProcNiceScore)) |
| 48 | // Ensure unrelated environment variables are preserved. |
| 49 | cmd.Env = append(cmd.Env, "CODER_TEST_ME_AGENTEXEC=true") |
| 50 | err := cmd.Start() |
| 51 | require.NoError(t, err) |
| 52 | go cmd.Wait() |
| 53 | waitForSentinel(ctx, t, cmd, path) |
| 54 | |
| 55 | env := procEnv(t, cmd.Process.Pid) |
| 56 | hasExecEnvs := slices.ContainsFunc( |
| 57 | env, |
| 58 | func(e string) bool { |
| 59 | return strings.HasPrefix(e, agentexec.EnvProcPrioMgmt) || |
| 60 | strings.HasPrefix(e, agentexec.EnvProcOOMScore) || |
| 61 | strings.HasPrefix(e, agentexec.EnvProcNiceScore) |
| 62 | }) |
| 63 | require.False(t, hasExecEnvs, "expected environment variables to be filtered") |
| 64 | userEnv := slices.Contains(env, "CODER_TEST_ME_AGENTEXEC=true") |
| 65 | require.True(t, userEnv, "expected user environment variables to be preserved") |
| 66 | }) |
| 67 | |
| 68 | t.Run("Defaults", func(t *testing.T) { |
| 69 | ctx := testutil.Context(t, testutil.WaitMedium) |
| 70 | cmd, path := cmd(ctx, t, 0, 0) |
| 71 | err := cmd.Start() |
| 72 | require.NoError(t, err) |
| 73 | go cmd.Wait() |
| 74 | |
| 75 | waitForSentinel(ctx, t, cmd, path) |
| 76 | |
| 77 | expectedNice := expectedNiceScore(t) |
| 78 | expectedOOM := expectedOOMScore(t) |
| 79 | requireOOMScore(t, cmd.Process.Pid, expectedOOM) |
| 80 | requireNiceScore(t, cmd.Process.Pid, expectedNice) |
| 81 | }) |
| 82 | |
| 83 | t.Run("Capabilities", func(t *testing.T) { |
| 84 | testdir := filepath.Dir(TestBin) |
| 85 | capDir := filepath.Join(testdir, "caps") |
| 86 | err := os.Mkdir(capDir, 0o755) |
nothing calls this directly
no test coverage detected