Skip to content

fix(gitlawb): add specialty validators for connection test — bypass /models probe - #2837

Merged
diegosouzapw merged 5 commits into
diegosouzapw:release/v3.8.6from
oyi77:fix/gitlawb-connection-test
May 29, 2026
Merged

diegosouzapw merged 5 commits into
diegosouzapw:release/v3.8.6from
oyi77:fix/gitlawb-connection-test

Conversation

@oyi77

@oyi77 oyi77 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The GitLawB OpenGateway API (xiaomi-mimo compatible) returns 404 on connection test for both gitlawb and gitlawb-gmi providers. This causes the dashboard to show persistent "error" status for these connections even with valid API keys.

Additionally, the models list endpoint showed a misleading "API unavailable — using local catalog" warning for gitlawb providers, even though all registered models are fully functional via POST /chat/completions.

Root Cause

Connection test

The generic validateOpenAILikeProvider validation flow works in two stages:

  1. Stage 1 — GET /models: Hits {baseUrl}/models (e.g., https://opengateway.gitlawb.com/v1/xiaomi-mimo/models) — returns 404 because the OpenGateway API does not expose a models endpoint at that provider-path.
  2. Stage 2 — Fallback POST /chat/completions: On non-401/403 failure, falls back to a chat completions probe. This also fails because the generic fallback doesn't handle the xiaomi-mimo-compatible auth model correctly.

Result: validateProviderApiKey returns "Provider validation endpoint not supported", and the connection is permanently marked as "error" with a 404 diagnosis.

Models list

Since gitlawb and gitlawb-gmi are not in PROVIDER_MODELS_CONFIG, the models route fell through to the generic fallback which returns static catalog models with the warning "API unavailable — using local catalog". This warning is misleading — the models are fully functional.

Changes

1. Connection test fix (src/lib/providers/validation.ts)

Add specialty validators for both gitlawb and gitlawb-gmi in the SPECIALTY_VALIDATORS map. These mirror the existing xiaomi-mimo validator — since all three use the same underlying API format:

  • Skip the GET /models probe entirely
  • Validate directly via POST /chat/completions with a minimal test message
  • 401/403 → invalid API key
  • Any other response (200, 400, 422, 429) → auth passed
Provider Default baseUrl Test model
gitlawb https://opengateway.gitlawb.com/v1/xiaomi-mimo mimo-v2.5-pro
gitlawb-gmi https://opengateway.gitlawb.com/v1/gmi-cloud XiaomiMiMo/MiMo-V2.5-Pro

2. Models list fix (src/app/api/providers/[id]/models/route.ts)

Add gitlawb and gitlawb-gmi as static model providers (same pattern as reka and qwen OAuth). Models are served from the provider registry without the misleading "API unavailable" warning, since all registered models are functional via the chat completions endpoint.

3. Unit tests (tests/unit/provider-validation-specialty.test.ts)

Add 12 new tests covering both providers:

Test gitlawb gitlawb-gmi
Valid API key (200) ✅ ✅
Auth-passing responses (400) ✅ ✅
Auth-passing responses (422) ✅ ✅
Auth-passing responses (429) ✅ ✅
Invalid API key (401) ✅ ✅
Invalid API key (403) ✅ ✅
Network failure ✅ ✅
Custom baseUrl override ✅ ✅

Testing

Connection test

  1. Add a GitLawB provider connection with a valid API key → connection test returns "active"
  2. Add a GitLawB provider connection with an invalid API key → connection test returns "Invalid API key"
  3. Add a GitLawB provider connection with no API key (free tier) → connection test returns "active"
  4. Verify existing xiaomi-mimo connections still pass — new validators follow the exact same pattern

Unit tests

# tests 80
# pass 80
# fail 0

Models list

  • Navigate to gitlawb or gitlawb-gmi provider settings → models appear without warning
  • All registered models returned from local catalog

Related

…models probe

GitLawB OpenGateway API (xiaomi-mimo compatible) does not expose a /models
endpoint, causing validateOpenAILikeProvider to 404 on the initial probe
and report 'Provider validation endpoint not supported'.

Add specialty validators for both gitlawb and gitlawb-gmi that follow the
same pattern as the existing xiaomi-mimo validator: skip GET /models,
validate directly via POST /chat/completions with a minimal test message.
Any 401/403 response means an invalid key; all other responses mean auth
is OK.

Fixes test-connection returning 404 for GitLawB providers.
@oyi77
oyi77 requested a review from diegosouzapw as a code owner May 28, 2026 10:57
@kilo-code-bot

kilo-code-bot Bot commented May 28, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds validation support for the gitlawb and gitlawb-gmi providers in src/lib/providers/validation.ts by bypassing the /models probe in favor of a /chat/completions request. The reviewer recommended refactoring the two new validators to eliminate code duplication by extracting a shared helper function. Additionally, the reviewer noted that unit tests must be added to cover these new validators, as required by Rule 9 of the Repository Style Guide when modifying production code.

Comment thread src/lib/providers/validation.ts Outdated
Comment on lines +3746 to +3803
// Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation.
// Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern.
gitlawb: async ({ apiKey, providerSpecificData }: any) => {
try {
const baseUrl = normalizeBaseUrl(
providerSpecificData?.baseUrl || "https://opengateway.gitlawb.com/v1/xiaomi-mimo"
);
const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`;
const res = await validationWrite(
chatUrl,
{
method: "POST",
headers: buildBearerHeaders(apiKey, providerSpecificData),
body: JSON.stringify({
model: "mimo-v2.5-pro",
messages: [{ role: "user", content: "test" }],
max_tokens: 1,
}),
},
isLocal
);
if (res.status === 401 || res.status === 403) {
return { valid: false, error: "Invalid API key" };
}
// Any non-auth response (200, 400, 422, 429) means auth passed
return { valid: true, error: null };
} catch (error: any) {
return toValidationErrorResult(error);
}
},
"gitlawb-gmi": async ({ apiKey, providerSpecificData }: any) => {
try {
const baseUrl = normalizeBaseUrl(
providerSpecificData?.baseUrl || "https://opengateway.gitlawb.com/v1/gmi-cloud"
);
const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`;
const res = await validationWrite(
chatUrl,
{
method: "POST",
headers: buildBearerHeaders(apiKey, providerSpecificData),
body: JSON.stringify({
model: "XiaomiMiMo/MiMo-V2.5-Pro",
messages: [{ role: "user", content: "test" }],
max_tokens: 1,
}),
},
isLocal
);
if (res.status === 401 || res.status === 403) {
return { valid: false, error: "Invalid API key" };
}
// Any non-auth response (200, 400, 422, 429) means auth passed
return { valid: true, error: null };
} catch (error: any) {
return toValidationErrorResult(error);
}
},

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.

medium

Code Duplication

The specialty validators for gitlawb and gitlawb-gmi are virtually identical, differing only in their default base URLs and model IDs. This duplication can be avoided by extracting a shared validation helper function using an inline IIFE. This improves maintainability and prevents future logic drift between the two providers.

    // Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation.
    // Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern.
    ...(() => {
      const validate = async ({ apiKey, providerSpecificData, defaultBaseUrl, model }: any) => {
        try {
          const baseUrl = normalizeBaseUrl(providerSpecificData?.baseUrl || defaultBaseUrl);
          const chatUrl = `${baseUrl.replace(/\/chat\/completions$/, "")}/chat/completions`;
          const res = await validationWrite(
            chatUrl,
            {
              method: "POST",
              headers: buildBearerHeaders(apiKey, providerSpecificData),
              body: JSON.stringify({
                model,
                messages: [{ role: "user", content: "test" }],
                max_tokens: 1,
              }),
            },
            isLocal
          );
          if (res.status === 401 || res.status === 403) {
            return { valid: false, error: "Invalid API key" };
          }
          return { valid: true, error: null };
        } catch (error: any) {
          return toValidationErrorResult(error);
        }
      };
      return {
        gitlawb: (args: any) =>
          validate({
            ...args,
            defaultBaseUrl: "https://opengateway.gitlawb.com/v1/xiaomi-mimo",
            model: "mimo-v2.5-pro",
          }),
        "gitlawb-gmi": (args: any) =>
          validate({
            ...args,
            defaultBaseUrl: "https://opengateway.gitlawb.com/v1/gmi-cloud",
            model: "XiaomiMiMo/MiMo-V2.5-Pro",
          }),
      };
    })(),

Comment thread src/lib/providers/validation.ts Outdated
},
// Gitlawb Opengateway — Xiaomi MiMo compatible, same /models endpoint limitation.
// Bypass /models probe in favor of chat/completions, matching xiaomi-mimo's pattern.
gitlawb: async ({ apiKey, providerSpecificData }: any) => {

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.

medium

Missing Tests for Production Code Change

According to the Repository Style Guide (Rule 9), changing production code under src/ requires including tests. Please ensure that appropriate unit tests are added in the tests/ directory to cover these new specialty validators for gitlawb and gitlawb-gmi.

References
  1. Rule 9: Always include tests when changing production code (src/, open-sse/, electron/, bin/). (link)

oyi77 added 4 commits May 28, 2026 18:44
…y validators

Covers success, auth failure (401/403), non-auth acceptance (400/422/429),
network errors, and custom baseUrl overrides for both providers.
…ble warning

GitLawB's OpenGateway API does not expose a /models endpoint per
provider-path. Previously the models route fell through to the generic
fallback which returned static catalog models with the misleading
'API unavailable — using local catalog' warning.

Now gitlawb and gitlawb-gmi are handled as static model providers
(same pattern as reka and qwen OAuth) — models are served from the
provider registry without any warning, since all registered models
are functional via POST /chat/completions.
…docs path in test

- Extract gitlawb/gitlawb-gmi validators into buildOpengatewayValidator factory
- Fix dockerignore-docs-coverage test: update stale docs/AUTO-COMBO.md -> docs/routing/AUTO-COMBO.md
Hybrid approach:
- gitlawb (xiaomi-mimo): dynamic /models endpoint → 356 models
- gitlawb-gmi (gmi-cloud): 404 fallback → local catalog gracefully
Mimics Gitlawb/openclaude's model-routing pattern
@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.6 May 29, 2026 00:44
@diegosouzapw
diegosouzapw merged commit e73a2ea into diegosouzapw:release/v3.8.6 May 29, 2026
84 of 85 checks passed
This was referenced May 29, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
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.

2 participants