From 90fcbe99b6a8a4f4b38ef2790ceb454422fbeda2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 14:21:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20BUG-2436=20=E3=80=8C=E5=86=85?= =?UTF-8?q?=E6=B5=8B=E7=BE=A4=E6=96=87=E6=A1=88=E3=80=8D=20card=20in=20the?= =?UTF-8?q?=20release-notes=20editor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same fields as the in-app pop-up, fixed template (no model): opening line, title, items numbered 1..n in 新功能 → 改进 → 修复 order, closing line, blank lines between, markdown stripped for WeChat. 复制 via navigator.clipboard, selects the text on failure, results by toast. Opening/closing lines are editable and kept server-side in a single-row admin setting (20261127010000_release_note_group_text.sql: admin_runtime select policy + grant, audited write function under content.release_notes.write). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp3RzgZVEpT1PXxkwHj --- docs/BUG_HISTORY.md | 13 +++ frontend/src/app/admin/admin.css | 2 + .../src/app/api/admin/release-notes/route.ts | 26 ++++- .../admin/release-note-group-text.tsx | 79 ++++++++++++++ .../admin/release-notes-management.tsx | 51 ++++++++- frontend/src/lib/release-notes.ts | 44 ++++++++ ...20261127010000_release_note_group_text.sql | 89 +++++++++++++++ frontend/tests/annual-questions-2085.test.tsx | 2 + frontend/tests/avatar-image-2057.test.ts | 2 + .../tests/database-local-business.test.ts | 4 + .../tests/database-release-notes-331.test.ts | 19 ++++ frontend/tests/onboarding-place-2167.test.tsx | 2 + .../release-note-group-text-2436.test.tsx | 103 ++++++++++++++++++ 13 files changed, 431 insertions(+), 5 deletions(-) create mode 100644 frontend/src/components/admin/release-note-group-text.tsx create mode 100644 frontend/supabase/migrations/20261127010000_release_note_group_text.sql create mode 100644 frontend/tests/release-note-group-text-2436.test.tsx diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 9de5d95a0..41fe35a18 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -33296,3 +33296,16 @@ - 防复发:所有只要几十个 token 的小调用都必须显式关思考;本条与 BUG-2284 同类,复发原因是 BUG-2284 只修了出问题的那一处调用,没有排查同样只设上限的其它调用。 - 关联记录:BUG-553 / BUG-557(标题生成与写库守卫)、BUG-2284(追问建议同因)、BUG-2433。 - 修复版本:`claude/chat-2433`(本地,未推送)。 + +## BUG-2436 | 后台「更新说明」只有站内弹窗预览,发内测群还要另外手写一遍文案 + +- 状态:fixed-pending-verify(推到 `next`,进 1.7;待 staging 复测)。 +- 首次发现 / 最近更新:2026-11-27(负责人提出,协调窗口转来,负责人已同意做)。 +- 现象:每次发版负责人在后台写一遍版本、标题和条目,发内测微信群时还要再手写一份群里用的文字。 +- 触发条件:每次发版。 +- 根因:#331 的编辑器只做了站内弹窗这一种呈现,没有给群公告用的纯文字。 +- 修复:编辑抽屉右侧在「用户看到的样子」下面加「内测群文案」卡片(`frontend/src/components/admin/release-note-group-text.tsx`):同一组字段按固定模板生成纯文字,不调用模型(`releaseNoteGroupMessage`,`frontend/src/lib/release-notes.ts`)。顺序是开头一句、标题、全部条目按 新功能 → 改进 → 修复 编号 1..n、结尾一句,块之间空一行;去掉 markdown 和列表符号,每块一行,粘到微信不走样。开头和结尾可以改,默认「大家好,Jyotisha 更新到 {版本} 啦~」「用着有任何感觉不对的地方,随时在群里说,我们都在看。」,`{版本}` 换成版本号。「复制」走 `navigator.clipboard`,失败时选中文字,结果都用 toast 提示。改过的开头结尾在复制或保存时存到服务端一行设置:新迁移 `20261127010000_release_note_group_text.sql`(单行表;admin_runtime 读要 select 策略加授权,BUG-1935 的教训;写只走带权限检查和审计的 `admin_save_release_note_group_text`,权限沿用 `content.release_notes.write`)。后台接口 GET 多返回 `groupText`,POST 多一个 `save_group_text`。 +- 验证:新增 `frontend/tests/release-note-group-text-2436.test.tsx`(6 项):模板顺序、编号和空行;改过的开头结尾和 `{版本}`;粘进来的 markdown 和列表符号被去掉;默认文案和非空校验;卡片渲染(两个输入框、只读文字、复制按钮);编辑器、接口和迁移的接线。`database-release-notes-331.test.ts` 加了这张表的权限、策略、写入和审计检查(需要 Docker,本机没有,由 CI 跑)。三份迁移清单测试和公开表清单按原值/新值/原因更新。 +- 防复发:群文案和弹窗用同一组字段,不再各写一份。 +- 关联记录:#331(更新说明)、BUG-1935(admin_runtime 策略)、负责人「结果用 toast」规则。 +- 修复版本:`next`(1.7)。 diff --git a/frontend/src/app/admin/admin.css b/frontend/src/app/admin/admin.css index 2c69557ff..4e7c2fab4 100644 --- a/frontend/src/app/admin/admin.css +++ b/frontend/src/app/admin/admin.css @@ -47,6 +47,8 @@ html, body { /* 「更新说明」 editor (issue #331): the form and a live preview side by side on wide screens. */ .admin-release-note-editor { display: grid; gap: 16px; } +/* BUG-2436: the pop-up preview and the 「内测群文案」 card stacked in the right column. */ +.admin-release-note-preview { display: grid; gap: 12px; align-content: start; } @media (min-width: 900px) { .admin-release-note-editor { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } .admin-release-note-preview { position: sticky; top: 0; } diff --git a/frontend/src/app/api/admin/release-notes/route.ts b/frontend/src/app/api/admin/release-notes/route.ts index 414ac9c36..42edf891f 100644 --- a/frontend/src/app/api/admin/release-notes/route.ts +++ b/frontend/src/app/api/admin/release-notes/route.ts @@ -4,14 +4,21 @@ import { z } from "zod"; import { requirePermission } from "@/lib/admin/auth"; import { queryAdminRows } from "@/lib/admin/database"; import { adminErrorResponse, invalidQueryResponse, requestId, requireAdminMutation } from "@/lib/admin/http"; -import { releaseNoteDraftSchema, releaseNoteItemSchema } from "@/lib/release-notes"; +import { + RELEASE_NOTE_GROUP_TEXT_DEFAULTS, + releaseNoteDraftSchema, + releaseNoteGroupTextSchema, + releaseNoteItemSchema, +} from "@/lib/release-notes"; export const runtime = "nodejs"; /** * 「更新说明」 in the admin console (issue #331). * GET — every version (draft, published, withdrawn), newest edit first. - * POST — { action: "save", id?, version, title, items } | { action: "publish" | "withdraw", id }. + * POST — { action: "save", id?, version, title, items } | { action: "publish" | "withdraw", id } + * | { action: "save_group_text", opening, closing } (BUG-2436 「内测群文案」 lines). + * GET also returns groupText: the saved opening/closing lines, or the defaults. */ type Row = { @@ -24,12 +31,14 @@ const saveSchema = releaseNoteDraftSchema.extend({ id: z.string().uuid().nullable().optional(), }).strict(); const statusSchema = z.object({ action: z.enum(["publish", "withdraw"]), id: z.string().uuid() }).strict(); -const bodySchema = z.union([saveSchema, statusSchema]); +const groupTextSchema = releaseNoteGroupTextSchema.extend({ action: z.literal("save_group_text") }).strict(); +const bodySchema = z.union([saveSchema, statusSchema, groupTextSchema]); const KNOWN_ERRORS: Record = { release_note_items_invalid: { status: 400, error: "条目不完整:每条要选分组并写内容" }, release_note_not_found: { status: 404, error: "这条更新说明不存在" }, release_note_not_published: { status: 409, error: "只有已发布的版本可以撤回" }, + release_note_group_text_invalid: { status: 400, error: "开头和结尾都要写,每句不超过 200 字" }, }; export async function GET() { @@ -38,7 +47,11 @@ export async function GET() { const rows = await queryAdminRows( "select id, version, title, items, status, published_at, updated_at from public.release_notes order by coalesce(published_at, updated_at) desc limit 200", ); + const groupRows = await queryAdminRows<{ opening: string; closing: string }>( + "select opening, closing from public.release_note_group_text where id", + ); return NextResponse.json({ + groupText: groupRows[0] ? { opening: groupRows[0].opening, closing: groupRows[0].closing } : RELEASE_NOTE_GROUP_TEXT_DEFAULTS, data: rows.map((row) => { const items = z.array(releaseNoteItemSchema).safeParse(row.items); return { @@ -64,6 +77,13 @@ export async function POST(request: Request) { const session = await requireAdminMutation(request, "content.release_notes.write"); const rid = requestId(request); try { + if (body.data.action === "save_group_text") { + await queryAdminRows( + "select public.admin_save_release_note_group_text($1,$2,$3,$4) as saved", + [session.user.id, body.data.opening, body.data.closing, rid], + ); + return NextResponse.json({ data: { opening: body.data.opening, closing: body.data.closing, requestId: rid } }); + } if (body.data.action === "save") { const rows = await queryAdminRows<{ id: string }>( "select public.admin_save_release_note($1,$2,$3,$4,$5::jsonb,$6) as id", diff --git a/frontend/src/components/admin/release-note-group-text.tsx b/frontend/src/components/admin/release-note-group-text.tsx new file mode 100644 index 000000000..844a6c7a7 --- /dev/null +++ b/frontend/src/components/admin/release-note-group-text.tsx @@ -0,0 +1,79 @@ +"use client"; + +import { CopyOutlined } from "@ant-design/icons"; +import { Button, Card, Input, Space, Typography } from "antd"; +import { useRef } from "react"; +import type { TextAreaRef } from "antd/es/input/TextArea"; + +import { + RELEASE_NOTE_GROUP_TEXT_LIMIT, + releaseNoteGroupMessage, + type ReleaseNoteGroup, + type ReleaseNoteGroupText, +} from "@/lib/release-notes"; + +const { Text } = Typography; + +type Props = Readonly<{ + note: Readonly<{ version: string; title: string; items: readonly Readonly<{ group: ReleaseNoteGroup; text: string }>[] }>; + lines: ReleaseNoteGroupText; + disabled?: boolean; + onLinesChange: (lines: ReleaseNoteGroupText) => void; + /** "copied" after a clipboard write; "selected" when the clipboard refused and the text was selected instead. */ + onCopy: (result: "copied" | "selected", text: string) => void; +}>; + +/** + * 「内测群文案」 (BUG-2436): the note as plain text for the beta WeChat group, from the + * same fields as the in-app pop-up, with editable opening and closing lines. + */ +export function ReleaseNoteGroupTextCard({ note, lines, disabled, onLinesChange, onCopy }: Props) { + const textRef = useRef(null); + const text = releaseNoteGroupMessage(note, lines); + + async function copy() { + try { + if (!navigator.clipboard?.writeText) throw new Error("clipboard unavailable"); + await navigator.clipboard.writeText(text); + onCopy("copied", text); + } catch { + const area = textRef.current?.resizableTextArea?.textArea; + area?.focus(); + area?.select(); + onCopy("selected", text); + } + } + + return ( + } onClick={() => void copy()}>复制} + > + +
+ 开头 + onLinesChange({ ...lines, opening: event.target.value })} + /> +
+
+ 结尾 + onLinesChange({ ...lines, closing: event.target.value })} + /> +
+ +
+
+ ); +} diff --git a/frontend/src/components/admin/release-notes-management.tsx b/frontend/src/components/admin/release-notes-management.tsx index 031a1736b..f27e5e1a7 100644 --- a/frontend/src/components/admin/release-notes-management.tsx +++ b/frontend/src/components/admin/release-notes-management.tsx @@ -8,11 +8,15 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import { adminRequestJson, type AdminIdentity } from "@/lib/admin/providers"; import { + RELEASE_NOTE_GROUP_TEXT_DEFAULTS, RELEASE_NOTE_GROUPS, RELEASE_NOTE_LIMITS, releaseNoteDraftSchema, + releaseNoteGroupTextSchema, type ReleaseNoteGroup, + type ReleaseNoteGroupText, } from "@/lib/release-notes"; +import { ReleaseNoteGroupTextCard } from "./release-note-group-text"; import { formatAdminDate } from "./resource-table"; const { Text, Title } = Typography; @@ -70,11 +74,19 @@ export default function ReleaseNotesManagement() { const [loadError, setLoadError] = useState(null); const [editing, setEditing] = useState(null); const [busy, setBusy] = useState(false); + // BUG-2436: the 「内测群文案」 opening/closing lines, as stored and as being edited. + const [savedLines, setSavedLines] = useState(RELEASE_NOTE_GROUP_TEXT_DEFAULTS); + const [lines, setLines] = useState(RELEASE_NOTE_GROUP_TEXT_DEFAULTS); const load = useCallback(async () => { try { - const payload = await adminRequestJson<{ data: Note[] }>("/api/admin/release-notes"); + const payload = await adminRequestJson<{ data: Note[]; groupText?: ReleaseNoteGroupText }>("/api/admin/release-notes"); setNotes(payload.data); + const stored = releaseNoteGroupTextSchema.safeParse(payload.groupText); + if (stored.success) { + setSavedLines(stored.data); + setLines(stored.data); + } setLoadError(null); } catch (error) { setLoadError(error instanceof Error ? error.message : "读取失败"); @@ -94,6 +106,31 @@ export default function ReleaseNotesManagement() { return adminRequestJson<{ data: { id: string } }>("/api/admin/release-notes", { method: "POST", body: JSON.stringify(body) }); } + // Keeps the owner's edited lines for the next version; quiet when nothing changed. + async function saveLines(): Promise { + if (!canWrite) return true; + const next = releaseNoteGroupTextSchema.safeParse(lines); + if (!next.success) { + message.error("群文案的开头和结尾都要写"); + return false; + } + if (next.data.opening === savedLines.opening && next.data.closing === savedLines.closing) return true; + try { + await post({ action: "save_group_text", ...next.data }); + setSavedLines(next.data); + return true; + } catch (error) { + message.error(`群文案的开头结尾没有保存:${error instanceof Error ? error.message : "请求失败"}`); + return false; + } + } + + async function copied(result: "copied" | "selected") { + if (result === "copied") message.success("已复制,可以直接粘贴到群里"); + else message.warning("没能自动复制,文字已经选中,请按 Ctrl+C 或长按复制"); + await saveLines(); + } + async function save(publish: boolean) { if (!editing) return; if (problem) { @@ -103,6 +140,7 @@ export default function ReleaseNotesManagement() { setBusy(true); try { const saved = await post({ action: "save", id: editing.id, ...draftOf(editing) }); + await saveLines(); if (publish) await post({ action: "publish", id: saved.data.id }); await load(); setEditing(null); @@ -208,7 +246,8 @@ export default function ReleaseNotesManagement() { ))} {problem && {problem}} - +
+ 版本 {preview?.version || "(未填)"} {preview?.title || "(未填标题)"} {RELEASE_NOTE_GROUPS.map(({ key, label }) => { @@ -224,6 +263,14 @@ export default function ReleaseNotesManagement() { ); })} + void copied(result)} + /> +
)} diff --git a/frontend/src/lib/release-notes.ts b/frontend/src/lib/release-notes.ts index 71f4e464e..bb5f6699c 100644 --- a/frontend/src/lib/release-notes.ts +++ b/frontend/src/lib/release-notes.ts @@ -67,3 +67,47 @@ export function releaseNoteFromRow(row: Readonly<{ export function unseenReleaseNote(notes: readonly ReleaseNote[]): ReleaseNote | null { return notes.find((note) => !note.seen) ?? null; } + +/** + * 「内测群文案」 (BUG-2436, owner-approved 2026-11-27): the same note as plain text for + * the beta WeChat group. A fixed template, no model: opening line, title, every item + * numbered 1..n in the order 新功能 → 改进 → 修复, closing line; a blank line between + * blocks, no markdown symbols. {版本} in the opening or closing line becomes the version. + */ +export const RELEASE_NOTE_GROUP_TEXT_DEFAULTS = { + opening: "大家好,Jyotisha 更新到 {版本} 啦~", + closing: "用着有任何感觉不对的地方,随时在群里说,我们都在看。", +} as const; +export const RELEASE_NOTE_GROUP_TEXT_LIMIT = 200; +export const RELEASE_NOTE_GROUP_ORDER: readonly ReleaseNoteGroup[] = ["feature", "improve", "fix"]; + +export const releaseNoteGroupTextSchema = z.object({ + opening: z.string().trim().min(1).max(RELEASE_NOTE_GROUP_TEXT_LIMIT), + closing: z.string().trim().min(1).max(RELEASE_NOTE_GROUP_TEXT_LIMIT), +}).strict(); +export type ReleaseNoteGroupText = z.infer; + +// Markdown and list marks that WeChat shows literally: leading #, >, -, *, + or "1." / +// "1、", and **bold**, __bold__, `code`. +function plainLine(text: string): string { + return text + .replace(/\r\n?/g, "\n") + .split("\n") + .map((line) => line.trim().replace(/^(?:#{1,6}\s*|>\s*|[-*+•·]\s+|\d+[.、))]\s*)+/u, "").replace(/\*\*|__|`/g, "")) + .filter((line) => line.length > 0) + .join(" "); +} + +export function releaseNoteGroupMessage( + note: Readonly<{ version: string; title: string; items: readonly Readonly<{ group: ReleaseNoteGroup; text: string }>[] }>, + lines: Readonly<{ opening: string; closing: string }> = RELEASE_NOTE_GROUP_TEXT_DEFAULTS, +): string { + const version = note.version.trim(); + const fill = (line: string) => plainLine(line.replaceAll("{版本}", version)); + const texts = RELEASE_NOTE_GROUP_ORDER + .flatMap((group) => note.items.filter((item) => item.group === group).map((item) => plainLine(item.text))) + .filter((text) => text.length > 0); + return [fill(lines.opening), plainLine(note.title), ...texts.map((text, at) => `${at + 1}. ${text}`), fill(lines.closing)] + .filter((block) => block.length > 0) + .join("\n\n"); +} diff --git a/frontend/supabase/migrations/20261127010000_release_note_group_text.sql b/frontend/supabase/migrations/20261127010000_release_note_group_text.sql new file mode 100644 index 000000000..a53acce45 --- /dev/null +++ b/frontend/supabase/migrations/20261127010000_release_note_group_text.sql @@ -0,0 +1,89 @@ +-- BUG-2436 「内测群文案」 (owner-approved 2026-11-27): the admin 「更新说明」 +-- editor also shows the same note as plain text for the beta WeChat group. +-- The opening and closing lines around the items are editable, and the +-- owner's last edit is kept for the next version. +-- +-- release_note_group_text: a single row (id = true) with the two lines. +-- Audit rows use a fixed target id (audit target_id is not null; there is one row). +-- +-- Access: +-- * RLS on; no table privilege for app, service or authenticated roles; +-- * the admin console reads the row through an admin_runtime select policy +-- (BUG-1935: a grant without a policy reads nothing) and writes through a +-- permission-checked, audited function (content.release_notes.write). +-- +-- Backward compatibility: additive only. + +begin; + +create table if not exists public.release_note_group_text ( + id boolean primary key default true check (id), + opening text not null check (char_length(btrim(opening)) between 1 and 200), + closing text not null check (char_length(btrim(closing)) between 1 and 200), + updated_by uuid references auth.users(id) on delete set null, + updated_at timestamptz not null default clock_timestamp() +); + +alter table public.release_note_group_text enable row level security; + +revoke all on table public.release_note_group_text from public, anon, authenticated, service_role; + +do $$ +begin + if exists (select 1 from pg_roles where rolname = 'app_runtime') then + revoke all on table public.release_note_group_text from app_runtime; + end if; + if exists (select 1 from pg_roles where rolname = 'service_runtime') then + revoke all on table public.release_note_group_text from service_runtime; + end if; +end; +$$; + +create or replace function public.admin_save_release_note_group_text( + p_actor_user_id uuid, p_opening text, p_closing text, p_request_id text +) +returns boolean +language plpgsql +security definer +set search_path = '' +as $$ +begin + if not public.admin_has_permission(p_actor_user_id, 'content.release_notes.write') then + raise exception 'admin_permission_denied' using errcode = '42501'; + end if; + if p_opening is null or p_closing is null + or char_length(btrim(p_opening)) not between 1 and 200 + or char_length(btrim(p_closing)) not between 1 and 200 then + raise exception 'release_note_group_text_invalid' using errcode = '22023'; + end if; + insert into public.release_note_group_text (id, opening, closing, updated_by) + values (true, btrim(p_opening), btrim(p_closing), p_actor_user_id) + on conflict (id) do update + set opening = excluded.opening, closing = excluded.closing, + updated_by = excluded.updated_by, updated_at = clock_timestamp(); + insert into audit.admin_audit_logs (actor_user_id, actor_email, actor_role, action, target_type, target_id, after_value, + request_id, permission_used, reason) + select p_actor_user_id, lower(btrim(u.email)), 'admin', 'content.release_notes.group_text', 'release_note_group_text', + '00000000-0000-4000-8000-000000002436'::uuid, + jsonb_build_object('opening', btrim(p_opening), 'closing', btrim(p_closing)), + p_request_id, 'content.release_notes.write', 'admin_console_release_notes' + from identity.users u where u.id = p_actor_user_id on conflict do nothing; + return true; +end; +$$; + +revoke all on function public.admin_save_release_note_group_text(uuid, text, text, text) from public, anon, authenticated; + +do $$ +begin + if exists (select 1 from pg_roles where rolname = 'admin_runtime') then + grant select on table public.release_note_group_text to admin_runtime; + drop policy if exists release_note_group_text_admin_read on public.release_note_group_text; + create policy release_note_group_text_admin_read on public.release_note_group_text + for select to admin_runtime using (true); + grant execute on function public.admin_save_release_note_group_text(uuid, text, text, text) to admin_runtime; + end if; +end; +$$; + +commit; diff --git a/frontend/tests/annual-questions-2085.test.tsx b/frontend/tests/annual-questions-2085.test.tsx index 4b826bc80..26a039ccd 100644 --- a/frontend/tests/annual-questions-2085.test.tsx +++ b/frontend/tests/annual-questions-2085.test.tsx @@ -339,6 +339,8 @@ test("the migration adds one column, one unique index and a guard; no settlement "20261126030000_report_exports.sql", // 原值:最后是 BUG-2359 一份;新值:再加 BUG-2418 报告按人排队(换两个唯一索引、改两个领取函数和排队视图,不碰这里检查的表);原因:20261126040000_report_queue_per_user.sql "20261126040000_report_queue_per_user.sql", + // 原值:最后是 BUG-2418 一份;新值:再加 BUG-2436 内测群文案(新表 release_note_group_text 和一个后台函数,不碰这里检查的表);原因:20261127010000_release_note_group_text.sql + "20261127010000_release_note_group_text.sql", ]); assert.equal(names.filter((item) => item.slice(0, 14) === name.slice(0, 14)).length, 1); const sql = read(`../supabase/migrations/${name}`); diff --git a/frontend/tests/avatar-image-2057.test.ts b/frontend/tests/avatar-image-2057.test.ts index 11fd2aed7..bca47c1a8 100644 --- a/frontend/tests/avatar-image-2057.test.ts +++ b/frontend/tests/avatar-image-2057.test.ts @@ -130,6 +130,8 @@ test("BUG-2057: the avatar table is owner-only, lives in the database, and its m "20261126030000_report_exports.sql", // 原值:最后是 BUG-2359 一份;新值:再加 BUG-2418 报告按人排队(换两个唯一索引、改两个领取函数和排队视图,不碰这里检查的表);原因:20261126040000_report_queue_per_user.sql "20261126040000_report_queue_per_user.sql", + // 原值:最后是 BUG-2418 一份;新值:再加 BUG-2436 内测群文案(新表 release_note_group_text 和一个后台函数,不碰这里检查的表);原因:20261127010000_release_note_group_text.sql + "20261127010000_release_note_group_text.sql", ], "the seconds migrations, the report-question column, the admin reading-log function and the coordinate-source column come after it"); for (const name of after) assert.doesNotMatch(read(`supabase/migrations/${name}`), /profile_avatar_images/u); // Idempotent. diff --git a/frontend/tests/database-local-business.test.ts b/frontend/tests/database-local-business.test.ts index 74c954adc..a27c85665 100644 --- a/frontend/tests/database-local-business.test.ts +++ b/frontend/tests/database-local-business.test.ts @@ -465,6 +465,10 @@ test("local PostgreSQL applies the reviewed business schema and serves authentic "redemption_codes", // 新值: 加入 release_note_reads、release_notes // 原因: 「更新说明」(issue #331,20261122130000_release_notes.sql) + // 原值: redemption_codes 之后直接是 release_note_reads + // 新值: 中间加入 release_note_group_text(按字母序 group < reads) + // 原因: BUG-2436 「内测群文案」 开头结尾一行设置(20261127010000_release_note_group_text.sql) + "release_note_group_text", "release_note_reads", "release_notes", "reply_quality_snapshots", diff --git a/frontend/tests/database-release-notes-331.test.ts b/frontend/tests/database-release-notes-331.test.ts index 2868bac1b..0512ff1d6 100644 --- a/frontend/tests/database-release-notes-331.test.ts +++ b/frontend/tests/database-release-notes-331.test.ts @@ -33,6 +33,7 @@ test("release notes: editors publish through audited functions; each user sees e }); assert.equal(migration.status, 0, `${migration.stdout}${migration.stderr}`); assert.match(migration.stdout, /applied 20261122130000_release_notes\.sql/); + assert.match(migration.stdout, /applied 20261127010000_release_note_group_text\.sql/); const save = "public.admin_save_release_note(uuid, uuid, text, text, jsonb, text)"; const status = "public.admin_set_release_note_status(uuid, uuid, text, text)"; @@ -110,6 +111,24 @@ test("release notes: editors publish through audited functions; each user sees e ); // A duplicate version is refused. assert.throws(() => fixture.psql(`select public.admin_save_release_note('${editorId}', null, '2026.11.23', '重复', '${items}'::jsonb, 'r-331-7')`)); + + // BUG-2436 「内测群文案」 lines: one stored row, read by admin_runtime through a policy, + // written only through the audited function by content.release_notes.write. + const groupSave = "public.admin_save_release_note_group_text(uuid, text, text, text)"; + assert.equal(fixture.psql(`select has_function_privilege('admin_runtime', '${groupSave}', 'EXECUTE')`), "t"); + assert.equal(fixture.psql(`select has_function_privilege('authenticated', '${groupSave}', 'EXECUTE')`), "f"); + assert.equal(fixture.psql(`select has_function_privilege('app_runtime', '${groupSave}', 'EXECUTE')`), "f"); + for (const role of ["app_runtime", "service_runtime", "authenticated", "admin_runtime"]) { + assert.equal(fixture.psql(`select has_table_privilege('${role}', 'public.release_note_group_text', 'INSERT')`), "f", role); + } + assert.equal(fixture.psql(`select has_table_privilege('admin_runtime', 'public.release_note_group_text', 'SELECT')`), "t"); + assert.equal(fixture.psql(`select count(*) from pg_policies where tablename = 'release_note_group_text' and policyname = 'release_note_group_text_admin_read'`), "1"); + assert.throws(() => fixture.psql(`select public.admin_save_release_note_group_text('${outsiderId}', '开头', '结尾', 'r-2436-0')`), /admin_permission_denied/); + assert.throws(() => fixture.psql(`select public.admin_save_release_note_group_text('${editorId}', ' ', '结尾', 'r-2436-1')`), /release_note_group_text_invalid/); + assert.equal(fixture.psql(`select public.admin_save_release_note_group_text('${editorId}', '大家好 {版本}', '有事说', 'r-2436-2')`), "t"); + assert.equal(fixture.psql(`select public.admin_save_release_note_group_text('${editorId}', ' 各位 {版本} ', '有事群里说', 'r-2436-3')`), "t"); + assert.equal(fixture.psql(`select count(*) || '|' || opening || '|' || closing from public.release_note_group_text group by opening, closing`), "1|各位 {版本}|有事群里说"); + assert.equal(fixture.psql(`select count(*) from audit.admin_audit_logs where action = 'content.release_notes.group_text'`), "2"); } finally { fixture.stop(); } diff --git a/frontend/tests/onboarding-place-2167.test.tsx b/frontend/tests/onboarding-place-2167.test.tsx index d48bc6732..ece0cfc5e 100644 --- a/frontend/tests/onboarding-place-2167.test.tsx +++ b/frontend/tests/onboarding-place-2167.test.tsx @@ -121,6 +121,8 @@ test("the migration widens the profiles CHECK to exactly the shared list; chart_ "20261126030000_report_exports.sql", // 原值:最后是 BUG-2359 一份;新值:再加 BUG-2418 报告按人排队(换两个唯一索引、改两个领取函数和排队视图,不碰这里检查的表);原因:20261126040000_report_queue_per_user.sql "20261126040000_report_queue_per_user.sql", + // 原值:最后是 BUG-2418 一份;新值:再加 BUG-2436 内测群文案(新表 release_note_group_text 和一个后台函数,不碰这里检查的表);原因:20261127010000_release_note_group_text.sql + "20261127010000_release_note_group_text.sql", ]); assert.doesNotMatch(read("../supabase/migrations/20261122130000_release_notes.sql"), /birth_place_provider/); assert.doesNotMatch(read("../supabase/migrations/20261122140000_redemption_code_kinds.sql"), /birth_place_provider/); diff --git a/frontend/tests/release-note-group-text-2436.test.tsx b/frontend/tests/release-note-group-text-2436.test.tsx new file mode 100644 index 000000000..6b4f7a457 --- /dev/null +++ b/frontend/tests/release-note-group-text-2436.test.tsx @@ -0,0 +1,103 @@ +// BUG-2436 「内测群文案」 (owner-approved 2026-11-27): the admin 「更新说明」 editor also shows the +// note as plain text for the beta WeChat group, from the same fields, by a fixed template (no model): +// opening line, title, every item numbered 1..n in the order 新功能 → 改进 → 修复, closing line, a blank +// line between blocks, no markdown symbols. The opening/closing lines are editable and kept server-side. +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; +import { renderToStaticMarkup } from "react-dom/server"; + +import { ReleaseNoteGroupTextCard } from "../src/components/admin/release-note-group-text.tsx"; +import { + RELEASE_NOTE_GROUP_TEXT_DEFAULTS, + releaseNoteGroupMessage, + releaseNoteGroupTextSchema, +} from "../src/lib/release-notes.ts"; + +const source = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8"); + +const note = { + version: "1.7", + title: "报告和对话更快了", + items: [ + { group: "fix" as const, text: "打开报告不再空白" }, + { group: "feature" as const, text: "报告里可以选中一段直接提问" }, + { group: "improve" as const, text: "报告打开更快" }, + { group: "feature" as const, text: "首页新增三个常见问题" }, + ], +}; + +test("the group text is opening, title, items 1..n in 新功能 → 改进 → 修复 order, closing, blank lines between", () => { + assert.equal( + releaseNoteGroupMessage(note), + [ + "大家好,Jyotisha 更新到 1.7 啦~", + "报告和对话更快了", + "1. 报告里可以选中一段直接提问", + "2. 首页新增三个常见问题", + "3. 报告打开更快", + "4. 打开报告不再空白", + "用着有任何感觉不对的地方,随时在群里说,我们都在看。", + ].join("\n\n"), + ); +}); + +test("edited opening/closing lines are used, {版本} filled in both", () => { + const text = releaseNoteGroupMessage(note, { opening: "各位,{版本} 上线了", closing: "有问题找我({版本})" }); + assert.ok(text.startsWith("各位,1.7 上线了\n\n")); + assert.ok(text.endsWith("\n\n有问题找我(1.7)")); +}); + +test("pasted markdown or list marks are stripped so WeChat shows plain numbered lines", () => { + const text = releaseNoteGroupMessage({ + version: "1.7", + title: "## **大更新**", + items: [ + { group: "feature", text: "- 新的 `报告` 页面" }, + { group: "improve", text: "1. 更快\n第二行" }, + { group: "fix", text: "> 修好了 __登录__" }, + ], + }); + assert.doesNotMatch(text, /[#*`>_]|^- /m); + assert.deepEqual(text.split("\n\n").slice(1, 5), ["大更新", "1. 新的 报告 页面", "2. 更快 第二行", "3. 修好了 登录"]); + // No line breaks inside a block: every block is one line. + for (const block of text.split("\n\n")) assert.doesNotMatch(block, /\n/); +}); + +test("the defaults are the owner's wording, and both lines must be non-empty", () => { + assert.equal(RELEASE_NOTE_GROUP_TEXT_DEFAULTS.opening, "大家好,Jyotisha 更新到 {版本} 啦~"); + assert.equal(RELEASE_NOTE_GROUP_TEXT_DEFAULTS.closing, "用着有任何感觉不对的地方,随时在群里说,我们都在看。"); + assert.equal(releaseNoteGroupTextSchema.safeParse({ opening: " ", closing: "x" }).success, false); + assert.equal(releaseNoteGroupTextSchema.safeParse({ opening: "a", closing: "b" }).success, true); +}); + +test("the admin card renders the plain text, both editable lines and a 复制 button", () => { + const markup = renderToStaticMarkup( + {}} onCopy={() => {}} />, + ); + assert.match(markup, /内测群文案/); + assert.match(markup, /复制/); + assert.match(markup, /aria-label="群文案开头"[^>]*value="大家好,Jyotisha 更新到 \{版本\} 啦~"|value="大家好,Jyotisha 更新到 \{版本\} 啦~"[^>]*aria-label="群文案开头"/); + assert.match(markup, /readOnly=""|readonly=""/i); + assert.match(markup, /1\. 报告里可以选中一段直接提问/); + assert.match(markup, /4\. 打开报告不再空白/); +}); + +test("the editor shows both previews, copies through the clipboard with a selection fallback, and reports by toast", () => { + const editor = source("src/components/admin/release-notes-management.tsx"); + assert.match(editor, /用户看到的样子/); + assert.match(editor, /