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
github-import.test.ts11.1 KB · 378 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/**
 * Block L — GitHub importer tests.
 *
 * Tests focus on the pure helpers (URL construction, pagination, filtering,
 * mappers). DB-backed runImport is exercised via the integration suite.
 */

import { describe, it, expect } from "bun:test";
import app from "../app";
import {
  buildAuthedCloneUrl,
  filterIssuesOnly,
  mapIssue,
  mapLabel,
  mapPull,
  mapRelease,
  normaliseColor,
  paginate,
  parseNextLink,
  redactCloneUrl,
  type GhIssue,
  type GhPull,
  type GhRelease,
} from "../lib/github-import";

// ---------------------------------------------------------------------------
// buildAuthedCloneUrl
// ---------------------------------------------------------------------------

describe("buildAuthedCloneUrl", () => {
  it("builds https clone URL with encoded token", () => {
    const r = buildAuthedCloneUrl("ghp_abc123", "octocat", "hello");
    expect(r.ok).toBe(true);
    if (r.ok) {
      expect(r.data).toBe(
        "https://x-access-token:ghp_abc123@github.com/octocat/hello.git"
      );
    }
  });

  it("rejects tokens containing whitespace/CRLF", () => {
    expect(buildAuthedCloneUrl("abc\ndef", "o", "r").ok).toBe(false);
    expect(buildAuthedCloneUrl("abc def", "o", "r").ok).toBe(false);
    expect(buildAuthedCloneUrl("abc\rdef", "o", "r").ok).toBe(false);
  });

  it("rejects invalid owner/repo", () => {
    expect(buildAuthedCloneUrl("t", "bad owner", "r").ok).toBe(false);
    expect(buildAuthedCloneUrl("t", "good", "bad/repo").ok).toBe(false);
  });

  it("url-encodes special chars in the token", () => {
    const r = buildAuthedCloneUrl("a%b", "o", "r");
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.data).toContain("a%25b");
  });
});

describe("redactCloneUrl", () => {
  it("redacts token from authed URL", () => {
    const input =
      "fatal: https://x-access-token:ghp_abc@github.com/o/r.git not found";
    expect(redactCloneUrl(input)).toBe(
      "fatal: https://***@github.com/o/r.git not found"
    );
  });
  it("is a no-op for plain URLs", () => {
    expect(redactCloneUrl("https://example.com")).toBe("https://example.com");
  });
});

// ---------------------------------------------------------------------------
// parseNextLink
// ---------------------------------------------------------------------------

describe("parseNextLink", () => {
  it("extracts next URL from Link header", () => {
    const link =
      '<https://api.github.com/repos/o/r/issues?page=2>; rel="next", <https://api.github.com/repos/o/r/issues?page=5>; rel="last"';
    expect(parseNextLink(link)).toBe(
      "https://api.github.com/repos/o/r/issues?page=2"
    );
  });
  it("returns undefined when no next link", () => {
    expect(parseNextLink(null)).toBeUndefined();
    expect(parseNextLink('<...>; rel="prev"')).toBeUndefined();
  });
});

// ---------------------------------------------------------------------------
// paginate — mocked fetch
// ---------------------------------------------------------------------------

