From ed8fcc17e486dab25a9dd7ea252232d816a69dbc Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 15:26:24 +0000 Subject: [PATCH] test(plugins): reproduce reload timeout and repeated open hooks Diagnostic tests only. The unchanged-hook test fails on the pre-fix manager with a slow-closing provider; the changed-hook test fails on the proposed contribution probe because it evaluates a hook twice for one replacement process. --- .../server/plugins/agent-tools.e2e.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/packages/server/src/server/plugins/agent-tools.e2e.test.ts b/packages/server/src/server/plugins/agent-tools.e2e.test.ts index 4e46121226..455127059c 100644 --- a/packages/server/src/server/plugins/agent-tools.e2e.test.ts +++ b/packages/server/src/server/plugins/agent-tools.e2e.test.ts @@ -1067,3 +1067,57 @@ test("session-open MCP configs are validated before a provider launches", async await h.close(); } }, 60_000); + +test("diagnostic: unchanged observer reload keeps a slow-closing provider usable", async () => { + let closes = 0; + const h = await setup( + false, + ` +export default function contribute(server) { + return server.addHook("agent.open.before", async () => {}); +} +`, + undefined, + { + closeSession: async () => { + closes++; + await new Promise((resolve) => setTimeout(resolve, 3700)); + }, + }, + ); + try { + const agent = await h.create(); + await sendAndFinish(h, agent.id, "first"); + await h.client.reloadPlugin("tools-test"); + await sendAndFinish(h, agent.id, "after reload"); + expect(closes).toBe(0); + expect(h.launches).toHaveLength(1); + } finally { + await h.close(); + } +}, 60_000); + +test("diagnostic: a changed session-open hook runs once for the replacement process", async () => { + const source = (value: string) => ` +let calls = 0; +export default function contribute(server) { + return server.addHook("agent.open.before", async ({ request }) => ({ + ...request, + env: { ...request.env, STABLE: ${JSON.stringify(value)}, HOOK_CALL: String(++calls) }, + })); +} +`; + const h = await setup(false, source("1")); + try { + const agent = await h.create(); + expect(h.launches.at(-1)!.context!.env!.HOOK_CALL).toBe("1"); + await writeFile(path.join(h.directory, "tools-test", "index.server.ts"), source("2")); + await h.client.reloadPlugin("tools-test"); + await sendAndFinish(h, agent.id, "after changed hook"); + expect(h.launches).toHaveLength(2); + expect(h.launches.at(-1)!.context!.env!.STABLE).toBe("2"); + expect(h.launches.at(-1)!.context!.env!.HOOK_CALL).toBe("1"); + } finally { + await h.close(); + } +}, 60_000);