
























@@ -0,0 +1,118 @@
1+import type { NativeHookRelayRegistrationHandle } from "openclaw/plugin-sdk/agent-harness-runtime";
2+import { describe, expect, it } from "vitest";
3+import {
4+buildCodexNativeHookRelayConfig,
5+buildCodexNativeHookRelayDisabledConfig,
6+} from "./native-hook-relay.js";
7+8+describe("Codex native hook relay config", () => {
9+it("builds deterministic Codex config overrides with command hooks", () => {
10+const config = buildCodexNativeHookRelayConfig({
11+relay: createRelay(),
12+hookTimeoutSec: 7,
13+});
14+15+expect(config).toEqual({
16+"features.codex_hooks": true,
17+"hooks.PreToolUse": [
18+{
19+matcher: null,
20+hooks: [
21+{
22+type: "command",
23+command:
24+"openclaw hooks relay --provider codex --relay-id relay-1 --event pre_tool_use",
25+timeout: 7,
26+async: false,
27+statusMessage: "OpenClaw native hook relay",
28+},
29+],
30+},
31+],
32+"hooks.PostToolUse": [
33+{
34+matcher: null,
35+hooks: [
36+{
37+type: "command",
38+command:
39+"openclaw hooks relay --provider codex --relay-id relay-1 --event post_tool_use",
40+timeout: 7,
41+async: false,
42+statusMessage: "OpenClaw native hook relay",
43+},
44+],
45+},
46+],
47+"hooks.PermissionRequest": [
48+{
49+matcher: null,
50+hooks: [
51+{
52+type: "command",
53+command:
54+"openclaw hooks relay --provider codex --relay-id relay-1 --event permission_request",
55+timeout: 7,
56+async: false,
57+statusMessage: "OpenClaw native hook relay",
58+},
59+],
60+},
61+],
62+});
63+expect(JSON.stringify(config)).not.toContain("timeoutSec");
64+expect(config).not.toHaveProperty("hooks.SessionStart");
65+expect(config).not.toHaveProperty("hooks.UserPromptSubmit");
66+expect(config).not.toHaveProperty("hooks.Stop");
67+});
68+69+it("includes only requested hook events", () => {
70+expect(
71+buildCodexNativeHookRelayConfig({
72+relay: createRelay(),
73+events: ["permission_request"],
74+}),
75+).toEqual({
76+"features.codex_hooks": true,
77+"hooks.PermissionRequest": [
78+{
79+matcher: null,
80+hooks: [
81+{
82+type: "command",
83+command:
84+"openclaw hooks relay --provider codex --relay-id relay-1 --event permission_request",
85+timeout: 5,
86+async: false,
87+statusMessage: "OpenClaw native hook relay",
88+},
89+],
90+},
91+],
92+});
93+});
94+95+it("builds deterministic clearing config when the relay is disabled", () => {
96+expect(buildCodexNativeHookRelayDisabledConfig()).toEqual({
97+"features.codex_hooks": false,
98+"hooks.PreToolUse": [],
99+"hooks.PostToolUse": [],
100+"hooks.PermissionRequest": [],
101+});
102+});
103+});
104+105+function createRelay(): NativeHookRelayRegistrationHandle {
106+return {
107+relayId: "relay-1",
108+provider: "codex",
109+sessionId: "session-1",
110+sessionKey: "agent:main:session-1",
111+runId: "run-1",
112+allowedEvents: ["pre_tool_use", "post_tool_use", "permission_request"],
113+expiresAtMs: Date.now() + 1000,
114+commandForEvent: (event) =>
115+`openclaw hooks relay --provider codex --relay-id relay-1 --event ${event}`,
116+unregister: () => undefined,
117+};
118+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。