Files
41536738c8 refactor(cd): hard-fork - rename CRD API group argoproj.io -> deploy.hanzo.ai (#1)
* feat(api): hard-fork CRD API group argoproj.io -> deploy.hanzo.ai

Hanzo CD hard-fork, phase 1.1. Single source of truth is
pkg/apis/application/register.go's Group constant (Application/AppProject/
ApplicationSet all derive their FullName from it); every other Go call-site
that hardcoded the literal group string is updated to match: the 3 generated
informer GVRs, the app-of-apps nested-Application detector in types.go, the
resource-tree Application-kind cache populator, the 3 NotFound error
constructors in server/application, and the applicationset-controller's
leader-election Lease name/ID (kept in lockstep across Go source + RBAC
resourceNames, or leader election would get RBAC-denied on startup).

CRD YAMLs (application/appproject/applicationset) and every RBAC apiGroups
rule that actually governs our 3 CRDs are repointed to deploy.hanzo.ai, across
both manifests/base/* (namespaced Roles) and manifests/cluster-rbac/* (cluster
scope). Two adjacent things that share the "argoproj.io" string but are NOT
ours are deliberately left untouched: gitops-engine's health-check dispatch
for Argo Workflows' `Workflow` kind, and argocd-server-clusterrole's second
apiGroups block granting read on Argo Workflows' `workflows` resource — both
belong to a separate, unrelated Argoproj-family project we are not forking.

Also untouched, per explicit scope: annotation/label keys (argocd.argoproj.io/*)
and finalizers (*.argoproj.io) that track already-applied live resources, and
argocd-cm.yaml's resource.customizations.ignoreResourceUpdates keys (a narrow
app-of-apps diffing nicety, not build- or RBAC-relevant).

CGO_ENABLED=0 go build ./... verified green.

* ci: wire canonical hanzo.yml + cicd.yml (Hanzo CD image build)

Phase 1.3. Follows the same one-way pattern every hanzo/lux/zoo repo uses:
hanzo.yml declares the image (root Dockerfile -> ghcr.io/hanzoai/deploy) and a
fast go-build sanity test (the multi-stage Dockerfile build is the slow, real
gate); cicd.yml is the ~10-line trigger shim importing hanzoai/ci's reusable
build workflow on the arc pool, secrets from KMS only.

No `deploy:` block yet, matching the hanzoai/cms build-only-first-cutover
pattern: this repo's own live hanzo-cd namespace runs the whole Hanzo fleet's
GitOps, so the prod image/CRD swap is a deliberate separate action (see the
[HELD] universe PR), never an automatic rollout on merge. Every PR/push still
builds and pushes an immutable ghcr.io/hanzoai/deploy:sha-<7>-amd64 image.

* feat(ui): rebrand Argo CD -> Hanzo CD (title, favicon, logo, sidebar)

Phase 1.2. User-facing "Argo CD"/"ArgoCD" text replaced with "Hanzo CD"
across the login page, help modal, settings screens, version-info panel,
sync-options warning, fullscreen-logs title, app.tsx page titles, and
index.html's <title>/noscript text (dropped the now-wrong upstream CLI
doc link rather than invent a hanzo.ai URL that doesn't exist).

Logo/favicon assets replaced with the canonical Hanzo mark (never
hand-drawn, copied from ~/work/hanzo/logo/dist): the two real usages of
Argo's logo collapse onto one Hanzo glyph (mono + white variants) at the
same 5 call sites (login icon + footer, login.scss $logoPath/
$logoNegativePath, sidebar text-logo), preserving the existing CSS
invert() filters so both the light login panel and dark sidebar still
render correctly. Old argologo.svg/argo_o.svg/argo.png deleted (no
longer referenced). favicon-{16x16,32x32}.png added at
ui/src/assets/favicon/ (index.html's links to that path were previously
dead - the directory didn't exist in this checkout). package.json name
argo-cd-ui -> hanzo-cd-ui.

Left alone, deliberately: the two Kubernetes resource-kind icon sets
under ui/src/assets/images/resources/ (unrelated to branding), and
upstream doc/project links (argoproj.io, argo-cd.readthedocs.io) since
we have no equivalent hanzo.ai docs to point to yet - except the login
footer logo's outbound link, which now points to hanzo.ai instead of
argoproj.io (a Hanzo-branded mark linking to the upstream project it
was forked from read as an obvious leftover).

* feat(module): rename Go module github.com/argoproj/argo-cd/v3 -> github.com/hanzoai/deploy

Phase 2. No version suffix on the new path (org policy: never publish our
own Go modules above v1.x.x / with a v2+ suffix) — this fork starts a fresh
v0/v1 module identity rather than carrying the v3 the upstream fork point
had reached.

Mechanical, symmetric rewrite: 704 .go files (import statements only; two
disjoint substitutions applied specific-first so the nested gitops-engine
module path never double-matches), plus go.mod (module line, the
gitops-engine require+replace pair, version reset to v0.0.0-... since a
suffix-less path can't carry a v3 semver), gitops-engine/go.mod, Makefile
(ldflags PACKAGE + 2 TEST_MODULE filters), .golangci.yaml, .goreleaser.yaml,
.mockery.yaml (+ gitops-engine's), Procfile, the codegen/proto generation
scripts (hack/generate-proto.sh, update-codegen.sh, update-openapi.sh), and
20 .proto files' go_package options. Also one OpenTelemetry tracer name
string in gitops-engine/pkg/sync/sync_context.go (a cosmestic label, not an
import, but worth keeping consistent).

CGO_ENABLED=0 go build ./... verified green for both the root module and
the nested gitops-engine module; go vet clean on both; go mod tidy run
(network available) to reconcile go.sum, dependency set unchanged.

Left alone, deliberately: doc-only mentions (docs/snyk/*.html scan reports,
gitops-engine/README.md), a comment-only reference in
.github/workflows/release.yaml, and one Renovate bot config line — none are
build- or codegen-load-bearing. Also left alone: comments citing upstream
GitHub issue URLs (github.com/argoproj/argo-cd/issues/NNNNN) and a handful
of test fixtures using "https://github.com/argoproj/argo-cd.git" as a
representative example repo URL — both are accurate historical/test-data
references, not stale self-references.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-29 18:27:58 -07:00

397 lines
12 KiB
Go

package commands
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
argocdclient "github.com/hanzoai/deploy/pkg/apiclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// setupPluginPath sets the PATH to the directory where plugins are stored for testing purpose
func setupPluginPath(t *testing.T) {
t.Helper()
wd, err := os.Getwd()
require.NoError(t, err)
testdataPath := filepath.Join(wd, "testdata")
t.Setenv("PATH", testdataPath)
}
// TestNormalCommandWithPlugin ensures that a standard ArgoCD command executes correctly
// even when a plugin with the same name exists in the PATH
func TestNormalCommandWithPlugin(t *testing.T) {
setupPluginPath(t)
_ = NewDefaultPluginHandler()
args := []string{"argocd", "version", "--short", "--client"}
buf := new(bytes.Buffer)
cmd := NewVersionCmd(&argocdclient.ClientOptions{}, nil)
cmd.SetArgs(args[1:])
cmd.SetOut(buf)
cmd.SilenceErrors = true
cmd.SilenceUsage = true
err := cmd.Execute()
require.NoError(t, err)
output := buf.String()
assert.Equal(t, "argocd: v99.99.99+unknown\n", output)
}
// TestPluginExecution verifies that a plugin found in the PATH executes successfully following the correct naming conventions
func TestPluginExecution(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
tests := []struct {
name string
args []string
expectedPluginErr string
}{
{
name: "'argocd-foo' binary exists in the PATH",
args: []string{"argocd", "foo"},
expectedPluginErr: "",
},
{
name: "'argocd-demo_plugin' binary exists in the PATH",
args: []string{"argocd", "demo_plugin"},
expectedPluginErr: "",
},
{
name: "'my-plugin' binary exists in the PATH",
args: []string{"argocd", "my-plugin"},
expectedPluginErr: "unknown command \"my-plugin\" for \"argocd\"",
},
{
name: "'argocd_my-plugin' binary exists in the PATH",
args: []string{"argocd", "my-plugin"},
expectedPluginErr: "unknown command \"my-plugin\" for \"argocd\"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd.SetArgs(tt.args[1:])
err := cmd.Execute()
require.Error(t, err)
// since the command is not a valid argocd command, check for plugin execution
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, tt.args)
if tt.expectedPluginErr == "" {
require.NoError(t, pluginErr)
} else {
assert.Equal(t, errMsg, fmt.Sprintf("Error: %s\nRun 'argocd --help' for usage.\n", tt.expectedPluginErr))
require.EqualError(t, pluginErr, tt.expectedPluginErr)
}
})
}
}
// TestNormalCommandError checks for an error when executing a normal ArgoCD command with invalid flags
func TestNormalCommandError(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
args := []string{"argocd", "version", "--non-existent-flag"}
cmd := NewVersionCmd(&argocdclient.ClientOptions{}, nil)
cmd.SetArgs(args[1:])
cmd.SilenceErrors = true
cmd.SilenceUsage = true
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, args)
require.Error(t, pluginErr)
assert.Equal(t, "Error: unknown flag: --non-existent-flag\n", errMsg)
require.EqualError(t, pluginErr, "unknown flag: --non-existent-flag")
}
// TestUnknownCommandNoPlugin tests the scenario when the command is neither a normal ArgoCD command
// nor exists as a plugin
func TestUnknownCommandNoPlugin(t *testing.T) {
pluginHandler := NewDefaultPluginHandler()
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
args := []string{"argocd", "non-existent"}
cmd.SetArgs(args[1:])
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, args)
require.Error(t, pluginErr)
assert.Equal(t, "Error: unknown command \"non-existent\" for \"argocd\"\nRun 'argocd --help' for usage.\n", errMsg)
require.EqualError(t, pluginErr, "unknown command \"non-existent\" for \"argocd\"")
}
// TestPluginNoExecutePermission verifies the behavior when a plugin doesn't have executable permissions
func TestPluginNoExecutePermission(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
args := []string{"argocd", "no-permission"}
cmd.SetArgs(args[1:])
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, args)
require.Error(t, pluginErr)
assert.Equal(t, "Error: unknown command \"no-permission\" for \"argocd\"\nRun 'argocd --help' for usage.\n", errMsg)
require.EqualError(t, pluginErr, "unknown command \"no-permission\" for \"argocd\"")
}
// TestPluginExecutionError checks for errors that occur during plugin execution
func TestPluginExecutionError(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
args := []string{"argocd", "error"}
cmd.SetArgs(args[1:])
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, args)
require.Error(t, pluginErr)
assert.Equal(t, "Error: exit status 1\n", errMsg)
require.EqualError(t, pluginErr, "exit status 1")
}
// TestPluginInRelativePathIgnored ensures that plugins in a relative path, even if the path is included in PATH,
// are ignored and not executed.
func TestPluginInRelativePathIgnored(t *testing.T) {
setupPluginPath(t)
relativePath := "./relative-plugins"
err := os.MkdirAll(relativePath, 0o755)
require.NoError(t, err)
defer os.RemoveAll(relativePath)
relativePluginPath := filepath.Join(relativePath, "argocd-ignore-plugin")
err = os.WriteFile(relativePluginPath, []byte("#!/bin/bash\necho 'This should not execute'\n"), 0o755)
require.NoError(t, err)
t.Setenv("PATH", os.Getenv("PATH")+string(os.PathListSeparator)+relativePath)
pluginHandler := NewDefaultPluginHandler()
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
args := []string{"argocd", "ignore-plugin"}
cmd.SetArgs(args[1:])
err = cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, args)
require.Error(t, pluginErr)
assert.Equal(t, "Error: unknown command \"ignore-plugin\" for \"argocd\"\nRun 'argocd --help' for usage.\n", errMsg)
require.EqualError(t, pluginErr, "unknown command \"ignore-plugin\" for \"argocd\"")
}
// TestPluginFlagParsing checks that the flags are parsed correctly by the plugin handler
func TestPluginFlagParsing(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
tests := []struct {
name string
args []string
shouldFail bool
expectedErrMsg string
}{
{
name: "Valid flags",
args: []string{"argocd", "test-plugin", "--flag1", "value1", "--flag2", "value2"},
shouldFail: false,
expectedErrMsg: "",
},
{
name: "Unknown flag",
args: []string{"argocd", "test-plugin", "--flag3", "invalid"},
shouldFail: true,
expectedErrMsg: "exit status 1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
cmd.SetArgs(tt.args[1:])
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, tt.args)
if tt.shouldFail {
require.Error(t, pluginErr)
assert.Equal(t, tt.expectedErrMsg, pluginErr.Error(), "Unexpected error message")
assert.Equal(t, errMsg, fmt.Sprintf("Error: %s\n", tt.expectedErrMsg))
} else {
assert.Empty(t, errMsg)
require.NoError(t, pluginErr, "Expected no error for valid flags")
}
})
}
}
// TestPluginStatusCode checks for a correct status code that a plugin binary would generate
func TestPluginStatusCode(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
tests := []struct {
name string
args []string
wantStatus int
throwErr bool
}{
{
name: "plugin generates the successful exit code",
args: []string{"argocd", "status-code-plugin", "--flag1", "value1"},
wantStatus: 0,
throwErr: false,
},
{
name: "plugin generates an error status code",
args: []string{"argocd", "status-code-plugin", "--flag3", "value3"},
wantStatus: 1,
throwErr: true,
},
{
name: "plugin generates a status code for an invalid command",
args: []string{"argocd", "status-code-plugin", "invalid"},
wantStatus: 127,
throwErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := NewCommand()
cmd.SilenceErrors = true
cmd.SilenceUsage = true
cmd.SetArgs(tt.args[1:])
err := cmd.Execute()
require.Error(t, err)
errMsg, pluginErr := pluginHandler.HandleCommandExecutionError(err, true, tt.args)
if !tt.throwErr {
require.NoError(t, pluginErr)
assert.Empty(t, errMsg)
} else {
require.Error(t, pluginErr)
var exitErr *exec.ExitError
if errors.As(pluginErr, &exitErr) {
assert.Equal(t, tt.wantStatus, exitErr.ExitCode(), "unexpected exit code")
} else {
t.Fatalf("expected an exit error, got: %v", pluginErr)
}
assert.Equal(t, errMsg, fmt.Sprintf("Error: exit status %d\n", tt.wantStatus))
}
})
}
}
// TestListAvailablePlugins tests the plugin discovery functionality for tab completion
func TestListAvailablePlugins(t *testing.T) {
setupPluginPath(t)
tests := []struct {
name string
validPrefix []string
expected []string
}{
{
name: "Standard argocd prefix finds plugins",
expected: []string{"demo_plugin", "error", "foo", "status-code-plugin", "test-plugin", "version"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pluginHandler := NewDefaultPluginHandler()
plugins := pluginHandler.ListAvailablePlugins()
assert.Equal(t, tt.expected, plugins)
})
}
}
// TestListAvailablePluginsEmptyPath tests plugin discovery when PATH is empty
func TestListAvailablePluginsEmptyPath(t *testing.T) {
// Set empty PATH
t.Setenv("PATH", "")
pluginHandler := NewDefaultPluginHandler()
plugins := pluginHandler.ListAvailablePlugins()
assert.Empty(t, plugins, "Should return empty list when PATH is empty")
}
// TestListAvailablePluginsNonExecutableFiles tests that non-executable files are ignored
func TestListAvailablePluginsNonExecutableFiles(t *testing.T) {
setupPluginPath(t)
pluginHandler := NewDefaultPluginHandler()
plugins := pluginHandler.ListAvailablePlugins()
// Should not include 'no-permission' since it's not executable
assert.NotContains(t, plugins, "no-permission")
}
// TestListAvailablePluginsDeduplication tests that duplicate plugins from different PATH dirs are handled
func TestListAvailablePluginsDeduplication(t *testing.T) {
// Create two temporary directories with the same plugin
dir1 := t.TempDir()
dir2 := t.TempDir()
// Create the same plugin in both directories
plugin1 := filepath.Join(dir1, "argocd-duplicate")
plugin2 := filepath.Join(dir2, "argocd-duplicate")
err := os.WriteFile(plugin1, []byte("#!/bin/bash\necho 'plugin1'\n"), 0o755)
require.NoError(t, err)
err = os.WriteFile(plugin2, []byte("#!/bin/bash\necho 'plugin2'\n"), 0o755)
require.NoError(t, err)
// Set PATH to include both directories
testPath := dir1 + string(os.PathListSeparator) + dir2
t.Setenv("PATH", testPath)
pluginHandler := NewDefaultPluginHandler()
plugins := pluginHandler.ListAvailablePlugins()
assert.Equal(t, []string{"duplicate"}, plugins)
}