describe("paginate", () => {
  function mkFetch(pages: unknown[][]): typeof fetch {
    let i = 0;
    return (async () => {
      const body = pages[i] ?? [];
      const linkNext =
        i < pages.length - 1
          ? `<https://api.github.com/next?page=${i + 2}>; rel="next"`
          : undefined;
      i += 1;
      return new Response(JSON.stringify(body), {
        status: 200,
        headers: linkNext ? { Link: linkNext } : {},
      });
    }) as unknown as typeof fetch;
  }

  it("walks all pages under cap", async () => {
    const f = mkFetch([[1, 2], [3, 4], [5]]);
    const r = await paginate<number>("t", "https://api.github.com/first", 100, f);
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.data).toEqual([1, 2, 3, 4, 5]);
  });

  it("stops at cap even mid-page", async () => {
    const f = mkFetch([[1, 2, 3], [4, 5, 6]]);
    const r = await paginate<number>("t", "https://api.github.com/first", 4, f);
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.data).toEqual([1, 2, 3, 4]);
  });

  it("returns error on non-2xx response", async () => {
    const f = (async () =>
      new Response("{}", { status: 404 })) as unknown as typeof fetch;
    const r = await paginate("t", "https://api.github.com/first", 10, f);
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.error).toContain("404");
  });

  it("returns error when body is not an array", async () => {
    const f = (async () =>
      new Response("{}", { status: 200 })) as unknown as typeof fetch;
    const r = await paginate("t", "https://api.github.com/first", 10, f);
    expect(r.ok).toBe(false);
  });

  it("degrades to ok:false when fetch throws", async () => {
    const f = (async () => {
      throw new Error("network");
    }) as unknown as typeof fetch;
    const r = await paginate("t", "https://api.github.com/first", 10, f);
    expect(r.ok).toBe(false);
  });
});

// ---------------------------------------------------------------------------
// filterIssuesOnly
// ---------------------------------------------------------------------------

describe("filterIssuesOnly", () => {
  it("drops entries that have a pull_request key", () => {
    const items: GhIssue[] = [
      mkIssue(1, "issue a", null),
      mkIssue(2, "issue b", { url: "x" }),
      mkIssue(3, "issue c", null),
    ];
    const out = filterIssuesOnly(items);
    expect(out.length).toBe(2);
    expect(out.map((i) => i.number)).toEqual([1, 3]);
  });
});

function mkIssue(
  n: number,
  title: string,
  pullRequest: { url: string } | null
): GhIssue {
  return {
    number: n,
    title,
    body: null,
    state: "open",
    created_at: "2024-01-01T00:00:00Z",
    updated_at: "2024-01-01T00:00:00Z",
    closed_at: null,
    labels: [],
    pull_request: pullRequest,
  };
}

// ---------------------------------------------------------------------------
// Mappers
// ---------------------------------------------------------------------------

describe("normaliseColor", () => {
  it("accepts 6-hex without hash", () => {
    expect(normaliseColor("ff8800")).toBe("#ff8800");
  });
  it("accepts 6-hex with hash", () => {
    expect(normaliseColor("#ff8800")).toBe("#ff8800");
  });
  it("lowercases mixed case", () => {
    expect(normaliseColor("FF88aa")).toBe("#ff88aa");
  });
  it("falls back for invalid input", () => {
    expect(normaliseColor("not-a-color")).toBe("#8b949e");
    expect(normaliseColor(null)).toBe("#8b949e");
    expect(normaliseColor("")).toBe("#8b949e");
    expect(normaliseColor("ff88")).toBe("#8b949e");
  });
});

describe("mapLabel", () => {
  it("maps shape + clamps name length", () => {
    const r = mapLabel(
      {
        name: "x".repeat(200),
        color: "00aabb",
        description: "y".repeat(500),
      },
      "repo-1"
    );
    expect(r.repositoryId).toBe("repo-1");
    expect(r.name.length).toBe(50);
    expect(r.color).toBe("#00aabb");
    expect(r.description?.length).toBe(200);
  });
});

describe("mapIssue", () => {
  it("preserves closed state + closedAt", () => {
    const r = mapIssue(
      {
        number: 1,
        title: "t",
        body: "b",
        state: "closed",
        created_at: "2024-01-01T00:00:00Z",
        updated_at: "2024-01-01T00:00:00Z",
        closed_at: "2024-02-01T00:00:00Z",
        labels: [],
      },
      "repo",
      "user"
    );
    expect(r.state).toBe("closed");
    expect(r.closedAt).toBeInstanceOf(Date);
  });
  it("defaults to open + null closedAt", () => {
    const r = mapIssue(
      {
        number: 1,
        title: "t",
        body: null,
        state: "open",
        created_at: "",
        updated_at: "",
        closed_at: null,
        labels: [],
      },
      "repo",
      "user"
    );
    expect(r.state).toBe("open");
    expect(r.closedAt).toBeNull();
  });
});

