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

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
WordPress大学
WordPress大学
雷峰网
雷峰网
小众软件
小众软件
D
DataBreaches.Net
V
Visual Studio Blog
博客园 - Franky
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
博客园 - 聂微东
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
云风的 BLOG
云风的 BLOG

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
fix(providers): apply wrappers to direct streams · opencl...
vincentkoc · 2026-06-17 · via Recent Commits to openclaw:main
1+

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

2+

import type { Model } from "../llm/types.js";

3+4+

const mocks = vi.hoisted(() => ({

5+

ensureCustomApiRegistered: vi.fn(),

6+

createTransportAwareStreamFnForModel: vi.fn(),

7+

resolveProviderStreamFn: vi.fn(),

8+

wrapProviderStreamFn: vi.fn(),

9+

}));

10+11+

vi.mock("../plugins/provider-runtime.js", () => ({

12+

resolveProviderStreamFn: mocks.resolveProviderStreamFn,

13+

wrapProviderStreamFn: mocks.wrapProviderStreamFn,

14+

}));

15+

vi.mock("./custom-api-registry.js", () => ({

16+

ensureCustomApiRegistered: mocks.ensureCustomApiRegistered,

17+

}));

18+

vi.mock("./provider-transport-stream.js", () => ({

19+

createTransportAwareStreamFnForModel: mocks.createTransportAwareStreamFnForModel,

20+

}));

21+22+

import { registerProviderStreamForModel } from "./provider-stream.js";

23+24+

const MODEL = {

25+

id: "anthropic/default",

26+

name: "Anthropic default",

27+

api: "anthropic-messages",

28+

provider: "clawrouter",

29+

baseUrl: "https://clawrouter.example/v1/native/anthropic",

30+

reasoning: false,

31+

input: ["text"],

32+

cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },

33+

contextWindow: 200_000,

34+

maxTokens: 32_768,

35+

} satisfies Model<"anthropic-messages">;

36+37+

describe("registerProviderStreamForModel", () => {

38+

beforeEach(() => {

39+

vi.clearAllMocks();

40+

});

41+42+

it("applies an opted-in provider wrapper after selecting the managed transport", () => {

43+

const baseStream = vi.fn();

44+

const wrappedStream = vi.fn();

45+

mocks.createTransportAwareStreamFnForModel.mockReturnValue(baseStream);

46+

mocks.wrapProviderStreamFn.mockReturnValue(wrappedStream);

47+48+

expect(

49+

registerProviderStreamForModel({

50+

model: MODEL,

51+

cfg: { models: {} },

52+

agentDir: "/agent",

53+

workspaceDir: "/workspace",

54+

applyProviderWrapper: true,

55+

}),

56+

).toBe(wrappedStream);

57+

expect(mocks.wrapProviderStreamFn).toHaveBeenCalledWith({

58+

provider: "clawrouter",

59+

config: { models: {} },

60+

workspaceDir: "/workspace",

61+

env: undefined,

62+

context: {

63+

config: { models: {} },

64+

agentDir: "/agent",

65+

workspaceDir: "/workspace",

66+

provider: "clawrouter",

67+

modelId: "anthropic/default",

68+

model: MODEL,

69+

streamFn: baseStream,

70+

},

71+

});

72+

expect(mocks.ensureCustomApiRegistered).toHaveBeenCalledWith(

73+

"anthropic-messages",

74+

wrappedStream,

75+

);

76+

});

77+78+

it("leaves existing callers unwrapped by default", () => {

79+

const baseStream = vi.fn();

80+

mocks.resolveProviderStreamFn.mockReturnValue(baseStream);

81+82+

expect(registerProviderStreamForModel({ model: MODEL })).toBe(baseStream);

83+

expect(mocks.wrapProviderStreamFn).not.toHaveBeenCalled();

84+

});

85+

});