File size: 1,423 Bytes
d197cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Internal hook event key validation tests.
import { describe, expect, it } from "vitest";
import { isKnownInternalHookEventKey } from "./internal-hook-types.js";

describe("isKnownInternalHookEventKey", () => {
  it("accepts every emitted type:action key", () => {
    for (const key of [
      "agent:bootstrap",
      "command:new",
      "command:reset",
      "command:stop",
      "gateway:pre-restart",
      "gateway:shutdown",
      "gateway:startup",
      "message:preprocessed",
      "message:received",
      "message:sent",
      "message:transcribed",
      "session:auto-reset",
      "session:compact:after",
      "session:compact:before",
      "session:patch",
    ]) {
      expect(isKnownInternalHookEventKey(key), key).toBe(true);
    }
  });

  it("accepts bare family keys that subscribe to every action", () => {
    for (const family of ["command", "session", "agent", "gateway", "message"]) {
      expect(isKnownInternalHookEventKey(family), family).toBe(true);
    }
  });

  it("rejects typos, bare actions, and unknown families", () => {
    for (const key of [
      "command:nwe",
      "message:recieved",
      "startup", // bare action without its family
      "gateway:started",
      "session:compact", // partial multi-segment action
      "webhook:received",
      "",
      "COMMAND:NEW",
    ]) {
      expect(isKnownInternalHookEventKey(key), key).toBe(false);
    }
  });
});