feat(runtime): add Google Workspace CLI support

This commit is contained in:
Goon committed 2026-05-24 12:12:16 +07:00
1 parent 68684e4859
commit 12fb1baf79
13 files changed
+336 -12

No files matched your search

@@ -49,6 +49,67 @@ func TestSecureCLICheckBinaryFindsRuntimeNpmBinary(t *testing.T) {
}
}
func TestSecureCLICheckBinaryFindsGoogleWorkspaceRuntimeBinary(t *testing.T) {
runtimeDir := t.TempDir()
t.Setenv("RUNTIME_DIR", runtimeDir)
t.Setenv("NPM_CONFIG_PREFIX", "")
t.Setenv("PATH", "/usr/bin")
binDir := filepath.Join(runtimeDir, "npm-global", "bin")
if err := os.MkdirAll(binDir, 0o755); err != nil {
t.Fatal(err)
}
wantPath := filepath.Join(binDir, "gws")
if err := os.WriteFile(wantPath, []byte("#!/bin/sh\n"), 0o755); err != nil {
t.Fatal(err)
}
req := httptest.NewRequest(http.MethodPost, "/v1/cli-credentials/check-binary", strings.NewReader(`{"binary_name":"gws"}`))
rec := httptest.NewRecorder()
NewSecureCLIHandler(nil, nil).handleCheckBinary(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", rec.Code, rec.Body.String())
}
var got struct {
Found bool `json:"found"`
Path string `json:"path"`
Error string `json:"error"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
if !got.Found {
t.Fatalf("found = false, error = %q", got.Error)
}
if got.Path != wantPath {
t.Fatalf("path = %q, want %q", got.Path, wantPath)
}
}
func TestSecureCLIPresetsIncludesGoogleWorkspace(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/v1/cli-credentials/presets", nil)
rec := httptest.NewRecorder()
NewSecureCLIHandler(nil, nil).handlePresets(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", rec.Code, rec.Body.String())
}
var got struct {
Presets map[string]struct {
BinaryName string `json:"binary_name"`
} `json:"presets"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
if got.Presets["gws"].BinaryName != "gws" {
t.Fatalf("gws preset = %#v, want binary_name gws", got.Presets["gws"])
}
}
func TestSecureCLICheckBinaryFindsNpmPackageCliAlias(t *testing.T) {
runtimeDir := t.TempDir()
t.Setenv("RUNTIME_DIR", runtimeDir)