


















@@ -130,13 +130,27 @@ function mockAgentStartFailure() {
130130});
131131}
132132133+function requireSpawnedHookCall(): [Record<string, unknown>, Record<string, unknown>] {
134+const call = hookRunnerMocks.runSubagentSpawned.mock.calls[0] as readonly unknown[] | undefined;
135+if (!call) {
136+throw new Error("expected spawned hook call");
137+}
138+return [requireRecord(call[0], "spawned event"), requireRecord(call[1], "spawned context")];
139+}
140+133141function getSpawnedEventCall(): Record<string, unknown> {
134-const [event] = (hookRunnerMocks.runSubagentSpawned.mock.calls.at(0) ?? []) as unknown as [
135-Record<string, unknown>,
136-];
142+const [event] = requireSpawnedHookCall();
137143return event;
138144}
139145146+function requireEndedHookEvent(): Record<string, unknown> {
147+const call = hookRunnerMocks.runSubagentEnded.mock.calls[0] as readonly unknown[] | undefined;
148+if (!call) {
149+throw new Error("expected ended hook call");
150+}
151+return requireRecord(call[0], "ended event");
152+}
153+140154function expectErrorResultMessage(
141155result: { error?: string; status: string },
142156pattern: RegExp,
@@ -276,10 +290,7 @@ describe("sessions_spawn subagent lifecycle hooks", () => {
276290);
277291278292expect(hookRunnerMocks.runSubagentSpawned).toHaveBeenCalledTimes(1);
279-const [event, ctx] = (hookRunnerMocks.runSubagentSpawned.mock.calls.at(0) ?? []) as unknown as [
280-Record<string, unknown>,
281-Record<string, unknown>,
282-];
293+const [event, ctx] = requireSpawnedHookCall();
283294expectFields(
284295event,
285296{
@@ -322,9 +333,7 @@ describe("sessions_spawn subagent lifecycle hooks", () => {
322333expectFields(result, { status: "accepted", runId: "run-1" }, "spawn result");
323334expect(hookRunnerMocks.runSubagentSpawning).not.toHaveBeenCalled();
324335expect(hookRunnerMocks.runSubagentSpawned).toHaveBeenCalledTimes(1);
325-const [event] = (hookRunnerMocks.runSubagentSpawned.mock.calls.at(0) ?? []) as unknown as [
326-Record<string, unknown>,
327-];
336+const event = getSpawnedEventCall();
328337expectFields(
329338event,
330339{
@@ -441,9 +450,7 @@ describe("sessions_spawn subagent lifecycle hooks", () => {
441450442451expect(result.status).toBe("error");
443452expect(hookRunnerMocks.runSubagentEnded).toHaveBeenCalledTimes(1);
444-const [event] = (hookRunnerMocks.runSubagentEnded.mock.calls.at(0) ?? []) as unknown as [
445-Record<string, unknown>,
446-];
453+const event = requireEndedHookEvent();
447454expectSubagentSessionKey(event.targetSessionKey, "ended event target session key");
448455expectFields(
449456event,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。