Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
integrations.test.ts7.8 KB · 270 lines
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/**
 * Pure-function tests for the integrations connector layer.
 * Covers config validation, redaction, and per-connector renderers.
 * No DB calls — that surface is covered by route smoke tests downstream.
 */

import { describe, it, expect } from "bun:test";
import {
  CONNECTORS,
  INTEGRATION_KINDS,
  INTEGRATION_EVENTS,
  __test,
  getConnector,
  isHttpUrl,
  isValidEvent,
  isValidKind,
  redactConfig,
  validateConfig,
} from "../lib/integrations";

const { render, summary, hmacHex } = __test;

describe("integrations — registry shape", () => {
  it("exposes one connector per declared kind", () => {
    for (const kind of INTEGRATION_KINDS) {
      expect(getConnector(kind)).toBeTruthy();
    }
  });

  it("validates kind + event whitelists", () => {
    expect(isValidKind("slack")).toBe(true);
    expect(isValidKind("not-a-thing")).toBe(false);
    expect(isValidEvent("push")).toBe(true);
    expect(isValidEvent("nope")).toBe(false);
  });

  it("CONNECTORS list matches INTEGRATION_KINDS", () => {
    const kinds = new Set(CONNECTORS.map((c) => c.kind));
    for (const k of INTEGRATION_KINDS) expect(kinds.has(k)).toBe(true);
  });
});

describe("integrations — isHttpUrl", () => {
  it("accepts http(s) only", () => {
    expect(isHttpUrl("https://example.com")).toBe(true);
    expect(isHttpUrl("http://example.com")).toBe(true);
    expect(isHttpUrl("ftp://example.com")).toBe(false);
    expect(isHttpUrl("not-a-url")).toBe(false);
    expect(isHttpUrl("")).toBe(false);
  });
});

describe("integrations — validateConfig", () => {
  it("flags missing required fields", () => {
    const r = validateConfig("slack", {});
    expect(r.ok).toBe(false);
    expect(r.error).toContain("Incoming webhook URL");
  });

  it("flags non-URL values for URL fields", () => {
    const r = validateConfig("slack", { webhookUrl: "not-a-url" });
    expect(r.ok).toBe(false);
    expect(r.error).toContain("URL");
  });

  it("accepts a valid Slack config", () => {
    const r = validateConfig("slack", {
      webhookUrl: "https://hooks.slack.com/services/xxx",
    });
    expect(r.ok).toBe(true);
  });

  it("rejects unknown kind", () => {
    const r = validateConfig("not-a-kind" as never, {});
    expect(r.ok).toBe(false);
  });

  it("PagerDuty requires only the routing key (no URL)", () => {
    expect(
      validateConfig("pagerduty", { integrationKey: "abc123" }).ok
    ).toBe(true);
    expect(validateConfig("pagerduty", {}).ok).toBe(false);
  });
});

describe("integrations — redactConfig", () => {
  it("redacts secret fields", () => {
    const out = redactConfig("slack", {
      webhookUrl: "https://hooks.slack.com/services/T0/B0/abc123",
      channel: "#eng",
    });
    expect(typeof out.webhookUrl).toBe("string");
    expect(String(out.webhookUrl)).toContain("…");
    expect(out.channel).toBe("#eng");
  });

  it("returns short-form for very short secrets", () => {
    const out = redactConfig("slack", { webhookUrl: "abcd" });
    expect(String(out.webhookUrl)).toBe("***");
  });

  it("ignores unknown fields", () => {
    const out = redactConfig("slack", { mystery: "value" });
    expect(out.mystery).toBeUndefined();
  });
});

describe("integrations — summary helper", () => {
  it("formats per-event human strings", () => {
    expect(summary("push", { repository: "a/b" })).toContain("Push to a/b");
    expect(summary("pr.opened", { repository: "a/b", title: "T" })).toContain(
      "PR opened"
    );
    expect(summary("deploy.failed", { repository: "a/b" })).toContain("FAILED");
  });
});

