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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
L
LangChain Blog
Jina AI
Jina AI
博客园 - 叶小钗
B
Blog RSS Feed
Recent Announcements
Recent Announcements
H
Help Net Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
B
Blog
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客

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
test: tighten compaction transcript assertions · openclaw...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -39,13 +39,43 @@ function requireString(value: string | undefined, label: string): string {

3939

return value;

4040

}

414142-

function requireValue<T>(value: T | undefined, label: string): T {

43-

if (value === undefined) {

42+

function requireValue<T>(value: T | null | undefined, label: string): T {

43+

if (value == null) {

4444

throw new Error(`expected ${label}`);

4545

}

4646

return value;

4747

}

484849+

type TranscriptEntry = ReturnType<SessionManager["getEntries"]>[number];

50+51+

function requireEntryByIdAndType<T extends TranscriptEntry["type"]>(

52+

entries: readonly TranscriptEntry[],

53+

id: string,

54+

type: T,

55+

label: string,

56+

): Extract<TranscriptEntry, { type: T }> {

57+

const entry = entries.find((candidate) => candidate.id === id);

58+

if (!entry) {

59+

throw new Error(`expected ${label}`);

60+

}

61+

if (entry.type !== type) {

62+

throw new Error(`expected ${label} to be ${type}, got ${entry.type}`);

63+

}

64+

return entry as Extract<TranscriptEntry, { type: T }>;

65+

}

66+67+

function requireEntryByType<T extends TranscriptEntry["type"]>(

68+

entries: readonly TranscriptEntry[],

69+

type: T,

70+

label: string,

71+

): Extract<TranscriptEntry, { type: T }> {

72+

const entry = entries.find((candidate) => candidate.type === type);

73+

if (!entry) {

74+

throw new Error(`expected ${label}`);

75+

}

76+

return entry as Extract<TranscriptEntry, { type: T }>;

77+

}

78+4979

function createCompactedSession(sessionDir: string): {

5080

manager: SessionManager;

5181

sessionFile: string;

@@ -91,10 +121,9 @@ describe("rotateTranscriptAfterCompaction", () => {

91121

const successorFile = requireString(result.sessionFile, "successor session file");

9212293123

const successor = SessionManager.open(successorFile);

94-

expect(successor.getHeader()).toMatchObject({

95-

parentSession: sessionFile,

96-

cwd: dir,

97-

});

124+

const header = requireValue(successor.getHeader(), "successor header");

125+

expect(header.parentSession).toBe(sessionFile);

126+

expect(header.cwd).toBe(dir);

98127

expect(successor.buildSessionContext().messages.length).toBeGreaterThan(0);

99128

});

100129

@@ -117,20 +146,19 @@ describe("rotateTranscriptAfterCompaction", () => {

117146

expect(await fs.readFile(sessionFile, "utf8")).toBe(originalBytes);

118147119148

const successor = SessionManager.open(successorFile);

120-

expect(successor.getHeader()).toMatchObject({

121-

id: successorSessionId,

122-

parentSession: sessionFile,

123-

cwd: dir,

124-

});

149+

const header = requireValue(successor.getHeader(), "successor header");

150+

expect(header.id).toBe(successorSessionId);

151+

expect(header.parentSession).toBe(sessionFile);

152+

expect(header.cwd).toBe(dir);

125153

expect(successor.getEntries().length).toBeLessThan(originalEntryCount);

126154

expect(successor.getBranch()[0]?.type).toBe("model_change");

127-

expect(successor.getBranch()).toContainEqual(

128-

expect.objectContaining({

129-

type: "custom",

130-

customType: "test-extension",

131-

data: { cursor: "before-compaction" },

132-

}),

155+

const customBranchEntry = requireEntryByType(

156+

successor.getBranch(),

157+

"custom",

158+

"preserved custom branch entry",

133159

);

160+

expect(customBranchEntry.customType).toBe("test-extension");

161+

expect(customBranchEntry.data).toStrictEqual({ cursor: "before-compaction" });

134162135163

const context = successor.buildSessionContext();

136164

const contextText = JSON.stringify(context.messages);

@@ -184,17 +212,12 @@ describe("rotateTranscriptAfterCompaction", () => {

184212

expect(countEntryType("model_change")).toBe(1);

185213

expect(countEntryType("thinking_level_change")).toBe(1);

186214

expect(countEntryType("session_info")).toBe(1);

187-

expect(entries.find((entry) => entry.type === "model_change")).toMatchObject({

188-

provider: "openai",

189-

modelId: "gpt-5.2",

190-

});

191-

expect(entries).toContainEqual(

192-

expect.objectContaining({

193-

type: "custom",

194-

customType: "test-extension",

195-

data: { cursor: "preserved" },

196-

}),

197-

);

215+

const modelChange = requireEntryByType(entries, "model_change", "current model change");

216+

expect(modelChange.provider).toBe("openai");

217+

expect(modelChange.modelId).toBe("gpt-5.2");

218+

const customEntry = requireEntryByType(entries, "custom", "preserved custom entry");

219+

expect(customEntry.customType).toBe("test-extension");

220+

expect(customEntry.data).toStrictEqual({ cursor: "preserved" });

198221199222

const context = successor.buildSessionContext();

200223

expect(context.thinkingLevel).toBe("high");

@@ -250,10 +273,8 @@ describe("rotateTranscriptAfterCompaction", () => {

250273

sessionFile: requireString(manager.getSessionFile(), "source session file"),

251274

});

252275253-

expect(result).toMatchObject({

254-

rotated: false,

255-

reason: "no compaction entry",

256-

});

276+

expect(result.rotated).toBe(false);

277+

expect(result.reason).toBe("no compaction entry");

257278

});

258279259280

it("uses a refreshed manager after manual boundary hardening", async () => {

@@ -297,9 +318,10 @@ describe("rotateTranscriptAfterCompaction", () => {

297318

const successorCompaction = successor

298319

.getEntries()

299320

.find((entry) => entry.type === "compaction" && entry.id === compactionId);

300-

expect(successorCompaction).toMatchObject({

301-

firstKeptEntryId: compactionId,

302-

});

321+

if (!successorCompaction || successorCompaction.type !== "compaction") {

322+

throw new Error("expected successor compaction entry");

323+

}

324+

expect(successorCompaction.firstKeptEntryId).toBe(compactionId);

303325

});

304326305327

it("preserves unsummarized sibling branches and branch summaries", async () => {

@@ -338,14 +360,23 @@ describe("rotateTranscriptAfterCompaction", () => {

338360

requireString(result.sessionFile, "successor session file"),

339361

);

340362

const allEntries = successor.getEntries();

341-

expect(allEntries.find((entry) => entry.id === branchSummaryId)).toMatchObject({

342-

type: "branch_summary",

343-

summary: "Summary of the abandoned branch.",

344-

});

345-

expect(allEntries.find((entry) => entry.id === siblingMsgId)).toMatchObject({

346-

type: "message",

347-

message: expect.objectContaining({ content: "do task B instead" }),

348-

});

363+

const branchSummary = requireEntryByIdAndType(

364+

allEntries,

365+

branchSummaryId,

366+

"branch_summary",

367+

"preserved branch summary",

368+

);

369+

expect(branchSummary.summary).toBe("Summary of the abandoned branch.");

370+

const siblingMessage = requireEntryByIdAndType(

371+

allEntries,

372+

siblingMsgId,

373+

"message",

374+

"preserved sibling message",

375+

);

376+

if (!("content" in siblingMessage.message)) {

377+

throw new Error("expected sibling message content");

378+

}

379+

expect(siblingMessage.message.content).toBe("do task B instead");

349380350381

const activeContextText = JSON.stringify(successor.buildSessionContext().messages);

351382

expect(activeContextText).toContain("Summary of main branch.");