feat: add gmail hooks wizard

This commit is contained in:
Peter Steinberger
2025-12-24 19:39:36 +00:00
parent aeb5455555
commit 523d9ec3c2
10 changed files with 1332 additions and 1 deletions

63
src/hooks/gmail.test.ts Normal file
View File

@@ -0,0 +1,63 @@
import { describe, expect, it } from "vitest";
import type { ClawdisConfig } from "../config/config.js";
import {
buildDefaultHookUrl,
buildTopicPath,
parseTopicPath,
resolveGmailHookRuntimeConfig,
} from "./gmail.js";
const baseConfig = {
hooks: {
token: "hook-token",
gmail: {
account: "clawdbot@gmail.com",
topic: "projects/demo/topics/gog-gmail-watch",
pushToken: "push-token",
},
},
} satisfies ClawdisConfig;
describe("gmail hook config", () => {
it("builds default hook url", () => {
expect(buildDefaultHookUrl("/hooks")).toBe(
"http://127.0.0.1:18789/hooks/gmail",
);
});
it("parses topic path", () => {
const topic = buildTopicPath("proj", "topic");
expect(parseTopicPath(topic)).toEqual({
projectId: "proj",
topicName: "topic",
});
});
it("resolves runtime config with defaults", () => {
const result = resolveGmailHookRuntimeConfig(baseConfig, {});
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.value.account).toBe("clawdbot@gmail.com");
expect(result.value.label).toBe("INBOX");
expect(result.value.includeBody).toBe(true);
expect(result.value.serve.port).toBe(8788);
expect(result.value.hookUrl).toBe("http://127.0.0.1:18789/hooks/gmail");
}
});
it("fails without hook token", () => {
const result = resolveGmailHookRuntimeConfig(
{
hooks: {
gmail: {
account: "clawdbot@gmail.com",
topic: "projects/demo/topics/gog-gmail-watch",
pushToken: "push-token",
},
},
},
{},
);
expect(result.ok).toBe(false);
});
});