mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
* feat(config): add canonical streaming config helpers * refactor(runtime): prefer canonical streaming accessors * feat(config): normalize preview channel streaming shape * test(config): lock streaming normalization followups * fix(config): polish streaming migration edges * chore(config): refresh streaming baseline hash
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
getChannelStreamingConfigObject,
|
|
resolveChannelStreamingBlockCoalesce,
|
|
resolveChannelStreamingBlockEnabled,
|
|
resolveChannelStreamingChunkMode,
|
|
resolveChannelStreamingNativeTransport,
|
|
resolveChannelStreamingPreviewChunk,
|
|
} from "./channel-streaming.js";
|
|
|
|
describe("channel-streaming", () => {
|
|
it("reads canonical nested streaming config first", () => {
|
|
const entry = {
|
|
streaming: {
|
|
chunkMode: "newline",
|
|
nativeTransport: true,
|
|
block: {
|
|
enabled: true,
|
|
coalesce: { minChars: 40, maxChars: 80, idleMs: 250 },
|
|
},
|
|
preview: {
|
|
chunk: { minChars: 10, maxChars: 20, breakPreference: "sentence" },
|
|
},
|
|
},
|
|
chunkMode: "length",
|
|
blockStreaming: false,
|
|
nativeStreaming: false,
|
|
blockStreamingCoalesce: { minChars: 5, maxChars: 15, idleMs: 100 },
|
|
draftChunk: { minChars: 2, maxChars: 4, breakPreference: "paragraph" },
|
|
} as const;
|
|
|
|
expect(getChannelStreamingConfigObject(entry)).toEqual(entry.streaming);
|
|
expect(resolveChannelStreamingChunkMode(entry)).toBe("newline");
|
|
expect(resolveChannelStreamingNativeTransport(entry)).toBe(true);
|
|
expect(resolveChannelStreamingBlockEnabled(entry)).toBe(true);
|
|
expect(resolveChannelStreamingBlockCoalesce(entry)).toEqual({
|
|
minChars: 40,
|
|
maxChars: 80,
|
|
idleMs: 250,
|
|
});
|
|
expect(resolveChannelStreamingPreviewChunk(entry)).toEqual({
|
|
minChars: 10,
|
|
maxChars: 20,
|
|
breakPreference: "sentence",
|
|
});
|
|
});
|
|
|
|
it("falls back to legacy flat fields when the canonical object is absent", () => {
|
|
const entry = {
|
|
chunkMode: "newline",
|
|
blockStreaming: true,
|
|
nativeStreaming: true,
|
|
blockStreamingCoalesce: { minChars: 120, maxChars: 240, idleMs: 500 },
|
|
draftChunk: { minChars: 8, maxChars: 16, breakPreference: "newline" },
|
|
} as const;
|
|
|
|
expect(getChannelStreamingConfigObject(entry)).toBeUndefined();
|
|
expect(resolveChannelStreamingChunkMode(entry)).toBe("newline");
|
|
expect(resolveChannelStreamingNativeTransport(entry)).toBe(true);
|
|
expect(resolveChannelStreamingBlockEnabled(entry)).toBe(true);
|
|
expect(resolveChannelStreamingBlockCoalesce(entry)).toEqual({
|
|
minChars: 120,
|
|
maxChars: 240,
|
|
idleMs: 500,
|
|
});
|
|
expect(resolveChannelStreamingPreviewChunk(entry)).toEqual({
|
|
minChars: 8,
|
|
maxChars: 16,
|
|
breakPreference: "newline",
|
|
});
|
|
});
|
|
});
|