Skip to content

Conversation

@Sagar-6203620715
Copy link
Contributor

Description

Added test files, coverage extended to 100% from 0%.

  • pkg/picod/auth_test.go
  • pkg/picod/execute_test.go
  • pkg/picod/files_test.go
  • pkg/picod/server_test.go

Related Issue

Partially fixes #88

Type of Change

  • Test addition/update

Changes Made

Added test for two files in pkg/picod

Testing

  • Unit tests added/updated
  • Integration tests pass
    Before
Screenshot 2026-01-22 203832

After
Screenshot 2026-01-22 203818

Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Sagar-6203620715, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the test coverage and reliability of the pkg/picod package by introducing a comprehensive suite of unit tests. The new tests validate critical components such as JWT authentication, secure command execution, file system path sanitization, and server lifecycle management, ensuring the core functionalities behave as expected and are resilient to various inputs and conditions.

Highlights

  • Enhanced Test Coverage for pkg/picod/auth: Comprehensive unit tests have been added for the authentication manager, covering initialization, public key loading from environment variables (including valid, missing, and invalid key scenarios), and the JWT authentication middleware's behavior under various conditions (missing/invalid headers, valid/expired/invalid tokens, wrong signing methods).
  • Extensive Testing for pkg/picod/execute: New unit tests thoroughly validate the command execution handler, addressing edge cases such as invalid JSON requests, empty commands, various timeout formats, and both valid and malicious working directory inputs. Tests also cover environment variable handling, exit code propagation, command timeouts, and the structure of the execution response.
  • Robust Path and File Mode Testing in pkg/picod/files: Unit tests are introduced for file-related utilities, specifically parseFileMode to ensure correct parsing of file permissions and sanitizePath to verify its ability to prevent path traversal attacks and correctly resolve paths within the defined workspace, including scenarios with symlinks.
  • Validation of pkg/picod/server Initialization and Health Checks: The server's initialization process, route registration, workspace setup (including default behavior and path resolution), and the health check endpoint are now covered by unit tests. This ensures the server starts correctly and its basic functionalities are operational.
  • Significant Coverage Increase: This pull request dramatically increases the test coverage for the pkg/picod package, bringing the coverage of the newly tested files from 0% to 100% and contributing to an overall package coverage improvement to 75.7%.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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

The pull request introduces new test files for auth, execute, and files packages, significantly improving test coverage. The new tests cover various scenarios for authentication, command execution, and file path sanitization. However, there are a couple of areas where test coverage could be enhanced to ensure robustness and security, particularly around MaxBodySize enforcement and symlink traversal prevention.

@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 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.
⚠️ Please upload report for BASE (main@ecea52a). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #161   +/-   ##
=======================================
  Coverage        ?   37.46%           
=======================================
  Files           ?       29           
  Lines           ?     2549           
  Branches        ?        0           
=======================================
  Hits            ?      955           
  Misses          ?     1479           
  Partials        ?      115           
Flag Coverage Δ
unittests 37.46% <ø> (?)

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: Sagar Choudhary <sagar6203620715@gmail.com>
Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
@Sagar-6203620715
Copy link
Contributor Author

/cc @hzxuzhonghu

@Sagar-6203620715
Copy link
Contributor Author

Hi @hzxuzhonghu
Its been about a week. Would love to get your review on this PR.

Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
@Sagar-6203620715
Copy link
Contributor Author

Hi @hzxuzhonghu Its been about a week. Would love to get your review on this PR.

I have refactored it to make it optimal
Ready for review->merge

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

Thanks for the coverage boost! The tests are generally useful, but please refactor for table‑driven style and remove a stray file.

Table‑driven refactors requested

  • pkg/picod/auth_test.go: consolidate TestLoadPublicKeyFromEnv_* cases into a table; likewise unify TestAuthMiddleware_* header/token cases into a table with expected status/body.
  • pkg/picod/execute_test.go: many single‑scenario tests can be grouped into table‑driven cases (invalid JSON/empty command/timeout formats/working dir variants/env vars/command args/response assertions) to reduce duplication.
  • pkg/picod/server_test.go: combine “new server” workspace variants and path‑resolution cases into table‑driven tests.

Remove stray file

  • x.diff is committed and contains a diff for pkg/api/errors_test.go. This appears accidental and should be removed from the PR.

Optional

  • TestExecuteHandler_TimeoutHandling uses sleep 10 with a 100ms timeout. Consider a shorter sleep (e.g., sleep 1) to keep tests fast.

Once these are addressed, the tests look good to me.

Signed-off-by: Sagar Choudhary <sagar6203620715@gmail.com>
@volcano-sh-bot
Copy link
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 yaozengzeng 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

@Sagar-6203620715
Copy link
Contributor Author

Once these are addressed, the tests look good to me.

Hi @hzxuzhonghu
I have addressed the review and refactored the code as instructed
Ready for review->merge.

@Sagar-6203620715
Copy link
Contributor Author

Also I have been working on a prototype for the mentorship project. It is based on the architecture of Agentcube and the instructions you gave in the project description issue #156 (comment)

This is a big project, it includes

caller-> router authentication and authorization{only the owner of session can be allowed to call the backend sandbox}
caller->router, authenticate the identity of the caller, and doing some policy check, whether this identify is allowed to create a session.
router->workload manager authn/authz
We also allow client directly call the sandbox creation api of the workload manager, this also need authn/authz
You should investigate existing cloud native identity provider like keycloak, spiffee, etc

I have built and deployed it on netlify. Would you be willing to review it. It demonstrates my knowledge on auth/authz/go/agentcube.

Would like to see your experience on security authn/authz

Prototype - https://sagar-authdemo-agentcube.netlify.app/
I would be really grateful to have your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Umbrella: strengthen unit test coverage across AgentCube components

4 participants