Repository navigation
fix(sandboxes): align CLI with hosting-2 lifetime contract #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package sandboxes | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRunSessionLifetime(t *testing.T) { | ||
| t.Parallel() | ||
| for _, local := range []bool{false, true} { | ||
| mode := map[bool]string{false: "cloud", true: "local"}[local] | ||
| for _, selector := range []string{"preset", "template"} { | ||
| for _, duration := range []string{"", "-1", "0", "1", "29", "30", "300", "28800", "28801"} { | ||
| t.Run(mode+"/"+selector+"/duration="+duration, func(t *testing.T) { | ||
| t.Parallel() | ||
| seconds, _ := strconv.Atoi(duration) | ||
| valid := duration == "" || (local && seconds >= 0) || (!local && seconds >= 30 && seconds <= 28800) | ||
| requests := 0 | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| requests++ | ||
| assert.True(t, valid, "invalid duration must not reach transport") | ||
| assert.Equal(t, http.MethodPost, r.Method) | ||
| assert.Equal(t, "/projects/"+testProject+"/sandbox-sessions", r.URL.Path) | ||
| var body map[string]any | ||
| decoder := json.NewDecoder(r.Body) | ||
| decoder.UseNumber() | ||
| if err := decoder.Decode(&body); !assert.NoError(t, err) { | ||
| w.WriteHeader(http.StatusBadRequest) | ||
| return | ||
| } | ||
| if duration == "" { | ||
| assert.NotContains(t, body, "max_duration_seconds", "inherit the template lifetime") | ||
| } else { | ||
| assert.Equal(t, json.Number(duration), body["max_duration_seconds"]) | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| w.WriteHeader(http.StatusCreated) | ||
| _, _ = w.Write([]byte(`{"id":"` + testSession + `","expires_at":null}`)) | ||
| })) | ||
| defer server.Close() | ||
| deps := testDeps(server) | ||
| cmd := New(deps) | ||
| if local { | ||
| // Local Sandbox APIs authenticate, so deps.LocalMode remains false. | ||
| cmd = NewLocal(deps, deps) | ||
| } | ||
| value := "node22" | ||
| if selector == "template" { | ||
| value = testSession | ||
| } | ||
| args := []string{"run", "--" + selector, value} | ||
| if duration != "" { | ||
| args = append(args, "--duration", duration) | ||
| } | ||
| cmd.SetArgs(args) | ||
| cmd.SetOut(&bytes.Buffer{}) | ||
| cmd.SetErr(&bytes.Buffer{}) | ||
| err := cmd.Execute() | ||
| if valid { | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 1, requests) | ||
| } else { | ||
| require.ErrorContains(t, err, "--duration") | ||
| assert.Zero(t, requests) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a local template is configured with the newly supported
ttl_seconds: 0,volcano sandboxes run --template ...still initializes--durationto 3600 and always sends it asMaxDurationSeconds(internal/cmd/sandboxes/exec.go:155-177), overriding the template default; explicitly passing--duration 0is also rejected. Thus the advertised unlimited lifetime cannot be used by the CLI's session-creation command. Leave the duration omitted unless the flag was supplied, and validate zero according to local/cloud mode.AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.