Skip to content

[BUG] make PicoD execute tests portable#308

Open
krrishrastogi05 wants to merge 1 commit intovolcano-sh:mainfrom
krrishrastogi05:krrish/picod-portable-tests
Open

[BUG] make PicoD execute tests portable#308
krrishrastogi05 wants to merge 1 commit intovolcano-sh:mainfrom
krrishrastogi05:krrish/picod-portable-tests

Conversation

@krrishrastogi05
Copy link
Copy Markdown

/kind cleanup

What this PR does / why we need it:
While testing a small PicoD change locally on Windows, I noticed that go test ./pkg/picod failed for reasons unrelated to the code under test. Some tests assumed Unix tools like sh, sleep, pwd, true, and false were available, and symlink tests failed when Windows denied symlink creation privileges.

This PR makes those tests more portable without changing PicoD runtime behavior. It should make the project a bit more welcoming for contributors who are developing on Windows, since they can run the PicoD test suite locally without needing a Unix-like shell setup or elevated symlink permissions.

The main changes are:

  • use a small Go test helper process instead of host-specific shell commands
  • keep the same coverage for stdout, stderr, exit codes, timeouts, working directory handling, and env vars
  • skip symlink-specific assertions only when the OS refuses symlink creation

Special notes for your reviewer:
This is a test-only cleanup. The production PicoD command execution path is unchanged.

Testing done:

  • gofmt
  • git diff --check
  • go test ./pkg/picod

Does this PR introduce a user-facing change?:

NONE

Copilot AI review requested due to automatic review settings May 8, 2026 19:52
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign acsoto for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the test suite to use a self-invoking helper process instead of relying on external shell commands, which improves test portability. The review feedback correctly identifies that the current implementation using -test.run will pollute stdout with test runner logs, potentially breaking assertions. It is recommended to refactor the helper logic into an init() function and use os.Executable() to ensure a reliable path to the test binary and clean output.

Comment thread pkg/picod/test_helpers_test.go Outdated
Comment on lines +31 to +34
func testCommand(args ...string) []string {
command := []string{os.Args[0], "-test.run=TestPicodHelperProcess", "--"}
return append(command, args...)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using os.Args[0] and -test.run for the helper process has two significant drawbacks:

  1. Portability/Reliability: os.Args[0] can be unreliable if the working directory is changed during tests (as seen in several test cases) and it contains a relative path. Using os.Executable() provides a more robust absolute path to the test binary.
  2. Test Runner Noise: Invoking the helper via -test.run causes the Go test runner to emit === RUN TestPicodHelperProcess to stdout. This extra output will be captured in resp.Stdout, causing assertions that expect exact matches (e.g., assert.Equal(t, "hello\n", resp.Stdout)) to fail.

It is recommended to move the helper logic trigger to an init() function and use os.Executable() for the command path. This bypasses the test runner's output entirely.

Suggested change
func testCommand(args ...string) []string {
command := []string{os.Args[0], "-test.run=TestPicodHelperProcess", "--"}
return append(command, args...)
}
func init() {
if os.Getenv(testHelperProcessEnv) == "1" {
picodHelperProcessMain()
os.Exit(0)
}
}
func testCommand(args ...string) []string {
exe, err := os.Executable()
if err != nil {
exe = os.Args[0]
}
return append([]string{exe, "--"}, args...)
}

Comment thread pkg/picod/test_helpers_test.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes PicoD’s test suite more portable across OSes (notably Windows) by removing dependencies on Unix shell utilities and by handling Windows symlink privilege limitations in tests, without changing PicoD production execution behavior.

Changes:

  • Introduces a Go “helper process” test binary entrypoint and helpers to replace host-specific commands like sh, sleep, pwd, true, and false.
  • Updates PicoD end-to-end and handler tests to execute commands via the helper process and to consistently inject the helper env var.
  • Adds a symlink helper that skips tests on Windows when symlink creation is denied.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/picod/test_helpers_test.go Adds helper-process command runner helpers and a Windows-aware symlink helper for portable tests.
pkg/picod/picod_test.go Switches E2E execute tests to use the helper-process commands and uses the symlink helper.
pkg/picod/execute_test.go Replaces OS-specific commands in ExecuteHandler tests with helper-process commands and adjusts env usage.

Comment thread pkg/picod/execute_test.go
Comment on lines 520 to 528
func TestExecuteHandler_EmptyEnvVars(t *testing.T) {
server, tmpDir := setupExecuteTestServer(t)
defer os.RemoveAll(tmpDir)
defer os.Unsetenv(PublicKeyEnvVar)

req := ExecuteRequest{
Command: []string{"echo", "test"},
Env: map[string]string{},
Command: testCommand("echo", "test"),
Env: testCommandEnv(nil),
}
Comment on lines +46 to +53
func requireSymlink(t *testing.T, oldname, newname string) {
t.Helper()
if err := os.Symlink(oldname, newname); err != nil {
if runtime.GOOS == "windows" {
t.Skipf("creating symlinks requires privileges on Windows: %v", err)
}
t.Fatalf("create symlink: %v", err)
}
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 8, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.75%. Comparing base (524e55e) to head (9b516eb).
⚠️ Report is 22 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #308      +/-   ##
==========================================
+ Coverage   47.57%   47.75%   +0.18%     
==========================================
  Files          30       30              
  Lines        2819     2854      +35     
==========================================
+ Hits         1341     1363      +22     
- Misses       1338     1343       +5     
- Partials      140      148       +8     
Flag Coverage Δ
unittests 47.75% <ø> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Krrish <krrishrastogi00@gmail.com>
@krrishrastogi05 krrishrastogi05 force-pushed the krrish/picod-portable-tests branch from f27efad to 9b516eb Compare May 8, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants