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
ai-tests.test.ts9.1 KB · 276 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
/**
 * Block D8 — AI-generated test suite tests.
 *
 * Pure-helper tests run directly; route tests tolerate the usual graceful
 * degradation envelope (200 / 404 / 503) because these suites run without
 * a live database.
 */

import { describe, it, expect } from "bun:test";
import {
  buildTestsPrompt,
  contentTypeFor,
  detectLanguage,
  detectTestFramework,
  generateTestStub,
} from "../lib/ai-tests";

// ---------------------------------------------------------------------------
// detectLanguage
// ---------------------------------------------------------------------------

describe("lib/ai-tests — detectLanguage", () => {
  it("maps .ts and .tsx to typescript", () => {
    expect(detectLanguage("src/foo.ts")).toBe("typescript");
    expect(detectLanguage("src/Foo.tsx")).toBe("typescript");
  });

  it("maps .js and .jsx to javascript", () => {
    expect(detectLanguage("lib/foo.js")).toBe("javascript");
    expect(detectLanguage("lib/bar.jsx")).toBe("javascript");
  });

  it("maps .py to python", () => {
    expect(detectLanguage("pkg/mod.py")).toBe("python");
  });

  it("maps .go to go", () => {
    expect(detectLanguage("cmd/main.go")).toBe("go");
  });

  it("maps .rs to rust", () => {
    expect(detectLanguage("src/lib.rs")).toBe("rust");
  });

  it("maps unknown / extensionless to other", () => {
    expect(detectLanguage("notes.txt")).toBe("other");
    expect(detectLanguage("Makefile")).toBe("other");
    expect(detectLanguage("README")).toBe("other");
  });
});

// ---------------------------------------------------------------------------
// detectTestFramework
// ---------------------------------------------------------------------------

describe("lib/ai-tests — detectTestFramework", () => {
  it("returns bun:test when repo looks bun-ish with jest-style test files", () => {
    const f = detectTestFramework("typescript", [
      "package.json",
      "bun.lockb",
      "src/__tests__/foo.test.ts",
      "src/__tests__/bar.test.ts",
    ]);
    expect(f).toBe("bun:test");
  });

  it("returns vitest when vitest.config.ts is present", () => {
    const f = detectTestFramework("typescript", [
      "package.json",
      "vitest.config.ts",
      "src/foo.ts",
    ]);
    expect(f).toBe("vitest");
  });

  it("returns jest when a jest.config.* file is present", () => {
    const f = detectTestFramework("javascript", [
      "package.json",
      "jest.config.js",
    ]);
    expect(f).toBe("jest");
  });

  it("returns pytest when pytest.ini is present", () => {
    const f = detectTestFramework("python", [
      "pytest.ini",
      "pkg/__init__.py",
      "pkg/mod.py",
    ]);
    expect(f).toBe("pytest");
  });

  it("returns pytest for python regardless of signals (sensible default)", () => {
    expect(detectTestFramework("python", [])).toBe("pytest");
  });

  it("returns go test for go language", () => {
    expect(detectTestFramework("go", ["go.mod"])).toBe("go test");
  });

  it("falls back to bun:test when repoFiles is empty", () => {
    expect(detectTestFramework("typescript", [])).toBe("bun:test");
    expect(detectTestFramework("javascript", [])).toBe("bun:test");
    expect(detectTestFramework("other", [])).toBe("bun:test");
  });
});

// ---------------------------------------------------------------------------
// buildTestsPrompt
// ---------------------------------------------------------------------------

describe("lib/ai-tests — buildTestsPrompt", () => {
  it("embeds the source code and file path", () => {
    const src = "export function add(a: number, b: number): number { return a + b; }";
    const prompt = buildTestsPrompt({
      path: "src/math.ts",
      language: "typescript",
      framework: "bun:test",
      sourceCode: src,
    });
    expect(prompt).toContain("src/math.ts");
    expect(prompt).toContain("bun:test");
    expect(prompt).toContain(src);
  });

  it("explicitly instructs Claude to emit FAILING stubs", () => {
    const prompt = buildTestsPrompt({
      path: "foo.ts",
      language: "typescript",
      framework: "bun:test",
      sourceCode: "export const x = 1;",
    });
    // Allow either casing — implementation uses *failing* with emphasis.
    expect(prompt.toLowerCase()).toContain("failing");
  });

  it("includes optional apiHints when provided", () => {
    const prompt = buildTestsPrompt({
      path: "foo.py",
      language: "python",
      framework: "pytest",
      sourceCode: "def add(a, b): return a + b",
      apiHints: "add() returns the arithmetic sum",
    });
    expect(prompt).toContain("add() returns the arithmetic sum");
  });

  it("truncates excessively large source files", () => {
    const huge = "a".repeat(50_000);
    const prompt = buildTestsPrompt({
      path: "big.ts",
      language: "typescript",
      framework: "bun:test",
      sourceCode: huge,
    });
    expect(prompt.length).toBeLessThan(huge.length + 4_000);
    expect(prompt).toContain("truncated");
  });
});

