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

推荐订阅源

小众软件
小众软件
B
Blog RSS Feed
美团技术团队
博客园 - 【当耐特】
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
Vercel News
Vercel News
P
Proofpoint News Feed
IT之家
IT之家
I
InfoQ
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More

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(cron): default missing sessionTarget on load and guar...
mvanhorn · 2026-04-25 · via Recent Commits to openclaw:main

@@ -0,0 +1,115 @@

1+

import fs from "node:fs/promises";

2+

import path from "node:path";

3+

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

4+

import { setupCronServiceSuite } from "../service.test-harness.js";

5+

import { assertSupportedJobSpec, findJobOrThrow } from "./jobs.js";

6+

import { createCronServiceState } from "./state.js";

7+

import { ensureLoaded } from "./store.js";

8+9+

const { logger, makeStorePath } = setupCronServiceSuite({

10+

prefix: "cron-service-store-missing-session-target-",

11+

});

12+13+

const STORE_TEST_NOW = Date.parse("2026-03-23T12:00:00.000Z");

14+15+

async function writeSingleJobStore(storePath: string, job: Record<string, unknown>) {

16+

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

17+

await fs.writeFile(storePath, JSON.stringify({ version: 1, jobs: [job] }, null, 2), "utf8");

18+

}

19+20+

function createStoreTestState(storePath: string) {

21+

return createCronServiceState({

22+

storePath,

23+

cronEnabled: true,

24+

log: logger,

25+

nowMs: () => STORE_TEST_NOW,

26+

enqueueSystemEvent: vi.fn(),

27+

requestHeartbeatNow: vi.fn(),

28+

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

29+

});

30+

}

31+32+

describe("cron service store load: missing sessionTarget", () => {

33+

it('defaults missing sessionTarget to "main" for systemEvent payloads', async () => {

34+

const { storePath } = await makeStorePath();

35+36+

await writeSingleJobStore(storePath, {

37+

id: "missing-session-target-system-event",

38+

name: "missing session target system event",

39+

enabled: true,

40+

createdAtMs: STORE_TEST_NOW - 60_000,

41+

updatedAtMs: STORE_TEST_NOW - 60_000,

42+

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

43+

wakeMode: "now",

44+

payload: { kind: "systemEvent", text: "tick" },

45+

state: {},

46+

});

47+48+

const state = createStoreTestState(storePath);

49+

await ensureLoaded(state);

50+51+

const job = findJobOrThrow(state, "missing-session-target-system-event");

52+

expect(job.sessionTarget).toBe("main");

53+

expect(() => assertSupportedJobSpec(job)).not.toThrow();

54+

});

55+56+

it('defaults missing sessionTarget to "isolated" for agentTurn payloads', async () => {

57+

const { storePath } = await makeStorePath();

58+59+

await writeSingleJobStore(storePath, {

60+

id: "missing-session-target-agent-turn",

61+

name: "missing session target agent turn",

62+

enabled: true,

63+

createdAtMs: STORE_TEST_NOW - 60_000,

64+

updatedAtMs: STORE_TEST_NOW - 60_000,

65+

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

66+

wakeMode: "now",

67+

payload: { kind: "agentTurn", message: "ping" },

68+

state: {},

69+

});

70+71+

const state = createStoreTestState(storePath);

72+

await ensureLoaded(state);

73+74+

const job = findJobOrThrow(state, "missing-session-target-agent-turn");

75+

expect(job.sessionTarget).toBe("isolated");

76+

expect(() => assertSupportedJobSpec(job)).not.toThrow();

77+

});

78+79+

it("assertSupportedJobSpec throws a clear error when sessionTarget is missing", () => {

80+

const bogus = {

81+

payload: { kind: "agentTurn" as const, message: "ping" },

82+

} as unknown as Parameters<typeof assertSupportedJobSpec>[0];

83+

expect(() => assertSupportedJobSpec(bogus)).toThrow(/missing sessionTarget/);

84+

});

85+86+

it("warns once per jobId across repeated forceReload cycles", async () => {

87+

const { storePath } = await makeStorePath();

88+89+

await writeSingleJobStore(storePath, {

90+

id: "log-dedupe-target",

91+

name: "log dedupe target",

92+

enabled: true,

93+

createdAtMs: STORE_TEST_NOW - 60_000,

94+

updatedAtMs: STORE_TEST_NOW - 60_000,

95+

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

96+

wakeMode: "now",

97+

payload: { kind: "agentTurn", message: "ping" },

98+

state: {},

99+

});

100+101+

const warnSpy = vi.spyOn(logger, "warn");

102+

const state = createStoreTestState(storePath);

103+104+

await ensureLoaded(state);

105+

await ensureLoaded(state, { forceReload: true });

106+

await ensureLoaded(state, { forceReload: true });

107+108+

const missingSessionTargetWarns = warnSpy.mock.calls.filter((call) => {

109+

const msg = typeof call[1] === "string" ? call[1] : "";

110+

return msg.includes("missing sessionTarget");

111+

});

112+

expect(missingSessionTargetWarns).toHaveLength(1);

113+

warnSpy.mockRestore();

114+

});

115+

});