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
mcp-tools-expanded.test.ts13.3 KB · 380 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
379
380
/**
 * Tests for the expanded MCP tool surface in src/lib/mcp-tools-expanded.ts.
 *
 * We focus on:
 *   - Manifest shape: every new tool has a name, description, inputSchema
 *   - Default tools registry merges the expanded set in (≥ 50 total)
 *   - Input validation: each tool rejects malformed args (missing fields)
 *   - Auth gating: write tools throw INVALID_PARAMS without ctx.userId
 *   - Scope gating: admin-grade tools throw INVALID_PARAMS without 'admin'
 *   - A handful of happy-path branches that exercise pure logic without
 *     touching Postgres (uses HAS_DB skipIf where DB is required).
 *
 * Mirrors the conventions of `mcp.test.ts` + `mcp-write.test.ts`.
 */

import { describe, it, expect } from "bun:test";
import {
  ERR_INVALID_PARAMS,
  ERR_METHOD_NOT_FOUND,
  McpError,
} from "../lib/mcp";
import { defaultTools } from "../lib/mcp-tools";
import { expandedTools, __expandedTest } from "../lib/mcp-tools-expanded";

const HAS_DB = Boolean(process.env.DATABASE_URL);

const anonCtx = { userId: null, scopes: [] };
const authedCtx = { userId: "user-fixture-id", scopes: ["repo", "user", "admin"] };
const limitedCtx = { userId: "user-fixture-id", scopes: ["repo"] };

// ---------------------------------------------------------------------------
// Registry
// ---------------------------------------------------------------------------

describe("expanded tool registry", () => {
  it("exports at least 40 tools", () => {
    const tools = expandedTools();
    expect(Object.keys(tools).length).toBeGreaterThanOrEqual(40);
  });

  it("merges into defaultTools() to surpass 50 total", () => {
    const all = defaultTools();
    expect(Object.keys(all).length).toBeGreaterThanOrEqual(50);
  });

  it("every tool name is gluecron_-prefixed", () => {
    for (const handler of Object.values(expandedTools())) {
      expect(handler.tool.name).toMatch(/^gluecron_/);
    }
  });

  it("every tool has a non-trivial description and object schema", () => {
    for (const handler of Object.values(expandedTools())) {
      expect(typeof handler.tool.description).toBe("string");
      expect(handler.tool.description.length).toBeGreaterThan(10);
      expect(handler.tool.inputSchema.type).toBe("object");
      expect(typeof handler.tool.inputSchema.properties).toBe("object");
    }
  });

  it("does not clobber any existing 15-tool name", () => {
    const expandedNames = new Set(Object.keys(expandedTools()));
    const legacy = [
      "gluecron_repo_search",
      "gluecron_repo_read_file",
      "gluecron_repo_list_issues",
      "gluecron_repo_explain_codebase",
      "gluecron_repo_health",
      "gluecron_create_issue",
      "gluecron_comment_issue",
      "gluecron_close_issue",
      "gluecron_reopen_issue",
      "gluecron_create_pr",
      "gluecron_get_pr",
      "gluecron_list_prs",
      "gluecron_comment_pr",
      "gluecron_merge_pr",
      "gluecron_close_pr",
    ];
    for (const name of legacy) {
      expect(expandedNames.has(name)).toBe(false);
    }
  });
});

// ---------------------------------------------------------------------------
// Input validation
// ---------------------------------------------------------------------------

