mirror of https://github.com/openclaw/openclaw.git
test: share venice model response fixtures
This commit is contained in:
parent
403e35e6b0
commit
a0fb5c7c41
|
|
@ -59,6 +59,55 @@ function makeModelsResponse(id: string): Response {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModelSpecOverride = {
|
||||||
|
id: string;
|
||||||
|
availableContextTokens?: number;
|
||||||
|
maxCompletionTokens?: number;
|
||||||
|
capabilities?: {
|
||||||
|
supportsReasoning?: boolean;
|
||||||
|
supportsVision?: boolean;
|
||||||
|
supportsFunctionCalling?: boolean;
|
||||||
|
};
|
||||||
|
includeModelSpec?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
function makeModelRow(params: ModelSpecOverride) {
|
||||||
|
if (params.includeModelSpec === false) {
|
||||||
|
return { id: params.id };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: params.id,
|
||||||
|
model_spec: {
|
||||||
|
name: params.id,
|
||||||
|
privacy: "private",
|
||||||
|
...(params.availableContextTokens === undefined
|
||||||
|
? {}
|
||||||
|
: { availableContextTokens: params.availableContextTokens }),
|
||||||
|
...(params.maxCompletionTokens === undefined
|
||||||
|
? {}
|
||||||
|
: { maxCompletionTokens: params.maxCompletionTokens }),
|
||||||
|
...(params.capabilities === undefined ? {} : { capabilities: params.capabilities }),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function stubVeniceModelsFetch(rows: ModelSpecOverride[]) {
|
||||||
|
const fetchMock = vi.fn(
|
||||||
|
async () =>
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
data: rows.map((row) => makeModelRow(row)),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
||||||
|
return fetchMock;
|
||||||
|
}
|
||||||
|
|
||||||
describe("venice-models", () => {
|
describe("venice-models", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.unstubAllGlobals();
|
vi.unstubAllGlobals();
|
||||||
|
|
@ -96,34 +145,18 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses API maxCompletionTokens for catalog models when present", async () => {
|
it("uses API maxCompletionTokens for catalog models when present", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{
|
||||||
new Response(
|
id: "llama-3.3-70b",
|
||||||
JSON.stringify({
|
availableContextTokens: 131072,
|
||||||
data: [
|
maxCompletionTokens: 2048,
|
||||||
{
|
capabilities: {
|
||||||
id: "llama-3.3-70b",
|
supportsReasoning: false,
|
||||||
model_spec: {
|
supportsVision: false,
|
||||||
name: "llama-3.3-70b",
|
supportsFunctionCalling: true,
|
||||||
privacy: "private",
|
},
|
||||||
availableContextTokens: 131072,
|
},
|
||||||
maxCompletionTokens: 2048,
|
]);
|
||||||
capabilities: {
|
|
||||||
supportsReasoning: false,
|
|
||||||
supportsVision: false,
|
|
||||||
supportsFunctionCalling: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const llama = models.find((m) => m.id === "llama-3.3-70b");
|
const llama = models.find((m) => m.id === "llama-3.3-70b");
|
||||||
|
|
@ -131,33 +164,17 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("retains catalog maxTokens when the API omits maxCompletionTokens", async () => {
|
it("retains catalog maxTokens when the API omits maxCompletionTokens", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{
|
||||||
new Response(
|
id: "qwen3-235b-a22b-instruct-2507",
|
||||||
JSON.stringify({
|
availableContextTokens: 131072,
|
||||||
data: [
|
capabilities: {
|
||||||
{
|
supportsReasoning: false,
|
||||||
id: "qwen3-235b-a22b-instruct-2507",
|
supportsVision: false,
|
||||||
model_spec: {
|
supportsFunctionCalling: true,
|
||||||
name: "qwen3-235b-a22b-instruct-2507",
|
},
|
||||||
privacy: "private",
|
},
|
||||||
availableContextTokens: 131072,
|
]);
|
||||||
capabilities: {
|
|
||||||
supportsReasoning: false,
|
|
||||||
supportsVision: false,
|
|
||||||
supportsFunctionCalling: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const qwen = models.find((m) => m.id === "qwen3-235b-a22b-instruct-2507");
|
const qwen = models.find((m) => m.id === "qwen3-235b-a22b-instruct-2507");
|
||||||
|
|
@ -172,34 +189,18 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses a conservative bounded maxTokens value for new models", async () => {
|
it("uses a conservative bounded maxTokens value for new models", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{
|
||||||
new Response(
|
id: "new-model-2026",
|
||||||
JSON.stringify({
|
availableContextTokens: 50_000,
|
||||||
data: [
|
maxCompletionTokens: 200_000,
|
||||||
{
|
capabilities: {
|
||||||
id: "new-model-2026",
|
supportsReasoning: false,
|
||||||
model_spec: {
|
supportsVision: false,
|
||||||
name: "new-model-2026",
|
supportsFunctionCalling: false,
|
||||||
privacy: "private",
|
},
|
||||||
availableContextTokens: 50_000,
|
},
|
||||||
maxCompletionTokens: 200_000,
|
]);
|
||||||
capabilities: {
|
|
||||||
supportsReasoning: false,
|
|
||||||
supportsVision: false,
|
|
||||||
supportsFunctionCalling: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const newModel = models.find((m) => m.id === "new-model-2026");
|
const newModel = models.find((m) => m.id === "new-model-2026");
|
||||||
|
|
@ -209,33 +210,17 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caps new-model maxTokens to the fallback context window when API context is missing", async () => {
|
it("caps new-model maxTokens to the fallback context window when API context is missing", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{
|
||||||
new Response(
|
id: "new-model-without-context",
|
||||||
JSON.stringify({
|
maxCompletionTokens: 200_000,
|
||||||
data: [
|
capabilities: {
|
||||||
{
|
supportsReasoning: false,
|
||||||
id: "new-model-without-context",
|
supportsVision: false,
|
||||||
model_spec: {
|
supportsFunctionCalling: true,
|
||||||
name: "new-model-without-context",
|
},
|
||||||
privacy: "private",
|
},
|
||||||
maxCompletionTokens: 200_000,
|
]);
|
||||||
capabilities: {
|
|
||||||
supportsReasoning: false,
|
|
||||||
supportsVision: false,
|
|
||||||
supportsFunctionCalling: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const newModel = models.find((m) => m.id === "new-model-without-context");
|
const newModel = models.find((m) => m.id === "new-model-without-context");
|
||||||
|
|
@ -244,37 +229,17 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ignores missing capabilities on partial metadata instead of aborting discovery", async () => {
|
it("ignores missing capabilities on partial metadata instead of aborting discovery", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{
|
||||||
new Response(
|
id: "llama-3.3-70b",
|
||||||
JSON.stringify({
|
availableContextTokens: 131072,
|
||||||
data: [
|
maxCompletionTokens: 2048,
|
||||||
{
|
},
|
||||||
id: "llama-3.3-70b",
|
{
|
||||||
model_spec: {
|
id: "new-model-partial",
|
||||||
name: "llama-3.3-70b",
|
maxCompletionTokens: 2048,
|
||||||
privacy: "private",
|
},
|
||||||
availableContextTokens: 131072,
|
]);
|
||||||
maxCompletionTokens: 2048,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "new-model-partial",
|
|
||||||
model_spec: {
|
|
||||||
name: "new-model-partial",
|
|
||||||
privacy: "private",
|
|
||||||
maxCompletionTokens: 2048,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const knownModel = models.find((m) => m.id === "llama-3.3-70b");
|
const knownModel = models.find((m) => m.id === "llama-3.3-70b");
|
||||||
|
|
@ -287,37 +252,19 @@ describe("venice-models", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps known models discoverable when a row omits model_spec", async () => {
|
it("keeps known models discoverable when a row omits model_spec", async () => {
|
||||||
const fetchMock = vi.fn(
|
stubVeniceModelsFetch([
|
||||||
async () =>
|
{ id: "llama-3.3-70b", includeModelSpec: false },
|
||||||
new Response(
|
{
|
||||||
JSON.stringify({
|
id: "new-model-valid",
|
||||||
data: [
|
availableContextTokens: 32_000,
|
||||||
{
|
maxCompletionTokens: 2_048,
|
||||||
id: "llama-3.3-70b",
|
capabilities: {
|
||||||
},
|
supportsReasoning: false,
|
||||||
{
|
supportsVision: false,
|
||||||
id: "new-model-valid",
|
supportsFunctionCalling: true,
|
||||||
model_spec: {
|
},
|
||||||
name: "new-model-valid",
|
},
|
||||||
privacy: "private",
|
]);
|
||||||
availableContextTokens: 32_000,
|
|
||||||
maxCompletionTokens: 2_048,
|
|
||||||
capabilities: {
|
|
||||||
supportsReasoning: false,
|
|
||||||
supportsVision: false,
|
|
||||||
supportsFunctionCalling: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
|
|
||||||
|
|
||||||
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
const models = await runWithDiscoveryEnabled(() => discoverVeniceModels());
|
||||||
const knownModel = models.find((m) => m.id === "llama-3.3-70b");
|
const knownModel = models.find((m) => m.id === "llama-3.3-70b");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue