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
post-deploy-smoke.test.ts12.9 KB · 388 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
381
382
383
384
385
386
387
388
/**
 * Block S1+S3 — post-deploy smoke suite tests.
 *
 * Covers the pure layer of `src/lib/post-deploy-smoke.ts`:
 *   - CHECKS array shape (every check has name + url + at least one
 *     expectation)
 *   - assertion helpers (assertStatus / assertKey / assertContains)
 *   - the runner returns ok=false when ANY check fails, ok=true when all
 *     green
 *   - missingMigrations + latestMigration helpers
 *
 * No real network, no mock pollution: every test supplies its own
 * fetch impl via DI.
 */

import { describe, it, expect } from "bun:test";
import {
  CHECKS,
  assertStatus,
  assertKey,
  assertContains,
  runChecks,
  formatTable,
  missingMigrations,
  latestMigration,
  type Check,
  type FetchLike,
} from "../lib/post-deploy-smoke";

// ─── helpers ────────────────────────────────────────────────────────

function res(status: number, body: string): { status: number; text: () => Promise<string> } {
  return { status, text: async () => body };
}

function jsonRes(status: number, obj: unknown) {
  return res(status, JSON.stringify(obj));
}

function alwaysOkFetch(): FetchLike {
  return async (url) => {
    // Default-OK responses that pass every shipped check in CHECKS.
    if (url.endsWith("/healthz"))
      return jsonRes(200, { ok: true, uptimeMs: 1 });
    if (url.endsWith("/readyz")) return jsonRes(200, { ok: true });
    if (url.endsWith("/api/version"))
      return jsonRes(200, { sha: "abcdef0", branch: "main", builtAt: "x", uptimeMs: 1 });
    if (url.endsWith("/login"))
      return res(200, "<html><body><h2>Sign in</h2></body></html>");
    if (url.endsWith("/register"))
      return res(200, "<html><body><h2>Create account</h2></body></html>");
    if (url.endsWith("/mcp"))
      return jsonRes(200, { serverInfo: { name: "gluecron" } });
    if (url.endsWith("/api/v2/healthz")) return res(404, "not found");
    if (url.endsWith("/demo")) return res(302, "");
    return res(200, "<html></html>");
  };
}

// ─── CHECKS array shape ─────────────────────────────────────────────

describe("CHECKS array shape", () => {
  it("has at least the 15 critical endpoints the owner specified", () => {
    expect(CHECKS.length).toBeGreaterThanOrEqual(15);
  });

  it("every check has a non-empty name + url + at least one expectation", () => {
    for (const c of CHECKS) {
      expect(typeof c.name).toBe("string");
      expect(c.name.length).toBeGreaterThan(0);
      expect(typeof c.url).toBe("string");
      expect(c.url.startsWith("/")).toBe(true);
      // expectStatus is required; either expectKey or expectContains may
      // additionally be supplied but a check is valid with just status.
      expect(c.expectStatus !== undefined).toBe(true);
    }
  });

  it("covers the specific endpoints the spec called out", () => {
    const names = CHECKS.map((c) => c.name);
    for (const required of [
      "healthz",
      "readyz",
      "version",
      "login renders",
      "register renders",
      "landing renders",
      "explore renders",
      "demo renders",
      "pricing renders",
      "status renders",
      "api v2 health",
      "mcp discovery",
      "manifest",
      "sw",
      "dxt download",
    ]) {
      expect(names).toContain(required);
    }
  });

  it("api v2 health accepts 200 OR 404 (route is optional)", () => {
    const v2 = CHECKS.find((c) => c.name === "api v2 health");
    expect(v2).toBeDefined();
    expect(Array.isArray(v2!.expectStatus)).toBe(true);
    expect((v2!.expectStatus as number[]).sort()).toEqual([200, 404]);
  });
});

// ─── Assertion helpers ──────────────────────────────────────────────

describe("assertStatus", () => {
  it("returns null when the actual status matches a single expected", () => {
    expect(assertStatus(200, 200)).toBeNull();
  });

  it("returns null when the actual status matches one of an array", () => {
    expect(assertStatus(404, [200, 404])).toBeNull();
    expect(assertStatus(200, [200, 404])).toBeNull();
  });

  it("returns a descriptive error when the status doesn't match", () => {
    const err = assertStatus(500, 200);
    expect(err).not.toBeNull();
    expect(err!).toContain("200");
    expect(err!).toContain("500");
  });

  it("returns an error including all acceptable codes when given an array", () => {
    const err = assertStatus(500, [200, 404]);
    expect(err!).toContain("200");
    expect(err!).toContain("404");
  });
});

