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

推荐订阅源

博客园_首页
N
Netflix TechBlog - Medium
V
Visual Studio Blog
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
V
V2EX
The Cloudflare Blog
月光博客
月光博客
Last Week in AI
Last Week in AI
雷峰网
雷峰网
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 聂微东
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

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: isolate Claude history HOME setup · openclaw/opencla...
shakkernerd · 2026-06-21 · via Recent Commits to openclaw:main

@@ -4,6 +4,7 @@ import fs from "node:fs/promises";

44

import os from "node:os";

55

import path from "node:path";

66

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

7+

import { withEnvAsync } from "../test-utils/env.js";

78

import {

89

augmentChatHistoryWithCliSessionImports,

910

mergeImportedChatHistoryMessages,

@@ -13,8 +14,6 @@ import {

1314

} from "./cli-session-history.js";

1415

import { expectRecordFields, requireRecord } from "./test-helpers.assertions.js";

151616-

const ORIGINAL_HOME = process.env.HOME;

17-1817

type ClaudeCliFallbackSeed = NonNullable<ReturnType<typeof readClaudeCliFallbackSeed>>;

1918

type AugmentCliHistoryParams = Parameters<typeof augmentChatHistoryWithCliSessionImports>[0];

2019

@@ -150,28 +149,14 @@ async function withClaudeProjectsDir<T>(

150149

const filePath = path.join(projectsDir, `${sessionId}.jsonl`);

151150

await fs.mkdir(projectsDir, { recursive: true });

152151

await fs.writeFile(filePath, createClaudeHistoryLines(sessionId), "utf-8");

153-

process.env.HOME = homeDir;

154152

try {

155-

return await run({ homeDir, sessionId, filePath });

153+

return await withEnvAsync({ HOME: homeDir }, () => run({ homeDir, sessionId, filePath }));

156154

} finally {

157-

if (ORIGINAL_HOME === undefined) {

158-

delete process.env.HOME;

159-

} else {

160-

process.env.HOME = ORIGINAL_HOME;

161-

}

162155

await fs.rm(root, { recursive: true, force: true });

163156

}

164157

}

165158166159

describe("cli session history", () => {

167-

afterEach(() => {

168-

if (ORIGINAL_HOME === undefined) {

169-

delete process.env.HOME;

170-

} else {

171-

process.env.HOME = ORIGINAL_HOME;

172-

}

173-

});

174-175160

it("reads claude-cli session messages from the Claude projects store", async () => {

176161

await withClaudeProjectsDir(async ({ homeDir, sessionId, filePath }) => {

177162

expect(resolveClaudeCliSessionFilePath({ cliSessionId: sessionId, homeDir })).toBe(filePath);

@@ -460,25 +445,25 @@ describe("readClaudeCliFallbackSeed", () => {

460445

homeDir = path.join(tmpRoot, "home");

461446

projectsDir = path.join(homeDir, ".claude", "projects", "demo-workspace");

462447

await fs.mkdir(projectsDir, { recursive: true });

463-

process.env.HOME = homeDir;

464448

});

465449466450

afterEach(async () => {

467-

if (ORIGINAL_HOME === undefined) {

468-

delete process.env.HOME;

469-

} else {

470-

process.env.HOME = ORIGINAL_HOME;

471-

}

472451

await fs.rm(tmpRoot, { recursive: true, force: true });

473452

});

474453454+

function readFallbackSeed(

455+

cliSessionId = SESSION_ID,

456+

): ReturnType<typeof readClaudeCliFallbackSeed> {

457+

return readClaudeCliFallbackSeed({ cliSessionId, homeDir });

458+

}

459+475460

async function writeJsonl(lines: ReadonlyArray<Record<string, unknown>>): Promise<void> {

476461

const file = path.join(projectsDir, `${SESSION_ID}.jsonl`);

477462

await fs.writeFile(file, `${lines.map((line) => JSON.stringify(line)).join("\n")}\n`, "utf-8");

478463

}

479464480465

it("returns undefined when the Claude session file does not exist", () => {

481-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

466+

const seed = readFallbackSeed();

482467

expect(seed).toBeUndefined();

483468

});

484469

@@ -505,7 +490,7 @@ describe("readClaudeCliFallbackSeed", () => {

505490

},

506491

]);

507492508-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

493+

const seed = readFallbackSeed();

509494

const fallbackSeed = requireFallbackSeed(seed, "uncompacted session");

510495

expect(fallbackSeed.summaryText).toBeUndefined();

511496

expect(fallbackSeed.recentTurns).toHaveLength(3);

@@ -555,7 +540,7 @@ describe("readClaudeCliFallbackSeed", () => {

555540

},

556541

]);

557542558-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

543+

const seed = readFallbackSeed();

559544

const fallbackSeed = requireFallbackSeed(seed, "compacted session");

560545

expect(fallbackSeed.summaryText).toBe(

561546

"User asked about deployment; agent recommended a blue-green strategy.",

@@ -587,7 +572,7 @@ describe("readClaudeCliFallbackSeed", () => {

587572

},

588573

]);

589574590-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

575+

const seed = readFallbackSeed();

591576

const fallbackSeed = requireFallbackSeed(seed, "compact boundary session");

592577

// Falls back to the boundary's content so the seed at least labels

593578

// that compaction happened, instead of replaying nothing.

@@ -632,7 +617,7 @@ describe("readClaudeCliFallbackSeed", () => {

632617

},

633618

]);

634619635-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

620+

const seed = readFallbackSeed();

636621

expect(seed?.summaryText).toBe("LATER summary that must win.");

637622

expect(seed?.recentTurns).toHaveLength(1);

638623

expect(JSON.stringify(seed?.recentTurns)).toContain("tail turn");

@@ -649,12 +634,12 @@ describe("readClaudeCliFallbackSeed", () => {

649634

message: { role: "user", content: "sidechain user turn" },

650635

},

651636

]);

652-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

637+

const seed = readFallbackSeed();

653638

expect(seed).toBeUndefined();

654639

});

655640656641

it("rejects path-like session ids instead of escaping the Claude projects tree", () => {

657-

const seed = readClaudeCliFallbackSeed({ cliSessionId: "../escape" });

642+

const seed = readFallbackSeed("../escape");

658643

expect(seed).toBeUndefined();

659644

});

660645

@@ -685,7 +670,7 @@ describe("readClaudeCliFallbackSeed", () => {

685670

},

686671

]);

687672688-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

673+

const seed = readFallbackSeed();

689674

const fallbackSeed = requireFallbackSeed(seed, "latest boundary session");

690675

expect(fallbackSeed.summaryText).toBe("Conversation compacted (2)");

691676

expect(fallbackSeed.summaryText).not.toBe("FIRST compact summary");

@@ -708,7 +693,7 @@ describe("readClaudeCliFallbackSeed", () => {

708693

},

709694

]);

710695711-

const seed = readClaudeCliFallbackSeed({ cliSessionId: SESSION_ID });

696+

const seed = readFallbackSeed();

712697

expect(seed?.summaryText).toBe("trailing summary without boundary");

713698

});

714699

});