Fix -f validation ordering and make CLI tests hermetic - #28
Merged
Merged
Conversation
Move -f/positional conflict checks before gateway dial so users get exit 2 (usage error) instead of "No active gateway" when combining -f with a positional name. Affects stop, start, get, connect, exec, logs, and ssh-config commands. Rewrite ssh-config to use gatewayconfig.Resolve directly instead of resolveTokenSource — a print-only command should not require auth. Add TestMain for package-level env isolation (HOME, XDG_CONFIG_HOME, OPENSHELL_*) so tests never read the real user config. Fix os.Args mutation in tokenflow tests with save/restore via t.Cleanup. Add viper.Reset to all tests that call NewRootCommand(). Add direct unit tests for checkFileArgConflict and resolveNameFromFileOrArgs. Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
Address review feedback on PR #28: - TestMain: avoid exitAfterDefer by capturing m.Run() before os.Exit, check os.Setenv/os.Unsetenv errors, use Unsetenv instead of Setenv("") - Remove unused isolateEnv helper from sandbox_cmd_test.go - Fix goimports grouping in version_test.go (viper in third-party group) - ssh-config: only ignore NoActiveGateway/UnknownGateway from Resolve, surface real errors like malformed metadata.json - Bump golangci-lint-action v6 to v7 (v6 rejects golangci-lint v2) - Use go-version-file instead of hardcoded Go version in CI Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
Now that CI uses golangci-lint-action v7, the linter actually runs. Fix all pre-existing findings so CI can go green: - errcheck: acknowledge intentional fmt.Fprintf/Fprintln discards with _, _ = assignment in sandbox_create, sandbox_transfer, sandbox_provider - gofumpt: fix formatting in sandbox_create, types.go, sshserver_test - staticcheck S1039: remove unnecessary fmt.Sprintf in provider_cli_test - staticcheck ST1005: lowercase error strings in sandbox_provider - staticcheck SA1019: nolint directives for intentional deprecated field access in merge.go (backward-compat reads) - unused: remove dead notImplementedLeaf function from sandbox.go Created with assistance from Claude 🤖 <claude@anthropic.com> Signed-off-by: Christopher Collins <collins.christopher@gmail.com>
Collaborator
Author
|
CI status: verify, test, and lint steps all pass. The only failure is the |
No users exist yet, so no backward compatibility needed. The deprecated spec-level fields (approvalMode, keep, detach, forward) are removed in favor of the sessionOpts block. Strict YAML decode now rejects manifests using these fields. Also renames testmain_test.go to main_test.go per idiomatic Go convention. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
go.mod requires Go 1.26 but the builder image was pinned to 1.25, causing the image build CI step to fail. Also add -buildvcs=false since the Docker build context excludes .git and Go 1.26 errors on missing VCS status by default. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
clcollins
force-pushed
the
fix/issue-4-hermetic-tests-validation-ordering
branch
from
September 22, 2026 23:36
9144d54 to
006fb0c
Compare
Two review fixes: 1. Restore capitalized, newline-separated provider conflict error strings to match upstream verbatim (A.12). The ST1005 lint fix in 018c4cb lowercased and flattened them. Suppress with nolint:staticcheck. 2. Revert removal of deprecated spec-level fields (approvalMode, keep, detach, forward). The removal was scope creep — it belongs in a separate PR with proper schema-change callout, not a hermetic-tests fix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #4 — unit tests fail on a clean checkout because
-f/positional conflict validation runs afterthe gateway dial, and CLI tests read the real
$HOME.checkFileArgConflictand call it beforewithGatewayTargetinall subcommands (
stop,start,connect,get,exec,logs).ssh-configrewritten to usegatewayconfig.Resolvedirectly so it works without auth (print-only command).TestMaininmain_test.gofor package-level env isolation(
HOME,XDG_CONFIG_HOME,OPENSHELL_*vars). Per-test overrides viat.Setenv.viper.Reset()in every test that constructs a root command.TestCheckFileArgConflict(5 cases),TestResolveNameFromFileOrArgs(5 cases),conflict tests for all 6 subcommands.
golangci-lint-actionv6→v7 (required for golangci-lint v2), usego-version-file: go.modinstead of hardcoded version, bump Dockerfilego-toolset:1.25→1.26with
-buildvcs=falsefor Docker build context.S1039/ST1005/SA1019, unused). Provider conflict error strings restored to upstream-verbatim (A.12)
with
//nolint:staticchecksuppression.Non-blocking notes for future PRs
name resolution is early, but file-open errors surface late). Moving
loadManifestahead ofwithGatewayTargetwould remove this inconsistency.gatewayconfig.Resolvemasks metadata.json parse failures as "Unknown gateway" (pre-existing,upstream of ssh-config change). Worth noting in issue [Medium][Security] Token write-back path derived from unvalidated metadata.json name; -g + --gateway-endpoint sends a gateway's token anywhere #12.
Test plan
make test— all packages passmake verify— go mod tidy cleanTestConnect_FilePlusPositionalConflict,TestExec_FilePlusNameConflict,TestGet_FilePlusPositionalConflict,TestStop_FilePlusPositionalConflict,TestStart_FilePlusPositionalConflict,TestSSHConfig_FileFlag— all return usage errorwithout dialing
🤖 Generated with Claude Code