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
version.ts3.6 KB · 97 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
/**
 * /api/version — public build-info endpoint.
 *
 * Returns the running process's commit SHA, branch, boot time, and uptime
 * as a tiny JSON payload. Used by:
 *   - The client-side auto-update banner (polls every 15s, prompts reload
 *     when sha changes)
 *   - Operators sanity-checking 'did my push actually deploy?'
 *   - Monitoring (latency to seeing a new sha = end-to-end deploy time)
 *
 * Cache-control: no-store. Must be live, never cached.
 *
 * Block S3 (2026-05-14): additively reports the 5 most recently applied
 * migrations from the live DB so the post-deploy smoke suite can verify
 * the latest drizzle/*.sql file actually landed in the running schema.
 * The migrations field is best-effort: if the DB query fails or the
 * connection isn't configured the field is omitted, never throws.
 */

import { Hono } from "hono";
import { sql } from "drizzle-orm";
import { getBuildInfo } from "../lib/build-info";
import { db } from "../db";

const version = new Hono();

// In-process cache for the migrations list. /api/version is polled
// every 15s by the auto-update banner — re-querying _migrations on
// every hit would be wasteful. 10s TTL is a reasonable compromise: a
// fresh deploy's new migration will show up in the smoke check within
// at most 10s of when migrate.ts inserted the row.
const MIGRATIONS_CACHE_TTL_MS = 10_000;
let _migrationsCache: { at: number; names: string[] } | null = null;

async function readRecentMigrations(): Promise<string[] | null> {
  const now = Date.now();
  if (_migrationsCache && now - _migrationsCache.at < MIGRATIONS_CACHE_TTL_MS) {
    return _migrationsCache.names;
  }
  try {
    // _migrations is created on first migration run; if the table doesn't
    // exist (very first boot before migrate.ts has ever run) we degrade
    // silently to an empty list.
    const rows = (await db.execute(
      sql`SELECT name FROM _migrations ORDER BY applied_at DESC LIMIT 5`
    )) as unknown as Array<{ name: string }>;
    const names = (rows ?? []).map((r) => r.name).filter(Boolean);
    _migrationsCache = { at: now, names };
    return names;
  } catch {
    // _migrations table missing, DB down, etc. — return null so the
    // endpoint can omit the field without 500ing.
    return null;
  }
}

/**
 * Test seam: lets `src/__tests__/post-deploy-smoke.test.ts` reset the
 * cache between assertions. Not part of the public API.
 */
export const __test = {
  clearMigrationsCache: () => {
    _migrationsCache = null;
  },
};

version.get("/api/version", async (c) => {
  c.header("cache-control", "no-store, no-cache, must-revalidate");
  c.header("pragma", "no-cache");
  const build = getBuildInfo();
  const migrations = await readRecentMigrations();
  if (migrations !== null) {
    return c.json({ ...build, migrations });
  }
  return c.json(build);
});

// Block S2 — minimal `/version` alias used by the service-worker cache
// bust + external uptime/deploy monitors. Kept additive (single new
// handler, no edits to existing shape) so the S1+S3 smoke-suite agent's
// edits to this file can land alongside without merge conflicts.
//
// S3 (2026-05-14): mirror the migrations field here so the smoke
// suite can check either endpoint.
version.get("/version", async (c) => {
  c.header("cache-control", "no-store, no-cache, must-revalidate");
  c.header("pragma", "no-cache");
  const migrations = await readRecentMigrations();
  const body: Record<string, unknown> = {
    sha: process.env.BUILD_SHA || "dev",
    buildAt: process.env.BUILD_TIME || null,
  };
  if (migrations !== null) body.migrations = migrations;
  return c.json(body);
});

export default version;