fix(providers): isolate model discovery test env guards · openclaw/openclaw@52cd76a
vincentkoc
·
2026-05-03
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +export function isChutesModelDiscoveryTestEnvironment( |
| 2 | +env: Record<string, string | undefined> = process.env, |
| 3 | +): boolean { |
| 4 | +return env.NODE_ENV === "test" || env.VITEST === "true"; |
| 5 | +} |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import {
|
4 | 4 | normalizeLowercaseStringOrEmpty, |
5 | 5 | normalizeOptionalString, |
6 | 6 | } from "openclaw/plugin-sdk/text-runtime"; |
| 7 | +import { isChutesModelDiscoveryTestEnvironment } from "./model-discovery-env.js"; |
7 | 8 | |
8 | 9 | const log = createSubsystemLogger("chutes-models"); |
9 | 10 | |
@@ -518,7 +519,7 @@ export async function discoverChutesModels(accessToken?: string): Promise<ModelD
|
518 | 519 | return cached.models; |
519 | 520 | } |
520 | 521 | |
521 | | -if (process.env.NODE_ENV === "test" || process.env.VITEST === "true") { |
| 522 | +if (isChutesModelDiscoveryTestEnvironment()) { |
522 | 523 | return CHUTES_MODEL_CATALOG.map(buildChutesModelDefinition); |
523 | 524 | } |
524 | 525 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +export function isHuggingfaceModelDiscoveryTestEnvironment( |
| 2 | +env: Record<string, string | undefined> = process.env, |
| 3 | +): boolean { |
| 4 | +return env.VITEST === "true" || env.NODE_ENV === "test"; |
| 5 | +} |
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-types"; |
2 | 2 | import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime"; |
| 3 | +import { isHuggingfaceModelDiscoveryTestEnvironment } from "./model-discovery-env.js"; |
3 | 4 | |
4 | 5 | export const HUGGINGFACE_BASE_URL = "https://router.huggingface.co/v1"; |
5 | 6 | export const HUGGINGFACE_POLICY_SUFFIXES = ["cheapest", "fastest"] as const; |
@@ -129,7 +130,7 @@ export async function discoverHuggingfaceModels(
|
129 | 130 | apiKey: string, |
130 | 131 | timeoutMs = HUGGINGFACE_DISCOVERY_TIMEOUT_MS, |
131 | 132 | ): Promise<ModelDefinitionConfig[]> { |
132 | | -if (process.env.VITEST === "true" || process.env.NODE_ENV === "test") { |
| 133 | +if (isHuggingfaceModelDiscoveryTestEnvironment()) { |
133 | 134 | return HUGGINGFACE_MODEL_CATALOG.map(buildHuggingfaceModelDefinition); |
134 | 135 | } |
135 | 136 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。