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
repo-pulse.test.ts9.9 KB · 329 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/**
 * Block J18 — Repository pulse. Pure rollup unit tests + a route-auth
 * smoke to make sure the pulse page is wired up.
 */

import { describe, it, expect } from "bun:test";
import app from "../app";
import {
  PULSE_WINDOWS,
  DEFAULT_WINDOW,
  parseWindow,
  windowStart,
  windowDays,
  summariseCommits,
  summarisePrs,
  summariseIssues,
  buildPulseReport,
  __internal,
  type PulseCommit,
  type PulsePr,
  type PulseIssue,
} from "../lib/repo-pulse";

const NOW = new Date("2026-04-15T12:00:00Z");

describe("repo-pulse — parseWindow", () => {
  it("accepts the four canonical windows", () => {
    for (const w of PULSE_WINDOWS) expect(parseWindow(w)).toBe(w);
  });

  it("falls back to DEFAULT_WINDOW on garbage", () => {
    expect(parseWindow("")).toBe(DEFAULT_WINDOW);
    expect(parseWindow("forever")).toBe(DEFAULT_WINDOW);
    expect(parseWindow(null)).toBe(DEFAULT_WINDOW);
    expect(parseWindow(undefined)).toBe(DEFAULT_WINDOW);
    expect(parseWindow(42)).toBe(DEFAULT_WINDOW);
  });
});

describe("repo-pulse — windowStart + windowDays", () => {
  it("subtracts the correct day count from `now`", () => {
    expect(windowDays("1d")).toBe(1);
    expect(windowDays("7d")).toBe(7);
    expect(windowDays("30d")).toBe(30);
    expect(windowDays("90d")).toBe(90);
    const s = windowStart(NOW, "7d");
    expect(NOW.getTime() - s.getTime()).toBe(7 * 24 * 3600 * 1000);
  });

  it("does not mutate `now`", () => {
    const t0 = NOW.getTime();
    windowStart(NOW, "30d");
    expect(NOW.getTime()).toBe(t0);
  });
});

describe("repo-pulse — summariseCommits", () => {
  const commits: PulseCommit[] = [
    // In window
    { sha: "a", author: "Alice", authorEmail: "a@x", date: "2026-04-14T00:00:00Z" },
    { sha: "b", author: "Bob", authorEmail: "b@x", date: "2026-04-13T00:00:00Z" },
    { sha: "c", author: "Alice", authorEmail: "a@x", date: "2026-04-12T00:00:00Z" },
    // Out of window (older than 7d)
    { sha: "d", author: "Alice", authorEmail: "a@x", date: "2026-04-01T00:00:00Z" },
  ];

  it("counts only commits in [start, end]", () => {
    const start = windowStart(NOW, "7d");
    const r = summariseCommits(commits, start, NOW);
    expect(r.total).toBe(3);
    expect(r.byAuthor.length).toBe(2);
  });

  it("sorts contributors by count desc, name asc as tiebreak", () => {
    const start = windowStart(NOW, "7d");
    const r = summariseCommits(commits, start, NOW);
    expect(r.byAuthor[0].author).toBe("Alice");
    expect(r.byAuthor[0].count).toBe(2);
    expect(r.byAuthor[1].author).toBe("Bob");
  });

  it("groups by lowercased email, falling back to name", () => {
    const cs: PulseCommit[] = [
      { sha: "1", author: "Alice", authorEmail: "A@X", date: "2026-04-14T00:00:00Z" },
      { sha: "2", author: "Alice", authorEmail: "a@x", date: "2026-04-13T00:00:00Z" },
    ];
    const r = summariseCommits(cs, windowStart(NOW, "7d"), NOW);
    expect(r.byAuthor.length).toBe(1);
    expect(r.byAuthor[0].count).toBe(2);
  });

  it("tracks firstSha + lastSha", () => {
    const start = windowStart(NOW, "7d");
    const r = summariseCommits(commits, start, NOW);
    // Commits are newest-first, so lastSha is the newest (first in array).
    expect(r.lastSha).toBe("a");
    expect(r.firstSha).toBe("c");
  });

  it("returns zero counts on empty input", () => {
    const r = summariseCommits([], windowStart(NOW, "7d"), NOW);
    expect(r.total).toBe(0);
    expect(r.byAuthor).toEqual([]);
    expect(r.firstSha).toBeNull();
    expect(r.lastSha).toBeNull();
  });

  it("ignores commits with invalid dates", () => {
    const cs: PulseCommit[] = [
      { sha: "1", author: "X", authorEmail: "x@x", date: "not-a-date" },
      { sha: "2", author: "Y", authorEmail: "y@x", date: "2026-04-14T00:00:00Z" },
    ];
    const r = summariseCommits(cs, windowStart(NOW, "7d"), NOW);
    expect(r.total).toBe(1);
  });

  it("falls back to (unknown) when author + email are both empty", () => {
    const cs: PulseCommit[] = [
      { sha: "1", author: "", authorEmail: "", date: "2026-04-14T00:00:00Z" },
    ];
    const r = summariseCommits(cs, windowStart(NOW, "7d"), NOW);
    expect(r.byAuthor[0].author).toBe("(unknown)");
  });
});

