-
Notifications
You must be signed in to change notification settings - Fork 2
feat: back get/describe/delete on the OpenShell SDK (PR7a) #105
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
6 commits
Select commit
Hold shift + click to select a range
de88b8e
feat(openshell): add SDK read/delete layer for read-UX commands (PR7a…
robbycochran c594aae
feat(cmd): back get on the OpenShell SDK (PR7a S2)
robbycochran 2756560
feat(cmd): back describe on the OpenShell SDK (PR7a S3)
robbycochran 8f95261
feat(cmd): back delete on the OpenShell SDK (PR7a S4)
robbycochran 3ea0c5c
fix(cmd): skip SDK dial for delete --k8s (review)
robbycochran 4ee50c7
fix(cmd): wrap SDK client init errors with context (review)
robbycochran 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/NVIDIA/OpenShell/sdk/go/openshell/v1/types" | ||
|
|
||
| "github.com/stackrox/harness-openshell/internal/openshell" | ||
| "github.com/stackrox/harness-openshell/internal/testutil" | ||
| ) | ||
|
|
||
| // The delete tests use keepOpenFactory (executor_inference_test.go) so the | ||
| // command's deferred Close doesn't shut the shared fake before the test can | ||
| // assert the resources were actually removed, not merely that a log line printed. | ||
|
|
||
| func sandboxNames(t *testing.T, c openshell.Client) []string { | ||
| t.Helper() | ||
| sandboxes, err := c.Sandboxes(context.Background()) | ||
| if err != nil { | ||
| t.Fatalf("list sandboxes: %v", err) | ||
| } | ||
| names := make([]string, len(sandboxes)) | ||
| for i, s := range sandboxes { | ||
| names[i] = s.Name | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| func providerNames(t *testing.T, c openshell.Client) []string { | ||
| t.Helper() | ||
| providers, err := c.Providers(context.Background()) | ||
| if err != nil { | ||
| t.Fatalf("list providers: %v", err) | ||
| } | ||
| names := make([]string, len(providers)) | ||
| for i, p := range providers { | ||
| names[i] = p.Name | ||
| } | ||
| return names | ||
| } | ||
|
|
||
| func TestDeleteTargeted(t *testing.T) { | ||
| client, fc := testutil.NewFakeClient("default") | ||
| fc.AddSandbox("default", &types.Sandbox{Name: "agent-a", Status: types.SandboxStatus{Phase: types.SandboxReady}}) | ||
| fc.AddSandbox("default", &types.Sandbox{Name: "agent-b", Status: types.SandboxStatus{Phase: types.SandboxReady}}) | ||
|
|
||
| cmd := NewDeleteCmd("", "", keepOpenFactory(client)) | ||
| cmd.SetArgs([]string{"agent-a"}) | ||
| if _, err := captureStdout(t, cmd.Execute); err != nil { | ||
| t.Fatalf("delete agent-a: %v", err) | ||
| } | ||
|
|
||
| remaining := sandboxNames(t, client) | ||
| if len(remaining) != 1 || remaining[0] != "agent-b" { | ||
| t.Errorf("targeted delete should remove only agent-a, got %v", remaining) | ||
| } | ||
| } | ||
|
|
||
| func TestDeleteSandboxesSweep(t *testing.T) { | ||
| client, fc := testutil.NewFakeClient("default") | ||
| fc.AddSandbox("default", &types.Sandbox{Name: "agent-a", Status: types.SandboxStatus{Phase: types.SandboxReady}}) | ||
| fc.AddSandbox("default", &types.Sandbox{Name: "agent-b", Status: types.SandboxStatus{Phase: types.SandboxReady}}) | ||
|
|
||
| cmd := NewDeleteCmd("", "", keepOpenFactory(client)) | ||
| cmd.SetArgs([]string{"--sandboxes", "--gateway", "prod"}) | ||
| if _, err := captureStdout(t, cmd.Execute); err != nil { | ||
| t.Fatalf("delete --sandboxes: %v", err) | ||
| } | ||
|
|
||
| if remaining := sandboxNames(t, client); len(remaining) != 0 { | ||
| t.Errorf("--sandboxes should sweep every sandbox, got %v", remaining) | ||
| } | ||
| } | ||
|
|
||
| func TestDeleteProvidersGuard(t *testing.T) { | ||
| client, fc := testutil.NewFakeClient("default") | ||
| fc.AddSandbox("default", &types.Sandbox{Name: "agent-a", Status: types.SandboxStatus{Phase: types.SandboxReady}}) | ||
| fc.AddProvider("default", &types.Provider{Name: "github", Type: "github"}) | ||
|
|
||
| cmd := NewDeleteCmd("", "", keepOpenFactory(client)) | ||
| cmd.SetArgs([]string{"--providers", "--gateway", "prod"}) | ||
| _, err := captureStdout(t, cmd.Execute) | ||
| if err == nil { | ||
| t.Fatal("deleting providers with a running sandbox should be refused") | ||
| } | ||
| if !contains(err.Error(), "running sandboxes") { | ||
| t.Errorf("unexpected guard error: %v", err) | ||
| } | ||
|
|
||
| // The guard must prevent deletion, not delete-then-error: the provider survives. | ||
| if names := providerNames(t, client); len(names) != 1 || names[0] != "github" { | ||
| t.Errorf("guard should leave the provider untouched, got %v", names) | ||
| } | ||
| } | ||
|
|
||
| // Note: `delete --k8s`-only skipping the SDK client (CodeRabbit finding) is not | ||
| // unit-tested — the --k8s path invokes the real, non-injectable teardownK8s, | ||
| // which shells out to the ambient kubeconfig and would destructively act on a | ||
| // live cluster. The gating (`needsSDK`) is a simple guard in delete.go. | ||
|
|
||
| func TestDeleteProvidersSweep(t *testing.T) { | ||
| client, fc := testutil.NewFakeClient("default") | ||
| fc.AddProvider("default", &types.Provider{Name: "github", Type: "github"}) | ||
| fc.AddProvider("default", &types.Provider{Name: "vertex", Type: "google-vertex-ai"}) | ||
|
|
||
| cmd := NewDeleteCmd("", "", keepOpenFactory(client)) | ||
| cmd.SetArgs([]string{"--providers", "--gateway", "prod"}) | ||
| if _, err := captureStdout(t, cmd.Execute); err != nil { | ||
| t.Fatalf("delete --providers: %v", err) | ||
| } | ||
|
|
||
| if names := providerNames(t, client); len(names) != 0 { | ||
| t.Errorf("--providers should sweep every provider, got %v", names) | ||
| } | ||
| } |
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.