Skip to content

Commit 7a71725

Browse files
giodl73-repoCopilot
andcommitted
Repair pairing and cron validation fixtures
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6991d11 commit 7a71725

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

src/cron/service.skips-main-jobs-empty-systemevent-text.test.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
createNoopLogger,
66
withCronServiceForTest,
77
} from "./service.test-harness.js";
8+
import { createCronServiceState } from "./service/state.js";
9+
import { executeJobCore } from "./service/timer.js";
810
import type { CronJob } from "./types.js";
911

1012
const noopLogger = createNoopLogger();
@@ -60,6 +62,39 @@ describe("CronService", () => {
6062
});
6163

6264
it("skips main jobs with empty systemEvent text", async () => {
65+
const enqueueSystemEvent = vi.fn();
66+
const requestHeartbeat = vi.fn();
67+
const state = createCronServiceState({
68+
cronEnabled: true,
69+
storePath: "cron-empty-systemevent-test.json",
70+
log: noopLogger,
71+
nowMs: () => Date.now(),
72+
enqueueSystemEvent,
73+
requestHeartbeat,
74+
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
75+
});
76+
const job: CronJob = {
77+
id: "empty-systemevent-test",
78+
name: "empty systemEvent test",
79+
enabled: true,
80+
schedule: { kind: "at", at: "2025-12-13T00:00:01.000Z" },
81+
sessionTarget: "main",
82+
wakeMode: "now",
83+
payload: { kind: "systemEvent", text: " " },
84+
createdAtMs: Date.now(),
85+
updatedAtMs: Date.now(),
86+
state: {},
87+
};
88+
89+
const result = await executeJobCore(state, job);
90+
91+
expect(result.status).toBe("skipped");
92+
expect(result.error).toMatch(/non-empty/i);
93+
expect(enqueueSystemEvent).not.toHaveBeenCalled();
94+
expect(requestHeartbeat).not.toHaveBeenCalled();
95+
});
96+
97+
it("drops persisted main jobs with empty systemEvent text before they run", async () => {
6398
await withCronService(true, async ({ cron, enqueueSystemEvent, requestHeartbeat }) => {
6499
const atMs = Date.parse("2025-12-13T00:00:01.000Z");
65100
await cron.add({
@@ -77,9 +112,8 @@ describe("CronService", () => {
77112
expect(enqueueSystemEvent).not.toHaveBeenCalled();
78113
expect(requestHeartbeat).not.toHaveBeenCalled();
79114

80-
const job = await waitForFirstJob(cron, (current) => current?.state.lastStatus === "skipped");
81-
expect(job?.state.lastStatus).toBe("skipped");
82-
expect(job?.state.lastError).toMatch(/non-empty/i);
115+
const job = await waitForFirstJob(cron, (current) => current === undefined);
116+
expect(job).toBeUndefined();
83117
});
84118
});
85119

src/cron/service/store.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe("cron service store seam coverage", () => {
291291
expect(findJobOrThrow(state, "reload-cron-expr-job").state.nextRunAtMs).toBe(dueNextRunAtMs);
292292
});
293293

294-
it("clears stale nextRunAtMs without throwing when a force-reloaded schedule is malformed", async () => {
294+
it("skips a force-reloaded job when the persisted schedule is malformed", async () => {
295295
const { storePath } = await makeStorePath();
296296
const staleNextRunAtMs = STORE_TEST_NOW + 3_600_000;
297297

@@ -316,9 +316,12 @@ describe("cron service store seam coverage", () => {
316316
undefined,
317317
);
318318

319-
const reloadedJob = findJobOrThrow(state, "reload-cron-expr-job");
320-
expect(reloadedJob.schedule).toBe("0 17 * * *");
321-
expect(reloadedJob.state.nextRunAtMs).toBeUndefined();
319+
expect(state.store?.jobs.find((job) => job.id === "reload-cron-expr-job")).toBeUndefined();
320+
expectWarnedJob({
321+
storePath,
322+
jobId: "reload-cron-expr-job",
323+
message: "skipped invalid persisted job",
324+
});
322325
});
323326

324327
it("preserves nextRunAtMs after force reload when scheduling inputs are unchanged", async () => {

src/pairing/pairing-store.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ async function expectPendingPairingRequestsIsolatedByAccount(params: {
301301
describe("pairing store", () => {
302302
it("skips malformed persisted pairing requests while approving valid codes", async () => {
303303
await withTempStateDir(async (stateDir) => {
304-
const now = new Date("2026-05-16T05:20:00.000Z").toISOString();
304+
const now = new Date().toISOString();
305305
writeJsonFixture(resolvePairingFilePath(stateDir, "telegram"), {
306306
version: 1,
307307
requests: [

0 commit comments

Comments
 (0)