mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 06:59:56 +00:00
test: bound gateway live model discovery
This commit is contained in:
@@ -59,6 +59,12 @@ for (const key of HIGH_SIGNAL_LIVE_MODEL_PRIORITY) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getHighSignalLiveModelProviders(): string[] {
|
||||
return [...HIGH_SIGNAL_LIVE_MODEL_IDS_BY_PROVIDER.keys()].toSorted((left, right) =>
|
||||
left.localeCompare(right),
|
||||
);
|
||||
}
|
||||
|
||||
function isHighSignalClaudeModelId(id: string): boolean {
|
||||
const normalized = id.replace(/[_.]/g, "-");
|
||||
if (!/\bclaude\b/i.test(normalized)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import { isModelNotFoundErrorMessage } from "../agents/live-model-errors.js";
|
||||
import {
|
||||
DEFAULT_HIGH_SIGNAL_LIVE_MODEL_LIMIT,
|
||||
getHighSignalLiveModelPriorityIndex,
|
||||
getHighSignalLiveModelProviders,
|
||||
isHighSignalLiveModelRef,
|
||||
resolveHighSignalLiveModelLimit,
|
||||
selectHighSignalLiveItems,
|
||||
@@ -169,7 +170,9 @@ function providerScopedModelRegistryProviders(params: {
|
||||
return params.providerList;
|
||||
}
|
||||
if (!params.useExplicit) {
|
||||
return undefined;
|
||||
return getHighSignalLiveModelProviders().filter((provider) =>
|
||||
params.providerFilter ? params.providerFilter.has(provider) : true,
|
||||
);
|
||||
}
|
||||
return providerListFromExplicitModelFilter({
|
||||
modelFilter: params.modelFilter,
|
||||
@@ -402,8 +405,10 @@ function enterProductionEnvForLiveRun() {
|
||||
const previous = {
|
||||
vitest: process.env.VITEST,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
testFast: process.env.OPENCLAW_TEST_FAST,
|
||||
};
|
||||
delete process.env.VITEST;
|
||||
delete process.env.OPENCLAW_TEST_FAST;
|
||||
process.env.NODE_ENV = "production";
|
||||
return previous;
|
||||
}
|
||||
@@ -411,12 +416,18 @@ function enterProductionEnvForLiveRun() {
|
||||
function restoreProductionEnvForLiveRun(previous: {
|
||||
vitest: string | undefined;
|
||||
nodeEnv: string | undefined;
|
||||
testFast: string | undefined;
|
||||
}) {
|
||||
if (previous.vitest === undefined) {
|
||||
delete process.env.VITEST;
|
||||
} else {
|
||||
process.env.VITEST = previous.vitest;
|
||||
}
|
||||
if (previous.testFast === undefined) {
|
||||
delete process.env.OPENCLAW_TEST_FAST;
|
||||
} else {
|
||||
process.env.OPENCLAW_TEST_FAST = previous.testFast;
|
||||
}
|
||||
if (previous.nodeEnv === undefined) {
|
||||
delete process.env.NODE_ENV;
|
||||
} else {
|
||||
@@ -424,6 +435,14 @@ function restoreProductionEnvForLiveRun(previous: {
|
||||
}
|
||||
}
|
||||
|
||||
function restoreOptionalEnv(key: string, value: string | undefined): void {
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function formatFailurePreview(
|
||||
failures: Array<{ model: string; error: string }>,
|
||||
maxItems: number,
|
||||
@@ -932,6 +951,28 @@ describe("resolveExplicitLiveModelCandidates", () => {
|
||||
});
|
||||
|
||||
describe("providerScopedModelRegistryProviders", () => {
|
||||
it("uses curated high-signal providers for default modern sweeps", () => {
|
||||
expect(
|
||||
providerScopedModelRegistryProviders({
|
||||
providerList: undefined,
|
||||
useExplicit: false,
|
||||
modelFilter: null,
|
||||
providerFilter: null,
|
||||
}),
|
||||
).toEqual(getHighSignalLiveModelProviders());
|
||||
});
|
||||
|
||||
it("intersects default modern sweeps with provider filters", () => {
|
||||
expect(
|
||||
providerScopedModelRegistryProviders({
|
||||
providerList: undefined,
|
||||
useExplicit: false,
|
||||
modelFilter: null,
|
||||
providerFilter: new Set(["openai", "not-high-signal"]),
|
||||
}),
|
||||
).toEqual(["openai"]);
|
||||
});
|
||||
|
||||
it("uses explicit provider-qualified model refs without enumerating the full registry", () => {
|
||||
expect(
|
||||
providerScopedModelRegistryProviders({
|
||||
@@ -1002,6 +1043,31 @@ describe("buildLiveGatewayConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("enterProductionEnvForLiveRun", () => {
|
||||
it("clears Vitest fast-reply flags while preserving caller state", () => {
|
||||
const previous = {
|
||||
vitest: process.env.VITEST,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
testFast: process.env.OPENCLAW_TEST_FAST,
|
||||
};
|
||||
process.env.VITEST = "1";
|
||||
process.env.NODE_ENV = "test";
|
||||
process.env.OPENCLAW_TEST_FAST = "1";
|
||||
|
||||
const runtimeEnv = enterProductionEnvForLiveRun();
|
||||
try {
|
||||
expect(process.env.VITEST).toBeUndefined();
|
||||
expect(process.env.NODE_ENV).toBe("production");
|
||||
expect(process.env.OPENCLAW_TEST_FAST).toBeUndefined();
|
||||
} finally {
|
||||
restoreProductionEnvForLiveRun(runtimeEnv);
|
||||
restoreOptionalEnv("VITEST", previous.vitest);
|
||||
restoreOptionalEnv("NODE_ENV", previous.nodeEnv);
|
||||
restoreOptionalEnv("OPENCLAW_TEST_FAST", previous.testFast);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function isGoogleModelNotFoundText(text: string): boolean {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed) {
|
||||
|
||||
Reference in New Issue
Block a user