Skip to content

Commit 4b08d9a

Browse files
committed
test(cron): narrow declarative add results
1 parent acb61d3 commit 4b08d9a

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

‎src/cron/service/ops.test.ts‎

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ import {
2929
import { list, writeScratch } from "./ops-read.js";
3030
import { inspectManualRunDisposition } from "./ops-run-preparation.js";
3131
import { run } from "./ops-run.js";
32-
import { createCronServiceState, type CronEvent } from "./state.js";
32+
import { createCronServiceState, type CronAddResult, type CronEvent } from "./state.js";
3333
import { tryCreateCronTaskRun, tryFinishCronTaskRun } from "./task-runs.js";
3434
import { runMissedJobs } from "./timer.js";
3535

3636
const { logger, makeStorePath } = setupCronServiceSuite({
3737
prefix: "cron-service-ops-seam",
3838
});
3939

40+
function requireDeclarativeAddResult(result: CronAddResult) {
41+
if (!("job" in result)) {
42+
throw new Error("expected declarative cron result");
43+
}
44+
return result;
45+
}
46+
4047
describe("scheduled tool policy provenance", () => {
4148
it("guards scratch and removal at their locked mutation owners", async () => {
4249
const { storePath } = await makeStorePath();
@@ -313,41 +320,49 @@ describe("scheduled tool policy provenance", () => {
313320
wakeMode: "now" as const,
314321
payload: { kind: "agentTurn" as const, message: "run", toolsAllow: ["*"] },
315322
};
316-
const created = await add(state, input, {
317-
captureRuntimeAuthority: () => baseAuthority,
318-
});
323+
const created = requireDeclarativeAddResult(
324+
await add(state, input, {
325+
captureRuntimeAuthority: () => baseAuthority,
326+
}),
327+
);
319328
expect(created.job.runtimeAuthority).toEqual(baseAuthority);
320329

321330
const commitGuard = vi.fn();
322-
const validated = await add(
323-
state,
324-
{
325-
...input,
326-
description: "validated",
327-
payload: { kind: "agentTurn", message: "run" },
328-
},
329-
{ commitGuard },
331+
const validated = requireDeclarativeAddResult(
332+
await add(
333+
state,
334+
{
335+
...input,
336+
description: "validated",
337+
payload: { kind: "agentTurn", message: "run" },
338+
},
339+
{ commitGuard },
340+
),
330341
);
331342
expect(commitGuard).toHaveBeenCalledOnce();
332343
expect(validated.job.runtimeAuthority).toEqual(baseAuthority);
333344

334-
const cleared = await add(state, {
335-
...input,
336-
description: "new tool cap",
337-
payload: { ...input.payload, toolsAllow: ["read"] },
338-
});
345+
const cleared = requireDeclarativeAddResult(
346+
await add(state, {
347+
...input,
348+
description: "new tool cap",
349+
payload: { ...input.payload, toolsAllow: ["read"] },
350+
}),
351+
);
339352
expect(cleared.job.runtimeAuthority).toBeUndefined();
340353
expect(cleared.job.runtimeAuthorityRecoveryRequired).toBe(true);
341354

342355
const replacement = { ...baseAuthority, payload: { apps: [{ id: "mail" }] } };
343-
const recaptured = await add(
344-
state,
345-
{
346-
...input,
347-
description: "recaptured",
348-
payload: { ...input.payload, toolsAllow: ["read"] },
349-
},
350-
{ captureRuntimeAuthority: () => replacement },
356+
const recaptured = requireDeclarativeAddResult(
357+
await add(
358+
state,
359+
{
360+
...input,
361+
description: "recaptured",
362+
payload: { ...input.payload, toolsAllow: ["read"] },
363+
},
364+
{ captureRuntimeAuthority: () => replacement },
365+
),
351366
);
352367
expect(recaptured.job.runtimeAuthority).toEqual(replacement);
353368
expect(recaptured.job.runtimeAuthorityRecoveryRequired).toBeUndefined();

0 commit comments

Comments
 (0)