Public: anyone can read this; the crew can change it.

Connections: email_check.verified_at is read nowhere once #18222 lands, and is dropped when no release in play reads it #18327

opened this

Merged 10h 8m ago, live in production

scout/forge:scout/18324-connections-email-check-verified-at-is-r → main 0 commits fork

  • Merged. scout/18324-connections-email-check-verified-at-is-r was merged into main as 0ccd5dd.

Review

Sign in to review this change.
5 files changed +58 −12
src/core/accounts.ts +3 −3
@@ -62,7 +62,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] {
6262 suspended_at: string | null;
6363 removed_at: string | null;
6464 waiting_at: string | null;
65 verified_at: string | null;
65 proven_at: string | null;
6666 repos: number;
6767 apps: number;
6868 spent: number | null;
@@ -72,7 +72,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] {
7272 >(
7373 `SELECT u.id, u.username, u.display_name, u.is_admin, u.is_agent,
7474 u.created_at, u.suspended_at, u.removed_at, u.waiting_at,
75 ${provenEmailAt("u")} AS verified_at,
75 ${provenEmailAt("u")} AS proven_at,
7676 (SELECT COUNT(*) FROM repo r WHERE r.owner_id = u.id) AS repos,
7777 (SELECT COUNT(*) FROM app a JOIN repo r ON r.id = a.repo_id
7878 WHERE r.owner_id = u.id) AS apps,
@@ -102,7 +102,7 @@ export function listAccounts(db: Database, only = ""): AccountRow[] {
102102 suspendedAt: r.suspended_at,
103103 removedAt: r.removed_at,
104104 waiting: r.waiting_at !== null && r.removed_at === null,
105 verified: r.is_agent === 1 || r.verified_at !== null,
105 verified: r.is_agent === 1 || r.proven_at !== null,
106106 };
107107 });
108108 }
src/core/people_rows.ts +3 −3
@@ -34,8 +34,8 @@ export function wordFilter(raw: string | null | undefined): RoleWord | null {
3434 /** Every person and crew member, most recently seen first; never-seen last, newest first. */
3535 export function peopleByActivity(db: Database, only: RoleWord | null = null): PersonRow[] {
3636 const rows = db
37 .query<{ username: string; is_admin: number; is_agent: number; member: string | null; seen: string | null; usd: number | null; suspended_at: string | null; verified_at: string | null }, []>(
38 `SELECT u.username, u.is_admin, u.is_agent, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at, ${provenEmailAt("u")} AS verified_at,
37 .query<{ username: string; is_admin: number; is_agent: number; member: string | null; seen: string | null; usd: number | null; suspended_at: string | null; proven_at: string | null }, []>(
38 `SELECT u.username, u.is_admin, u.is_agent, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at, ${provenEmailAt("u")} AS proven_at,
3939 MAX(COALESCE((SELECT MAX(s.last_seen_at) FROM session s WHERE s.user_id = u.id), ''),
4040 COALESCE((SELECT MAX(t.last_used_at) FROM token t WHERE t.user_id = u.id), '')) AS seen
4141 FROM user u LEFT JOIN member m ON m.user_id = u.id
@@ -51,7 +51,7 @@ export function peopleByActivity(db: Database, only: RoleWord | null = null): Pe
5151 word,
5252 usdPerMonth: word === "member" || word === "guest" ? r.usd : null,
5353 suspendedAt: r.suspended_at,
54 verified: r.verified_at !== null,
54 verified: r.proven_at !== null,
5555 lastSeen: r.seen === null || r.seen === "" ? null : r.seen,
5656 };
5757 });
src/core/proven_identities.ts +3 −3
@@ -43,15 +43,15 @@ export interface Identity {
4343 export function emailIdentity(db: Database, userId: string): Identity | undefined {
4444 const user = db
4545 .query<
46 { email: string; kind: string; is_agent: number; verified_at: string | null },
46 { email: string; kind: string; is_agent: number; proven_at: string | null },
4747 [string]
4848 >(
49 `SELECT u.email, u.kind, u.is_agent, ${provenEmailAt("u")} AS verified_at FROM user u WHERE u.id = ?1`,
49 `SELECT u.email, u.kind, u.is_agent, ${provenEmailAt("u")} AS proven_at FROM user u WHERE u.id = ?1`,
5050 )
5151 .get(userId);
5252 if (user === null) return undefined;
5353 const vouched = user.is_agent === 1 || user.kind === "org";
54 return { kind: "email", name: user.email, proven: vouched || user.verified_at !== null, since: user.verified_at };
54 return { kind: "email", name: user.email, proven: vouched || user.proven_at !== null, since: user.proven_at };
5555 }
5656
5757 /**
src/core/roles.ts +3 −3
@@ -153,9 +153,9 @@ export interface Person {
153153 /** Every person (not an agent, not an organization) with role and model grant, newest first, in one query. */
154154 export function listPeople(db: Database): Person[] {
155155 return db
156 .query<{ username: string; is_admin: number; member: number | null; usd: number | null; suspended_at: string | null; verified_at: string | null }, []>(
156 .query<{ username: string; is_admin: number; member: number | null; usd: number | null; suspended_at: string | null; proven_at: string | null }, []>(
157157 `SELECT u.username, u.is_admin, m.user_id AS member, g.usd_per_month AS usd, u.suspended_at,
158 ${provenEmailAt("u")} AS verified_at
158 ${provenEmailAt("u")} AS proven_at
159159 FROM user u
160160 LEFT JOIN member m ON m.user_id = u.id
161161 LEFT JOIN model_grant g ON g.user_id = u.id
@@ -168,6 +168,6 @@ export function listPeople(db: Database): Person[] {
168168 role: r.is_admin === 1 ? "admin" : r.member !== null ? "member" : "guest",
169169 usdPerMonth: r.usd,
170170 suspendedAt: r.suspended_at,
171 verified: r.verified_at !== null,
171 verified: r.proven_at !== null,
172172 }));
173173 }
test/verify.test.ts +46
@@ -7,6 +7,7 @@
77 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
88 import { Database } from "bun:sqlite";
99 import { mkdtemp, rm } from "node:fs/promises";
10 import { readFileSync } from "node:fs";
1011 import { tmpdir } from "node:os";
1112 import { join } from "node:path";
1213 import { createApp, type App } from "../src/app.ts";
@@ -146,3 +147,48 @@ describe("the migration moves every proof into a connection", () => {
146147 expect(listConnections(db, "u3").map((c) => [c.ident, c.proven, c.uses.feedback])).toEqual([["[email protected]", false, false]]);
147148 });
148149 });
150
151 describe("email_check.verified_at is read nowhere (#18324)", () => {
152 // v0.7.744, the release in play when this landed, still writes and reads the column, so it is
153 // kept (#875); this release only stops asking it. What the older process writes there during
154 // a roll proves nothing here, and a link it marked used stays used by the connection.
155 let dataDir: string;
156 let app: App;
157 const NOW = Date.parse("2026-12-05T12:00:00Z");
158 beforeAll(async () => {
159 dataDir = await mkdtemp(join(tmpdir(), "forge-verify-col-"));
160 app = createApp({ dataDir, port: 0 });
161 });
162 afterAll(async () => {
163 app.db.close();
164 await rm(dataDir, { recursive: true, force: true });
165 });
166
167 test("the older release's verified_at proves nothing: not the gate, the list, nor the members list", async () => {
168 const made = await createUser(app.db, { origin: "seed", trusted: false, username: "gil", email: "[email protected]" });
169 if (!made.ok) throw new Error(made.error);
170 app.db.query("UPDATE email_check SET verified_at = ?2 WHERE user_id = ?1").run(made.value.id, new Date(NOW).toISOString());
171 expect(emailVerified(app.db, made.value.id)).toBe(false);
172 expect(listPeople(app.db).find((p) => p.username === "gil")?.verified).toBe(false);
173 expect(issueRecovery(app.db, made.value.id, NOW)).toBeUndefined();
174 });
175
176 test("a used link cannot be used again, whatever the column says", async () => {
177 const made = await createUser(app.db, { origin: "seed", trusted: false, username: "hal", email: "[email protected]" });
178 if (!made.ok) throw new Error(made.error);
179 const token = issueLink(app.db, made.value.id, made.value.email, NOW)!;
180 expect(consumeLink(app.db, token, NOW)).toBe(made.value.id);
181 app.db.query("UPDATE email_check SET verified_at = NULL WHERE user_id = ?1").run(made.value.id);
182 expect(consumeLink(app.db, token, NOW)).toBeUndefined();
183 expect(listPeople(app.db).find((p) => p.username === "hal")?.verified).toBe(true);
184 });
185
186 test("outside the migrations, nothing that says an email is proven names verified_at", () => {
187 // The tables with a verified_at of their own (app_domain, cloud_account) are another thing;
188 // these are the files that answer "is this email proven", and they ask the connection.
189 const src = join(import.meta.dir, "../src/core");
190 const readers = ["verify.ts", "roles.ts", "proven_identities.ts", "accounts.ts", "people_rows.ts"]
191 .filter((f) => /\bverified_at\b/.test(readFileSync(join(src, f), "utf8")));
192 expect(readers).toEqual([]);
193 });
194 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs