Skip to content

fix(config): preserve provider while stripping CRLF - #110

Open
eljoe182 wants to merge 5 commits into
Gentleman-Programming:mainfrom
eljoe182:fix/config-provider-crlf-parsing
Open

fix(config): preserve provider while stripping CRLF#110
eljoe182 wants to merge 5 commits into
Gentleman-Programming:mainfrom
eljoe182:fix/config-provider-crlf-parsing

Conversation

@eljoe182

@eljoe182 eljoe182 commented Jul 9, 2026

Copy link
Copy Markdown

Linked Issue

Closes #109

PR Type

  • type:bug — Bug fix
  • type:feature — New feature or enhancement
  • type:docs — Documentation changes only
  • type:refactor — Code refactor (no behavior change)
  • type:chore — Maintenance (deps, CI, tooling)
  • type:breaking-change — Breaking change (add ! to commit type)

Summary

Fixes .gga config loading so PROVIDER remains configured when project config files use CRLF line endings.

The previous sanitization path could fail to preserve the PROVIDER assignment on macOS Bash, causing gga run to report No provider configured for valid providers such as lmstudio, lmstudio:qwen/qwen3.5-9b, and minimax:MiniMax-M3.

This also improves LM Studio request failure diagnostics so long-running API failures report the endpoint, curl exit code, HTTP status, and response body instead of the generic Failed to connect message.

Changes

File Change
bin/gga Replaces process-substitution config sourcing with a sanitized temporary config file, and strips CR characters using tr -d '\015'.
lib/providers.sh Reports detailed LM Studio request failures with curl exit code, HTTP status, endpoint, and response body.
spec/integration/commands_spec.sh Adds parameterized regression coverage for preserving the PROVIDER key and exact value with CRLF config files.
spec/unit/providers_spec.sh Adds LM Studio failure diagnostics coverage for network and HTTP error responses.

Test Plan

  • make lint (ShellCheck) passes locally
  • make test passes locally (all unit tests)
  • shellspec spec/unit/providers_spec.sh passes
  • shellspec spec/integration/commands_spec.sh passes
  • Manual testing: reproduced .gga config loading with CRLF and validated provider values lmstudio, lmstudio:qwen/qwen3.5-9b, and minimax:MiniMax-M3
  • Manual testing: ran a small gga run --no-cache against LM Studio at http://100.107.225.97:1234/v1 and received STATUS: PASSED

Full make test was run locally, but it currently fails on existing OpenCode-related tests in untouched pre-existing provider behavior with opencode_args[@]: unbound variable. The focused suites for this PR pass.

Automated Checks

The following checks run automatically on every PR:

