Skip to content

test: cover SSH-based commands - #240

Merged
pjcdawkins merged 6 commits into
mainfrom
cli-212-integration-tests-ssh-based-commands
Oct 15, 2026
Merged

pjcdawkins merged 6 commits into
mainfrom
cli-212-integration-tests-ssh-based-commands

Conversation

@pjcdawkins

Copy link
Copy Markdown
Contributor

Integration tests for commands that run over SSH, using the mock SSH server's ExecHandler with fake remote clients (shell scripts on the remote PATH that print their arguments).

  • ssh: --pipe, --all, and app and worker selection in a multi-app project
  • ssh-cert:load (--new, --new-key, --refresh-only, SSH config files) and ssh-cert:info (--no-refresh with missing, expired and mismatched certificates, expiry)
  • db:dump, db:sql, db:size
  • mount:size, and mount:upload/mount:download via rsync (skipped if rsync is missing)
  • service:redis-cli and service:mongo:*

Fix: ssh --all selected an app before listing all SSH URLs, so it failed in non-interactive mode in multi-app projects.

The mock auth server's SSH certificate key ID and lifetime are now configurable: the CLI only reuses a certificate whose key ID is the user ID and which expires in more than 2 minutes, which the previous fixed values never satisfied.

SFTP (scp) and port forwarding (tunnel:*, environment:xdebug) need mock SSH server changes, and will follow separately.

🤖 Generated with Claude Code

pjcdawkins and others added 4 commits October 15, 2026 13:41
`ssh --all` lists the SSH URLs of every app, but it selected a container
first, so it failed in non-interactive mode in a project with several
apps ("Specifying the --app or --worker is required").

Add integration tests for `ssh --pipe`, `--all`, and app and worker
selection, with helpers to serve the layout project over the mock SSH
server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Test certificate generation and reuse, --new, --new-key, --refresh-only,
the SSH configuration files, and ssh-cert:info --no-refresh with missing,
expired and mismatched certificates.

The mock auth server's certificate key ID and lifetime are now
configurable, as the CLI only reuses a certificate whose key ID is the
user ID and which expires in more than 2 minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the commands against the mock SSH server, with fake remote clients
(shell scripts on the remote PATH) which print their arguments:

- db:dump: default and --file names, --gzip, --stdout, --directory,
  table and schema options, MariaDB and PostgreSQL, and remote failures
- db:sql: queries, --raw, --schema, and piped input
- db:size: PostgreSQL and MariaDB usage
- mount:size: df and du output parsing
- mount:upload and mount:download with rsync: --exclude and --delete
- service:redis-cli and service:mongo:* commands

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Changes suggested — 🟡 1 warning · 🔵 1 minor point

🔍 Full review · 9 files reviewed

Verification
  • SelectorConfig::$selectRemoteContainer exists (default true), and Selector::getSelection skips container selection only when it is false, so non---all paths still go through getRemoteContainer().
  • nextSSHCertificate falls back to "test-key-id" and one minute when unset, so TestSSHCerts and the other existing tests still get the old certificate values.
  • remoteEnv appends a second PATH after os.Environ(). ExecHandler passes that to exec.Cmd.Env, whose dedup keeps the last value, so the fake binaries take precedence.
  • Certificate counts in TestSSHCertLoad go 1 (--refresh-only), 2 (--new with the wrong key ID), 3 (the regenerating info), then stay at 3 on reuse, then 4 (--new) and 5 (--new-key). Each count matches one issuing step.

The PR consists mostly of new integration tests in integration-tests/, which skip on Windows; the rsync tests also skip when rsync is missing. TestSSHAppSelection covers the PHP --all fix in a multi-app project. No test covers --all on an inactive or paused environment.

Review details
  • Commit: 6127436
  • Model: claude-opus-5-5

Review 1 of 10 for this pull request · View the full run

Comment thread legacy/src/Command/Environment/EnvironmentSshCommand.php
Comment thread integration-tests/ssh_test.go Outdated
Skipping the container selection for `ssh --all` also skipped the
deployment lookup that reported paused and inactive environments, so
the command printed the SSH URLs and exited successfully.

Also assert the app-not-found message in TestSSHAppSelection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upsun-dispatch

upsun-dispatch Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

📋 PR Summary

This PR adds integration tests for CLI commands that run over SSH: ssh, ssh-cert:*, db:*, mount:* and service:*. The tests use the mock SSH server's ExecHandler with fake remote clients. It also fixes ssh --all so it no longer selects an app first, which made it fail in non-interactive multi-app projects. The mock auth server's certificate key ID and lifetime can now be configured so the CLI's certificate reuse logic can be tested. The latest push changes the mount:size test's fake df script to use a quoted heredoc, with the app directory filled in on the Go side instead of expanded by the shell.

Changes
Layer / File(s) Summary
Integration tests
integration-tests/db_ssh_test.go Tests for db:dump, db:sql and db:size using fake remote clients.
integration-tests/mount_ssh_test.go Tests for mount:size and for rsync-based mount:upload/mount:download. The fake df output now uses a quoted heredoc, with APP_DIR replaced in Go.
integration-tests/service_ssh_test.go Tests for service:redis-cli and service:mongo:*.
integration-tests/ssh_cert_test.go Tests for ssh-cert:load options and for ssh-cert:info with missing, expired and mismatched certificates.
integration-tests/ssh_test.go Tests for ssh with --pipe, --all, and app/worker selection.
integration-tests/project_setup_test.go Shared helpers for setting up SSH-enabled projects and the remote environment.
Mock server
pkg/mockapi/auth_server.go Makes the SSH certificate key ID and lifetime configurable.
Bug fix
legacy/src/Command/Environment/EnvironmentSshCommand.php ssh --all now lists SSH URLs without selecting an app first.
Docs
CLAUDE.md Changes one line of the guidance.

@pjcdawkins
pjcdawkins disabled auto-merge October 15, 2026 13:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pjcdawkins
pjcdawkins merged commit 31901ff into main Oct 15, 2026
7 checks passed
@pjcdawkins
pjcdawkins deleted the cli-212-integration-tests-ssh-based-commands branch October 15, 2026 13:32
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.

1 participant