Lightweight Go CLI and embeddable client for NVIDIA OpenShell gateways, built for HyperShell integration with automatic OIDC token refresh and YAML-templated sandbox configuration processing (sandbox-as-code). Pure-Go reimplementation of the upstream Rust CLI — no shell-out to ssh, tar, git, or any external binary.
make build # build via goreleaser (snapshot)
make test # unit tests
make lint # golangci-lint
make test-race # tests with race detector
make coverage # coverage report
make test-coverage-threshold # enforce coverage minimums
make verify # pin + tidy + generate checks
make test-all # all of the aboveGo version is declared in go.mod (currently 1.26). CI runs outside GitHub Actions; run make test-all locally to reproduce what CI checks (verify, test, lint, image build).
cmd/openshellctl/ # main entrypoint
internal/cli/ # cobra command tree, CLI integration tests
pkg/api/v1alpha1/ # API types (Sandbox manifest schema)
pkg/auth/ # OIDC token resolution and refresh
pkg/gateway/ # gRPC gateway client (interface + impl)
pkg/gateway/mock/ # generated mock for gateway.Gateway
pkg/gatewayconfig/ # config file and env resolution
pkg/output/ # table/json/yaml output formatting
pkg/policyyaml/ # sandbox policy parsing and validation
pkg/sandbox/ # sandbox spec merging and construction
pkg/transfer/ # SSH file transfer (upload/download/connect/exec)
internal/version/ # build metadata (version, commit, pin)
docs/plans/ # design docs and implementation plan
hack/ # verification scripts, pins
hack/parity/ # upstream CLI parity tracking
build/ # Dockerfile
The codebase follows a main-driver + pure-functions pattern:
- Thin entry points (
internal/cli/) wire cobra commands to business logic. - Pure functions contain all decisions and transformations — they take values in and return values out with no side effects. Examples:
sanitizeTarName,validateSymlinkTarget,parseAndValidateSourcePath,planUpload,shellEscape. - Thin I/O shells call the pure functions and handle the actual SSH/gRPC/filesystem interaction. The shells are deliberately small so they don't need complex mocking.
- Interfaces at boundaries:
gateway.Gatewayis the primary seam —pkg/sandboxandpkg/gatewaytests use the generated mock. CLI tests inject the same mock through thecliDepscontext seam (internal/cli/deps.go).withDeps(ctx, cliDeps{Gateway: ..., Target: ..., TokenSource: ...})attaches test doubles to a context, anddepsFrom(ctx)reads them back.resolveAuth/dialOrInjected(authwiring.go) are the single decision point that checks for injected deps before doing a real token resolve/dial;withGatewayTarget(sandbox_cmd.go) composes those two rather than re-checkingcliDepsitself, so a command never sees one seam honor an injected dep that another ignores. This lets a test run a command end-to-end throughroot.Execute()against amock.MockGatewaywith no network. TherunCmdWithGateway(t, deps, args...)test helper (runcmd_gateway_test.go) builds the root command, injectsdepsviawithDeps, and executes it, mirroring the plainrunCmdhelper used for usage-only tests.fs.FSwith extension interfaces (LstatFS,ReadlinkFS) abstracts filesystem access for upload logic.
When adding new functionality, follow this pattern: extract every decision into a pure function, test it exhaustively, and keep the I/O shell minimal.
Follow test-driven development:
- Write tests first based on the desired behavior and edge cases.
- Implement the code to make the tests pass.
- Validate by running
make testandmake lint.
These apply to every change, not just new features:
- TDD, strictly. Write the failing test first, confirm it fails for the intended reason, implement the minimum to pass, then refactor. A commit whose tests were written after the code is rejected in review.
- Pure functions first, thin I/O shells second. Parsing, validation,
precedence, message formatting, and decision logic are pure functions;
I/O (filesystem, network, gRPC, terminal) lives in a shell deliberately
too small to need mocking. Inject
fs.FS,func() time.Time,getenv, and interfaces at boundaries — see "Code architecture" above for thecliDeps/gateway.Gatewayseam this codebase already uses everywhere. - Flat structure. A cobra
RunEcalls at most one orchestration function; that function calls pure functions. Two levels deep is the target, three is the ceiling and must be justified in the commit message. No new package-level mutable state or globals. - Hermetic tests, always. No network, no real filesystem outside
t.TempDir()/fstest.MapFS, no host env, no binaries. HTTP endpoints usehttptest.Serveronly; gRPC usesmock.MockGatewayorbufconn. - Typed errors. New errors are structs implementing
errorwithIs/Unwrap, matched witherrors.As, never by string. Exit-code mapping goes inexitCodeForonly. - Upstream strings are sacred. Where upstream prints a message,
reproduce it byte-for-byte except the binary name becomes
openshellctl. Deviations are documented under README "Differences from the upstream Rust CLI". - No shell-out, ever. Not to
openshell,ssh,curl,getent,python. DNS isnet.Resolver; HTTP isnet/http; the OIDC mint ispkg/auth. - Small changes. One commit = one behaviour change + its tests, typically under ~200 changed lines. Split a task further before coding if it grows beyond that.
Run through these dimensions before considering a change done — whether you're the author or reviewing someone else's diff:
Per-commit (one task's diff):
- Correctness — does the code do what the commit says; trace every branch; check error returns and nil pointers.
- Tests — written first; cover each input/output path and error; are they hermetic; are tables complete.
- Idiomatic Go —
gofumpt, naming, receiver choice,%werror wrapping, context first, no unnecessary exports, doc comments on exported identifiers. - Lint —
make lintandgo vetclean. - Intent — does the diff match what was actually asked for; flag scope creep and missing requirements.
- Security — secrets never logged or written to disk unless specified;
file perms
0600/0700; no path traversal via gateway names; TLS verification never implicitly disabled; tokens never printed in full. - Quality — readability, function length, the two-level depth rule, duplicated logic that should be a shared pure function, message wording consistency with upstream.
Per-PR (the whole branch diff):
- Acceptance — walk the feature's acceptance criteria one by one; cite the test or code that satisfies each; fail any unmet item.
- Parity — for any command mirroring an upstream
openshellcommand, diff flags/strings againsthack/parity/; update it when they drift. - Docs — README/docs updated for every new flag, command, env var, exit
code, and error hint; examples parse (
go test ./internal/cli/... -run TestDocsExamplesParse). - Regression —
make test-all,make test-coverage-threshold,make verifyall green; no coverage reduction for touched packages.
Coverage thresholds are available via make test-coverage-threshold (not yet enforced in CI — see the CI-hardening issue #10):
pkg/packages: minimum 85% (enforced, exits non-zero)internal/cli/: minimum 70% (aspirational, prints warning only)
These thresholds are a floor, not a target. Aim to cover every input/output path for a given function. Do not test imported libraries or standard-library behavior — test your code's logic.
All unit tests must be fully hermetic:
- No network calls: no HTTP, gRPC, or API requests. Mock all external services via interfaces (e.g.,
gateway.Gatewaymock). - No host filesystem access: use
t.TempDir()for any filesystem operations. Never read from or write to the real filesystem outside the temp directory. - No external tooling: do not shell out to
ssh,tar,git,sh, or any other binary. All such functionality is implemented in-process (archive/tar, golang.org/x/crypto/ssh, go-gitignore). - No host state: tests must not depend on environment variables, user config, running services, or network availability.
internal/cli'sTestMainunsets everyOPENSHELL_*andVAULT_*variable; a new env var read directly withos.Getenv(not via a persistent flag) must be added to the list inTestEnvScrub_CoversEveryEnvBackedInput.
The test SSH server runs in-process over buffered in-memory connections, authenticates with NoClientAuth, and implements remote commands in Go against t.TempDir() trees.
- Use table-driven tests with named subtests (
t.Run). - Use
t.Helper()in test helper functions. - Test both valid and invalid inputs — every error path a function can produce should have a corresponding test case.
- Place pure-function tests in
*_test.goalongside the code. Thepure_test.goconvention groups all pure-logic tests in a package;smoke_test.gocovers I/O integration.
Test: every pure function's input/output paths — valid inputs, boundary cases, and each distinct error condition your code produces.
Do not test: behavior of imported libraries (e.g., don't test that archive/tar correctly reads tar headers, or that os.OpenRoot rejects escapes — test that your code calls them correctly and handles their return values). Do not test Go standard library contracts.
- Go source follows
gofumptformatting (enforced by golangci-lint). - Prefer unexported functions unless the API surface requires export.
- No CGO — the binary is statically linked (
CGO_ENABLED=0). - Container engine is
podman(not docker) for local development; CI usesdocker.