Check Validates
Check Issue Reference PR body contains Closes/Fixes/Resolves #N
Check Issue Has status:approved Linked issue was approved by a maintainer
Check PR Has type:* Label PR has exactly one type:* label
Lint ShellCheck passes on bin/gga and lib/*.sh
Unit Tests shellspec spec/unit passes
Integration Tests shellspec spec/integration/commands_spec.sh passes

Contributor Checklist

  • I have linked the issue above with Closes #N
  • The linked issue has status:approved
  • I have added a type:* label to this PR
  • make lint passes (ShellCheck)
  • make test passes (all unit tests)
  • Integration tests pass
  • New functions/commands have tests in spec/
  • I followed conventional commits (feat:, fix:, docs:, etc.)
  • I have NOT added "Co-Authored-By" or AI attribution to commits
  • Breaking changes are documented and use ! in the commit type (feat!:, fix!:)

Notes for Reviewers

Issue #109 still needs the status:approved label from a maintainer before this PR can pass the repository issue-first validation.

The LM Studio diagnostics change intentionally does not change provider execution semantics. It only exposes the curl/HTTP details needed to distinguish network failures from LM Studio API failures.

Summary by CodeRabbit

  • Bug Fixes
    • Improved config loading by stripping CR characters and safely sourcing sanitized configs from temporary files (with reliable cleanup).
    • Enhanced LM Studio request failures to report the endpoint, curl exit code, HTTP status (when available), and any response body.
  • Tests
    • Extended CRLF coverage for provider parsing with new parameterized integration tests and removed a redundant single-case test.
    • Added failure-mode integration tests for temporary config creation and sanitization, and expanded unit assertions for LM Studio curl error reporting.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates config loading to sanitize CRLF content through temporary files before sourcing. It also adds structured LM Studio curl failure reporting with HTTP status and response-body capture, plus integration and unit test coverage.

Changes

Config loading and LM Studio failure reporting

Layer / File(s) Summary
CRLF-safe config sourcing
bin/gga
Config sanitization strips CR characters, temporary sanitized files are sourced and removed, and both global and project configs use the new helper.
CRLF parsing and config failure tests
spec/integration/commands_spec.sh
Tests cover multiple CRLF provider values and failures from mktemp and sanitization commands.
Centralized LM Studio failure reporting
lib/providers.sh
Shared curl handling captures HTTP status and response bodies, then reports structured failure details.
LM Studio API integration and tests
lib/providers.sh, spec/unit/providers_spec.sh
Both execution paths use the shared helper, with tests covering curl connection failures and HTTP error responses.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant load_config
  participant source_config_file
  participant sanitize_config_file
  participant TempFile
  load_config->>source_config_file: source global or project config
  source_config_file->>sanitize_config_file: sanitize config contents
  sanitize_config_file->>TempFile: write sanitized config
  source_config_file->>TempFile: source and remove temporary file
  source_config_file-->>load_config: return success or failure
Loading
sequenceDiagram
  participant execute_lmstudio_api
  participant call_lmstudio_curl
  participant curl
  participant report_lmstudio_request_failure
  execute_lmstudio_api->>call_lmstudio_curl: send endpoint and JSON payload
  call_lmstudio_curl->>curl: request with HTTP status marker
  curl-->>call_lmstudio_curl: response body and HTTP status
  call_lmstudio_curl->>report_lmstudio_request_failure: report non-zero curl result
  report_lmstudio_request_failure-->>execute_lmstudio_api: structured failure output
Loading

Possibly related PRs

Suggested labels: type:bug

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The LM Studio request-failure diagnostics and tests are unrelated to fixing CRLF provider loading in .gga config files. Move the LM Studio error-reporting changes and tests to a separate PR focused on provider loading.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The config loader change preserves PROVIDER values from CRLF .gga files and adds matching regression coverage for the linked issue.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preserving provider config while handling CRLF line endings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bin/gga`:
- Around line 276-291: The source_config_file helper currently assumes mktemp
always succeeds, so an empty sanitized_config can lead to confusing
redirect/source failures. Update source_config_file to check the mktemp result
before calling sanitize_config_file or source, and if it fails, cleanly return 1
from source_config_file without attempting to use the temp file.

In `@lib/providers.sh`:
- Around line 655-674: The curl call, __GGA_HTTP_STATUS parsing, and error
handling in the LM Studio request path are duplicated in both request branches.
Extract that logic into a shared helper such as call_lmstudio_curl used by the
existing request function and execute_lmstudio_api_fallback, with the helper
handling endpoint/json_payload, parsing the marker, and calling
report_lmstudio_request_failure on errors. Since bash 3.2 has no nameref, return
results via clearly named globals or another simple shared mechanism so both
paths stay aligned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0f57c0bb-71e1-494e-ba69-93a5d9fd8587

📥 Commits

Reviewing files that changed from the base of the PR and between fbf1091 and 4635aa2.

📒 Files selected for processing (4)
  • bin/gga
  • lib/providers.sh
  • spec/integration/commands_spec.sh
  • spec/unit/providers_spec.sh

Comment thread bin/gga
Comment thread lib/providers.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bin/gga (1)

268-273: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

sed | tr hides sed failures here. source_config_file can treat an unreadable config as valid because the pipeline reports tr’s exit status, leaving an empty temp file that still sources cleanly. Return the first command’s status or enable pipefail before sourcing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/gga` around lines 268 - 273, The sanitize_config_file pipeline currently
masks failures from sed, so source_config_file may proceed with an empty temp
file instead of rejecting an unreadable config. Update sanitize_config_file to
preserve the first command’s failure (for example by enabling pipefail in the
relevant flow or explicitly checking the sed status) before the result is
sourced, and keep the fix localized around sanitize_config_file and
source_config_file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@bin/gga`:
- Around line 268-273: The sanitize_config_file pipeline currently masks
failures from sed, so source_config_file may proceed with an empty temp file
instead of rejecting an unreadable config. Update sanitize_config_file to
preserve the first command’s failure (for example by enabling pipefail in the
relevant flow or explicitly checking the sed status) before the result is
sourced, and keep the fix localized around sanitize_config_file and
source_config_file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d6ed33a5-a425-4b24-b7e1-644bbcefc0d0

📥 Commits

Reviewing files that changed from the base of the PR and between 4635aa2 and 0ac3c9d.

📒 Files selected for processing (3)
  • bin/gga
  • lib/providers.sh
  • spec/integration/commands_spec.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bin/gga (1)

314-320: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider explicit error handling for source_config_file in load_config.

The return value of source_config_file is not checked. The source_config_file function carefully returns exit codes on failure, but load_config ignores them. The integration test at line 240 (The output should not include "Not configured") implies the script aborts via set -e when sourcing fails — but relying on set -e for error propagation is fragile. If someone later wraps the call (e.g., source_config_file "$PROJECT_CONFIG" || true), failures would be silently swallowed and the user would see "Not configured" instead of the actual error.

Explicit error handling would make the contract clearer:

♻️ Suggested refactor
   if [[ -f "$GLOBAL_CONFIG" ]]; then
-    source_config_file "$GLOBAL_CONFIG"
+    if ! source_config_file "$GLOBAL_CONFIG"; then
+      echo "Error: Failed to load global config: $GLOBAL_CONFIG" >&2
+      return 1
+    fi
   fi

   # Load project config (overrides global)
   PROJECT_CONFIG=".gga"
   if [[ -f "$PROJECT_CONFIG" ]]; then
-    source_config_file "$PROJECT_CONFIG"
+    if ! source_config_file "$PROJECT_CONFIG"; then
+      echo "Error: Failed to load project config: $PROJECT_CONFIG" >&2
+      return 1
+    fi
   fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/gga` around lines 314 - 320, Update load_config to explicitly check the
return status of source_config_file for both GLOBAL_CONFIG and PROJECT_CONFIG
loads, rather than relying on set -e. On failure, immediately propagate the
nonzero status so configuration errors cannot be swallowed; use the
source_config_file function’s existing return code and preserve the actual error
output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@bin/gga`:
- Around line 314-320: Update load_config to explicitly check the return status
of source_config_file for both GLOBAL_CONFIG and PROJECT_CONFIG loads, rather
than relying on set -e. On failure, immediately propagate the nonzero status so
configuration errors cannot be swallowed; use the source_config_file function’s
existing return code and preserve the actual error output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 09a9fef6-8261-4523-8817-7fa11567be02

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac3c9d and 9aa4b99.

📒 Files selected for processing (2)
  • bin/gga
  • spec/integration/commands_spec.sh

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.

fix(config): preserve provider while stripping CRLF

1 participant