-
Notifications
You must be signed in to change notification settings - Fork 0
feat: versioned Node runtimes — node22/npm22/npx22, generalized cb expose (RM-11) #30
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
4 commits
Select commit
Hold shift + click to select a range
0fbe12e
feat: versioned Node runtimes — add node22/npm22/npx22 and generalize…
AviBackToBlack 6e96f3c
test: cover Expose's non-npm-shaped source tool guard (RM-11 GLM find…
AviBackToBlack df44349
fix(cli): address Devin and Copilot review findings for cb expose (RM…
AviBackToBlack 67a0c7b
docs: note exposed profiles can't share a binary name across runtimes…
AviBackToBlack 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "reflect" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/AviBackToBlack/container-bin/internal/registry" | ||
| ) | ||
|
|
||
| // These tests cover Expose guard paths that need no Docker daemon. | ||
| // The Docker-dependent discovery path (discoverNPMGlobalBins onward) remains | ||
| // untested here because it requires a real Docker daemon and a populated | ||
| // npm-global volume. | ||
|
|
||
| func TestExposeRequiresSourceTool(t *testing.T) { | ||
| reg := registry.Default() | ||
| if err := Expose(reg, filepath.Join(t.TempDir(), "container-bin.toml"), nil); err == nil { | ||
| t.Fatal("expected usage error for empty args") | ||
| } else if !strings.Contains(err.Error(), "usage: cb expose TOOL") { | ||
| t.Fatalf("unexpected error message: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestExposeRejectsUnknownSource(t *testing.T) { | ||
| reg := registry.Default() | ||
| if err := Expose(reg, filepath.Join(t.TempDir(), "container-bin.toml"), []string{"notarealtool"}); err == nil { | ||
| t.Fatal("expected not-found error") | ||
| } else if !strings.Contains(err.Error(), `tool "notarealtool" not found`) { | ||
| t.Fatalf("unexpected error message: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // terraform exists in the registry but is not npm-shaped (stateless), so | ||
| // Expose must fail closed here before any docker invocation. This also pins | ||
| // that the new %q-formatted error carries the source tool's actual name rather | ||
| // than an empty string. | ||
| func TestExposeRejectsNonNpmShapedTool(t *testing.T) { | ||
| reg := registry.Default() | ||
| err := Expose(reg, filepath.Join(t.TempDir(), "container-bin.toml"), []string{"terraform"}) | ||
| if err == nil { | ||
| t.Fatal("expected error for non-npm-shaped source tool") | ||
| } | ||
| if !strings.Contains(err.Error(), "is not a stateful npm-shaped profile") { | ||
| t.Fatalf("unexpected error message: %v", err) | ||
| } | ||
| if !strings.Contains(err.Error(), `"terraform"`) { | ||
| t.Fatalf("error message does not name the source tool: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // TestRenderExposedToolSection proves that the TOML section generated by | ||
| // cb expose inherits the source tool's identity (image, state_group, | ||
| // shared_volumes and environment settings), not a hardcoded npm default. | ||
| // It uses npm22 from the default registry so the parsed tool carries the | ||
| // Node 22 runtime identity. | ||
| func TestRenderExposedToolSection(t *testing.T) { | ||
| reg := registry.Default() | ||
| source, ok := reg.Tools["npm22"] | ||
| if !ok { | ||
| t.Fatal("npm22 not in default registry") | ||
| } | ||
|
|
||
| const binary = "cowsay" | ||
| section := renderExposedToolSection("npm22", source, binary) | ||
| parsed, err := registry.ParseTOML("schema_version = 1\n" + section) | ||
| if err != nil { | ||
| t.Fatalf("rendered section invalid: %v", err) | ||
| } | ||
|
|
||
| got, ok := parsed.Tools[binary] | ||
| if !ok { | ||
| t.Fatal("parsed registry missing exposed tool") | ||
| } | ||
| if got.Image != "node:22-slim" { | ||
| t.Errorf("image = %q, want %q", got.Image, "node:22-slim") | ||
| } | ||
| if got.StateGroup != "node22" { | ||
| t.Errorf("state_group = %q, want %q", got.StateGroup, "node22") | ||
| } | ||
| if !reflect.DeepEqual(got.SharedVolumes, source.SharedVolumes) { | ||
| t.Errorf("shared_volumes = %v, want %v", got.SharedVolumes, source.SharedVolumes) | ||
| } | ||
| wantCommand := []string{"/cb/npm-global/bin/" + binary} | ||
| if !reflect.DeepEqual(got.Command, wantCommand) { | ||
| t.Errorf("command = %v, want %v", got.Command, wantCommand) | ||
| } | ||
| } |
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.
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.