Skip to content

fix(go-models): validate URL suffix config keys - #15734

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
oktofeesh1:codex/model-url-suffix-config
Jun 8, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
oktofeesh1:codex/model-url-suffix-config

Conversation

@oktofeesh1

@oktofeesh1 oktofeesh1 commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes typoed model-provider URL suffix keys and adds strict nested decoding so future URL suffix config mistakes fail during provider loading instead of being silently ignored.

What changed

  • Rename CoHere url_suffix.embeddings to embedding so the embedding endpoint is loaded.
  • Rename xAI url_suffix.ast to asr so the transcription endpoint is loaded.
  • Add explicit strict url_suffix decoding in the provider config loader with unknown-field rejection.
  • Add regression tests for corrected suffix loading and future unknown suffix keys.

Why

The Go provider loader previously used normal JSON unmarshalling, so unknown url_suffix keys were dropped silently. That left affected endpoints empty at runtime while the config looked valid.

Fixes #15591

Validation

  • go test ./internal/entity
  • go test ./internal/entity/models -run '^$'
  • go vet ./internal/entity
  • jq empty conf/models/*.json
  • git diff --check

Notes

  • go test ./internal/entity/models currently fails on pre-existing API-key validation expectations in unrelated model-driver tests; the package compiles with -run '^$', and the changed loader behavior is covered by go test ./internal/entity.
  • CodeRabbit did not return findings before timing out on the final local run.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 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: 57431680-b0a4-4a6c-8c4c-4d4644384779

📥 Commits

Reviewing files that changed from the base of the PR and between fe17a76 and a35a344.

📒 Files selected for processing (4)
  • conf/models/cohere.json
  • conf/models/xai.json
  • internal/entity/model.go
  • internal/entity/model_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • conf/models/cohere.json
  • internal/entity/model_test.go
  • conf/models/xai.json

📝 Walkthrough

Walkthrough

Provider configuration loading adds strict validation for url_suffix keys using json.Decoder with DisallowUnknownFields, rejecting unknown fields with descriptive errors. Shipped configs for Cohere and xAI are corrected to use canonical JSON field names, and tests verify both successful loads and failure cases.

Changes

URL Suffix validation and config fixes

Layer / File(s) Summary
Strict url_suffix unmarshalling in provider config loading
internal/entity/model.go
decodeProviderConfig helper first unmarshals a Provider, then re-decodes the url_suffix field using json.Decoder with DisallowUnknownFields to reject unknown keys. NewProviderManager switches from direct json.Unmarshal to call decodeProviderConfig, preserving file-path error wrapping.
Fix shipped provider url_suffix keys
conf/models/cohere.json, conf/models/xai.json
Cohere embedding endpoint key renamed from embeddings to embedding to match URLSuffix.Embedding JSON tag; xAI speech-to-text key renamed from ast to asr to match URLSuffix.ASR tag. Line-ending normalization applied to xAI config.
Tests for url_suffix validation and config loading
internal/entity/model_test.go
TestProviderConfigsLoadURLSuffixKeys loads shipped configs and asserts correct URLSuffix fields (Embedding for Cohere, ASR for xAI). TestProviderConfigRejectsUnknownURLSuffixKey writes invalid config with unknown url_suffix key, expects NewProviderManager to fail with error message containing both the unknown field name and the config filename.

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • infiniflow/ragflow#15236: Introduces url_suffix.models key for xAI—direct dependency on the strict validation added here, which now allows and validates the new key.
  • infiniflow/ragflow#15234: Adds url_suffix.models field for VolcEngine provider—depends on the strict unmarshalling in this PR to validate the new suffix key.

Suggested reviewers

  • Haruko386

Poem

🐰 A hop through configs, keys made right,
From embeddings → embedding, a unified sight,
Strict decoders catch typos at dawn,
No silent fails—validation is on! 🎯

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Description check ❓ Inconclusive The PR description includes a summary, detailed list of changes, reasoning, validation steps, and notes. However, it does not follow the provided template structure with 'What problem does this PR solve?' and 'Type of change' sections. Consider restructuring the description to match the repository template with explicit 'What problem does this PR solve?' and 'Type of change' sections for consistency.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(go-models): validate URL suffix config keys' clearly summarizes the main change—adding validation for URL suffix configuration keys in the go-models package.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #15591: fixes typoed config keys in CoHere (embeddings→embedding) and xAI (ast→asr), adds strict nested JSON decoding with unknown-field rejection, and includes regression tests for corrected suffix loading and unknown key rejection.
Out of Scope Changes check ✅ Passed All changes are directly related to the objectives of fixing URL suffix config keys and adding validation. The modifications to conf/models/*.json, the strict decoding logic in model.go, and test additions in model_test.go are all within scope.

✏️ 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.

🧹 Nitpick comments (1)
internal/entity/model_test.go (1)

184-186: ⚡ Quick win

Assert config-file context in the failure message.

Line 184 currently validates only the unknown-field fragment. Add a second check for unknown_suffix.json to lock in the wrapped file-context contract from NewProviderManager.

Proposed test hardening
  if !strings.Contains(err.Error(), `unknown field "unknown_suffix"`) {
      t.Fatalf("error=%q, want unknown_suffix field", err)
  }
+ if !strings.Contains(err.Error(), "unknown_suffix.json") {
+     t.Fatalf("error=%q, want source config filename in error", err)
+ }
🤖 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 `@internal/entity/model_test.go` around lines 184 - 186, The test currently
only asserts the error contains the unknown-field fragment; update the assertion
that checks err to also verify the wrapped config-file context string
(unknown_suffix.json) is present so the NewProviderManager file-context contract
is enforced; specifically, in the test where err is produced (the block that
checks strings.Contains(err.Error(), `unknown field "unknown_suffix"`)), add a
second check that strings.Contains(err.Error(), "unknown_suffix.json") and fail
the test (t.Fatalf) if that context is missing.
🤖 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.

Nitpick comments:
In `@internal/entity/model_test.go`:
- Around line 184-186: The test currently only asserts the error contains the
unknown-field fragment; update the assertion that checks err to also verify the
wrapped config-file context string (unknown_suffix.json) is present so the
NewProviderManager file-context contract is enforced; specifically, in the test
where err is produced (the block that checks strings.Contains(err.Error(),
`unknown field "unknown_suffix"`)), add a second check that
strings.Contains(err.Error(), "unknown_suffix.json") and fail the test
(t.Fatalf) if that context is missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c8c0f841-38e5-40f9-835a-9d1152cf39e9

📥 Commits

Reviewing files that changed from the base of the PR and between 5a04ac0 and 1f463f8.

📒 Files selected for processing (4)
  • conf/models/cohere.json
  • conf/models/xai.json
  • internal/entity/model_test.go
  • internal/entity/models/types.go

@oktofeesh1
oktofeesh1 force-pushed the codex/model-url-suffix-config branch from 1f463f8 to fe17a76 Compare June 7, 2026 16:05

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

Comment thread internal/entity/models/types.go Resolved
@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files. and removed 🐞 bug Something isn't working, pull request that fix bug. size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 8, 2026
@oktofeesh1
oktofeesh1 force-pushed the codex/model-url-suffix-config branch from fe17a76 to a35a344 Compare June 8, 2026 06:21
@oktofeesh1

Copy link
Copy Markdown
Contributor Author

Thanks, good point. I removed the custom URLSuffix.UnmarshalJSON hook so this is no longer hidden on the shared model type. The strict unknown-field check is now explicit in NewProviderManager via decodeProviderConfig, where provider config JSON is loaded and url_suffix is decoded with DisallowUnknownFields.

@oktofeesh1
oktofeesh1 requested a review from Haruko386 June 8, 2026 06:22
@codecov

codecov Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (220ee9d) to head (a35a344).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15734   +/-   ##
=======================================
  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 Harness.
📢 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.

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

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 8, 2026
@JinHai-CN
JinHai-CN merged commit 25df0a6 into infiniflow:main Jun 8, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 9, 2026
2 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Validate and normalize model URL suffix config keys

3 participants