Skip to content

feat(rayapp): Anyscale CLI pr1 core infrastructure#396

Open
elliot-barn wants to merge 6 commits intomainfrom
anyscale-cli-pr1-core-infrastructure
Open

feat(rayapp): Anyscale CLI pr1 core infrastructure#396
elliot-barn wants to merge 6 commits intomainfrom
anyscale-cli-pr1-core-infrastructure

Conversation

@elliot-barn
Copy link
Collaborator

@elliot-barn elliot-barn commented Jan 27, 2026

Add foundational components for Anyscale CLI wrapper:

  • AnyscaleCLI struct and NewAnyscaleCLI() constructor
  • errAnyscaleNotInstalled error sentinel for installation checks
  • isAnyscaleInstalled() helper to verify CLI availability
  • runAnyscaleCLI() base method for executing anyscale commands
  • Ring buffer to forward anyscale cli output to the console

Includes comprehensive test coverage with setupMockAnyscale test helper.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @elliot-barn, 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 establishes the foundational components for integrating with the Anyscale CLI within the rayapp package. It provides a structured way to check for the CLI's presence, execute commands, and manage their output, ensuring robust and testable interactions with the external tool.

Highlights

  • Anyscale CLI Wrapper: Introduces the AnyscaleCLI struct and its constructor NewAnyscaleCLI to encapsulate interactions with the Anyscale command-line interface.
  • Installation Check: Adds errAnyscaleNotInstalled and the isAnyscaleInstalled() helper function to verify if the Anyscale CLI is present in the system's PATH.
  • Command Execution: Implements runAnyscaleCLI() as a core method to execute Anyscale commands, capture their output, and display it to the terminal while preserving colors.
  • Comprehensive Testing: Includes a dedicated test file (anyscale_cli_test.go) with a setupMockAnyscale helper and various test cases covering installation, successful command execution, and error handling.

🧠 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

This pull request adds the foundational components for an Anyscale CLI wrapper, including the main struct, installation check, and a command runner, along with comprehensive tests. The implementation is solid, but I have a few suggestions. In the main implementation, a debug print statement should be removed. In the tests, there's an opportunity to make path construction more robust. More importantly, I've identified and suggested a fix for a bug in the test logic that was causing an output check to be skipped in error scenarios.

Comment on lines 92 to 140
if tt.wantErr != nil {
if err == nil {
t.Fatal("expected error, got nil")
}
if errors.Is(tt.wantErr, errAnyscaleNotInstalled) {
if !errors.Is(err, errAnyscaleNotInstalled) {
t.Errorf("expected errAnyscaleNotInstalled, got: %v", err)
}
} else if !strings.Contains(err.Error(), tt.wantErr.Error()) {
t.Errorf("error %q should contain %q", err.Error(), tt.wantErr.Error())
}
return
}

if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tt.wantSubstr != "" && !strings.Contains(output, tt.wantSubstr) {
t.Errorf("output %q should contain %q", output, tt.wantSubstr)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current test logic for checking errors has a bug. The return statement on line 103 prevents the wantSubstr check on line 109 from running for test cases that expect an error. This means the output check for the "command fails with stderr" case is skipped. The logic should be refactored to ensure wantSubstr is checked for all cases.

			if tt.wantErr != nil {
				if err == nil {
					t.Fatal("expected error, got nil")
				}
				if errors.Is(tt.wantErr, errAnyscaleNotInstalled) {
					if !errors.Is(err, errAnyscaleNotInstalled) {
						t.Errorf("expected errAnyscaleNotInstalled, got: %v", err)
					}
				} else if !strings.Contains(err.Error(), tt.wantErr.Error()) {
					t.Errorf("error %q should contain %q", err.Error(), tt.wantErr.Error())
				}
			} else if err != nil {
				t.Fatalf("unexpected error: %v", err)
			}

			if tt.wantSubstr != "" && !strings.Contains(output, tt.wantSubstr) {
				t.Errorf("output %q should contain %q", output, tt.wantSubstr)
			}

return "", errAnyscaleNotInstalled
}

fmt.Println("anyscale cli args: ", args)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This fmt.Println appears to be a debug statement. It should be removed or replaced with a proper logging mechanism to avoid polluting the standard output in production environments. Such output can be noisy and might expose sensitive information.

tmp := t.TempDir()

if script != "" {
mockScript := tmp + "/anyscale"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For constructing file paths, it's more robust and platform-independent to use path/filepath.Join instead of string concatenation. This avoids issues with path separators on different operating systems. You'll need to add "path/filepath" to your imports.

Suggested change
mockScript := tmp + "/anyscale"
mockScript := filepath.Join(tmp, "anyscale")

@gitar-bot
Copy link

gitar-bot bot commented Jan 27, 2026

Code Review 👍 Approved with suggestions 0 resolved / 2 findings

Solid foundational CLI wrapper with good test coverage. Main concern is unconditional debug output in production code that could leak CLI arguments.

⚠️ Quality: Debug print statement in production code

📄 rayapp/anyscale_cli.go:41

The line fmt.Println("anyscale cli args: ", args) unconditionally prints CLI arguments to stdout. This has several concerns:

  1. Noisy output: Every CLI invocation will print debug info, which pollutes the output when used in automation/scripts
  2. Potential information leakage: CLI arguments could contain sensitive information (tokens, secrets) that shouldn't be logged by default
  3. Not controllable: There's no way to disable this output without modifying the code

Suggested fix: Either remove the debug statement, or make it conditional based on a debug/verbose flag or environment variable:

if os.Getenv("RAYAPP_DEBUG") != "" {
    fmt.Println("anyscale cli args: ", args)
}

Or use a logging package with configurable levels.

💡 Quality: Test helper replaces entire PATH instead of prepending

📄 rayapp/anyscale_cli_test.go:84

In setupMockAnyscale, the line os.Setenv("PATH", tmp) completely replaces the PATH environment variable with just the temp directory. While this works for the current tests (since they only need to find/not find the mock anyscale script), it could cause issues:

  1. If future tests in the same file need other system tools during execution
  2. If sub-tests or parallel tests depend on system utilities

Suggested fix: Prepend the temp directory to PATH instead of replacing it:

os.Setenv("PATH", tmp + ":" + origPath)

However, note that the current approach does have the advantage of complete isolation - ensuring no real anyscale binary is accidentally called. If that isolation is intentional, consider adding a comment explaining the design choice.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

// Capture output while also displaying to terminal with colors
var outputBuf bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &outputBuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &outputBuf)
Copy link

Choose a reason for hiding this comment

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

⚠️ Quality: Debug print statement in production code

Details

The line fmt.Println("anyscale cli args: ", args) unconditionally prints CLI arguments to stdout. This has several concerns:

  1. Noisy output: Every CLI invocation will print debug info, which pollutes the output when used in automation/scripts
  2. Potential information leakage: CLI arguments could contain sensitive information (tokens, secrets) that shouldn't be logged by default
  3. Not controllable: There's no way to disable this output without modifying the code

Suggested fix: Either remove the debug statement, or make it conditional based on a debug/verbose flag or environment variable:

if os.Getenv("RAYAPP_DEBUG") != "" {
    fmt.Println("anyscale cli args: ", args)
}

Or use a logging package with configurable levels.


Was this helpful? React with 👍 / 👎

@elliot-barn elliot-barn changed the title feat(rayapp): add Anyscale CLI core infrastructure feat(rayapp): Anyscale CLI pr1 core infrastructure Jan 27, 2026
@gitar-bot
Copy link

gitar-bot bot commented Jan 27, 2026

I've addressed the code review feedback:

Changes made:

  1. Debug output now conditional (rayapp/anyscale_cli.go:35-37): The fmt.Println statement is now only executed when RAYAPP_DEBUG environment variable is set, preventing noisy output in production and avoiding potential information leakage.

  2. Documented PATH replacement (rayapp/anyscale_cli_test.go:11-12): Added a comment explaining that the complete PATH replacement in setupMockAnyscale is intentional for test isolation, ensuring no real anyscale binary is accidentally invoked.

  3. Fixed go.mod: Corrected invalid Go version from 1.25.2 to 1.23.

All tests pass successfully.

@aslonnie aslonnie self-requested a review February 2, 2026 20:53
@elliot-barn elliot-barn marked this pull request as ready for review February 3, 2026 00:29
cmd := exec.Command("anyscale", args...)

// Capture output while also displaying to terminal with colors
var outputBuf bytes.Buffer
Copy link
Collaborator

Choose a reason for hiding this comment

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

you might want to set a limit (e.g. first / last several k of bytes), otherwise, this can easily run into out of memory.


output, err := cli.runAnyscaleCLI(tt.args)

if tt.wantErr != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, this error checking logic feels a bit unclear.. what is this trying to do?

why is errAnyscaleNotInstalled type error having special treatment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed!

@elliot-barn elliot-barn requested a review from aslonnie February 5, 2026 01:25
Comment on lines 43 to 44
output := outputBuf.Bytes()
if len(output) > maxOutputBufferSize {
Copy link
Collaborator

Choose a reason for hiding this comment

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

at this point it already runs out of memory..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using a ring buffer now

@elliot-barn elliot-barn requested a review from aslonnie February 5, 2026 22:14
return tw.String(), nil
}

// tailWriter is a circular buffer that keeps the most recent `limit`
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks ok. could you:

  • split this tailwriter into another file and in a leading PR?
  • rather than allocating a limit length buffer, could you use bytes.Buffer so that the initial and idle memory footprint is near zero? you can achieve this with two limit/2 bytes.Buffer.

elliot-barn and others added 6 commits February 6, 2026 20:54
Extract tailWriter into its own file with a bytes.Buffer-based
double-buffer design. Initial memory footprint is near zero (no
upfront 1MB allocation); buffers grow lazily as data is written.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add foundational components for Anyscale CLI wrapper:
- AnyscaleCLI struct and NewAnyscaleCLI() constructor
- errAnyscaleNotInstalled error sentinel for installation checks
- isAnyscaleInstalled() helper to verify CLI availability
- runAnyscaleCLI() base method for executing anyscale commands

Includes comprehensive test coverage with setupMockAnyscale test helper.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
Replace bytes.Buffer with a fixed-size circular buffer (tailWriter)
so memory usage never exceeds maxOutputBufferSize during command
execution. The previous approach truncated after the command finished,
allowing unbounded growth during long-running commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the inline ring-buffer tailWriter from anyscale_cli.go and
its tests from anyscale_cli_test.go. The tailWriter now lives in
tail_writer.go (from the tailwriter-extract branch) with a lazy
double-buffer implementation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@elliot-barn elliot-barn force-pushed the anyscale-cli-pr1-core-infrastructure branch from d51c0db to 829ba7b Compare February 6, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants