test(cli): unit tests for identity resolution, exit codes, and secret hygiene - #345
Merged
blockchain-maxis merged 5 commits intoSep 2, 2026
Merged
Conversation
Every CLI issue is blocked on this module existing. Add cli/ as a standalone Go module (go 1.25, no cgo) alongside the pnpm workspace, building a signet binary via cobra: cmd/signet/main.go is the entrypoint, internal/cmd holds the command tree, and internal/link, internal/keys, internal/spec are placeholder packages for the wallet-linking, key-management, and API-spec work that follows. signet --version carries a version and commit string injected via ldflags. signet --help and a bare `signet` invocation both print real usage text — cobra only renders the Usage: section when a command is Runnable() or has subcommands, so the root command needed an explicit RunE (falling through to cmd.Help()) to show it before any subcommand exists. golangci-lint is configured via cli/.golangci.yml, and a new CI job builds, vets, tests, and lints the module. Verified go build/go vet/go test all pass, and the binary cross-compiles with CGO_ENABLED=0 for linux/amd64 and darwin/arm64.
…entity Self-hosters and testnet users need to point the CLI at a deployment other than the default, and repeat runs shouldn't re-ask which identity to use. Every invocation needing --url and --source made self-hosted deployments second-class. Add internal/config: Load/Save a JSON file under os.UserConfigDir()/ signet (baseUrl, source), and Resolve combines flag > env (SIGNET_URL, baseUrl only) > config file > built-in default per field. Wire --url/ --source as persistent flags on the root command, resolved in PersistentPreRunE and attached to the command context via config.WithResolved/FromContext for subcommands to read once they exist. An explicit --source is saved back to the config file (RememberSource) so the next run without it picks the same identity back up. No config file is required for the default deployment. Document the precedence and file location in cli/README.md, and add SIGNET_URL to check-docs.mjs's ENV_ALLOW list — it's the cli/ module's own shell env, not part of the pnpm workspace's .env.
CI pipelines that link a deploy wallet need to parse the result, and
without structured output automation scrapes human-formatted text
that's free to change between releases.
Add internal/link.Link(handle, publicKey, network), validating the
handle (mirroring HANDLE_PATTERN from packages/types) and the public
key's charset/length, returning a Result{Handle, PublicKey, Network,
Status}. This doesn't yet perform a real on-chain claim or call a
deployment's HTTP API — internal/keys and internal/spec, which it
would need for that, are themselves still scaffolded — but the output
contract is real and stable now.
Wire it up as `signet link <handle> --public-key ... [--network]
[--json]`. Without --json, prints a human summary to stdout. With
--json, encodes exactly one JSON object to stdout via encoding/json
and nothing else; on a validation error, stdout stays empty in both
modes and the error reaches the user via stderr (main.go's existing
error handling), never stdout.
Covered by cmd/link_test.go (asserting --json's stdout decodes as the
expected JSON and is exactly one line, non-json output is not JSON,
and an invalid input leaves stdout empty) and link/link_test.go (the
validation logic in isolation).
… hygiene The CLI orchestrates the developer's deploy identity and ships as a prebuilt binary with no preview deploy or browser console — a regression surfaces on a user's machine, not in a PR check. - internal/keys.ResolvePublicKey(binary, source) resolves a named local identity to its public key by shelling out to `stellar keys address <source>`, rather than the CLI owning key storage or signing itself. Tested against a real faked `stellar` binary (internal/keys/testdata /fakestellar, compiled on first use — the standard Go helper-binary pattern), not just a swapped-out Go function, so the actual exec.Command wiring is exercised. - internal/exitcode + internal/cmd.ExitCode(err) map an error to a process exit code (0 ok, 1 generic, 2 invalid input) via an ExitCoder interface — link.ValidationError is the first implementer. exitcode lives in its own leaf package so internal/link's error type and internal/cmd's classifier can both depend on it without a cycle (cmd already imports link for the `link` command). - secrets_test.go asserts no secret-shaped value (a Stellar S... key) ever reaches stdout, stderr, or an error string, across --json and non-json runs — which caught a real issue while writing it: the invalid-public-key error echoed the raw value back, which would leak a real secret key a user passed to the wrong flag by mistake. Fixed in link.go to report the shape problem without repeating the value. - go test -race now runs in CI (needs cgo — a C toolchain, which ubuntu-latest has — unrelated to the production binary's CGO_ENABLED=0 requirement, since the test binary is never shipped). Not runnable in this environment for lack of a local C compiler. - Config precedence (flag > env > config > default) and --json stdout purity were already covered by blockchain-maxis#262/blockchain-maxis#264's tests; unchanged here. Scoping note: this does not cover "loopback single-use and timeout behaviour" or a "state mismatch" — no loopback HTTP server exists in the CLI's architecture today (neither blockchain-maxis#269 nor blockchain-maxis#263 needed one; the CLI-link challenge exchange is a plain two-request HTTP round trip, not a browser callback flow), so there is nothing yet to write that test against. Documented here rather than fabricated.
|
@Mamavee001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@Mamavee001 is attempting to deploy a commit to the blockchainmaxis-8449's projects Team on Vercel. A member of the Team first needs to authorize it. |
✅ Deploy Preview for stellar-signet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This was referenced Aug 30, 2026
…error Conflict resolution against the squashed blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342: - .github/workflows/ci.yml, README.md: main's. - cli/cmd/signet/main.go: this branch's exit-code mapping (the point of the PR). - cli/internal/cmd/link.go, cli/README.md: main's honest 'Validated … not yet submitted' wording rather than this branch's older 'Linked …'. - cli/internal/link/link.go: this branch's ValidationError and public-key redaction. The secret-hygiene test only inspected cobra's output buffers. The command tree runs with SilenceErrors, so a returned error never reaches those buffers — cmd/signet/main.go prints it to the process's real stderr. The test therefore could not fail no matter what an error message said, which is the half of the acceptance criterion ('stdout, stderr, or an error string') that most needed covering. Now asserts the error string too. That immediately caught a real leak. The public-key path was already careful not to echo its input, but the handle path was not: $ signet link SASAAEJC6P5U…UUEMCD --public-key GASAAEJC… invalid handle "SASAAEJC6P5U…UUEMCD": expected 1-32 lowercase letters… Reproduced with the built binary, not just in a test — a seed put in the wrong argument slot was read straight back into shell history and any CI log. Errors now pass the value through redactSecrets, so an ordinary typo is still echoed ('invalid handle "Bad Handle"') while a secret-shaped value becomes '[redacted: secret-shaped value]'. Verified: go build, go vet, gofmt -l, golangci-lint v2.13.2 (0 issues) and go test -race ./... all clean, plus the built binary — redaction confirmed, typo feedback intact, and exit codes 2 for invalid input / 0 for success.
blockchain-maxis
added a commit
to Mamavee001/signet
that referenced
this pull request
Sep 2, 2026
Conflict resolution against the squashed blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342: - .github/workflows/ci.yml, README.md: main's. - cli/cmd/signet/main.go, cli/internal/link/link.go, cli/internal/cmd/link.go: this branch's, which carry blockchain-maxis#345's exit-code mapping that this PR is stacked on. Taking main's first silently dropped it — caught because the shim then forwarded exit 1 instead of 2 in the end-to-end check below. - cli/README.md: this branch's, with the stale 'Linked …' example updated to main's honest 'Validated … not yet submitted' wording. - scripts/check-docs.mjs: keep the CLI_RELEASE_ENABLED / NPM_TOKEN allowlist entries (GitHub repo variable and Actions secret, not app env). Reapplied the handle-error secret redaction from blockchain-maxis#345, which this branch predates. Verified the release path end to end rather than by reading it — built a linux/amd64 binary with the workflow's own ldflags, staged it through scripts/release/stage-platform-package.mjs, pinned with pin-shim-version.mjs, laid the two packages out as npm would under node_modules/@signet, and ran the shim: --version -> signet version 9.9.9-test (commit deadbeef) link --json -> one JSON object, nothing else invalid handle, $? -> 2 (the shim forwards the binary's real exit code) Then reverted the staged binary and the 9.9.9-test version pins. Publishing stays inert on merge: release-cli.yml triggers only on a cli-v* tag (none exist) and the npm publish step is additionally gated on vars.CLI_RELEASE_ENABLED, which is not set. go build/vet/test -race, gofmt, golangci-lint v2.13.2 (0 issues) and check-docs all clean.
blockchain-maxis
merged commit Sep 2, 2026
593ce59
into
blockchain-maxis:main
10 of 11 checks passed
blockchain-maxis
added a commit
to Mamavee001/signet
that referenced
this pull request
Sep 2, 2026
secrets_test.go: take main's, which carries the strengthened assertion on the error string (the branch's copy predates it).
blockchain-maxis
added a commit
to Otfrugger/signet
that referenced
this pull request
Sep 2, 2026
This PR's only real change is the cross-compile smoke build; everything else in the diff is cherry-picked blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342/blockchain-maxis#345, all now squashed onto main. Took main's version of every one of those files. ci.yml keeps all three improvements rather than either side: - `go test -race ./...` from this branch (issue blockchain-maxis#252 asks for -race; main still had a plain `go test`), - the golangci-lint action v8 + pinned v2.13.2 from main, - the four-target cross-compile smoke build this PR adds. Noted in the comment that the target set matches what release-cli.yml publishes, so the two cannot silently diverge. Verified locally: all four targets build with CGO_ENABLED=0, and go test -race ./... is clean across all 7 packages.
blockchain-maxis
added a commit
to Otfrugger/signet
that referenced
this pull request
Sep 2, 2026
Everything except cli/internal/browser/ and its docs was a cherry-pick of blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342/blockchain-maxis#345/blockchain-maxis#356/blockchain-maxis#357/blockchain-maxis#358, all now on main — took main's for all of those. scripts/check-docs.mjs keeps all three allowlist entries rather than either side's pair (WAYLAND_DISPLAY from this branch, CLI_RELEASE_ENABLED and NPM_TOKEN from blockchain-maxis#346). Verified the fallback behaves as issue blockchain-maxis#257 requires, by driving OpenOrPrint with DISPLAY and WAYLAND_DISPLAY unset: headless, browser allowed -> prints 'Open this URL to continue: <url>', returns nil --no-browser -> same so the opener's failure is absorbed rather than propagated, and both paths reach the developer at the same URL. Left unwired deliberately, unlike blockchain-maxis#357's CheckStellarCLI: there is no call site to attach it to yet — `signet link` performs no approval flow (that lands with the loopback server and the pairing endpoints), so wiring it now would mean inventing the flow rather than connecting to one. Both the package doc and cli/README say so plainly. go build/vet, gofmt, golangci-lint v2.13.2 (0 issues), go test -race ./... and check-docs all clean.
blockchain-maxis
added a commit
to manchesternews98-jpg/signet
that referenced
this pull request
Sep 2, 2026
This branch introduced its own internal/keys design (a Runner interface plus context-taking List/PublicKey/Resolve) while blockchain-maxis#345/blockchain-maxis#357/blockchain-maxis#358 built a different one on main — a package-level `run` seam, CheckStellarCLI version guard, exitcode sentinels, and secret redaction. Rather than pick a side and lose work, kept main's package and ported this PR's new capability onto it: - keys.List(binary) shells `stellar keys ls` through the same `run` seam and the same CheckStellarCLI guard, so a missing or too-old stellar is reported identically here. - keys.Resolve(binary, explicit, prompt) picks --source, else the sole identity, else the prompt; a nil prompt (CI, --json) yields ErrAmbiguousIdentity instead of hanging on stdin. Both new sentinels wrap exitcode.ErrNoIdentity, so they map to the documented exit code 4. - identity.go keeps its command and interactive selector, rewired to keys.Resolve/keys.ResolvePublicKey and registered on main's root (which carries blockchain-maxis#336's config resolution). - execrunner_test.go is dropped with the ExecRunner type it tested; it also declared a second TestMain, which broke the package build. - Ported six tests onto main's fixtures: List returns every identity, an explicit source never shells out, the sole identity is auto-picked, no identities and an ambiguous set each report their sentinel, and the prompt is offered the full list. Extended the fake stellar to answer `keys ls` (via FAKESTELLAR_IDENTITIES) and to resolve a second identity. golangci-lint flagged four unchecked writes in identity.go (errcheck); now checked, matching how link.go already returns its write error. Verified against the fake binary end to end: one identity resolves silently, several with no tty refuses rather than hanging, none reports the actionable message, and piping a selection picks that identity and prints its public key. Also grepped the whole cli/ tree — no `keys show`, no `--sign-with-key`, no secret parsing anywhere, which is what issue blockchain-maxis#253 is actually about. All 6 Go packages pass go test -race; gofmt, golangci-lint v2.13.2 (0 issues) and check-docs clean.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #290
Stacked on #335, #336, and #342 (the CLI scaffold, config file, and
link/--jsonwork) — this branch cherry-picks all three (authorship preserved) since #290 asks to test the CLI as it stands today. The commit to review here is the top one (26c5ea6).Summary
The CLI orchestrates the developer's deploy identity, and ships as a prebuilt binary with no preview deploy or browser console — a regression surfaces on a user's machine, not in a PR check.
Changes
cli/internal/keys/keys.go(new):ResolvePublicKey(binary, source string) (string, error)resolves a named local identity to its public key by shelling out tostellar keys address <source>— the CLI doesn't own key storage or signing itself (see the package doc for why). Tested inkeys_test.goagainst a real fakedstellarbinary, compiled on first use frominternal/keys/testdata/fakestellar(the standard Go "helper binary" pattern, e.g. used throughoutos/exec's own tests) — not a swapped-out Go function, so the actualexec.Commandwiring, argument order, stdout/stderr capture, and exit-code handling are all exercised for real. Covers: successful resolution, an unknown identity, malformed output from the CLI, and a missing binary.cli/internal/exitcode(new) +cli/internal/cmd/exitcode.go(new):ExitCode(err) intmaps an error to a process exit code —0ok,1generic,2invalid input — via anExitCoderinterface;link.ValidationErroris the first implementer.exitcodeis its own leaf package specifically sointernal/link's error type andinternal/cmd's classifier can both depend on the codes without a cycle (cmdalready importslinkfor thelinkcommand).main.gonow callsos.Exit(cmd.ExitCode(err))instead of a hardcoded1.cli/internal/cmd/secrets_test.go(new): asserts no secret-shaped value (a StellarS...seed) ever reaches stdout, stderr, or an error string, across--jsonand non---jsonruns, and acrosslink,--source, and--url. This caught a real issue while writing it: the invalid-public-key error inlink.goechoed the raw value straight back, which would leak a real secret key if a user passed one to the wrong flag by mistake. Fixed in the same commit — the error now reports the shape problem without repeating the value..github/workflows/ci.yml: theclijob's test step is nowgo test -race ./....-raceneeds cgo (a C toolchain) to build the instrumented test binary — unrelated to the production binary'sCGO_ENABLED=0cross-compile requirement from Scaffold thecli/Go module — the @signet/cli binary #251, since the test binary is never distributed.ubuntu-latestships a C compiler; I don't have one in my local environment, so I couldn't run-racehere myself — it's verified in CI instead (plaingo test ./...passes locally, all 32 tests).Scoping note — please read before assuming this is exhaustive
This does not cover two things #290's acceptance criteria names: "loopback single-use and timeout behaviour" and "state mismatch rejection." Neither exists in the CLI's architecture today — the CLI-link challenge exchange built in #343 is a plain two-request HTTP round trip (fetch a challenge, sign it, submit it), not a browser-callback/loopback-server flow, and neither #269 nor #263 needed one. I'd rather flag that gap explicitly than fabricate tests against a mechanism that doesn't exist. If a loopback flow is intended for a future
linkimplementation (e.g. to let a browser-extension wallet sign, rather than a headlessstellar-CLI-managed identity), that's a separate, unscoped design question worth its own issue.Config precedence (flag > env > config > default) and
--jsonstdout purity were already covered by #262's and #264's tests and are unchanged here.Verification
go build ./.../go vet ./.../go test ./...— all pass (32/32 tests: +9 new acrossinternal/keys,internal/cmd).golangci-lint run ./...— 0 issues.0on success/--help,2on an invalid public key (with the fixed, non-echoing error message).CGO_ENABLED=0forlinux/amd64— still clean.