describe("assertKey", () => {
  it("returns null when the JSON has the key", () => {
    expect(assertKey(`{"ok":true}`, "ok")).toBeNull();
    expect(assertKey(`{"sha":"abc","x":1}`, "sha")).toBeNull();
  });

  it("returns null even when the key's value is null/0/empty (presence-only)", () => {
    expect(assertKey(`{"ok":null}`, "ok")).toBeNull();
    expect(assertKey(`{"ok":0}`, "ok")).toBeNull();
    expect(assertKey(`{"ok":""}`, "ok")).toBeNull();
  });

  it("returns an error when the body isn't JSON", () => {
    expect(assertKey("<html></html>", "ok")).not.toBeNull();
  });

  it("returns an error when the body is JSON but lacks the key", () => {
    expect(assertKey(`{"other":1}`, "ok")).not.toBeNull();
  });

  it("returns an error when the body is a JSON array (not an object)", () => {
    expect(assertKey(`[1,2,3]`, "ok")).not.toBeNull();
  });

  it("doesn't fall for prototype-pollution lookups", () => {
    // `__proto__` is not an own property of {}, so the helper must
    // treat it as missing. (Object.prototype.hasOwnProperty.call is the
    // implementation choice.)
    expect(assertKey(`{}`, "toString")).not.toBeNull();
    expect(assertKey(`{}`, "__proto__")).not.toBeNull();
  });
});

describe("assertContains", () => {
  it("returns null when the body contains the substring", () => {
    expect(assertContains("hello world", "world")).toBeNull();
  });

  it("returns an error including the missing substring", () => {
    const err = assertContains("hello", "world");
    expect(err).not.toBeNull();
    expect(err!).toContain("world");
  });

  it("is case-sensitive (matches the production check exactly)", () => {
    expect(assertContains("Sign In", "Sign in")).not.toBeNull();
  });
});

// ─── runChecks runner ───────────────────────────────────────────────

describe("runChecks", () => {
  it("returns ok=true and failed=0 when every check passes", async () => {
    const summary = await runChecks({
      baseUrl: "http://localhost:3010",
      fetchImpl: alwaysOkFetch(),
    });
    expect(summary.ok).toBe(true);
    expect(summary.failed).toBe(0);
    expect(summary.passed).toBe(summary.results.length);
    expect(summary.results.length).toBe(CHECKS.length);
  });

  it("returns ok=false and failed>=1 when any check fails", async () => {
    const fetchImpl: FetchLike = async (url) => {
      // Break /readyz specifically. Everything else passes.
      if (url.endsWith("/readyz")) return res(503, "db down");
      return alwaysOkFetch()(url);
    };
    const summary = await runChecks({
      baseUrl: "http://localhost:3010",
      fetchImpl,
    });
    expect(summary.ok).toBe(false);
    expect(summary.failed).toBeGreaterThanOrEqual(1);
    const readyzResult = summary.results.find((r) => r.name === "readyz")!;
    expect(readyzResult.ok).toBe(false);
    expect(readyzResult.status).toBe(503);
    expect(readyzResult.error).toContain("503");
  });

  it("records a failure when the fetch impl itself throws", async () => {
    const checks: Check[] = [{ name: "x", url: "/x", expectStatus: 200 }];
    const fetchImpl: FetchLike = async () => {
      throw new Error("ECONNREFUSED");
    };
    const summary = await runChecks({
      baseUrl: "http://localhost:3010",
      checks,
      fetchImpl,
    });
    expect(summary.ok).toBe(false);
    expect(summary.results[0].error).toContain("fetch failed");
    expect(summary.results[0].error).toContain("ECONNREFUSED");
  });

  it("fails a check that expects a JSON key when the body is HTML", async () => {
    const checks: Check[] = [
      { name: "x", url: "/x", expectStatus: 200, expectKey: "sha" },
    ];
    const fetchImpl: FetchLike = async () => res(200, "<html>not json</html>");
    const summary = await runChecks({
      baseUrl: "http://localhost:3010",
      checks,
      fetchImpl,
    });
    expect(summary.ok).toBe(false);
    expect(summary.results[0].error).toContain("JSON");
  });

  it("fails a check that expects a substring when the body lacks it", async () => {
    const checks: Check[] = [
      {
        name: "x",
        url: "/x",
        expectStatus: 200,
        expectContains: "Sign in",
      },
    ];
    const fetchImpl: FetchLike = async () => res(200, "<html>Welcome</html>");
    const summary = await runChecks({
      baseUrl: "http://localhost:3010",
      checks,
      fetchImpl,
    });
    expect(summary.ok).toBe(false);
    expect(summary.results[0].error).toContain("Sign in");
  });

  it("hits checks sequentially in declared order", async () => {
    const calls: string[] = [];
    const checks: Check[] = [
      { name: "a", url: "/a", expectStatus: 200 },
      { name: "b", url: "/b", expectStatus: 200 },
      { name: "c", url: "/c", expectStatus: 200 },
    ];
    const fetchImpl: FetchLike = async (url) => {
      calls.push(url);
      return res(200, "");
    };
    await runChecks({ baseUrl: "http://x", checks, fetchImpl });
    expect(calls).toEqual(["http://x/a", "http://x/b", "http://x/c"]);
  });

  it("records a duration_ms field on every result using the injected clock", async () => {
    let t = 0;
    const checks: Check[] = [{ name: "x", url: "/x", expectStatus: 200 }];
    const fetchImpl: FetchLike = async () => res(200, "");
    const summary = await runChecks({
      baseUrl: "http://x",
      checks,
      fetchImpl,
      now: () => (t += 17),
    });
    expect(summary.results[0].durationMs).toBe(17);
  });
});