describe("input validation — malformed args throw McpError", () => {
  // We assert one schema-validation behaviour per tool: missing required
  // argument → McpError. Reading happens before any DB call so these
  // never need a live DB.
  const malformedCases: Array<{ name: string; args: Record<string, unknown> }> = [
    { name: "fork_repo", args: {} },
    { name: "delete_repo", args: { owner: "x" } },
    { name: "update_repo", args: {} },
    { name: "search_repos", args: {} },
    { name: "clone_url", args: { owner: "x" } },
    { name: "label_issue", args: { owner: "x", repo: "y" } },
    { name: "unlabel_issue", args: { owner: "x", repo: "y", number: 1 } },
    { name: "assign_issue", args: { owner: "x", repo: "y" } },
    { name: "search_issues", args: { owner: "x", repo: "y" } },
    { name: "request_changes", args: { owner: "x", repo: "y" } },
    { name: "search_prs", args: { owner: "x", repo: "y" } },
    { name: "open_draft_pr", args: { owner: "x", repo: "y" } },
    { name: "generate_pr_description", args: {} },
    { name: "read_file", args: { owner: "x", repo: "y" } },
    { name: "write_file", args: { owner: "x", repo: "y" } },
    { name: "delete_file", args: { owner: "x", repo: "y" } },
    { name: "list_tree", args: { owner: "x" } },
    { name: "get_commit", args: { owner: "x", repo: "y" } },
    { name: "create_branch", args: { owner: "x", repo: "y" } },
    { name: "atomic_multi_file_commit", args: { owner: "x", repo: "y" } },
    { name: "ship_spec", args: { owner: "x", repo: "y" } },
    { name: "voice_to_pr", args: { owner: "x", repo: "y" } },
    { name: "refactor_across_repos", args: {} },
    { name: "explain_repo", args: {} },
    { name: "chat_with_repo", args: { owner: "x", repo: "y" } },
    { name: "chat_continue", args: {} },
    { name: "generate_tests", args: { owner: "x", repo: "y" } },
    { name: "generate_commit_message", args: {} },
    { name: "generate_release_notes", args: { owner: "x", repo: "y" } },
    { name: "propose_migration", args: { owner: "x", repo: "y" } },
    { name: "propose_doc_update", args: { owner: "x" } },
    { name: "trigger_workflow", args: { owner: "x", repo: "y" } },
    { name: "get_workflow_run", args: { owner: "x", repo: "y" } },
    { name: "get_workflow_logs", args: { owner: "x", repo: "y" } },
    { name: "cancel_workflow_run", args: { owner: "x", repo: "y" } },
    { name: "get_preview_url", args: { owner: "x", repo: "y" } },
    { name: "provision_pr_sandbox", args: { owner: "x", repo: "y" } },
    { name: "create_agent_session", args: {} },
    { name: "acquire_lease", args: {} },
    { name: "release_lease", args: {} },
    { name: "get_agent_budget", args: {} },
    { name: "semantic_search", args: { owner: "x", repo: "y" } },
    { name: "find_symbol", args: { owner: "x", repo: "y" } },
    { name: "pr_status_summary", args: { owner: "x", repo: "y" } },
  ];

  for (const tc of malformedCases) {
    it(`gluecron_${tc.name} rejects missing required args`, async () => {
      const tools = expandedTools();
      // The malformed test cases above name the tool sans `gluecron_`
      // prefix so the tool name and the case name line up.
      const handler = tools[`gluecron_${tc.name}`];
      expect(handler).toBeDefined();
      // We always pass an authed ctx so the arg-validation path is the
      // *first* failure point — not the auth gate.
      await expect(handler.run(tc.args, authedCtx)).rejects.toThrow(McpError);
    });
  }
});

// ---------------------------------------------------------------------------
// Auth gates
// ---------------------------------------------------------------------------

describe("auth gates — write tools reject anonymous callers", () => {
  const writeTools = [
    {
      name: "gluecron_fork_repo",
      args: { owner: "a", repo: "b" },
    },
    {
      name: "gluecron_delete_repo",
      args: { owner: "a", repo: "b" },
    },
    {
      name: "gluecron_update_repo",
      args: { owner: "a", repo: "b", description: "x" },
    },
    {
      name: "gluecron_label_issue",
      args: { owner: "a", repo: "b", number: 1, labels: ["bug"] },
    },
    {
      name: "gluecron_unlabel_issue",
      args: { owner: "a", repo: "b", number: 1, label: "bug" },
    },
    {
      name: "gluecron_assign_issue",
      args: { owner: "a", repo: "b", number: 1, assignee: "x" },
    },
    {
      name: "gluecron_request_changes",
      args: { owner: "a", repo: "b", number: 1, body: "x" },
    },
    {
      name: "gluecron_open_draft_pr",
      args: { owner: "a", repo: "b", title: "t", head_branch: "h" },
    },
    {
      name: "gluecron_write_file",
      args: { owner: "a", repo: "b", path: "x", branch: "b", message: "m", content: "y" },
    },
    {
      name: "gluecron_delete_file",
      args: { owner: "a", repo: "b", path: "x", branch: "b", message: "m", sha: "0".repeat(40) },
    },
    {
      name: "gluecron_create_branch",
      args: { owner: "a", repo: "b", branch: "n", sha: "0".repeat(40) },
    },
    {
      name: "gluecron_atomic_multi_file_commit",
      args: {
        owner: "a",
        repo: "b",
        branch: "n",
        message: "m",
        changes: [{ path: "f", content: "x" }],
      },
    },
    {
      name: "gluecron_ship_spec",
      args: { owner: "a", repo: "b", title: "t", body: "x" },
    },
    {
      name: "gluecron_voice_to_pr",
      args: { owner: "a", repo: "b", transcript: "hi" },
    },
    {
      name: "gluecron_refactor_across_repos",
      args: { description: "x" },
    },
    {
      name: "gluecron_chat_with_repo",
      args: { owner: "a", repo: "b", message: "hi" },
    },
    {
      name: "gluecron_chat_continue",
      args: { chat_id: "x", message: "hi" },
    },
    {
      name: "gluecron_generate_tests",
      args: { owner: "a", repo: "b", number: 1 },
    },
    {
      name: "gluecron_propose_migration",
      args: {
        owner: "a",
        repo: "b",
        dependency: "d",
        from_version: "1",
        to_version: "2",
        base_sha: "x",
      },
    },
    {
      name: "gluecron_propose_doc_update",
      args: { owner: "a", repo: "b" },
    },
    {
      name: "gluecron_trigger_workflow",
      args: { owner: "a", repo: "b", filename: "ci.yml" },
    },
    {
      name: "gluecron_cancel_workflow_run",
      args: { owner: "a", repo: "b", run_id: "x" },
    },
    {
      name: "gluecron_provision_pr_sandbox",
      args: { owner: "a", repo: "b", number: 1 },
    },
    {
      name: "gluecron_create_agent_session",
      args: { name: "x" },
    },
    {
      name: "gluecron_acquire_lease",
      args: { agent_session_id: "x", target_type: "y", target_id: "z" },
    },
    {
      name: "gluecron_release_lease",
      args: { lease_id: "x" },
    },
    {
      name: "gluecron_get_agent_budget",
      args: { agent_session_id: "x" },
    },
    {
      name: "gluecron_ai_cost_summary",
      args: {},
    },
  ];

  for (const t of writeTools) {
    it(`${t.name} throws on anonymous ctx`, async () => {
      const tools = expandedTools();
      const handler = tools[t.name];
      await expect(handler.run(t.args, anonCtx)).rejects.toThrow(McpError);
    });
  }
});

// ---------------------------------------------------------------------------
// Scope gates
// ---------------------------------------------------------------------------

describe("scope gates", () => {
  it("delete_repo requires 'admin' scope", async () => {
    const { deleteRepo } = __expandedTest;
    await expect(
      deleteRepo.run({ owner: "a", repo: "b" }, limitedCtx)
    ).rejects.toMatchObject({ code: ERR_INVALID_PARAMS });
  });

  it("create_agent_session requires 'admin' scope", async () => {
    const { createAgentSession } = __expandedTest;
    await expect(
      createAgentSession.run({ name: "agent-x" }, limitedCtx)
    ).rejects.toMatchObject({ code: ERR_INVALID_PARAMS });
  });

  it("requireScope helper passes when 'admin' is held", () => {
    const { requireScope } = __expandedTest;
    expect(() =>
      requireScope({ userId: "u", scopes: ["admin"] }, "repo", "x")
    ).not.toThrow();
  });

  it("requireScope helper passes when undefined scopes (legacy permissive)", () => {
    const { requireScope } = __expandedTest;
    expect(() =>
      requireScope({ userId: "u" }, "admin", "x")
    ).not.toThrow();
  });
});

// ---------------------------------------------------------------------------
// Pure-logic happy paths
// ---------------------------------------------------------------------------

describe("pure-logic tools", () => {
  it("generate_commit_message returns a subject + body", async () => {
    const { generateCommitMessageTool } = __expandedTest;
    const out = (await generateCommitMessageTool.run(
      { diff: "diff --git a/x b/x\n+hello\n" },
      authedCtx
    )) as { subject: string; body: string };
    expect(typeof out.subject).toBe("string");
    expect(out.subject.length).toBeGreaterThan(0);
  });

  it("generate_pr_description routes through ai-commit-message", async () => {
    const { generatePrDescription } = __expandedTest;
    const out = (await generatePrDescription.run(
      { diff: "diff --git a/x b/x\n+hi\n" },
      authedCtx
    )) as { subject: string };
    expect(typeof out.subject).toBe("string");
  });

  it.skipIf(!HAS_DB)("clone_url throws METHOD_NOT_FOUND for missing repo", async () => {
    // resolveAccessibleRepo is the first gate; a non-existent repo
    // surfaces as a method_not_found error code regardless of caller
    // auth (privacy contract).
    const { cloneUrl } = __expandedTest;
    await expect(
      cloneUrl.run({ owner: "nobody-xyz-fixture", repo: "nope" }, anonCtx)
    ).rejects.toMatchObject({ code: ERR_METHOD_NOT_FOUND });
  });
});

// ---------------------------------------------------------------------------
// DB-backed smoke (HAS_DB gated)
// ---------------------------------------------------------------------------

describe.skipIf(!HAS_DB)("DB-backed smoke checks", () => {
  it("search_repos runs against the live DB and returns a shaped payload", async () => {
    const { searchRepos } = __expandedTest;
    const out = (await searchRepos.run(
      { query: "test", limit: 1 },
      anonCtx
    )) as { total: number; repos: unknown[] };
    expect(typeof out.total).toBe("number");
    expect(Array.isArray(out.repos)).toBe(true);
  });
});