// ---------------------------------------------------------------------------
// generateTestStub
// ---------------------------------------------------------------------------

describe("lib/ai-tests — generateTestStub (AI unavailable)", () => {
  const hadKey = !!process.env.ANTHROPIC_API_KEY;
  const originalKey = process.env.ANTHROPIC_API_KEY;

  // Ensure we exercise the AI-unavailable path deterministically.
  if (hadKey) delete process.env.ANTHROPIC_API_KEY;

  it("returns empty code and framework=fallback when no API key is set", async () => {
    const result = await generateTestStub({
      path: "src/lib/foo.ts",
      language: "typescript",
      framework: "bun:test",
      sourceCode: "export const x = 1;",
    });
    expect(result.code).toBe("");
    expect(result.framework).toBe("fallback");
    expect(result.language).toBe("typescript");
  });

  it("still computes a sensible suggestedPath for bun:test", async () => {
    const result = await generateTestStub({
      path: "src/lib/foo.ts",
      language: "typescript",
      framework: "bun:test",
      sourceCode: "export const x = 1;",
    });
    expect(result.suggestedPath).toContain("foo");
    expect(result.suggestedPath).toContain(".test.");
  });

  it("picks `test_*.py` for pytest", async () => {
    const result = await generateTestStub({
      path: "pkg/widgets.py",
      language: "python",
      framework: "pytest",
      sourceCode: "def f(): pass",
    });
    expect(result.suggestedPath.endsWith("test_widgets.py")).toBe(true);
  });

  it("picks `*_test.go` for go test", async () => {
    const result = await generateTestStub({
      path: "cmd/server.go",
      language: "go",
      framework: "go test",
      sourceCode: "package main",
    });
    expect(result.suggestedPath.endsWith("server_test.go")).toBe(true);
  });

  // Restore the env we found on entry — other test files may depend on it.
  if (hadKey && originalKey !== undefined) {
    process.env.ANTHROPIC_API_KEY = originalKey;
  }
});

// ---------------------------------------------------------------------------
// contentTypeFor
// ---------------------------------------------------------------------------

describe("lib/ai-tests — contentTypeFor", () => {
  it("returns a typescript MIME for typescript", () => {
    expect(contentTypeFor("typescript")).toContain("typescript");
  });
  it("returns a python MIME for python", () => {
    expect(contentTypeFor("python")).toContain("python");
  });
  it("returns a safe plain fallback for unknown", () => {
    expect(contentTypeFor("other")).toContain("text/plain");
  });
});

// ---------------------------------------------------------------------------
// Route-level guard tests
// ---------------------------------------------------------------------------

describe("routes/ai-tests — guards", () => {
  it("GET /:owner/:repo/ai/tests renders a form or 404s when repo doesn't exist", async () => {
    const { default: aiTestsRoutes } = await import("../routes/ai-tests");
    const res = await aiTestsRoutes.request("/alice/does-not-exist/ai/tests");
    // 200 means the page rendered a form (repo exists, somehow), 404 means
    // our handler matched but the repo row was absent, 503 means the DB
    // proxy was down. Any of those is acceptable in CI.
    expect([200, 404, 503]).toContain(res.status);
  });

  it("POST /:owner/:repo/ai/tests/generate without auth redirects to /login or 404s", async () => {
    const { default: aiTestsRoutes } = await import("../routes/ai-tests");
    const res = await aiTestsRoutes.request(
      "/alice/does-not-exist/ai/tests/generate",
      {
        method: "POST",
        redirect: "manual",
        headers: { "content-type": "application/x-www-form-urlencoded" },
        body: "path=src/foo.ts",
      }
    );
    expect([302, 303, 404, 503]).toContain(res.status);
    if (res.status === 302 || res.status === 303) {
      const loc = res.headers.get("location") || "";
      expect(loc).toContain("/login");
    }
  });

  it("GET /:owner/:repo/ai/tests?format=raw without path returns 400 / 404 / 503", async () => {
    const { default: aiTestsRoutes } = await import("../routes/ai-tests");
    const res = await aiTestsRoutes.request(
      "/alice/does-not-exist/ai/tests?format=raw"
    );
    expect([400, 404, 503]).toContain(res.status);
  });
});