describe("mapPull", () => {
  const base: GhPull = {
    number: 1,
    title: "t",
    body: null,
    state: "open",
    merged_at: null,
    closed_at: null,
    created_at: "",
    updated_at: "",
    draft: false,
    base: { ref: "main" },
    head: { ref: "feature" },
  };

  it("open when neither merged nor closed", () => {
    expect(mapPull(base, "r", "u").state).toBe("open");
  });
  it("merged takes precedence over closed", () => {
    const r = mapPull(
      { ...base, state: "closed", merged_at: "2024-02-01T00:00:00Z" },
      "r",
      "u"
    );
    expect(r.state).toBe("merged");
    expect(r.mergedAt).toBeInstanceOf(Date);
  });
  it("closed when state=closed and no merge", () => {
    const r = mapPull(
      { ...base, state: "closed", closed_at: "2024-02-01T00:00:00Z" },
      "r",
      "u"
    );
    expect(r.state).toBe("closed");
    expect(r.closedAt).toBeInstanceOf(Date);
  });
  it("keeps branches verbatim", () => {
    expect(mapPull(base, "r", "u").baseBranch).toBe("main");
    expect(mapPull(base, "r", "u").headBranch).toBe("feature");
  });
  it("propagates isDraft", () => {
    expect(mapPull({ ...base, draft: true }, "r", "u").isDraft).toBe(true);
  });
});

describe("mapRelease", () => {
  it("falls back to tag_name when name is null", () => {
    const gh: GhRelease = {
      tag_name: "v1.0",
      name: null,
      body: null,
      target_commitish: "main",
      prerelease: false,
      draft: false,
      created_at: "",
      published_at: null,
    };
    expect(mapRelease(gh, "r", "u").name).toBe("v1.0");
  });
  it("passes through draft + prerelease flags", () => {
    const gh: GhRelease = {
      tag_name: "v1",
      name: "One",
      body: null,
      target_commitish: "main",
      prerelease: true,
      draft: true,
      created_at: "",
      published_at: "2024-01-01T00:00:00Z",
    };
    const r = mapRelease(gh, "r", "u");
    expect(r.isDraft).toBe(true);
    expect(r.isPrerelease).toBe(true);
    expect(r.publishedAt).toBeInstanceOf(Date);
  });
});

// ---------------------------------------------------------------------------
// Route auth smokes
// ---------------------------------------------------------------------------

describe("github-import — route auth smokes", () => {
  it("GET /new/import without session → 302 /login", async () => {
    const res = await app.fetch(new Request("http://test/new/import"));
    expect(res.status).toBe(302);
    expect(res.headers.get("location")).toMatch(/\/login/);
  });

  it("POST /new/import without session → 302 /login", async () => {
    const res = await app.fetch(
      new Request("http://test/new/import", {
        method: "POST",
        headers: { "content-type": "application/x-www-form-urlencoded" },
        body: new URLSearchParams({
          source: "octocat/hello",
          token: "ghp_x",
          name: "hello",
          visibility: "public",
        }),
      })
    );
    expect(res.status).toBe(302);
    expect(res.headers.get("location")).toMatch(/\/login/);
  });

  it("GET /api/imports/:id without session → 401 JSON", async () => {
    const res = await app.fetch(
      new Request(
        "http://test/api/imports/00000000-0000-0000-0000-000000000000",
        { headers: { accept: "application/json" } }
      )
    );
    // Bearer-less request to a JSON endpoint under requireAuth → 401.
    // (Cookie-less GETs to non-API paths redirect; this path is /api/*.)
    expect([302, 401]).toContain(res.status);
  });
});