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

推荐订阅源

小众软件
小众软件
WordPress大学
WordPress大学
IT之家
IT之家
G
Google Developers Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
V
V2EX
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
V
Visual Studio Blog
有赞技术团队
有赞技术团队
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网

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(acp): isolate persistent binding lifecycle coverage ...
vincentkoc · 2026-05-04 · via Recent Commits to openclaw:main

@@ -1,6 +1,9 @@

11

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

22

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

3-

import { buildConfiguredAcpSessionKey } from "./persistent-bindings.types.js";

3+

import {

4+

buildConfiguredAcpSessionKey,

5+

type ConfiguredAcpBindingSpec,

6+

} from "./persistent-bindings.types.js";

4758

const managerMocks = vi.hoisted(() => ({

69

resolveSession: vi.fn(),

@@ -41,6 +44,7 @@ const baseCfg = {

4144

},

4245

} satisfies OpenClawConfig;

434647+

let ensureConfiguredAcpBindingSession: typeof import("./persistent-bindings.lifecycle.js").ensureConfiguredAcpBindingSession;

4448

let resetAcpSessionInPlace: typeof import("./persistent-bindings.lifecycle.js").resetAcpSessionInPlace;

45494650

beforeEach(async () => {

@@ -54,7 +58,127 @@ beforeEach(async () => {

5458

managerMocks.updateSessionRuntimeOptions.mockReset().mockResolvedValue(undefined);

5559

sessionMetaMocks.readAcpSessionEntry.mockReset().mockReturnValue(undefined);

5660

resolveMocks.resolveConfiguredAcpBindingSpecBySessionKey.mockReset().mockReturnValue(null);

57-

({ resetAcpSessionInPlace } = await import("./persistent-bindings.lifecycle.js"));

61+

({ ensureConfiguredAcpBindingSession, resetAcpSessionInPlace } =

62+

await import("./persistent-bindings.lifecycle.js"));

63+

});

64+65+

function createPersistentSpec(

66+

overrides: Partial<ConfiguredAcpBindingSpec> = {},

67+

): ConfiguredAcpBindingSpec {

68+

return {

69+

channel: "discord",

70+

accountId: "default",

71+

conversationId: "1478836151241412759",

72+

agentId: "codex",

73+

mode: "persistent",

74+

...overrides,

75+

};

76+

}

77+78+

function mockReadySession(params: {

79+

spec: ConfiguredAcpBindingSpec;

80+

cwd: string;

81+

state?: "idle" | "running" | "error";

82+

}) {

83+

const sessionKey = buildConfiguredAcpSessionKey(params.spec);

84+

managerMocks.resolveSession.mockReturnValue({

85+

kind: "ready",

86+

sessionKey,

87+

meta: {

88+

backend: "acpx",

89+

agent: params.spec.acpAgentId ?? params.spec.agentId,

90+

runtimeSessionName: "existing",

91+

mode: params.spec.mode,

92+

runtimeOptions: { cwd: params.cwd },

93+

state: params.state ?? "idle",

94+

lastActivityAt: Date.now(),

95+

},

96+

});

97+

return sessionKey;

98+

}

99+100+

describe("ensureConfiguredAcpBindingSession", () => {

101+

it("keeps an existing ready session when configured binding omits cwd", async () => {

102+

const spec = createPersistentSpec();

103+

const sessionKey = mockReadySession({

104+

spec,

105+

cwd: "/workspace/openclaw",

106+

});

107+108+

const ensured = await ensureConfiguredAcpBindingSession({

109+

cfg: baseCfg,

110+

spec,

111+

});

112+113+

expect(ensured).toEqual({ ok: true, sessionKey });

114+

expect(managerMocks.closeSession).not.toHaveBeenCalled();

115+

expect(managerMocks.initializeSession).not.toHaveBeenCalled();

116+

});

117+118+

it("reinitializes a ready session when binding config explicitly sets mismatched cwd", async () => {

119+

const spec = createPersistentSpec({

120+

cwd: "/workspace/repo-a",

121+

});

122+

const sessionKey = mockReadySession({

123+

spec,

124+

cwd: "/workspace/other-repo",

125+

});

126+127+

const ensured = await ensureConfiguredAcpBindingSession({

128+

cfg: baseCfg,

129+

spec,

130+

});

131+132+

expect(ensured).toEqual({ ok: true, sessionKey });

133+

expect(managerMocks.closeSession).toHaveBeenCalledTimes(1);

134+

expect(managerMocks.closeSession).toHaveBeenCalledWith(

135+

expect.objectContaining({

136+

sessionKey,

137+

clearMeta: false,

138+

}),

139+

);

140+

expect(managerMocks.initializeSession).toHaveBeenCalledTimes(1);

141+

});

142+143+

it("reinitializes a matching session when the stored ACP session is in error state", async () => {

144+

const spec = createPersistentSpec({

145+

cwd: "/home/bob/clawd",

146+

});

147+

const sessionKey = mockReadySession({

148+

spec,

149+

cwd: "/home/bob/clawd",

150+

state: "error",

151+

});

152+153+

const ensured = await ensureConfiguredAcpBindingSession({

154+

cfg: baseCfg,

155+

spec,

156+

});

157+158+

expect(ensured).toEqual({ ok: true, sessionKey });

159+

expect(managerMocks.closeSession).toHaveBeenCalledTimes(1);

160+

expect(managerMocks.initializeSession).toHaveBeenCalledTimes(1);

161+

});

162+163+

it("initializes ACP session with runtime agent override when provided", async () => {

164+

const spec = createPersistentSpec({

165+

agentId: "coding",

166+

acpAgentId: "codex",

167+

});

168+

managerMocks.resolveSession.mockReturnValue({ kind: "none" });

169+170+

const ensured = await ensureConfiguredAcpBindingSession({

171+

cfg: baseCfg,

172+

spec,

173+

});

174+175+

expect(ensured.ok).toBe(true);

176+

expect(managerMocks.initializeSession).toHaveBeenCalledWith(

177+

expect.objectContaining({

178+

agent: "codex",

179+

}),

180+

);

181+

});

58182

});

5918360184

describe("resetAcpSessionInPlace", () => {