BUG-HUNT: [Boundary] Git version parsing fails with localized or non-standard git output formats #7167

Open
opened 2026-04-10 08:25:01 +00:00 by HAL9000 · 2 comments
Owner

Background

During Bug Hunt Cycle 2 Batch 3, Worker 22 identified a boundary-condition bug in the platform detection utilities within the CLI system commands module (src/cleveragents/cli/commands/system.py). The _check_git() function uses a naive string replacement to extract the Git version number, which silently fails on non-English systems or alternative Git distributions.

Current Behavior (Bug)

The function at lines ~282–295 of src/cleveragents/cli/commands/system.py parses the Git version string using:

result.stdout.strip().replace("git version ", "")

This approach assumes the output always begins with the English prefix "git version ". It fails silently in the following cases:

Input Actual Output Expected Output
"git versión 2.34.1" (Spanish locale) "git versión 2.34.1" (unchanged) "2.34.1"
"Git for Windows 2.34.1" "Git for Windows 2.34.1" (unchanged) "2.34.1"
"" (empty output) "" graceful fallback / "unknown"
"git version" (no version number) "git version" (unchanged) graceful fallback / "unknown"

Affected file: src/cleveragents/cli/commands/system.py
Affected function: _check_git()
Affected lines: ~282–295

Expected Behavior

Git version detection should robustly handle:

  • Localized Git output (any language/locale)
  • Alternative Git distributions (e.g. Git for Windows, Xcode Git)
  • Empty or malformed output
  • Missing version numbers

A regex-based approach that extracts the semantic version number (e.g. \d+\.\d+(?:\.\d+)*) from the output string, regardless of prefix, is the recommended fix.

Reproduction Steps

  1. Set a Spanish locale: LANG=es_ES.UTF-8 git --version"git versión 2.34.1"
  2. Run agents info or agents diagnostics on such a system
  3. Observe that the reported Git version is the full raw string rather than "2.34.1"

Impact

  • Scope: Git version detection in agents info / agents diagnostics / agents version output
  • Likelihood: Medium — affects international deployments and systems with non-standard Git installations (Git for Windows, Xcode bundled Git, Homebrew Git on macOS with locale set)
  • Severity: Medium — incorrect version display; no data loss or security risk, but degrades diagnostic reliability

Suggested Fix

  1. Replace the str.replace() call with a regex extraction:
    import re
    match = re.search(r"(\d+\.\d+(?:\.\d+)*)", result.stdout)
    version = match.group(1) if match else "unknown"
    
  2. Handle multiple known Git output patterns (English, localized, Git for Windows).
  3. Provide a graceful fallback ("unknown") when version parsing fails.
  4. Consider using git --version --no-localize if available (Git ≥ 2.35).
  5. Add BDD scenarios covering localized and non-standard Git output formats.

Test Evidence

  • Input "git versión 2.34.1" → produces "git versión 2.34.1" instead of "2.34.1"
  • Input "Git for Windows 2.34.1" → produces "Git for Windows 2.34.1" instead of "2.34.1"

Metadata

  • Branch: bugfix/cli/git-version-parsing-localized-output
  • Commit Message: fix(cli): use regex extraction for git version parsing to handle localized output
  • Milestone: Backlog (no milestone — see backlog note below)
  • Parent Epic: Orphan — no matching Bug Hunt Cycle 2 Epic found; requires manual linking

Subtasks

  • Replace str.replace("git version ", "") with a regex-based version extraction in _check_git()
  • Add graceful fallback to "unknown" when no version number is found in the output
  • Handle edge cases: empty stdout, stdout with no numeric version, git --version --no-localize availability check
  • Add BDD feature scenarios in features/ covering localized Git output, Git for Windows format, and empty output
  • Verify all nox stages pass (lint, typecheck, unit_tests, integration_tests, coverage)

Definition of Done

  • _check_git() correctly extracts the version number from English, Spanish, and Git-for-Windows output formats
  • _check_git() returns "unknown" (or equivalent sentinel) gracefully when version cannot be parsed
  • No str.replace("git version ", "") pattern remains in _check_git()
  • BDD scenarios cover all identified failure modes (localized prefix, alternative distribution, empty output)
  • No # type: ignore or bare except: introduced
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone Bug Hunt Cycle 2 Batch 3. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunt Cycle 2 Batch 3 | Agent: new-issue-creator

