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

推荐订阅源

博客园 - 聂微东
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
博客园 - 司徒正美
博客园 - Franky
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
量子位
博客园 - 叶小钗
博客园_首页
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

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
refactor: share session history message fixtures · opencl...
vincentkoc · 2026-06-02 · via Recent Commits to openclaw:main

@@ -4,6 +4,35 @@ import { HEARTBEAT_PROMPT } from "../auto-reply/heartbeat.js";

44

import { buildSessionHistorySnapshot, SessionHistorySseState } from "./session-history-state.js";

55

import * as sessionUtils from "./session-utils.js";

667+

type HistorySnapshot = ReturnType<typeof buildSessionHistorySnapshot>;

8+9+

function assistantTextMessage(text: string, seq: number) {

10+

return {

11+

role: "assistant" as const,

12+

content: [{ type: "text" as const, text }],

13+

__openclaw: { seq },

14+

};

15+

}

16+17+

function userTextMessage(text: string, seq: number) {

18+

return {

19+

role: "user" as const,

20+

content: [{ type: "text" as const, text }],

21+

__openclaw: { seq },

22+

};

23+

}

24+25+

function newStateWithUserText(text: string): SessionHistorySseState {

26+

return SessionHistorySseState.fromRawSnapshot({

27+

target: { sessionId: "sess-main" },

28+

rawMessages: [userTextMessage(text, 1)],

29+

});

30+

}

31+32+

function expectOnlyAssistantText(snapshot: HistorySnapshot, text: string, seq: number): void {

33+

expect(snapshot.history.messages).toEqual([assistantTextMessage(text, seq)]);

34+

}

35+736

describe("SessionHistorySseState", () => {

837

test("uses the initial raw snapshot for both first history and seq seeding", () => {

938

const readSpy = vi.spyOn(sessionUtils, "readSessionMessagesAsync").mockResolvedValue([

@@ -58,18 +87,7 @@ describe("SessionHistorySseState", () => {

58875988

test("reuses one canonical array for items and messages", () => {

6089

const snapshot = buildSessionHistorySnapshot({

61-

rawMessages: [

62-

{

63-

role: "assistant",

64-

content: [{ type: "text", text: "first" }],

65-

__openclaw: { seq: 1 },

66-

},

67-

{

68-

role: "assistant",

69-

content: [{ type: "text", text: "second" }],

70-

__openclaw: { seq: 2 },

71-

},

72-

],

90+

rawMessages: [assistantTextMessage("first", 1), assistantTextMessage("second", 2)],

7391

limit: 1,

7492

});

7593

@@ -103,16 +121,7 @@ describe("SessionHistorySseState", () => {

103121

});

104122105123

test("emits message-tool mirror when silent control reply completes inline append", () => {

106-

const state = SessionHistorySseState.fromRawSnapshot({

107-

target: { sessionId: "sess-main" },

108-

rawMessages: [

109-

{

110-

role: "user",

111-

content: [{ type: "text", text: "reply here" }],

112-

__openclaw: { seq: 1 },

113-

},

114-

],

115-

});

124+

const state = newStateWithUserText("reply here");

116125117126

expect(

118127

state.appendInlineMessage({

@@ -219,18 +228,7 @@ describe("SessionHistorySseState", () => {

219228220229

test("does not coerce partial cursor values", () => {

221230

const snapshot = buildSessionHistorySnapshot({

222-

rawMessages: [

223-

{

224-

role: "assistant",

225-

content: [{ type: "text", text: "first" }],

226-

__openclaw: { seq: 1 },

227-

},

228-

{

229-

role: "assistant",

230-

content: [{ type: "text", text: "second" }],

231-

__openclaw: { seq: 2 },

232-

},

233-

],

231+

rawMessages: [assistantTextMessage("first", 1), assistantTextMessage("second", 2)],

234232

cursor: "seq:2next",

235233

});

236234

@@ -314,16 +312,7 @@ describe("SessionHistorySseState", () => {

314312

});

315313316314

test("does not emit a no-op hidden inline control reply", () => {

317-

const state = SessionHistorySseState.fromRawSnapshot({

318-

target: { sessionId: "sess-main" },

319-

rawMessages: [

320-

{

321-

role: "user",

322-

content: [{ type: "text", text: "reply here" }],

323-

__openclaw: { seq: 1 },

324-

},

325-

],

326-

});

315+

const state = newStateWithUserText("reply here");

327316328317

const appended = state.appendInlineMessage({

329318

message: {

@@ -528,21 +517,11 @@ describe("SessionHistorySseState", () => {

528517

],

529518

__openclaw: { seq: 1 },

530519

},

531-

{

532-

role: "assistant",

533-

content: [{ type: "text", text: "visible answer" }],

534-

__openclaw: { seq: 2 },

535-

},

520+

assistantTextMessage("visible answer", 2),

536521

],

537522

});

538523539-

expect(snapshot.history.messages).toEqual([

540-

{

541-

role: "assistant",

542-

content: [{ type: "text", text: "visible answer" }],

543-

__openclaw: { seq: 2 },

544-

},

545-

]);

524+

expectOnlyAssistantText(snapshot, "visible answer", 2);

546525

});

547526548527

test("drops hidden runtime-context custom messages from projected history", () => {

@@ -555,21 +534,11 @@ describe("SessionHistorySseState", () => {

555534

display: false,

556535

__openclaw: { seq: 1 },

557536

},

558-

{

559-

role: "assistant",

560-

content: [{ type: "text", text: "visible answer" }],

561-

__openclaw: { seq: 2 },

562-

},

537+

assistantTextMessage("visible answer", 2),

563538

],

564539

});

565540566-

expect(snapshot.history.messages).toEqual([

567-

{

568-

role: "assistant",

569-

content: [{ type: "text", text: "visible answer" }],

570-

__openclaw: { seq: 2 },

571-

},

572-

]);

541+

expectOnlyAssistantText(snapshot, "visible answer", 2);

573542

expect(snapshot.rawTranscriptSeq).toBe(2);

574543

});

575544