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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
量子位
博客园 - 司徒正美
V
V2EX
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
N
Netflix TechBlog - Medium
L
LangChain Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure 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
perf(gateway): defer cron and sentinel startup work · ope...
steipete · 2026-05-03 · via Recent Commits to openclaw:main

@@ -0,0 +1,117 @@

1+

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

2+

import type { CliDeps } from "../cli/deps.types.js";

3+

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

4+

import type { CronServiceContract } from "../cron/service-contract.js";

5+

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

6+7+

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

8+

let state: unknown;

9+

return {

10+

buildGatewayCronService: vi.fn(() => state),

11+

setState(nextState: unknown) {

12+

state = nextState;

13+

},

14+

};

15+

});

16+17+

vi.mock("./server-cron.js", () => ({

18+

buildGatewayCronService: hoisted.buildGatewayCronService,

19+

}));

20+21+

const { createLazyGatewayCronState } = await import("./server-cron-lazy.js");

22+23+

describe("createLazyGatewayCronState", () => {

24+

beforeEach(() => {

25+

vi.unstubAllEnvs();

26+

hoisted.buildGatewayCronService.mockClear();

27+

});

28+29+

it("does not build the heavy cron service until an async cron operation needs it", async () => {

30+

const cron = createCronService();

31+

const state = createCronState(cron);

32+

hoisted.setState(state);

33+34+

const lazy = createLazyGatewayCronState(createParams());

35+36+

expect(hoisted.buildGatewayCronService).not.toHaveBeenCalled();

37+

expect(lazy.cron.getJob("demo")).toBeUndefined();

38+

expect(lazy.cron.getDefaultAgentId()).toBeUndefined();

39+40+

await lazy.cron.status();

41+42+

expect(hoisted.buildGatewayCronService).toHaveBeenCalledTimes(1);

43+

expect(cron.status).toHaveBeenCalledTimes(1);

44+

});

45+46+

it("starts the loaded cron service once", async () => {

47+

const cron = createCronService();

48+

hoisted.setState(createCronState(cron));

49+50+

const lazy = createLazyGatewayCronState(createParams());

51+52+

await lazy.cron.start();

53+

await lazy.cron.start();

54+55+

expect(hoisted.buildGatewayCronService).toHaveBeenCalledTimes(1);

56+

expect(cron.start).toHaveBeenCalledTimes(1);

57+

});

58+59+

it("keeps synchronous wake non-blocking before the cron service is loaded", async () => {

60+

const cron = createCronService();

61+

hoisted.setState(createCronState(cron));

62+63+

const lazy = createLazyGatewayCronState(createParams());

64+65+

expect(lazy.cron.wake({ mode: "now", text: "ping" })).toEqual({ ok: false });

66+67+

await vi.waitFor(() => {

68+

expect(hoisted.buildGatewayCronService).toHaveBeenCalledTimes(1);

69+

});

70+

expect(cron.wake).not.toHaveBeenCalled();

71+

});

72+73+

it("preserves the startup cron enabled flag without loading cron runtime", () => {

74+

vi.stubEnv("OPENCLAW_SKIP_CRON", "1");

75+76+

const lazy = createLazyGatewayCronState(createParams());

77+78+

expect(lazy.cronEnabled).toBe(false);

79+

expect(hoisted.buildGatewayCronService).not.toHaveBeenCalled();

80+

});

81+

});

82+83+

function createParams(overrides: Partial<OpenClawConfig> = {}) {

84+

return {

85+

cfg: {

86+

...overrides,

87+

} as OpenClawConfig,

88+

deps: {} as CliDeps,

89+

broadcast: vi.fn(),

90+

};

91+

}

92+93+

function createCronState(cron: CronServiceContract): GatewayCronState {

94+

return {

95+

cron,

96+

storePath: "/tmp/openclaw-cron.json",

97+

cronEnabled: true,

98+

} as GatewayCronState;

99+

}

100+101+

function createCronService(): CronServiceContract {

102+

return {

103+

start: vi.fn(async () => undefined),

104+

stop: vi.fn(),

105+

status: vi.fn(async () => ({ enabled: true }) as never),

106+

list: vi.fn(async () => [] as never),

107+

listPage: vi.fn(async () => ({ items: [], total: 0 }) as never),

108+

add: vi.fn(async () => ({ ok: true }) as never),

109+

update: vi.fn(async () => ({ ok: true }) as never),

110+

remove: vi.fn(async () => ({ ok: true }) as never),

111+

run: vi.fn(async () => ({ ok: true, ran: false, reason: "invalid-spec" }) as never),

112+

enqueueRun: vi.fn(async () => ({ ok: true, ran: false, reason: "invalid-spec" }) as never),

113+

getJob: vi.fn(() => undefined),

114+

getDefaultAgentId: vi.fn(() => "default"),

115+

wake: vi.fn(() => ({ ok: true })),

116+

};

117+

}