Skip to content

fix(go-models): add xAI model listing suffix - #15236

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
oktofeesh1:codex/xai-models-suffix
May 26, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
oktofeesh1:codex/xai-models-suffix

Conversation

@oktofeesh1

Copy link
Copy Markdown
Contributor

Summary

  • add the xAI models URL suffix used by the existing Go ListModels implementation
  • return a clear error when the xAI models suffix is missing
  • add focused xAI model-listing and connection-check regression tests

What changed

  • Added url_suffix.models to conf/models/xai.json.
  • Normalized the configured models suffix before building the request URL.
  • Covered config loading, successful model listing, upstream errors, API-key validation, missing suffix handling, and CheckConnection delegation.

Why

XAIModel.ListModels already builds requests from URLSuffix.Models, and CheckConnection delegates to that method. The bundled xAI config did not define that suffix, which left the model-listing path unable to call the provider /models endpoint from the existing provider config.

Validation

  • go test ./internal/entity/models -run TestXAI -count=1
  • go test ./internal/entity -count=1
  • git diff HEAD~1..HEAD --check

Notes

  • go test ./internal/entity/models -count=1 currently fails in unchanged Astraflow coverage: TestAstraflowEmbedReturnsNoSuchMethod panics before reaching any xAI assertions.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e8d5f209-8a7d-473e-b194-32528382d981

📥 Commits

Reviewing files that changed from the base of the PR and between eaf26fc and 74d4687.

📒 Files selected for processing (1)
  • internal/entity/models/xai_test.go

📝 Walkthrough

Walkthrough

The PR adds a models URL suffix to xAI config, validates/normalizes that suffix in ListModels (trimming and rejecting empty values), constructs the request URL from a cleaned base URL plus the suffix, and adds tests covering configuration, successful listing, auth validation, error propagation, and delegation.

Changes

XAI Model Listing Configuration and Validation

Layer / File(s) Summary
Configuration schema
conf/models/xai.json
Configuration extended with models URL suffix mapping alongside the existing chat suffix.
URL suffix validation and normalization
internal/entity/models/xai.go
ListModels validates and normalizes the models URL suffix by trimming whitespace and slashes, errors when unset/empty, and builds the request URL from the normalized base URL and cleaned suffix.
Test coverage for configuration and validation
internal/entity/models/xai_test.go
Test suite verifies config presence, successful /models request with required headers, API key validation, provider HTTP error propagation (401), CheckConnection delegation to ListModels, and early rejection when models suffix is missing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • infiniflow/ragflow#14550: The main PR's changes to internal/entity/models/xai.go (normalizing/validating URLSuffix.Models and building the /models request URL) are direct follow-ups to the xAI provider implementation in the retrieved PR, which introduced the xAI ListModels//models behavior.

Suggested labels

🐞 bug, size:M

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped into xAI's config glade,
Trimmed suffixes tidy, no mistakes were made,
Tests watched the endpoint, headers in tune,
Errors caught early — a neat little boon,
Now models reply beneath the moon.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding the xAI model listing suffix configuration. It is concise, specific, and clearly reflects the primary objective of the changeset.
Description check ✅ Passed The description covers all required template sections with substantial detail. It explains the problem, lists changes with file specifics, justifies the work, includes validation steps, and notes related issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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 `@internal/entity/models/xai_test.go`:
- Around line 117-119: The httptest server handler currently calls t.Fatalf
(inside the goroutine created by httptest.NewServer) which is unsafe; update the
handler to call t.Errorf instead so failures are reported from the handler
goroutine without terminating the test goroutine. Locate the handler used to
construct srv := httptest.NewServer(http.HandlerFunc(...)) in the xai test and
replace the t.Fatalf call with t.Errorf, keeping the same error message and
ensuring ListModels-related assertion logic remains unchanged.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8734ef7-848f-4ed2-877c-14b63ac5ed5e

📥 Commits

Reviewing files that changed from the base of the PR and between 036ed5b and eaf26fc.

📒 Files selected for processing (3)
  • conf/models/xai.json
  • internal/entity/models/xai.go
  • internal/entity/models/xai_test.go

Comment thread internal/entity/models/xai_test.go Resolved

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@oktofeesh1 LGTM
Thank you for your contribution

@Haruko386 Haruko386 added the ci Continue Integration label May 26, 2026
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3619cec) to head (220c57e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15236   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 557024e into infiniflow:main May 26, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request May 27, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants