mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 13:04:45 +00:00
test: dedupe subagent lifecycle mock reads
This commit is contained in:
@@ -114,8 +114,16 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
}
|
||||
}
|
||||
|
||||
function firstCall(mock: ReturnType<typeof vi.fn>): ReadonlyArray<unknown> {
|
||||
const call = mock.mock.calls[0];
|
||||
if (!call) {
|
||||
throw new Error("expected first mock call");
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
function firstCallArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> {
|
||||
const [arg] = mock.mock.calls.at(0) ?? [];
|
||||
const [arg] = firstCall(mock);
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first call argument object");
|
||||
}
|
||||
@@ -206,8 +214,9 @@ describe("subagent registry lifecycle hardening", () => {
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
expect(warn.mock.calls.at(0)?.[0]).toBe("failed to finalize subagent background task state");
|
||||
expectFields(warn.mock.calls.at(0)?.[1], {
|
||||
const [warning, warningFields] = firstCall(warn);
|
||||
expect(warning).toBe("failed to finalize subagent background task state");
|
||||
expectFields(warningFields, {
|
||||
error: { name: "Error", message: "task store boom" },
|
||||
runId: "***",
|
||||
childSessionKey: "agent:main:…",
|
||||
@@ -250,10 +259,9 @@ describe("subagent registry lifecycle hardening", () => {
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
expect(warn.mock.calls.at(0)?.[0]).toBe(
|
||||
"failed to update subagent background task delivery state",
|
||||
);
|
||||
expectFields(warn.mock.calls.at(0)?.[1], {
|
||||
const [warning, warningFields] = firstCall(warn);
|
||||
expect(warning).toBe("failed to update subagent background task delivery state");
|
||||
expectFields(warningFields, {
|
||||
error: { name: "Error", message: "delivery state boom" },
|
||||
runId: "***",
|
||||
childSessionKey: "agent:main:…",
|
||||
@@ -677,10 +685,9 @@ describe("subagent registry lifecycle hardening", () => {
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
expect(warn).toHaveBeenCalledTimes(1);
|
||||
expect(warn.mock.calls.at(0)?.[0]).toBe(
|
||||
"failed to update subagent background task delivery state",
|
||||
);
|
||||
expectFields(warn.mock.calls.at(0)?.[1], {
|
||||
const [warning, warningFields] = firstCall(warn);
|
||||
expect(warning).toBe("failed to update subagent background task delivery state");
|
||||
expectFields(warningFields, {
|
||||
error: { name: "Error", message: "delivery status boom" },
|
||||
deliveryStatus: "delivered",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user