惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
V
Visual Studio Blog
博客园 - 叶小钗
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
U
Unit 42
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf: keep models list responsive during catalog discover...
steipete · 2026-05-01 · via Recent Commits to openclaw:main

@@ -0,0 +1,156 @@

1+

import { describe, expect, it, vi } from "vitest";

2+

import type { OpenClawConfig } from "../../config/types.openclaw.js";

3+

import { ErrorCodes } from "../protocol/index.js";

4+

import { modelsHandlers } from "./models.js";

5+6+

type Deferred<T> = {

7+

promise: Promise<T>;

8+

resolve: (value: T) => void;

9+

reject: (error: unknown) => void;

10+

};

11+12+

function createDeferred<T>(): Deferred<T> {

13+

let resolve!: (value: T) => void;

14+

let reject!: (error: unknown) => void;

15+

const promise = new Promise<T>((resolvePromise, rejectPromise) => {

16+

resolve = resolvePromise;

17+

reject = rejectPromise;

18+

});

19+

return { promise, resolve, reject };

20+

}

21+22+

describe("models.list", () => {

23+

it("does not block the configured view on slow model catalog discovery", async () => {

24+

const catalog = createDeferred<never>();

25+

const respond = vi.fn();

26+27+

vi.useFakeTimers();

28+

try {

29+

const request = modelsHandlers["models.list"]({

30+

req: {

31+

type: "req",

32+

id: "req-models-list-slow-catalog",

33+

method: "models.list",

34+

params: { view: "configured" },

35+

},

36+

params: { view: "configured" },

37+

respond,

38+

client: null,

39+

isWebchatConnect: () => false,

40+

context: {

41+

getRuntimeConfig: () => {

42+

const config = {

43+

models: {

44+

providers: {

45+

openai: {

46+

baseUrl: "https://openai.example.com",

47+

models: [{ id: "gpt-test", name: "GPT Test" }],

48+

},

49+

},

50+

},

51+

};

52+

return config as unknown as OpenClawConfig;

53+

},

54+

loadGatewayModelCatalog: vi.fn(() => catalog.promise),

55+

logGateway: {

56+

debug: vi.fn(),

57+

},

58+

} as never,

59+

});

60+61+

await vi.advanceTimersByTimeAsync(800);

62+

await request;

63+64+

expect(respond).toHaveBeenCalledWith(

65+

true,

66+

{

67+

models: [

68+

{

69+

id: "gpt-test",

70+

name: "GPT Test",

71+

provider: "openai",

72+

},

73+

],

74+

},

75+

undefined,

76+

);

77+

} finally {

78+

vi.useRealTimers();

79+

}

80+

});

81+82+

it("keeps the all view exact instead of timing out to a partial catalog", async () => {

83+

const catalog = createDeferred<[{ id: string; name: string; provider: string }]>();

84+

const respond = vi.fn();

85+86+

vi.useFakeTimers();

87+

try {

88+

const request = modelsHandlers["models.list"]({

89+

req: {

90+

type: "req",

91+

id: "req-models-list-all-slow-catalog",

92+

method: "models.list",

93+

params: { view: "all" },

94+

},

95+

params: { view: "all" },

96+

respond,

97+

client: null,

98+

isWebchatConnect: () => false,

99+

context: {

100+

getRuntimeConfig: () => ({}) as OpenClawConfig,

101+

loadGatewayModelCatalog: vi.fn(() => catalog.promise),

102+

logGateway: {

103+

debug: vi.fn(),

104+

},

105+

} as never,

106+

});

107+108+

await vi.advanceTimersByTimeAsync(800);

109+

expect(respond).not.toHaveBeenCalled();

110+111+

catalog.resolve([{ id: "gpt-test", name: "GPT Test", provider: "openai" }]);

112+

await request;

113+114+

expect(respond).toHaveBeenCalledWith(

115+

true,

116+

{ models: [{ id: "gpt-test", name: "GPT Test", provider: "openai" }] },

117+

undefined,

118+

);

119+

} finally {

120+

vi.useRealTimers();

121+

}

122+

});

123+124+

it("preserves catalog load errors before the timeout fallback wins", async () => {

125+

const respond = vi.fn();

126+127+

await modelsHandlers["models.list"]({

128+

req: {

129+

type: "req",

130+

id: "req-models-list-catalog-error",

131+

method: "models.list",

132+

params: { view: "configured" },

133+

},

134+

params: { view: "configured" },

135+

respond,

136+

client: null,

137+

isWebchatConnect: () => false,

138+

context: {

139+

getRuntimeConfig: () => ({}) as OpenClawConfig,

140+

loadGatewayModelCatalog: vi.fn(() => Promise.reject(new Error("catalog failed"))),

141+

logGateway: {

142+

debug: vi.fn(),

143+

},

144+

} as never,

145+

});

146+147+

expect(respond).toHaveBeenCalledWith(

148+

false,

149+

undefined,

150+

expect.objectContaining({

151+

code: ErrorCodes.UNAVAILABLE,

152+

message: "Error: catalog failed",

153+

}),

154+

);

155+

});

156+

});