mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:01:24 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
let modelsListCommand: typeof import("./models/list.list-command.js").modelsListCommand;
|
||||
let loadModelRegistry: typeof import("./models/list.registry.js").loadModelRegistry;
|
||||
let toModelRow: typeof import("./models/list.registry.js").toModelRow;
|
||||
|
||||
const loadConfig = vi.fn();
|
||||
const ensureOpenClawModelsJson = vi.fn().mockResolvedValue(undefined);
|
||||
@@ -274,6 +276,7 @@ describe("models list/status", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
({ modelsListCommand } = await import("./models/list.list-command.js"));
|
||||
({ loadModelRegistry, toModelRow } = await import("./models/list.registry.js"));
|
||||
});
|
||||
|
||||
it("models list syncs auth-profiles into auth.json before availability checks", async () => {
|
||||
@@ -309,17 +312,12 @@ describe("models list/status", () => {
|
||||
expect(runtime.log.mock.calls[0]?.[0]).toBe("zai/glm-4.7");
|
||||
});
|
||||
|
||||
it("models list provider filter normalizes z.ai alias", async () => {
|
||||
await expectZaiProviderFilter("z.ai");
|
||||
});
|
||||
|
||||
it("models list provider filter normalizes Z.AI alias casing", async () => {
|
||||
await expectZaiProviderFilter("Z.AI");
|
||||
});
|
||||
|
||||
it("models list provider filter normalizes z-ai alias", async () => {
|
||||
await expectZaiProviderFilter("z-ai");
|
||||
});
|
||||
it.each(["z.ai", "Z.AI", "z-ai"] as const)(
|
||||
"models list provider filter normalizes %s alias",
|
||||
async (provider) => {
|
||||
await expectZaiProviderFilter(provider);
|
||||
},
|
||||
);
|
||||
|
||||
it("models list marks auth as unavailable when ZAI key is missing", async () => {
|
||||
setDefaultZaiRegistry({ available: false });
|
||||
@@ -331,57 +329,67 @@ describe("models list/status", () => {
|
||||
expect(payload.models[0]?.available).toBe(false);
|
||||
});
|
||||
|
||||
it("models list resolves antigravity opus 4.6 thinking from 4.5 template", async () => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
it.each([
|
||||
{
|
||||
name: "thinking",
|
||||
configuredModelId: "claude-opus-4-6-thinking",
|
||||
templateId: "claude-opus-4-5-thinking",
|
||||
templateName: "Claude Opus 4.5 Thinking",
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: "google-antigravity/claude-opus-4-6-thinking",
|
||||
available: false,
|
||||
includesTags: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("models list resolves antigravity opus 4.6 (non-thinking) from 4.5 template", async () => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
expectedKey: "google-antigravity/claude-opus-4-6-thinking",
|
||||
},
|
||||
{
|
||||
name: "non-thinking",
|
||||
configuredModelId: "claude-opus-4-6",
|
||||
templateId: "claude-opus-4-5",
|
||||
templateName: "Claude Opus 4.5",
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: "google-antigravity/claude-opus-4-6",
|
||||
available: false,
|
||||
includesTags: true,
|
||||
});
|
||||
});
|
||||
expectedKey: "google-antigravity/claude-opus-4-6",
|
||||
},
|
||||
] as const)(
|
||||
"models list resolves antigravity opus 4.6 $name from 4.5 template",
|
||||
async ({ configuredModelId, templateId, templateName, expectedKey }) => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
configuredModelId,
|
||||
templateId,
|
||||
templateName,
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: expectedKey,
|
||||
available: false,
|
||||
includesTags: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("models list marks synthesized antigravity opus 4.6 thinking as available when template is available", async () => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
it.each([
|
||||
{
|
||||
name: "thinking",
|
||||
configuredModelId: "claude-opus-4-6-thinking",
|
||||
templateId: "claude-opus-4-5-thinking",
|
||||
templateName: "Claude Opus 4.5 Thinking",
|
||||
available: true,
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: "google-antigravity/claude-opus-4-6-thinking",
|
||||
available: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("models list marks synthesized antigravity opus 4.6 (non-thinking) as available when template is available", async () => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
expectedKey: "google-antigravity/claude-opus-4-6-thinking",
|
||||
},
|
||||
{
|
||||
name: "non-thinking",
|
||||
configuredModelId: "claude-opus-4-6",
|
||||
templateId: "claude-opus-4-5",
|
||||
templateName: "Claude Opus 4.5",
|
||||
available: true,
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: "google-antigravity/claude-opus-4-6",
|
||||
available: true,
|
||||
});
|
||||
});
|
||||
expectedKey: "google-antigravity/claude-opus-4-6",
|
||||
},
|
||||
] as const)(
|
||||
"models list marks synthesized antigravity opus 4.6 $name as available when template is available",
|
||||
async ({ configuredModelId, templateId, templateName, expectedKey }) => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
configuredModelId,
|
||||
templateId,
|
||||
templateName,
|
||||
available: true,
|
||||
});
|
||||
expectAntigravityModel(payload, {
|
||||
key: expectedKey,
|
||||
available: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("models list prefers registry availability over provider auth heuristics", async () => {
|
||||
const payload = await runGoogleAntigravityListCase({
|
||||
@@ -472,13 +480,10 @@ describe("models list/status", () => {
|
||||
makeGoogleAntigravityTemplate("claude-opus-4-5-thinking", "Claude Opus 4.5 Thinking"),
|
||||
];
|
||||
|
||||
const { loadModelRegistry } = await import("./models/list.registry.js");
|
||||
await expect(loadModelRegistry({})).rejects.toThrow("model discovery unavailable");
|
||||
});
|
||||
|
||||
it("toModelRow does not crash without cfg/authStore when availability is undefined", async () => {
|
||||
const { toModelRow } = await import("./models/list.registry.js");
|
||||
|
||||
const row = toModelRow({
|
||||
model: makeGoogleAntigravityTemplate(
|
||||
"claude-opus-4-6-thinking",
|
||||
|
||||
Reference in New Issue
Block a user