test: guard task registry calls

This commit is contained in:
Peter Steinberger
2026-05-11 22:31:20 +01:00
parent fc9b8c94a9
commit 671f0e653f
2 changed files with 19 additions and 4 deletions

View File

@@ -25,10 +25,14 @@ function requireFirstUpsertParams(upsertTaskWithDeliveryState: ReturnType<typeof
task?: { taskId?: string };
deliveryState?: { lastNotifiedEventAt?: number };
} {
const params = upsertTaskWithDeliveryState.mock.calls[0]?.[0];
if (!params) {
const [call] = upsertTaskWithDeliveryState.mock.calls;
if (!call) {
throw new Error("expected task upsert params");
}
const [params] = call;
if (typeof params !== "object" || params === null || Array.isArray(params)) {
throw new Error("expected task upsert params to be an object");
}
return params;
}

View File

@@ -287,6 +287,17 @@ function sentMessageCall(callIndex = 0): Record<string, unknown> {
return call[0] as Record<string, unknown>;
}
function firstMockArg(
mock: { mock: { calls: readonly unknown[][] } },
label: string,
): Record<string, unknown> {
const [call] = mock.mock.calls;
if (!call) {
throw new Error(`Expected ${label} call`);
}
return expectRecordFields(call[0], {});
}
function createInMemoryTaskRegistryStore() {
const tasks = new Map<string, TaskRecord>();
const deliveryStates = new Map<string, TaskDeliveryState>();
@@ -2897,7 +2908,7 @@ describe("task-registry", () => {
taskId: task.taskId,
});
const cancelArgs = hoisted.cancelSessionMock.mock.calls[0]?.[0];
const cancelArgs = firstMockArg(hoisted.cancelSessionMock, "cancelSession");
expectRecordFields(cancelArgs, {
cfg: {},
sessionKey: "agent:codex:acp:child",
@@ -2950,7 +2961,7 @@ describe("task-registry", () => {
taskId: task.taskId,
});
const killArgs = hoisted.killSubagentRunAdminMock.mock.calls[0]?.[0];
const killArgs = firstMockArg(hoisted.killSubagentRunAdminMock, "killSubagentRunAdmin");
expectRecordFields(killArgs, {
cfg: {},
sessionKey: "agent:worker:subagent:child",