describe("repo-pulse — summarisePrs", () => {
  const iso = (s: string) => s;
  const prs: PulsePr[] = [
    // Opened + merged in window
    {
      number: 1,
      title: "A",
      state: "merged",
      createdAt: iso("2026-04-14T00:00:00Z"),
      updatedAt: iso("2026-04-14T00:00:00Z"),
      closedAt: iso("2026-04-14T00:00:00Z"),
      mergedAt: iso("2026-04-14T00:00:00Z"),
    },
    // Opened in window, still open
    {
      number: 2,
      title: "B",
      state: "open",
      createdAt: iso("2026-04-13T00:00:00Z"),
      updatedAt: iso("2026-04-14T00:00:00Z"),
      closedAt: null,
      mergedAt: null,
    },
    // Closed (not merged) in window
    {
      number: 3,
      title: "C",
      state: "closed",
      createdAt: iso("2026-01-01T00:00:00Z"),
      updatedAt: iso("2026-04-12T00:00:00Z"),
      closedAt: iso("2026-04-12T00:00:00Z"),
      mergedAt: null,
    },
    // Entirely outside window
    {
      number: 4,
      title: "D",
      state: "merged",
      createdAt: iso("2026-01-01T00:00:00Z"),
      updatedAt: iso("2026-01-02T00:00:00Z"),
      closedAt: iso("2026-01-02T00:00:00Z"),
      mergedAt: iso("2026-01-02T00:00:00Z"),
    },
  ];

  const start = windowStart(NOW, "7d");

  it("counts opened/merged/closed correctly", () => {
    const r = summarisePrs(prs, start, NOW);
    expect(r.opened).toBe(2);
    expect(r.mergedCount).toBe(1);
    expect(r.closed).toBe(1);
  });

  it("reports `active` only for state=open with updatedAt in window", () => {
    const r = summarisePrs(prs, start, NOW);
    expect(r.active).toBe(1);
  });

  it("includes the merged PR in mergedList + opened PRs in openedList", () => {
    const r = summarisePrs(prs, start, NOW);
    expect(r.mergedList.map((p) => p.number)).toEqual([1]);
    expect(r.openedList.map((p) => p.number).sort()).toEqual([1, 2]);
  });

  it("accepts Date instances as well as ISO strings", () => {
    const withDates: PulsePr[] = [
      {
        number: 5,
        title: "E",
        state: "merged",
        createdAt: new Date("2026-04-14T00:00:00Z"),
        updatedAt: new Date("2026-04-14T00:00:00Z"),
        closedAt: new Date("2026-04-14T00:00:00Z"),
        mergedAt: new Date("2026-04-14T00:00:00Z"),
      },
    ];
    const r = summarisePrs(withDates, start, NOW);
    expect(r.opened).toBe(1);
    expect(r.mergedCount).toBe(1);
  });

  it("handles empty list", () => {
    const r = summarisePrs([], start, NOW);
    expect(r.opened).toBe(0);
    expect(r.mergedCount).toBe(0);
    expect(r.closed).toBe(0);
    expect(r.active).toBe(0);
  });
});