// ─── formatTable ────────────────────────────────────────────────────

describe("formatTable", () => {
  it("renders a header row with all four columns", () => {
    const table = formatTable([
      { name: "x", url: "/x", status: 200, durationMs: 5, ok: true },
    ]);
    expect(table).toContain("name");
    expect(table).toContain("status");
    expect(table).toContain("duration_ms");
    expect(table).toContain("result");
    expect(table).toContain("PASS");
  });

  it("renders FAIL with the error message for failed rows", () => {
    const table = formatTable([
      {
        name: "x",
        url: "/x",
        status: 500,
        durationMs: 5,
        ok: false,
        error: "expected status 200, got 500",
      },
    ]);
    expect(table).toContain("FAIL");
    expect(table).toContain("500");
  });
});

// ─── Migration verification helpers ─────────────────────────────────

describe("missingMigrations", () => {
  it("returns [] when every file is applied", () => {
    const files = ["0001_init.sql", "0002_users.sql", "0003_repos.sql"];
    const applied = ["0001_init.sql", "0002_users.sql", "0003_repos.sql"];
    expect(missingMigrations(files, applied)).toEqual([]);
  });

  it("returns the unapplied files sorted", () => {
    const files = [
      "0001_init.sql",
      "0002_users.sql",
      "0050_a.sql",
      "0051_b.sql",
      "0053_c.sql",
    ];
    const applied = ["0001_init.sql", "0002_users.sql", "0050_a.sql"];
    expect(missingMigrations(files, applied)).toEqual([
      "0051_b.sql",
      "0053_c.sql",
    ]);
  });

  it("ignores non-sql files", () => {
    const files = ["0001_init.sql", "README.md", "0002_x.sql"];
    const applied: string[] = [];
    expect(missingMigrations(files, applied)).toEqual([
      "0001_init.sql",
      "0002_x.sql",
    ]);
  });

  it("returns [] when the file list is empty", () => {
    expect(missingMigrations([], ["any.sql"])).toEqual([]);
  });

  it("treats the applied list as a set (duplicates don't matter)", () => {
    const files = ["0001.sql", "0002.sql"];
    const applied = ["0001.sql", "0001.sql", "0002.sql"];
    expect(missingMigrations(files, applied)).toEqual([]);
  });
});

describe("latestMigration", () => {
  it("returns the lexicographic max .sql", () => {
    expect(
      latestMigration(["0001_init.sql", "0050_x.sql", "0010_y.sql"])
    ).toBe("0050_x.sql");
  });

  it("returns null on empty input", () => {
    expect(latestMigration([])).toBeNull();
  });

  it("ignores non-sql files", () => {
    expect(latestMigration(["0001_init.sql", "README.md", "z.txt"])).toBe(
      "0001_init.sql"
    );
  });

  it("returns null when only non-sql files are present", () => {
    expect(latestMigration(["README.md", "z.txt"])).toBeNull();
  });
});