-
Notifications
You must be signed in to change notification settings - Fork 17
feat(components/execd): add new api for context management #48
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
Open
Pangjiping
wants to merge
7
commits into
alibaba:main
Choose a base branch
from
Pangjiping:feat/execd/contextmanagement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
124d4ef
feat(components/execd): add new api for context management
Pangjiping 650ef8e
feat(workflow): add cancel-in-progress in workflow
Pangjiping 4d79b3c
fix(components/execd): fix missing return statement in response error…
Pangjiping 1ff8569
fix(components/execd): delete context from memcache when DeleteContex…
Pangjiping ac2b017
Merge remote-tracking branch 'origin' into feat/execd/contextmanagement
Pangjiping 98b2e92
feat(components/execd): add GetContext api
Pangjiping 3637d92
fix(components/execd): return empty array not null
Pangjiping 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
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
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,110 @@ | ||
| // Copyright 2025 Alibaba Group Holding Ltd. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package runtime | ||
|
|
||
| import ( | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestListContextsAndNewIpynbPath(t *testing.T) { | ||
| c := NewController("http://example", "token") | ||
| c.jupyterClientMap["session-python"] = &jupyterKernel{language: Python} | ||
| c.defaultLanguageJupyterSessions[Go] = "session-go-default" | ||
|
|
||
| pyContexts, err := c.listLanguageContexts(Python) | ||
| if err != nil { | ||
| t.Fatalf("listLanguageContexts returned error: %v", err) | ||
| } | ||
| if len(pyContexts) != 1 || pyContexts[0].ID != "session-python" || pyContexts[0].Language != Python { | ||
| t.Fatalf("unexpected python contexts: %#v", pyContexts) | ||
| } | ||
|
|
||
| allContexts, err := c.listAllContexts() | ||
| if err != nil { | ||
| t.Fatalf("listAllContexts returned error: %v", err) | ||
| } | ||
| if len(allContexts) != 2 { | ||
| t.Fatalf("expected two contexts, got %d", len(allContexts)) | ||
| } | ||
|
|
||
| tmpDir := filepath.Join(t.TempDir(), "nested") | ||
| path, err := c.newIpynbPath("abc123", tmpDir) | ||
| if err != nil { | ||
| t.Fatalf("newIpynbPath error: %v", err) | ||
| } | ||
| if _, statErr := os.Stat(tmpDir); statErr != nil { | ||
| t.Fatalf("expected directory to be created: %v", statErr) | ||
| } | ||
| expected := filepath.Join(tmpDir, "abc123.ipynb") | ||
| if path != expected { | ||
| t.Fatalf("unexpected ipynb path: got %s want %s", path, expected) | ||
| } | ||
| } | ||
|
|
||
| func TestNewContextID_UniqueAndLength(t *testing.T) { | ||
| c := NewController("", "") | ||
| id1 := c.newContextID() | ||
| id2 := c.newContextID() | ||
|
|
||
| if id1 == "" || id2 == "" { | ||
| t.Fatalf("expected non-empty ids") | ||
| } | ||
| if id1 == id2 { | ||
| t.Fatalf("expected unique ids, got identical: %s", id1) | ||
| } | ||
| if len(id1) != 32 || len(id2) != 32 { | ||
| t.Fatalf("expected 32-char ids, got %d and %d", len(id1), len(id2)) | ||
| } | ||
| } | ||
|
|
||
| func TestNewIpynbPath_ErrorWhenCwdIsFile(t *testing.T) { | ||
| c := NewController("", "") | ||
| tmpFile := filepath.Join(t.TempDir(), "file.txt") | ||
| if err := os.WriteFile(tmpFile, []byte("x"), 0o644); err != nil { | ||
| t.Fatalf("prepare file: %v", err) | ||
| } | ||
|
|
||
| if _, err := c.newIpynbPath("abc", tmpFile); err == nil { | ||
| t.Fatalf("expected error when cwd is a file") | ||
| } | ||
| } | ||
|
|
||
| func TestListContextUnsupportedLanguage(t *testing.T) { | ||
| c := NewController("", "") | ||
| _, err := c.ListContext(Command.String()) | ||
| if err == nil { | ||
| t.Fatalf("expected error for command language") | ||
| } | ||
| if _, err := c.ListContext(BackgroundCommand.String()); err == nil { | ||
| t.Fatalf("expected error for background-command language") | ||
| } | ||
| if _, err := c.ListContext(SQL.String()); err == nil { | ||
| t.Fatalf("expected error for sql language") | ||
| } | ||
| } | ||
|
|
||
| func TestDeleteContext_NotFound(t *testing.T) { | ||
| c := NewController("", "") | ||
| err := c.DeleteContext("missing") | ||
| if err == nil { | ||
| t.Fatalf("expected ErrContextNotFound") | ||
| } | ||
| if !errors.Is(err, ErrContextNotFound) { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| } |
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,19 @@ | ||
| // Copyright 2025 Alibaba Group Holding Ltd. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package runtime | ||
|
|
||
| import "errors" | ||
|
|
||
| var ErrContextNotFound = errors.New("context not found") |
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.
Uh oh!
There was an error while loading. Please reload this page.