
























@@ -9,6 +9,9 @@ const cliMocks = vi.hoisted(() => ({
991010const runtimeMocks = vi.hoisted(() => ({
1111ensureMatrixCryptoRuntime: vi.fn(async () => {}),
12+handleMatrixSubagentDeliveryTarget: vi.fn(() => "delivery-target"),
13+handleMatrixSubagentEnded: vi.fn(async () => {}),
14+handleMatrixSubagentSpawning: vi.fn(async () => "spawned"),
1215handleVerificationBootstrap: vi.fn(async () => {}),
1316handleVerificationStatus: vi.fn(async () => {}),
1417handleVerifyRecoveryKey: vi.fn(async () => {}),
@@ -23,6 +26,7 @@ vi.mock("./src/cli.js", () => {
23262427vi.mock("./plugin-entry.handlers.runtime.js", () => runtimeMocks);
2528vi.mock("./runtime-setter-api.js", () => ({ setMatrixRuntime: runtimeMocks.setMatrixRuntime }));
29+vi.mock("./src/matrix/subagent-hooks.js", () => runtimeMocks);
26302731describe("matrix plugin", () => {
2832it("registers matrix CLI through a descriptor-backed lazy registrar", async () => {
@@ -68,7 +72,10 @@ describe("matrix plugin", () => {
6872expect(entry.kind).toBe("bundled-channel-entry");
6973expect(entry.id).toBe("matrix");
7074expect(entry.name).toBe("Matrix");
71-expect(entry.setChannelRuntime).toEqual(expect.any(Function));
75+if (!entry.setChannelRuntime) {
76+throw new Error("expected Matrix runtime setter");
77+}
78+expect(() => entry.setChannelRuntime?.({ marker: "runtime" } as never)).not.toThrow();
7279});
73807481it("wires CLI metadata through the bundled entry", () => {
@@ -99,7 +106,7 @@ describe("matrix plugin", () => {
99106expect(registerGatewayMethod).not.toHaveBeenCalled();
100107});
101108102-it("registers subagent lifecycle hooks during full runtime registration", () => {
109+it("registers subagent lifecycle hooks during full runtime registration", async () => {
103110const on = vi.fn();
104111const registerGatewayMethod = vi.fn();
105112const api = createTestPluginApi({
@@ -121,8 +128,14 @@ describe("matrix plugin", () => {
121128"subagent_ended",
122129"subagent_delivery_target",
123130]);
124-for (const [, handler] of on.mock.calls) {
125-expect(handler).toEqual(expect.any(Function));
126-}
131+const handlers = Object.fromEntries(on.mock.calls);
132+await expect(handlers.subagent_spawning({ id: "spawn" })).resolves.toBe("spawned");
133+await expect(handlers.subagent_ended({ id: "ended" })).resolves.toBeUndefined();
134+await expect(handlers.subagent_delivery_target({ id: "target" })).resolves.toBe(
135+"delivery-target",
136+);
137+expect(runtimeMocks.handleMatrixSubagentSpawning).toHaveBeenCalledWith(api, { id: "spawn" });
138+expect(runtimeMocks.handleMatrixSubagentEnded).toHaveBeenCalledWith({ id: "ended" });
139+expect(runtimeMocks.handleMatrixSubagentDeliveryTarget).toHaveBeenCalledWith({ id: "target" });
127140});
128141});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。