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

推荐订阅源

N
Netflix TechBlog - Medium
I
InfoQ
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Docker
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
博客园 - Franky
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
WordPress大学
WordPress大学
MyScale Blog
MyScale 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
Add cron changed plugin hook (#72773) · openclaw/openclaw...
amknight · 2026-04-28 · via Recent Commits to openclaw:main

@@ -14,6 +14,8 @@ const {

1414

fetchWithSsrFGuardMock,

1515

runCronIsolatedAgentTurnMock,

1616

cleanupBrowserSessionsForLifecycleEndMock,

17+

getGlobalHookRunnerMock,

18+

runCronChangedMock,

1719

} = vi.hoisted(() => ({

1820

enqueueSystemEventMock: vi.fn(),

1921

requestHeartbeatNowMock: vi.fn(),

@@ -24,6 +26,11 @@ const {

2426

fetchWithSsrFGuardMock: vi.fn(),

2527

runCronIsolatedAgentTurnMock: vi.fn(async () => ({ status: "ok" as const, summary: "ok" })),

2628

cleanupBrowserSessionsForLifecycleEndMock: vi.fn(async () => {}),

29+

runCronChangedMock: vi.fn(async () => {}),

30+

getGlobalHookRunnerMock: vi.fn(() => ({

31+

hasHooks: (hookName: string) => hookName === "cron_changed",

32+

runCronChanged: runCronChangedMock,

33+

})),

2734

}));

28352936

function enqueueSystemEvent(...args: unknown[]) {

@@ -65,6 +72,14 @@ vi.mock("../config/config.js", async () => {

6572

};

6673

});

677475+

vi.mock("../config/io.js", async () => {

76+

const actual = await vi.importActual<typeof import("../config/io.js")>("../config/io.js");

77+

return {

78+

...actual,

79+

getRuntimeConfig: () => loadConfigMock(),

80+

};

81+

});

82+6883

vi.mock("../infra/net/fetch-guard.js", () => ({

6984

fetchWithSsrFGuard: fetchWithSsrFGuardMock,

7085

}));

@@ -77,6 +92,10 @@ vi.mock("../browser-lifecycle-cleanup.js", () => ({

7792

cleanupBrowserSessionsForLifecycleEnd: cleanupBrowserSessionsForLifecycleEndMock,

7893

}));

799495+

vi.mock("../plugins/hook-runner-global.js", () => ({

96+

getGlobalHookRunner: getGlobalHookRunnerMock,

97+

}));

98+8099

import { buildGatewayCronService } from "./server-cron.js";

8110082101

function createCronConfig(name: string): OpenClawConfig {

@@ -100,6 +119,121 @@ describe("buildGatewayCronService", () => {

100119

fetchWithSsrFGuardMock.mockClear();

101120

runCronIsolatedAgentTurnMock.mockClear();

102121

cleanupBrowserSessionsForLifecycleEndMock.mockClear();

122+

runCronChangedMock.mockClear();

123+

getGlobalHookRunnerMock.mockClear();

124+

getGlobalHookRunnerMock.mockReturnValue({

125+

hasHooks: (hookName: string) => hookName === "cron_changed",

126+

runCronChanged: runCronChangedMock,

127+

});

128+

});

129+130+

it("emits cron_changed hooks with computed next run state", async () => {

131+

const cfg = createCronConfig("server-cron-hook");

132+

loadConfigMock.mockReturnValue(cfg);

133+134+

const state = buildGatewayCronService({

135+

cfg,

136+

deps: {} as CliDeps,

137+

broadcast: () => {},

138+

});

139+

try {

140+

const job = await state.cron.add({

141+

name: "scheduler-hook",

142+

enabled: true,

143+

schedule: { kind: "every", everyMs: 60_000, anchorMs: 1_000 },

144+

sessionTarget: "main",

145+

wakeMode: "next-heartbeat",

146+

payload: { kind: "systemEvent", text: "sync external wake" },

147+

});

148+149+

expect(runCronChangedMock).toHaveBeenCalledWith(

150+

expect.objectContaining({

151+

action: "added",

152+

jobId: job.id,

153+

job: expect.objectContaining({

154+

id: job.id,

155+

state: expect.objectContaining({ nextRunAtMs: job.state.nextRunAtMs }),

156+

}),

157+

}),

158+

expect.objectContaining({

159+

config: cfg,

160+

getCron: expect.any(Function),

161+

}),

162+

);

163+

} finally {

164+

state.cron.stop();

165+

}

166+

});

167+168+

it("cron_changed removed events include the deleted job snapshot", async () => {

169+

const cfg = createCronConfig("server-cron-hook-removed");

170+

loadConfigMock.mockReturnValue(cfg);

171+172+

const state = buildGatewayCronService({

173+

cfg,

174+

deps: {} as CliDeps,

175+

broadcast: () => {},

176+

});

177+

try {

178+

const job = await state.cron.add({

179+

name: "to-be-removed",

180+

enabled: true,

181+

schedule: { kind: "every", everyMs: 60_000, anchorMs: 1_000 },

182+

sessionTarget: "main",

183+

wakeMode: "next-heartbeat",

184+

payload: { kind: "systemEvent", text: "will be removed" },

185+

});

186+187+

runCronChangedMock.mockClear();

188+

await state.cron.remove(job.id);

189+190+

expect(runCronChangedMock).toHaveBeenCalledWith(

191+

expect.objectContaining({

192+

action: "removed",

193+

jobId: job.id,

194+

job: expect.objectContaining({

195+

id: job.id,

196+

name: "to-be-removed",

197+

}),

198+

}),

199+

expect.objectContaining({

200+

getCron: expect.any(Function),

201+

}),

202+

);

203+

} finally {

204+

state.cron.stop();

205+

}

206+

});

207+208+

it("cron_changed hook context uses runtime config from getRuntimeConfig()", async () => {

209+

const startupCfg = createCronConfig("server-cron-hook-runtime-cfg");

210+

const runtimeCfg = { ...startupCfg, _marker: "runtime" };

211+

loadConfigMock.mockReturnValue(runtimeCfg);

212+213+

const state = buildGatewayCronService({

214+

cfg: startupCfg,

215+

deps: {} as CliDeps,

216+

broadcast: () => {},

217+

});

218+

try {

219+

await state.cron.add({

220+

name: "runtime-cfg-check",

221+

enabled: true,

222+

schedule: { kind: "every", everyMs: 60_000, anchorMs: 1_000 },

223+

sessionTarget: "main",

224+

wakeMode: "next-heartbeat",

225+

payload: { kind: "systemEvent", text: "cfg check" },

226+

});

227+228+

// The hook context should use getRuntimeConfig() (runtimeCfg), not startupCfg

229+

expect(runCronChangedMock).toHaveBeenCalledTimes(1);

230+

const calls = runCronChangedMock.mock.calls as unknown[][];

231+

const hookCtx = calls[0]?.[1] as { config?: unknown } | undefined;

232+

expect(hookCtx?.config).toBe(runtimeCfg);

233+

expect(hookCtx?.config).not.toBe(startupCfg);

234+

} finally {

235+

state.cron.stop();

236+

}

103237

});

104238105239

it("routes main-target jobs to the scoped session for enqueue + wake", async () => {