mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 22:54:46 +00:00
test: guard task registry calls
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user