Commit graph

2 commits

Author SHA1 Message Date
Andras Bacsai
652f523f5b test: improve Git ls-remote parsing tests with uppercase SHA and negative cases
Enhanced test coverage to match production code regex pattern and prevent
false positives by adding comprehensive edge case testing.

**Changes:**

1. **Updated regex pattern to match production code**:
   - Changed from `/([0-9a-f]{40})\s*\t/` to `/\b([0-9a-fA-F]{40})(?=\s*\t)/`
   - Now handles both uppercase and lowercase hex characters (A-F and a-f)
   - Uses word boundary `\b` for more precise matching
   - Uses lookahead `(?=\s*\t)` instead of capturing whitespace

2. **Added uppercase SHA test**:
   - Tests extraction of uppercase commit SHA (196D3DF7...)
   - Normalizes to lowercase using `strtolower()` for comparison
   - Reflects Git's case-insensitive SHA handling

3. **Added negative test cases**:
   - Tests output with no commit SHA present (error messages only)
   - Tests output with tab but invalid SHA format
   - Ensures `null` is returned to prevent false positives

**Test Coverage:**
- 8 total tests (up from 5)
- Covers all positive cases (lowercase, uppercase, warnings, whitespace)
- Covers negative cases (missing SHA, invalid format)
- Regex pattern now exactly matches production code in ApplicationDeploymentJob.php:1908

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 17:34:26 +02:00
Andras Bacsai
bf00405971 fix(git): handle Git redirects and improve URL parsing for tangled.sh and other Git hosts
Fixes deployment failures when Git repositories redirect (e.g., tangled.sh → tangled.org)
and improves security by adding proper shell escaping for repository URLs.

**Root Cause:**
Git redirect warnings can appear on the same line as ls-remote output with no newline:
`warning: redirecting to https://tangled.org/...196d3df...	refs/heads/master`

The previous parsing logic split by newlines and extracted text before tabs, which
included the entire warning message instead of just the 40-character commit SHA.

**Changes:**

1. **Fixed commit SHA extraction** (ApplicationDeploymentJob.php):
   - Changed from line-based parsing to regex pattern matching
   - Uses `/([0-9a-f]{40})\s*\t/` to find valid 40-char hex commit SHA before tab
   - Handles warnings on same line, separate lines, multiple warnings, and whitespace
   - Added comprehensive Ray debug logs for troubleshooting

2. **Added security fix** (Application.php):
   - Added `escapeshellarg()` for repository URLs in 'other' deployment type
   - Prevents shell injection and fixes parsing issues with special characters like `@`
   - Added Ray debug logs for deployment type tracking

3. **Comprehensive test coverage** (GitLsRemoteParsingTest.php):
   - Tests normal output without warnings
   - Tests redirect warning on separate line
   - Tests redirect warning on same line (actual tangled.sh format)
   - Tests multiple warning lines
   - Tests extra whitespace handling

**Resolves:**
- Linear issue COOLGH-53: Valid git URLs are rejected as being invalid
- GitHub issue #6568: tangled.sh deployments failing
- Handles Git redirects universally for all Git hosting services

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 11:55:17 +02:00