Staging loading report, 2026-11-03. - Sidebar (BUG-1526): 生时校正 / 婚恋合盘 rows follow the product registry default until the account has been read; only an account that says off hides them, so rows are no longer inserted mid-list. The shell commits the account as soon as it is read (loadSessionList onAccount), ahead of the people list and the sessions. 「最近」 reserves an empty fixed-height block while the sessions are read instead of a line of copy (no skeleton). - /api/account GET: avatar columns ride on the first profile select; profile, membership, admin check and both product flags run in one Promise.all. - loadRuntimeFeatureFlags caches per key, joins in-flight keys and batches same-tick single-key calls into one query (parallel calls no longer evict each other). - GET /api/sessions (BUG-1527): page and pinned queries run in parallel. The messages <> '[]' filter was measured on a local PG16 with synthetic data (EXPLAIN ANALYZE: ~0.7 ms -> ~0.1 ms warm, ~2-3 ms -> ~0.2 ms cold buffers per query); not worth a production schema change, so no migration. - /rectification (BUG-1528): gated only on the account (plus the people list for someone else); the intro, person line and a fixed-height status card slot paint at once and only the card fills when the summary lands. The first summary read joins Home's in-flight read or the HTML early read (/rectification added to BOOT_READ_PAGES); Home's warm-snapshot summary seeds the card and is revalidated. shell-motion NAV gains /rectification. - /synastry (BUG-1529): open/closed comes from the shell account (registry default until known); people and balance come from the shell; the price and the history are read at mount without the setTimeout tick and fill in on arrival; 开始合盘 stays disabled until the price is known. /api/product-access runs its flags, catalog and prices in parallel. Tests: new loading-shell-20261103 and loading-routes-20261103; every changed assertion (six files) carries 原值/新值/原因 comments. BUG_HISTORY, CHANGELOG, DESIGN.md and the pre-work ledger updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
50 lines
3.0 KiB
TypeScript
50 lines
3.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
const root = new URL("../", import.meta.url);
|
|
const adminSource = readFileSync(new URL("src/lib/supabase/admin.ts", root), "utf8");
|
|
const adminCoreSource = readFileSync(new URL("src/lib/supabase/admin-client-core.ts", root), "utf8");
|
|
const codesSource = readFileSync(new URL("src/app/api/admin/codes/route.ts", root), "utf8");
|
|
const sessionSource = readFileSync(new URL("src/app/api/admin/session/route.ts", root), "utf8");
|
|
const accountSource = readFileSync(new URL("src/app/api/account/route.ts", root), "utf8");
|
|
const usersSource = readFileSync(new URL("src/app/api/admin/users/route.ts", root), "utf8");
|
|
const migration = readFileSync(new URL("supabase/migrations/20260805020000_reconcile_payment_admin_schema.sql", root), "utf8");
|
|
|
|
test("ADMIN_EMAILS remains a case-insensitive comma-separated allowlist", () => {
|
|
assert.match(adminCoreSource, /configured/);
|
|
assert.match(adminCoreSource, /split\(","\)/);
|
|
assert.match(adminCoreSource, /toLowerCase/);
|
|
assert.match(adminCoreSource, /export function isAdminEmail/);
|
|
});
|
|
|
|
test("admin surfaces await database-backed administrator checks", () => {
|
|
assert.match(adminSource, /export async function isAdminUser/);
|
|
assert.match(adminSource, /admin_has_permission\(\$1, 'admin\.access'\)/);
|
|
assert.match(sessionSource, /await requirePermission\("admin\.access"\)/);
|
|
assert.match(codesSource, /await requireAdminMutation\(\s*request,\s*"admin\.access",?\s*\)/);
|
|
assert.doesNotMatch(codesSource, /requireHighRiskAdminMutation/);
|
|
// 原值:/const isAdmin = await isAdminUser\(user\)/
|
|
// 新值:isAdminUser(user) 是账户读取那一轮 Promise.all 里的一项,结果解构成 isAdmin,仍在返回前等到
|
|
// 原因:BUG-1526。管理员检查和资料、会员、开关同一轮查,不再排在后面单独等
|
|
assert.match(accountSource, /\n\s+isAdmin,\n[\s\S]*?\] = await Promise\.all\(\[[\s\S]*?\n\s+isAdminUser\(user\),\n/);
|
|
assert.match(accountSource, /isAdmin,/);
|
|
});
|
|
|
|
test("admin_users migration is service-role-only and auditable", () => {
|
|
assert.match(migration, /user_id uuid primary key references auth\.users\(id\)/);
|
|
assert.match(migration, /created_at timestamptz/);
|
|
assert.match(migration, /created_by uuid/);
|
|
assert.match(migration, /revoked_at timestamptz/);
|
|
assert.match(migration, /revoked_by uuid/);
|
|
assert.match(migration, /enable row level security/);
|
|
assert.match(migration, /revoke all on table public\.admin_users from anon, authenticated/);
|
|
assert.match(migration, /grant select, insert, update on table public\.admin_users to service_role/);
|
|
});
|
|
|
|
test("legacy admin users route aliases handlers but declares runtime statically", () => {
|
|
assert.match(usersSource, /export const runtime = "nodejs"/);
|
|
assert.match(usersSource, /export \{ DELETE, GET, PATCH, POST, PUT \} from "\.\.\/customers\/route"/);
|
|
assert.doesNotMatch(usersSource, /export \{[^}]*\bruntime\b[^}]*\} from/);
|
|
});
|