Item 2 — founder counter is REAL or hidden (kills the hardcoded 47/100)

ClaimMeter rendered a fabricated "47 / 100 CLAIMED" (a hardcoded default; the
comment even said "Cosmetic conversion driver… Static here"). Now:

- GET /api/founders/count counts ONLY real paying founders — user_profiles
  where founder_pricing = true AND subscription_status = 'active' (the
  Stripe-webhook-synced mirror, so we never hammer the Stripe API). Cached 5
  min in Redis on top of that.
- If the source is unavailable (Supabase unconfigured, query error, column not
  migrated, client throws) the endpoint returns { available: false } and the
  ClaimMeter renders NOTHING — counter and progress bar both hidden. We never
  fall back to a number.
- A low real count is shown honestly (0 → "0 / 100"); the truth is the feature.

Next proxy at app/api/founders/count. 6 route tests cover real count, low
count, error/unconfigured/throw → hidden, and cache-hit. Suite 271/3260 green,
web build exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-07-17 15:32:18 -04:00
parent 66d52a9ce0
commit 41fc2b90e2
5 changed files with 203 additions and 5 deletions
+1
View File
@@ -215,6 +215,7 @@ app.use('/api/internal', internalRoutes);
// A1 S3 — partner attribution report. Internal-key gated (router-level
// requireInternalAuth); no Next proxy on purpose — never browser-facing.
app.use('/api/partners', require('./routes/partners'));
app.use('/api/founders', require('./routes/founders'));
// Session 10 — Sentry's Express error handler catches uncaught
// errors from every route mounted above. Must come AFTER routes but
+70
View File
@@ -0,0 +1,70 @@
/**
* GET /api/founders/count — the REAL founder-seat counter.
*
* TRUTH LAW (Truth-Everywhere Part 2, item 2): the ClaimMeter used to render a
* hardcoded "47 / 100 CLAIMED". This counts ONLY real paying founders — the
* Stripe-synced subscription records in Supabase (`user_profiles` where
* founder_pricing = true AND subscription_status = 'active'). Counting the
* webhook-synced mirror, not the Stripe API, is the cache — we never hammer
* Stripe. Cached 5 min in Redis on top of that.
*
* If the source is unavailable (Supabase unconfigured, query error, column not
* migrated), we return { available: false } and the UI HIDES the counter — we
* never fall back to a number. A low real count is fine; the truth is the feature.
*/
const express = require('express');
const { getSupabaseServiceClient } = require('../utils/supabase');
const { cacheGet, cacheSet } = require('../utils/redis');
const router = express.Router();
const TOTAL = Number(process.env.FOUNDER_SEATS_TOTAL || 100);
const CACHE_KEY = 'founders:count';
const CACHE_TTL = 300; // 5 min — the founder count moves slowly
// Injectable for tests (never hits network in the unit suite).
let _getClient = getSupabaseServiceClient;
let _cacheGet = cacheGet;
let _cacheSet = cacheSet;
function __setDeps({ getClient, cacheGet: cg, cacheSet: cs } = {}) {
_getClient = getClient || getSupabaseServiceClient;
_cacheGet = cg || cacheGet;
_cacheSet = cs || cacheSet;
}
router.get('/count', async (req, res) => {
// Cache first — don't recount on every landing hit.
try {
const cached = await _cacheGet(CACHE_KEY);
if (cached && typeof cached.claimed === 'number') {
return res.json({ available: true, claimed: cached.claimed, total: TOTAL });
}
} catch { /* cache miss/degraded — fall through to a live count */ }
let supabase;
try {
supabase = _getClient();
} catch {
return res.json({ available: false }); // unconfigured → hide, never a number
}
if (!supabase) return res.json({ available: false });
try {
const { count, error } = await supabase
.from('user_profiles')
.select('id', { count: 'exact', head: true })
.eq('founder_pricing', true)
.eq('subscription_status', 'active');
if (error) return res.json({ available: false }); // column missing / query error → hide
const claimed = Math.max(0, Number(count) || 0);
try { await _cacheSet(CACHE_KEY, { claimed }, CACHE_TTL); } catch { /* best-effort */ }
return res.json({ available: true, claimed, total: TOTAL });
} catch {
return res.json({ available: false }); // any failure → hide, never fabricate
}
});
router.__setDeps = __setDeps;
router.__internals = { TOTAL, CACHE_KEY, CACHE_TTL };
module.exports = router;
+76
View File
@@ -0,0 +1,76 @@
'use strict';
// Item 2 (Truth-Everywhere Part 2) — the founder-seat counter is REAL or hidden,
// never a fabricated "47 / 100". Redis mocked; the Supabase client injected.
const request = require('supertest');
let mockStore = {};
jest.mock('../../src/utils/redis', () => ({
getRedisClient: () => ({}),
cacheGet: async (k) => (k in mockStore ? mockStore[k] : null),
cacheSet: async (k, v) => { mockStore[k] = v; return true; },
cacheDel: async () => true,
isDegraded: () => false,
}));
const app = require('../../src/app');
const foundersRouter = require('../../src/routes/founders');
// A fake Supabase query builder that resolves to a fixed count/error.
function fakeClient({ count = 0, error = null } = {}) {
const b = {
from() { return b; },
select() { return b; },
eq() { return b; },
then(resolve) { return Promise.resolve({ count, error }).then(resolve); },
};
return b;
}
beforeEach(() => { mockStore = {}; foundersRouter.__setDeps({}); });
describe('GET /api/founders/count', () => {
test('real active-founder count → { available, claimed, total }', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ count: 3 }) });
const res = await request(app).get('/api/founders/count');
expect(res.status).toBe(200);
expect(res.body.available).toBe(true);
expect(res.body.claimed).toBe(3);
expect(res.body.total).toBe(100);
});
test('a low real count is shown honestly (no fabricated floor)', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ count: 0 }) });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: true, claimed: 0, total: 100 });
});
test('query error (column missing) → available:false, NEVER a number', async () => {
foundersRouter.__setDeps({ getClient: () => fakeClient({ error: { message: 'no column' } }) });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
expect(res.body).not.toHaveProperty('claimed');
});
test('unconfigured source (no client) → available:false, hidden', async () => {
foundersRouter.__setDeps({ getClient: () => null });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
});
test('client throws → available:false, never fabricates', async () => {
foundersRouter.__setDeps({ getClient: () => { throw new Error('down'); } });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: false });
});
test('served from cache when warm (no client call)', async () => {
mockStore['founders:count'] = { claimed: 7 };
let clientCalled = false;
foundersRouter.__setDeps({ getClient: () => { clientCalled = true; return fakeClient({ count: 999 }); } });
const res = await request(app).get('/api/founders/count');
expect(res.body).toEqual({ available: true, claimed: 7, total: 100 });
expect(clientCalled).toBe(false);
});
});
+25
View File
@@ -0,0 +1,25 @@
import { NextResponse } from 'next/server';
export const dynamic = 'force-dynamic';
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';
/**
* Founder-seat count proxy (Truth-Everywhere Part 2, item 2) — forwards
* GET /api/founders/count to Express (real active paying founders). On any
* upstream failure we return { available: false } so the ClaimMeter HIDES —
* never a fabricated number.
*/
export async function GET() {
try {
const upstream = await fetch(`${BACKEND_URL}/api/founders/count`, {
method: 'GET',
headers: { Accept: 'application/json' },
cache: 'no-store',
});
const data = await upstream.json().catch(() => ({ available: false }));
return NextResponse.json(data, { status: upstream.ok ? 200 : 200 });
} catch {
return NextResponse.json({ available: false }, { status: 200 });
}
}
+31 -5
View File
@@ -1,17 +1,43 @@
'use client';
import { useEffect, useState } from 'react';
import SectionHead from '@/components/vyndr/SectionHead';
interface ClaimMeterProps {
interface FounderCount {
available: boolean;
claimed?: number;
total?: number;
}
/**
* Founder-seat scarcity meter (§12 ClaimMeter) — "47 / 100 seats claimed",
* amber bar. Cosmetic conversion driver; the live tick-up wires into the
* living layer in Session 38. Static here.
* Founder-seat scarcity meter (§12 ClaimMeter).
*
* TRUTH LAW (Truth-Everywhere Part 2, item 2): this used to render a hardcoded
* "47 / 100 CLAIMED". It now fetches the REAL count of active paying founders
* from /api/founders/count (Stripe-synced, cached). If the source is
* unavailable — or the fetch fails — the counter and progress bar HIDE
* entirely. We never fall back to a number. A low real count is fine; the
* truth is the feature.
*/
export default function ClaimMeter({ claimed = 47, total = 100 }: ClaimMeterProps) {
export default function ClaimMeter() {
const [data, setData] = useState<FounderCount | null>(null);
useEffect(() => {
let active = true;
fetch('/api/founders/count', { cache: 'no-store' })
.then((r) => r.json())
.then((d) => { if (active) setData(d); })
.catch(() => { if (active) setData({ available: false }); });
return () => { active = false; };
}, []);
// Hide until we have a REAL number. Unavailable source → render nothing.
if (!data || !data.available || typeof data.claimed !== 'number') return null;
const total = data.total || 100;
const claimed = Math.max(0, Math.min(total, data.claimed));
const pct = Math.min(100, Math.round((claimed / total) * 100));
return (
<div style={{ maxWidth: 420, margin: '0 auto', width: '100%' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 8 }}>