Skip to content

Fix: Remove SSH key file existence validation from config parsing#341

Merged
josecelano merged 2 commits into
mainfrom
340-validate-ssh-key-file-existence
Feb 12, 2026
Merged

Fix: Remove SSH key file existence validation from config parsing#341
josecelano merged 2 commits into
mainfrom
340-validate-ssh-key-file-existence

Conversation

@josecelano
Copy link
Copy Markdown
Member

Fixes #340

Problem

The validate command was incorrectly checking whether SSH key files exist on the filesystem during configuration validation. This caused valid configurations with absolute paths to be rejected if the SSH key files weren't present at validation time.

This was an architectural issue: file existence is a runtime concern that should be checked when SSH connections are actually attempted (during provision or configure), not during configuration parsing.

Solution

Removed all file existence checks from the TryFrom<SshCredentialsConfig> implementation:

  • SSH key paths are still validated to ensure they are absolute (not relative)
  • File existence is now only checked at runtime when SSH connections are needed
  • Error messages remain user-friendly with clear troubleshooting steps

Changes

Core Fix

  • src/application/command_handlers/create/config/ssh_credentials_config.rs: Removed file existence validation from TryFrom implementation
  • src/application/command_handlers/validate/handler.rs: Updated comments to clarify validation scope

UI Polish

  • src/presentation/controllers/validate/handler.rs: Fixed duplicate ✅ emoji in success message (Theme already adds checkmark automatically)

Tests

  • tests/e2e/validate_command.rs: Removed obsolete E2E test expecting file validation
  • Marked 5 unit tests as #[ignore] with explanatory comments (tests now check old behavior)

Testing

Bug fixed: validate now accepts absolute paths even if files don't exist
Path validation preserved: Relative paths still rejected with clear error
Runtime errors user-friendly: provision shows clear error when SSH keys missing:

❌ SSH public key file not found or unreadable: /nonexistent/key.pub

Possible solutions:
- Verify the file exists at the specified path
- Check file permissions (should be readable)
- Ensure the path in your configuration is correct

All tests passing: 425 passed, 54 ignored, 0 failed

Verification Commands

# Validate accepts absolute paths without file existence check
cargo run -- validate --env-file envs/bug-validation-valid-absolute-paths.json

# Relative paths still rejected
cargo run -- validate --env-file envs/bug-validation-invalid-relative-paths.json

# Runtime error when SSH keys actually needed
cargo run -- provision --env-name test-missing-keys

SSH key files are external resources that should be validated at runtime
when actually needed (during provision/configure), not during configuration
parsing or validation. This allows:

- Configs to be validated on machines without SSH keys
- SSH keys to be on different machines than where config is validated
- More flexible deployment workflows

Changes:
- Removed file existence checks from TryFrom<SshCredentialsConfig>
- Updated validate command to skip file existence validation
- Marked 5 obsolete tests as #[ignore] with explanatory comments
- SSH keys now validated when SSH connections are attempted (runtime)

Error handling remains user-friendly - provision command will fail with
clear message if SSH keys don't exist when actually needed.

Fixes #340
The success() method automatically adds a checkmark emoji via the theme,
so we shouldn't include it in the message text. This caused a duplicate
'✅ ✅' to appear in the validate command success message.

Output before: ✅ ✅ Configuration file 'x.json' is valid
Output after:  ✅ Configuration file 'x.json' is valid
@josecelano josecelano self-assigned this Feb 12, 2026
@josecelano
Copy link
Copy Markdown
Member Author

ACK 5c873cd

@josecelano josecelano merged commit bb95810 into main Feb 12, 2026
42 of 49 checks passed
@josecelano
Copy link
Copy Markdown
Member Author

ℹ️ Test Failure Notice

The dependency-installer test failure in the Testing workflow is a pre-existing issue unrelated to this PR. This PR only changes SSH validation logic and does not modify the dependency-installer package.

What's Failing

The test it_should_report_missing_dependencies_when_checking_all_in_fresh_ubuntu_container fails with a Docker BuildKit error:

ERROR: image "docker.io/library/dependency-installer-test:ubuntu-24.04": already exists

This is a Docker BuildKit cache/tag conflict issue in GitHub Actions CI environments, not a failure caused by the changes in this PR.

Tracking Issue

🔗 Issue #342: Fix Docker BuildKit "image already exists" error in dependency-installer tests

The fix will be implemented in a separate PR to maintain clean separation of concerns.

Why Merge This PR

  1. All SSH validation changes work correctly - the actual functionality this PR implements is fully tested and working
  2. Test failure is unrelated - the Docker test was already failing on main before this PR
  3. Issue is tracked separately - Fix Docker BuildKit "image already exists" error in dependency-installer tests #342 documents the problem with full details and implementation plan
  4. Clean PR scope - mixing unrelated fixes would make the git history unclear

This PR can be safely merged as the changes are complete, tested, and do not introduce any regressions.

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.

Validate Command Should Not Check SSH Key File Existence

1 participant