Skip to content

Fix -f validation ordering and make CLI tests hermetic - #28

Merged
clcollins merged 6 commits into
mainfrom
fix/issue-4-hermetic-tests-validation-ordering
Sep 22, 2026
Merged

clcollins merged 6 commits into
mainfrom
fix/issue-4-hermetic-tests-validation-ordering

Conversation

@clcollins

@clcollins clcollins commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4 — unit tests fail on a clean checkout because -f/positional conflict validation runs after
the gateway dial, and CLI tests read the real $HOME.

  • Validation ordering: Extract checkFileArgConflict and call it before withGatewayTarget in
    all subcommands (stop, start, connect, get, exec, logs). ssh-config rewritten to use
    gatewayconfig.Resolve directly so it works without auth (print-only command).
  • Hermetic tests: Add TestMain in main_test.go for package-level env isolation
    (HOME, XDG_CONFIG_HOME, OPENSHELL_* vars). Per-test overrides via t.Setenv.
    viper.Reset() in every test that constructs a root command.
  • New unit tests: TestCheckFileArgConflict (5 cases), TestResolveNameFromFileOrArgs (5 cases),
    conflict tests for all 6 subcommands.
  • CI fixes: Bump golangci-lint-action v6→v7 (required for golangci-lint v2), use
    go-version-file: go.mod instead of hardcoded version, bump Dockerfile go-toolset:1.25→1.26
    with -buildvcs=false for Docker build context.
  • Lint cleanup: Fix 22 pre-existing golangci-lint findings (errcheck, gofumpt, staticcheck
    S1039/ST1005/SA1019, unused). Provider conflict error strings restored to upstream-verbatim (A.12)
    with //nolint:staticcheck suppression.

Non-blocking notes for future PRs

Test plan

  • make test — all packages pass
  • make verify — go mod tidy clean
  • golangci-lint v2.12.2 — zero findings
  • CI green (verify, test, lint, image)
  • Conflict tests: TestConnect_FilePlusPositionalConflict, TestExec_FilePlusNameConflict,
    TestGet_FilePlusPositionalConflict, TestStop_FilePlusPositionalConflict,
    TestStart_FilePlusPositionalConflict, TestSSHConfig_FileFlag — all return usage error
    without dialing

🤖 Generated with Claude Code

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>
@clcollins

Copy link
Copy Markdown
Collaborator Author

CI status: verify, test, and lint steps all pass. The only failure is the image build step — build/Dockerfile uses ubi9/go-toolset:1.25 but go.mod requires Go 1.26. This is a pre-existing issue on main (run 35672466428 also fails). Tracking separately.

clcollins and others added 2 commits September 22, 2026 13:26
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
clcollins force-pushed the fix/issue-4-hermetic-tests-validation-ordering branch from 9144d54 to 006fb0c Compare September 22, 2026 23:36
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>
@clcollins
clcollins merged commit 02a0cc7 into main Sep 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Critical] Unit tests fail on a clean checkout: -f conflict validation runs after gateway dial, CLI tests read the real $HOME

1 participant