## Background During Bug Hunt Cycle 2 Batch 3, Worker 22 identified a boundary-condition bug in the platform detection utilities within the CLI system commands module (`src/cleveragents/cli/commands/system.py`). The `_check_git()` function uses a naive string replacement to extract the Git version number, which silently fails on non-English systems or alternative Git distributions. ## Current Behavior (Bug) The function at lines ~282–295 of `src/cleveragents/cli/commands/system.py` parses the Git version string using: ```python result.stdout.strip().replace("git version ", "") ``` This approach assumes the output always begins with the English prefix `"git version "`. It fails silently in the following cases: | Input | Actual Output | Expected Output | |---|---|---| | `"git versión 2.34.1"` (Spanish locale) | `"git versión 2.34.1"` (unchanged) | `"2.34.1"` | | `"Git for Windows 2.34.1"` | `"Git for Windows 2.34.1"` (unchanged) | `"2.34.1"` | | `""` (empty output) | `""` | graceful fallback / `"unknown"` | | `"git version"` (no version number) | `"git version"` (unchanged) | graceful fallback / `"unknown"` | **Affected file:** `src/cleveragents/cli/commands/system.py` **Affected function:** `_check_git()` **Affected lines:** ~282–295 ## Expected Behavior Git version detection should robustly handle: - Localized Git output (any language/locale) - Alternative Git distributions (e.g. Git for Windows, Xcode Git) - Empty or malformed output - Missing version numbers A regex-based approach that extracts the semantic version number (e.g. `\d+\.\d+(?:\.\d+)*`) from the output string, regardless of prefix, is the recommended fix. ## Reproduction Steps 1. Set a Spanish locale: `LANG=es_ES.UTF-8 git --version` → `"git versión 2.34.1"` 2. Run `agents info` or `agents diagnostics` on such a system 3. Observe that the reported Git version is the full raw string rather than `"2.34.1"` ## Impact - **Scope:** Git version detection in `agents info` / `agents diagnostics` / `agents version` output - **Likelihood:** Medium — affects international deployments and systems with non-standard Git installations (Git for Windows, Xcode bundled Git, Homebrew Git on macOS with locale set) - **Severity:** Medium — incorrect version display; no data loss or security risk, but degrades diagnostic reliability ## Suggested Fix 1. Replace the `str.replace()` call with a regex extraction: ```python import re match = re.search(r"(\d+\.\d+(?:\.\d+)*)", result.stdout) version = match.group(1) if match else "unknown" ``` 2. Handle multiple known Git output patterns (English, localized, Git for Windows). 3. Provide a graceful fallback (`"unknown"`) when version parsing fails. 4. Consider using `git --version --no-localize` if available (Git ≥ 2.35). 5. Add BDD scenarios covering localized and non-standard Git output formats. ## Test Evidence - Input `"git versión 2.34.1"` → produces `"git versión 2.34.1"` instead of `"2.34.1"` - Input `"Git for Windows 2.34.1"` → produces `"Git for Windows 2.34.1"` instead of `"2.34.1"` --- ## Metadata - **Branch**: `bugfix/cli/git-version-parsing-localized-output` - **Commit Message**: `fix(cli): use regex extraction for git version parsing to handle localized output` - **Milestone**: Backlog (no milestone — see backlog note below) - **Parent Epic**: _Orphan — no matching Bug Hunt Cycle 2 Epic found; requires manual linking_ ## Subtasks - [ ] Replace `str.replace("git version ", "")` with a regex-based version extraction in `_check_git()` - [ ] Add graceful fallback to `"unknown"` when no version number is found in the output - [ ] Handle edge cases: empty stdout, stdout with no numeric version, `git --version --no-localize` availability check - [ ] Add BDD feature scenarios in `features/` covering localized Git output, Git for Windows format, and empty output - [ ] Verify all nox stages pass (lint, typecheck, unit_tests, integration_tests, coverage) ## Definition of Done - [ ] `_check_git()` correctly extracts the version number from English, Spanish, and Git-for-Windows output formats - [ ] `_check_git()` returns `"unknown"` (or equivalent sentinel) gracefully when version cannot be parsed - [ ] No `str.replace("git version ", "")` pattern remains in `_check_git()` - [ ] BDD scenarios cover all identified failure modes (localized prefix, alternative distribution, empty output) - [ ] No `# type: ignore` or bare `except:` introduced - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone Bug Hunt Cycle 2 Batch 3. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunt Cycle 2 Batch 3 | Agent: new-issue-creator
Author
Owner

⚠️ Orphan Issue — Manual Linking Required

This issue was created during Bug Hunt Cycle 2 Batch 3 (Worker 22) and no matching parent Epic was found in the repository for platform detection / CLI system utilities bugs.

A maintainer must manually link this issue to the appropriate parent Epic using Forgejo's dependency system:

  • The child issue (this issue, #7167) should block the parent Epic
  • The parent Epic should depend on this issue

Related issue with the same file/module scope: #7152 (also orphaned, same discovery cycle).


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunt Cycle 2 Batch 3 | Agent: new-issue-creator

⚠️ **Orphan Issue — Manual Linking Required** This issue was created during Bug Hunt Cycle 2 Batch 3 (Worker 22) and no matching parent Epic was found in the repository for platform detection / CLI system utilities bugs. A maintainer must manually link this issue to the appropriate parent Epic using Forgejo's dependency system: - The **child issue** (this issue, #7167) should **block** the parent Epic - The **parent Epic** should **depend on** this issue Related issue with the same file/module scope: #7152 (also orphaned, same discovery cycle). --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunt Cycle 2 Batch 3 | Agent: new-issue-creator
Author
Owner

Verified — Critical bug: git version parsing fails with non-standard output. MoSCoW: Must-have. Priority: Critical.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Critical bug: git version parsing fails with non-standard output. MoSCoW: Must-have. Priority: Critical. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#7167
No description provided.