describe("repo-pulse — summariseIssues", () => {
  const start = windowStart(NOW, "7d");
  const issueList: PulseIssue[] = [
    {
      number: 1,
      title: "x",
      state: "open",
      createdAt: "2026-04-14T00:00:00Z",
      updatedAt: "2026-04-14T00:00:00Z",
      closedAt: null,
    },
    {
      number: 2,
      title: "y",
      state: "closed",
      createdAt: "2026-04-01T00:00:00Z",
      updatedAt: "2026-04-13T00:00:00Z",
      closedAt: "2026-04-13T00:00:00Z",
    },
    // Out of window
    {
      number: 3,
      title: "z",
      state: "closed",
      createdAt: "2026-01-01T00:00:00Z",
      updatedAt: "2026-01-02T00:00:00Z",
      closedAt: "2026-01-02T00:00:00Z",
    },
  ];

  it("buckets opened / closed / active", () => {
    const r = summariseIssues(issueList, start, NOW);
    expect(r.opened).toBe(1);
    expect(r.closed).toBe(1);
    expect(r.active).toBe(1);
  });

  it("populates openedList + closedList", () => {
    const r = summariseIssues(issueList, start, NOW);
    expect(r.openedList.map((i) => i.number)).toEqual([1]);
    expect(r.closedList.map((i) => i.number)).toEqual([2]);
  });

  it("tolerates null closedAt / weird dates", () => {
    const bad: PulseIssue[] = [
      {
        number: 99,
        title: "bad",
        state: "open",
        createdAt: "oops",
        updatedAt: "also oops",
        closedAt: null,
      },
    ];
    const r = summariseIssues(bad, start, NOW);
    expect(r.opened).toBe(0);
    expect(r.closed).toBe(0);
    expect(r.active).toBe(0);
  });
});

describe("repo-pulse — buildPulseReport", () => {
  it("bundles all three rollups with a resolved window", () => {
    const r = buildPulseReport({
      window: "7d",
      now: NOW,
      commits: [
        {
          sha: "a",
          author: "A",
          authorEmail: "a@x",
          date: "2026-04-14T00:00:00Z",
        },
      ],
      prs: [],
      issues: [],
    });
    expect(r.window).toBe("7d");
    expect(r.days).toBe(7);
    expect(r.start < r.end).toBe(true);
    expect(r.commits.total).toBe(1);
    expect(r.prs.opened).toBe(0);
    expect(r.issues.opened).toBe(0);
  });
});

describe("repo-pulse — __internal", () => {
  it("re-exports the pure helpers for parity", () => {
    expect(__internal.parseWindow).toBe(parseWindow);
    expect(__internal.windowStart).toBe(windowStart);
    expect(__internal.windowDays).toBe(windowDays);
    expect(__internal.summariseCommits).toBe(summariseCommits);
    expect(__internal.summarisePrs).toBe(summarisePrs);
    expect(__internal.summariseIssues).toBe(summariseIssues);
    expect(__internal.buildPulseReport).toBe(buildPulseReport);
    expect(__internal.PULSE_WINDOWS).toBe(PULSE_WINDOWS);
    expect(__internal.DEFAULT_WINDOW as string).toBe(DEFAULT_WINDOW);
  });
});

describe("repo-pulse — routes", () => {
  it("GET /:o/:r/pulse returns 404 for unknown repo", async () => {
    const res = await app.request("/alice/nope/pulse");
    expect(res.status).toBe(404);
  });

  it("GET /:o/:r/pulse?window=bogus normalises to default", async () => {
    // Route resolves repo first, so we still expect 404 for unknown — this
    // asserts the route accepts the query without crashing.
    const res = await app.request("/alice/nope/pulse?window=bogus");
    expect(res.status).toBe(404);
  });
});