mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-06-01 14:40:10 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
/**
|
|
* Test: session_start & session_end hook wiring
|
|
*
|
|
* Tests the hook runner methods directly since session init is deeply integrated.
|
|
*/
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { createHookRunnerWithRegistry } from "./hooks.test-helpers.js";
|
|
import type {
|
|
PluginHookSessionContext,
|
|
PluginHookSessionEndEvent,
|
|
PluginHookSessionStartEvent,
|
|
} from "./types.js";
|
|
|
|
async function expectSessionHookCall(params: {
|
|
hookName: "session_start" | "session_end";
|
|
event: PluginHookSessionStartEvent | PluginHookSessionEndEvent;
|
|
sessionCtx: PluginHookSessionContext & { sessionKey: string; agentId: string };
|
|
}) {
|
|
const handler = vi.fn();
|
|
const { runner } = createHookRunnerWithRegistry([{ hookName: params.hookName, handler }]);
|
|
|
|
if (params.hookName === "session_start") {
|
|
await runner.runSessionStart(params.event as PluginHookSessionStartEvent, params.sessionCtx);
|
|
} else {
|
|
await runner.runSessionEnd(params.event as PluginHookSessionEndEvent, params.sessionCtx);
|
|
}
|
|
|
|
expect(handler).toHaveBeenCalledWith(params.event, params.sessionCtx);
|
|
}
|
|
|
|
describe("session hook runner methods", () => {
|
|
const sessionCtx = { sessionId: "abc-123", sessionKey: "agent:main:abc", agentId: "main" };
|
|
|
|
it.each([
|
|
{
|
|
name: "runSessionStart invokes registered session_start hooks",
|
|
hookName: "session_start" as const,
|
|
event: { sessionId: "abc-123", sessionKey: "agent:main:abc", resumedFrom: "old-session" },
|
|
},
|
|
{
|
|
name: "runSessionEnd invokes registered session_end hooks",
|
|
hookName: "session_end" as const,
|
|
event: { sessionId: "abc-123", sessionKey: "agent:main:abc", messageCount: 42 },
|
|
},
|
|
] as const)("$name", async ({ hookName, event }) => {
|
|
await expectSessionHookCall({ hookName, event, sessionCtx });
|
|
});
|
|
|
|
it("hasHooks returns true for registered session hooks", () => {
|
|
const { runner } = createHookRunnerWithRegistry([
|
|
{ hookName: "session_start", handler: vi.fn() },
|
|
]);
|
|
|
|
expect(runner.hasHooks("session_start")).toBe(true);
|
|
expect(runner.hasHooks("session_end")).toBe(false);
|
|
});
|
|
});
|