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

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
Jina AI
Jina AI
B
Blog
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
Check Point Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
罗磊的独立博客
B
Blog RSS Feed
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
M
MIT News - Artificial intelligence
GbyAI
GbyAI

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: stabilize startup session migration flake (#97370) ...
RomneyDa · 2026-06-28 · via Recent Commits to openclaw:main
11

// Tests migration cleanup for orphaned state keys.

22

import fs from "node:fs";

33

import path from "node:path";

4-

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

4+

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

55

import type { OpenClawConfig } from "../config/config.js";

66

import { withTempDir } from "../test-helpers/temp-dir.js";

77

import {

88

migrateOrphanedSessionKeys,

99

sessionStoreTextMayNeedCanonicalization,

1010

} from "./state-migrations.js";

111112+

const listPluginDoctorSessionStoreAgentIdsMock = vi.hoisted(() => vi.fn((): string[] => []));

13+14+

vi.mock("../plugins/doctor-contract-registry.js", async (importOriginal) => {

15+

const actual = await importOriginal<typeof import("../plugins/doctor-contract-registry.js")>();

16+

return {

17+

...actual,

18+

listPluginDoctorSessionStoreAgentIds: listPluginDoctorSessionStoreAgentIdsMock,

19+

};

20+

});

21+1222

function writeStore(storePath: string, store: Record<string, unknown>): void {

1323

fs.mkdirSync(path.dirname(storePath), { recursive: true });

1424

fs.writeFileSync(storePath, JSON.stringify(store));

@@ -55,14 +65,24 @@ function sharedMainOpsConfig(sharedStorePath: string): OpenClawConfig {

5565

} as OpenClawConfig;

5666

}

576758-

async function migrateFixtureState(stateDir: string, cfg: OpenClawConfig = OPS_WORK_CONFIG) {

68+

async function migrateFixtureState(

69+

stateDir: string,

70+

cfg: OpenClawConfig = OPS_WORK_CONFIG,

71+

additionalAgentIds?: readonly string[],

72+

) {

5973

return migrateOrphanedSessionKeys({

6074

cfg,

6175

env: { OPENCLAW_STATE_DIR: stateDir },

76+

additionalAgentIds,

6277

});

6378

}

64796580

describe("migrateOrphanedSessionKeys", () => {

81+

beforeEach(() => {

82+

listPluginDoctorSessionStoreAgentIdsMock.mockReset();

83+

listPluginDoctorSessionStoreAgentIdsMock.mockReturnValue([]);

84+

});

85+6686

it("recognizes canonical stores without parsing them for migration", () => {

6787

const raw = JSON.stringify({

6888

"agent:main:discord:channel:123": { sessionId: "channel", updatedAt: 1 },

@@ -238,6 +258,7 @@ describe("migrateOrphanedSessionKeys", () => {

238258

const result = await migrateOrphanedSessionKeys({

239259

cfg,

240260

env: { OPENCLAW_STATE_DIR: stateDir },

261+

additionalAgentIds: ["voice"],

241262

});

242263243264

const store = readStore(voiceStorePath);

@@ -254,6 +275,41 @@ describe("migrateOrphanedSessionKeys", () => {

254275

});

255276

});

256277278+

it("discovers plugin-owned agents through doctor contracts", async () => {

279+

await withStateFixture(async ({ tmpDir, stateDir }) => {

280+

listPluginDoctorSessionStoreAgentIdsMock.mockReturnValue(["voice"]);

281+

const storeTemplate = path.join(tmpDir, "stores", "{agentId}", "sessions.json");

282+

const voiceStorePath = path.join(tmpDir, "stores", "voice", "sessions.json");

283+

writeStore(voiceStorePath, {

284+

"voice:15550001111": { sessionId: "legacy-voice", updatedAt: 2000 },

285+

});

286+

const cfg = {

287+

session: { store: storeTemplate },

288+

agents: { list: [{ id: "main", default: true }] },

289+

plugins: {

290+

entries: {

291+

"voice-call": { config: { agentId: "voice" } },

292+

},

293+

},

294+

} as OpenClawConfig;

295+296+

const result = await migrateFixtureState(stateDir, cfg);

297+298+

expect(listPluginDoctorSessionStoreAgentIdsMock).toHaveBeenCalledWith({

299+

config: cfg,

300+

env: { OPENCLAW_STATE_DIR: stateDir },

301+

pluginIds: ["voice-call"],

302+

});

303+

const store = readStore(voiceStorePath);

304+

expect(requireStoreEntry(store, "agent:voice:voice:15550001111").sessionId).toBe(

305+

"legacy-voice",

306+

);

307+

expect(store["voice:15550001111"]).toBeUndefined();

308+

expect(result.changes).toHaveLength(1);

309+

expect(result.warnings).toHaveLength(0);

310+

});

311+

});

312+257313

it.each([

258314

{ scope: undefined, canonicalMainKey: "agent:voice:main" },

259315

{ scope: "global" as const, canonicalMainKey: "global" },

@@ -278,7 +334,7 @@ describe("migrateOrphanedSessionKeys", () => {

278334

},

279335

} as OpenClawConfig;

280336281-

const result = await migrateFixtureState(stateDir, cfg);

337+

const result = await migrateFixtureState(stateDir, cfg, ["voice"]);

282338283339

const store = readStore(voiceStorePath);

284340

expect(requireStoreEntry(store, "agent:main:main").sessionId).toBe("explicit-foreign");

@@ -310,7 +366,7 @@ describe("migrateOrphanedSessionKeys", () => {

310366

},

311367

} as OpenClawConfig;

312368313-

const result = await migrateFixtureState(stateDir, cfg);

369+

const result = await migrateFixtureState(stateDir, cfg, ["voice"]);

314370315371

const store = readStore(sharedStorePath);

316372

expect(requireStoreEntry(store, "agent:main:main").sessionId).toBe("ambiguous-main");

@@ -336,7 +392,7 @@ describe("migrateOrphanedSessionKeys", () => {

336392

},

337393

} as OpenClawConfig;

338394339-

const result = await migrateFixtureState(stateDir, cfg);

395+

const result = await migrateFixtureState(stateDir, cfg, ["voice"]);

340396341397

const store = readStore(sharedStorePath);

342398

expect(requireStoreEntry(store, "agent:main:work").sessionId).toBe("ambiguous-main");

@@ -370,8 +426,8 @@ describe("migrateOrphanedSessionKeys", () => {

370426

},

371427

} as OpenClawConfig;

372428373-

const result = await migrateFixtureState(stateDir, cfg);

374-

const rerun = await migrateFixtureState(stateDir, cfg);

429+

const result = await migrateFixtureState(stateDir, cfg, ["voice"]);

430+

const rerun = await migrateFixtureState(stateDir, cfg, ["voice"]);

375431376432

expect(result.changes).toHaveLength(0);

377433

expect(result.warnings).toEqual([

@@ -457,7 +513,7 @@ describe("migrateOrphanedSessionKeys", () => {

457513

},

458514

} as OpenClawConfig;

459515460-

const result = await migrateFixtureState(stateDir, cfg);

516+

const result = await migrateFixtureState(stateDir, cfg, ["voice"]);

461517462518

expect(result.changes).toHaveLength(0);

463519

expect(result.warnings).toEqual([