describe("integrations — render Slack", () => {
  it("returns null on missing webhook", () => {
    expect(
      render("slack", {}, "push", { repository: "a/b" })
    ).toBeNull();
  });
  it("renders a JSON Slack body", () => {
    const r = render(
      "slack",
      { webhookUrl: "https://hooks.slack.com/services/abc" },
      "push",
      { repository: "a/b" }
    )!;
    expect(r.url).toContain("hooks.slack.com");
    expect(r.headers["Content-Type"]).toBe("application/json");
    expect(JSON.parse(r.body).text).toContain("Push to a/b");
  });
  it("includes channel override when provided", () => {
    const r = render(
      "slack",
      {
        webhookUrl: "https://hooks.slack.com/services/abc",
        channel: "#eng",
      },
      "push",
      { repository: "a/b" }
    )!;
    expect(JSON.parse(r.body).channel).toBe("#eng");
  });
});

describe("integrations — render Discord", () => {
  it("renders a content payload", () => {
    const r = render(
      "discord",
      { webhookUrl: "https://discord.com/api/webhooks/x/y" },
      "pr.opened",
      { repository: "a/b", title: "PR" }
    )!;
    expect(JSON.parse(r.body).content).toContain("PR opened");
  });
});

describe("integrations — render Vercel", () => {
  it("only fires on push or deploy.success", () => {
    expect(
      render(
        "vercel",
        { deployHookUrl: "https://api.vercel.com/v1/integrations/deploy/x" },
        "issue.opened",
        { repository: "a/b" }
      )
    ).toBeNull();
    const r = render(
      "vercel",
      { deployHookUrl: "https://api.vercel.com/v1/integrations/deploy/x" },
      "push",
      { repository: "a/b" }
    )!;
    expect(r.url).toContain("vercel.com");
    expect(r.body).toBe("");
  });
});

describe("integrations — render PagerDuty", () => {
  it("only escalates failures", () => {
    expect(
      render("pagerduty", { integrationKey: "k" }, "push", { repository: "a/b" })
    ).toBeNull();
    const r = render("pagerduty", { integrationKey: "k" }, "deploy.failed", {
      repository: "a/b",
    })!;
    const body = JSON.parse(r.body);
    expect(body.routing_key).toBe("k");
    expect(body.event_action).toBe("trigger");
    expect(body.payload.severity).toBe("error");
  });
  it("respects user-set severity", () => {
    const r = render(
      "pagerduty",
      { integrationKey: "k", severity: "critical" },
      "ai.incident",
      { repository: "a/b", title: "down" }
    )!;
    expect(JSON.parse(r.body).payload.severity).toBe("critical");
  });
});

describe("integrations — render Datadog", () => {
  it("requires apiKey, defaults site, alert_type maps from event", () => {
    expect(render("datadog", {}, "push", { repository: "a/b" })).toBeNull();
    const r = render("datadog", { apiKey: "k" }, "deploy.failed", {
      repository: "a/b",
    })!;
    expect(r.url).toContain("api.datadoghq.com");
    expect(r.headers["DD-API-KEY"]).toBe("k");
    expect(JSON.parse(r.body).alert_type).toBe("error");
  });
});

describe("integrations — render generic_webhook", () => {
  it("requires a URL", () => {
    expect(
      render("generic_webhook", {}, "push", { repository: "a/b" })
    ).toBeNull();
  });
  it("signs body when secret is set", () => {
    const r = render(
      "generic_webhook",
      {
        webhookUrl: "https://example.com/hook",
        secret: "shh",
      },
      "push",
      { repository: "a/b" }
    )!;
    expect(r.headers["X-Gluecron-Signature"]).toContain("sha256=");
  });
  it("omits signature without secret", () => {
    const r = render(
      "generic_webhook",
      { webhookUrl: "https://example.com/hook" },
      "push",
      { repository: "a/b" }
    )!;
    expect(r.headers["X-Gluecron-Signature"]).toBeUndefined();
  });
});

describe("integrations — hmacHex", () => {
  it("produces deterministic sha256 digests", () => {
    const a = hmacHex("k", "body");
    const b = hmacHex("k", "body");
    expect(a).toBe(b);
    expect(a).toMatch(/^sha256=[0-9a-f]{64}$/);
  });
});

describe("integrations — INTEGRATION_EVENTS shape", () => {
  it("includes the canonical lifecycle events", () => {
    for (const ev of [
      "push",
      "pr.opened",
      "pr.merged",
      "deploy.success",
      "deploy.failed",
      "ai.repair",
      "ai.incident",
    ]) {
      expect(INTEGRATION_EVENTS).toContain(ev as never);
    }
  });
});