feat: add prompt based hooks (#795)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -2,7 +2,19 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { CommandHookConfig, HookCommand } from "../hooks/types";
|
||||
import { settingsManager } from "../settings-manager";
|
||||
|
||||
// Type-safe helper to extract command from a hook (tests only use command hooks)
|
||||
function asCommand(
|
||||
hook: HookCommand | undefined,
|
||||
): CommandHookConfig | undefined {
|
||||
if (hook && hook.type === "command") {
|
||||
return hook as CommandHookConfig;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
import {
|
||||
deleteSecureTokens,
|
||||
isKeychainAvailable,
|
||||
@@ -558,7 +570,7 @@ describe("Settings Manager - Hooks", () => {
|
||||
|
||||
const settings = settingsManager.getSettings();
|
||||
expect(settings.hooks?.PreToolUse).toHaveLength(1);
|
||||
expect(settings.hooks?.PreToolUse?.[0]?.hooks[0]?.command).toBe(
|
||||
expect(asCommand(settings.hooks?.PreToolUse?.[0]?.hooks[0])?.command).toBe(
|
||||
"echo persisted",
|
||||
);
|
||||
expect(settings.hooks?.SessionStart).toHaveLength(1);
|
||||
@@ -631,7 +643,9 @@ describe("Settings Manager - Hooks", () => {
|
||||
|
||||
expect(reloaded.hooks?.Stop).toHaveLength(1);
|
||||
// Simple event hooks are in SimpleHookMatcher format with hooks array
|
||||
expect(reloaded.hooks?.Stop?.[0]?.hooks[0]?.command).toBe("echo stop-hook");
|
||||
expect(asCommand(reloaded.hooks?.Stop?.[0]?.hooks[0])?.command).toBe(
|
||||
"echo stop-hook",
|
||||
);
|
||||
});
|
||||
|
||||
test("All 11 hook event types can be configured", async () => {
|
||||
|
||||
Reference in New Issue
Block a user