fix(defaults): seed 改补缺、.prose 层真生效、写库 E2E 走临时库
三件事的共同点:默认值本来就在鼓励做错事。
1) seed 不再无条件覆盖(OPEN-08 / §17.2 根治)
`seedItems()` 原为 upsert 全字段覆盖、案例还无条件 deleteMany ⇒
「跑一次 seed」= 「冲掉 CMS 人工编辑」。改为默认补缺:
已存在同 slug 的行跳过并计入汇总(全跳过时日志明写「未写任何一行」),
只有显式 --force 才覆盖/删除,未知参数直接中止。
- src/lib/seed-write-policy.ts(纯函数)+ 14 例单测
- 临时库三向负对照:人工编辑存活 / --force 还原 / --forced 零写入
2) .prose 排版层从「从未定义」变成真规则(OPEN-09 / §18.6-1)
privacy/terms 写了两年 `prose prose-lg`,而仓里没装
@tailwindcss/typography ⇒ 两个类从未生成过任何 CSS。手写一份(ADR-0010),
整层用 :where() 保持零特异性 —— 库里已存的法律页 HTML 自带 inline utility,
层若按 `.prose p`(0,1,1) 写就会盖掉它们(实测:/terms 呼出块标签被染灰 329px、
日期行高 1.65→1.85 共 1222px)。行高与节奏刻意留在标记上。
- src/app/globals.css + 12 例判据(含「层内不许裸选择器」反方向守卫)
- 列表选择器钉死为 `:where(.prose) ul:where(:not(.list-none))`:
特异性 0 会输给基座 `ul`(0,0,1)(点静默消失、padding 却生效)
- 等价性:新种子库(无 inline 类)vs 已入库基线 = 0 像素差异、同高
- 视觉只读复核:/privacy /terms × 5 project = 10/10 通过,未写基线
3) 写库型 E2E 从「未授权」变成「可随时跑」(OPEN-07 / AUTH-D4 闭合)
11 例改为指向 /tmp 一次性 SQLite(migrate → seed → 路由预热 → next dev),
`npm run test:e2e:write-db` ⇒ 11 passed / 0 failed,prisma/dev.db 的
inode+size+mtime 跑前跑后不变。三个坑记入 lessons §5.66
(cookie domain 字面量、revalidate 密钥要同源、dev 懒编译需预热)。
文档:qa-tracker §19 新建 OPEN-* 登记表(15 行,只增不改名)、lessons §5.65–5.67、
ADR-0010、CONTEXT 决策表 3 行、quality-gates / testing / CLAUDE / README 同步。
门禁:type-check / type-check:e2e / lint(0 error, 88 warning) / jest(162 套件 1904 例)
/ check:grammar(21/21) / selftest / check:accents / check:dead / check:motion
/ check:a11y 全部 EXIT=0。
已知:check:visual 整段红是 pre-existing(check:accents:selftest 在 HEAD 纯净树上
同样 8/10 红),登记 OPEN-15;写库 E2E 有残差抖动,宣称前须连续两次 EXIT=0。
This commit is contained in:
1 parent
683f693b48
commit
9d144f623f
20 files changed
+1091
-250
No files matched your search
@@ -0,0 +1,113 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* `.prose` 排版层的判据(2026-11-25)。
|
||||
*
|
||||
* 为什么需要这组测试:privacy / terms 从 2026-07 起在标记里写着 `prose` / `prose-lg`,
|
||||
* 而本仓没装 `@tailwindcss/typography` ⇒ 这两个类**从未生成过任何规则**,
|
||||
* type-check / lint / build / 单测 / axe 五道全绿(qa-tracker §18.6-1、lessons §5.62 同族)。
|
||||
*
|
||||
* 只断言「CSS 里出现过 .prose」不够 —— 那正是当初的失效模式:名字在,规则不在,
|
||||
* 或者规则在、没人用。所以这里钉三侧:
|
||||
* ① 规则侧:h2 / h3 / p / ul 必须存在,且**取令牌**(不许写字面量字阶)。
|
||||
* ② 使用侧:privacy / terms 的内容根节点必须挂 `prose`(否则规则没有落点)。
|
||||
* ③ **特异性侧**:整层必须裹在 `:where(...)` 里(特异性恒 0)。这不是洁癖 ——
|
||||
* 库里已存的法律页 HTML 自带 `text-[var(--color-text-primary)]` 这类 utility,
|
||||
* 层内若是 `.prose p`(0,1,1)就会把它们盖掉:实测 /terms 底部「最后更新日期」
|
||||
* 被染成 muted,329 像素差异,包围盒正是那一行(细节见 ADR-0010)。
|
||||
*/
|
||||
|
||||
const ROOT = process.cwd();
|
||||
const css = readFileSync(path.join(ROOT, 'src/app/globals.css'), 'utf-8').replace(
|
||||
/\/\*[\s\S]*?\*\//g,
|
||||
(m) => '\n'.repeat(m.match(/\n/g)?.length ?? 0),
|
||||
);
|
||||
|
||||
/** 取 `.prose` 层正文:从 `:where(.prose) {` 到 ol 规则收尾。 */
|
||||
function proseBlock(): string {
|
||||
const start = css.indexOf(' :where(.prose) {');
|
||||
expect(start).toBeGreaterThan(-1);
|
||||
const end = css.indexOf(':where(.prose) ol:where(:not(.list-none))');
|
||||
expect(end).toBeGreaterThan(start);
|
||||
const tail = css.indexOf('}', css.indexOf('padding-left: 1.5rem;', end));
|
||||
return css.slice(start, tail + 1);
|
||||
}
|
||||
|
||||
describe('.prose 排版层(规则侧)', () => {
|
||||
const block = proseBlock();
|
||||
|
||||
it('四条元素规则都在:h2 / h3 / p / ul(按「选择器 + 左花括号」判,不用子串)', () => {
|
||||
for (const selector of ['h2', 'h3', 'p', 'ul']) {
|
||||
expect(block).toMatch(new RegExp(`:where\\(\\.prose\\) ${selector}\\s*[{,]`));
|
||||
}
|
||||
});
|
||||
|
||||
it('字阶与颜色走令牌,不写字面量(字面量会让排版层与令牌体系脱钩)', () => {
|
||||
expect(block).toContain('font-size: var(--font-size-2xl)');
|
||||
expect(block).toContain('font-size: var(--font-size-xl)');
|
||||
expect(block).toContain('color: var(--color-text-muted)');
|
||||
expect(block).toContain('color: var(--color-text-primary)');
|
||||
});
|
||||
|
||||
it('无符号清单必须能豁免项目符号(`:not(.list-none)`)—— 否则联系方式类清单会长出圆点', () => {
|
||||
expect(block).toContain(':where(.prose) ul:where(:not(.list-none))');
|
||||
expect(block).toContain('list-style-type: disc');
|
||||
});
|
||||
|
||||
it('列表选择器的特异性形状被钉死:`:not(...)` 必须在 `:where()` 里', () => {
|
||||
// 两侧都实测踩过(详见 ADR-0010 与 globals.css 该处注释):
|
||||
// · `:where(.prose ul:not(.list-none))` ⇒ 特异性 0 < 基座 `ul`(0,0,1)
|
||||
// ⇒ `list-style-type` 静默变 none(点消失,padding 却生效,像「只生效一半」);
|
||||
// · `:where(.prose ul):not(.list-none)` ⇒ 特异性 (0,1,0) > 基座
|
||||
// ⇒ 连作者写的 `list-decimal` 一起盖掉。
|
||||
const shaped = block.match(/:where\(\.prose\) (?:ul|ol):where\(:not\(\.list-none\)\)\s*\{/g) ?? [];
|
||||
expect(shaped.length).toBe(2);
|
||||
// 反方向:` :not(...) ` 不许出现在 ` :where(.prose) ` 里面(那会把特异性压到 0,输给基座元素选择器)
|
||||
expect(block).not.toMatch(/:where\(\.prose[^)]*:not\(/);
|
||||
});
|
||||
|
||||
it('反方向守卫①:整层零特异性 —— 每条规则都必须裹 `:where(`,不许裸 `.prose ...`', () => {
|
||||
const selectors = block.match(/^ {2}[^@{}\n][^{}]*\{$/gm) ?? [];
|
||||
expect(selectors.length).toBeGreaterThan(3);
|
||||
for (const selector of selectors) {
|
||||
expect(selector.trim().startsWith(':where(')).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('反方向守卫②:line-height 不进本层(进了就会盖掉库里 HTML 自己的行高)', () => {
|
||||
expect(block).not.toContain('line-height');
|
||||
});
|
||||
|
||||
it('不在排版层里定节奏:section / li 的间距属版式选择,收进来会抹平逐段差异', () => {
|
||||
expect(block).not.toMatch(/:where\(\.prose\) (section|li)\b/);
|
||||
expect(block).not.toMatch(/margin-bottom:\s*(1rem|0\.75rem)/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prose 排版层(使用侧)', () => {
|
||||
it.each([
|
||||
['src/app/privacy/page.tsx'],
|
||||
['src/app/terms/page.tsx'],
|
||||
])('%s 的内容根节点挂着 prose', (file) => {
|
||||
const src = readFileSync(path.join(ROOT, file), 'utf-8');
|
||||
expect(src).toContain('className="prose max-w-none"');
|
||||
});
|
||||
|
||||
it.each([
|
||||
['src/app/privacy/page.tsx'],
|
||||
['src/app/terms/page.tsx'],
|
||||
])('%s 不再把字阶/字重/正文色重复写回标记(重复 = 排版层不承重,删了也看不出来)', (file) => {
|
||||
const src = readFileSync(path.join(ROOT, file), 'utf-8');
|
||||
expect(src).not.toContain('text-2xl font-bold');
|
||||
expect(src).not.toContain('text-xl font-semibold');
|
||||
// 行高仍留在标记上(本层刻意不管它),所以这里**必须**还看得到 leading-relaxed。
|
||||
expect(src).toContain('leading-relaxed');
|
||||
});
|
||||
|
||||
it('CMS 种子 HTML 同样只留 prose(不再写从未定义过的 prose-lg)', () => {
|
||||
const seed = readFileSync(path.join(ROOT, 'prisma/seeds/legal-pages.ts'), 'utf-8');
|
||||
expect(seed).toContain('class="prose max-w-none"');
|
||||
expect(seed).not.toContain('prose-lg');
|
||||
});
|
||||
});
|
||||
@@ -927,6 +927,72 @@ html[data-theme='dark'] body {
|
||||
text-wrap: balance;
|
||||
}
|
||||
|
||||
/* === .prose:法律页/长文正文排版层(2026-11-25) ===
|
||||
背景:privacy / terms 从 2026-07 起一直写着 `prose prose-lg`,而本仓**没装**
|
||||
`@tailwindcss/typography` ⇒ 这两个类从未生成过任何规则(qa-tracker §18.6-1)。
|
||||
手写而非加依赖的理由见 docs/adr/0010-prose-layer-by-hand.md。
|
||||
|
||||
为什么整层都裹 `:where(...)`:**这是一层默认值,不是覆盖层。**
|
||||
本仓的正文有两代来源 —— React 组件(本次已迁移,标记上只剩 `prose`)与
|
||||
库里已存的法律页 HTML(2026-07 起带着 `text-2xl font-bold text-[var(--color-text-primary)]`
|
||||
这类 inline utility,且不能为了排版改写库)。若写成 `.prose h2`(0,1,1),
|
||||
它的特异性高于单类名 utility(0,1,0),就会强行盖掉库里那些显式取值 ——
|
||||
实测代价很具体:`/terms` 底部「最后更新日期」标签被从 text-primary 染成 text-muted
|
||||
(329 像素,包围盒正是那一行)。`:where()` 的特异性恒为 0,于是
|
||||
「有显式 utility 的地方听标记的,没有的地方听这层默认」—— 两代来源同时成立。
|
||||
|
||||
值不是新设计:逐条取自已渲染的 inline utility ——
|
||||
text-2xl→--font-size-2xl、font-bold→700、font-semibold→600、
|
||||
text-muted→--color-text-muted、pl-6→1.5rem。
|
||||
**行高与节奏刻意不收进本层**:leading / section 间距 / p 的 mb-* 仍留在标记上,
|
||||
因为它们逐段不同(法律页里 mb-4 / mb-2 / 无间距并存),收进来会抹平差异。
|
||||
判据:R21(自定义类名必须有定义)+ src/app/__tests__/prose-layer.test.ts。 */
|
||||
:where(.prose) {
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
|
||||
:where(.prose) h2 {
|
||||
font-size: var(--font-size-2xl);
|
||||
font-weight: 700;
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
|
||||
:where(.prose) h3 {
|
||||
font-size: var(--font-size-xl);
|
||||
font-weight: 600;
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
|
||||
:where(.prose) p {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
/* 列表:色与项目符号都走这层默认;`:not(.list-none)` 让「无符号清单」(联系方式类)
|
||||
由标记的 `list-none` 决定。整个选择器裹在 `:where()` 里 ⇒ `.list-none`
|
||||
这类 utility 仍然胜出(两者特异性若打平,就变成靠书写顺序决定,太脆)。 */
|
||||
:where(.prose) ul,
|
||||
:where(.prose) ol {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
/* ⚠ 这两个选择器必须是 `:where(.prose) ul:where(:not(.list-none))` 这个形状:
|
||||
把 `:not(...)` 直接写在 `:where()` 外面会让特异性变成 (0,1,0),**高于**基座
|
||||
`ul { list-style-type: none }` 的 (0,0,1) —— 那样倒是能生效,但会连作者写的
|
||||
`list-decimal` 一起盖掉;而把整条塞进 `:where()` 又会让特异性降到 0,**低于**基座
|
||||
`ul`(0,0,1) ⇒ 实测列表点直接消失(`list-style-type` 计算值为 none,
|
||||
padding 却是对的,看起来像"规则生效了一半",最容易误判)。
|
||||
正确形状 = `:where(.prose)`(0) + `ul`(0,0,1) + `:where(:not(...))`(0) ⇒ 与基座同特异性、
|
||||
靠层序取胜,同时让 `.list-none` / `.list-decimal` 这类 utility(0,1,0) 继续赢。 */
|
||||
:where(.prose) ul:where(:not(.list-none)) {
|
||||
list-style-type: disc;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
:where(.prose) ol:where(:not(.list-none)) {
|
||||
list-style-type: decimal;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
|
||||
.bg-dots {
|
||||
background-image: radial-gradient(circle, var(--color-border-primary) 1px, transparent 1px);
|
||||
|
||||
+49
-49
@@ -13,33 +13,33 @@ export const revalidate = 3600;
|
||||
|
||||
function PrivacyContent() {
|
||||
return (
|
||||
<div className="max-w-none">
|
||||
<div className="prose max-w-none">
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">引言</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">引言</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
四川睿新致远科技有限公司(以下简称“我们”、“公司”)深知个人信息对您的重要性,并会尽全力保护您的个人信息安全可靠。我们致力于维持您对我们的信任,恪守以下原则,保护您的个人信息:权责一致原则、目的明确原则、选择同意原则、最少够用原则、确保安全原则、主体参与原则、公开透明原则等。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
本隐私政策适用于您通过四川睿新致远科技有限公司官方网站、移动应用、产品服务等渠道访问和使用我们的产品和服务时,我们收集和使用您的个人信息的情形。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">一、我们如何收集和使用您的个人信息</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">一、我们如何收集和使用您的个人信息</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们会遵循正当、合法、必要的原则,仅为实现产品功能,向您提供服务之目的,收集和使用您的个人信息。
|
||||
</p>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">1.1 我们收集的个人信息</h3>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2 mb-4">
|
||||
<h3 className="mb-3">1.1 我们收集的个人信息</h3>
|
||||
<ul className="space-y-2 mb-4">
|
||||
<li>账户信息:当您注册账户时,我们可能收集您的姓名、电子邮箱地址、手机号码、公司名称等。</li>
|
||||
<li>联系信息:当您通过联系表单或客服与我们沟通时,我们可能收集您的姓名、电子邮箱地址、手机号码、留言内容等。</li>
|
||||
<li>使用信息:我们可能收集您使用我们产品和服务的信息,包括访问时间、浏览记录、操作日志等。</li>
|
||||
<li>设备信息:我们可能收集您使用的设备信息,包括设备型号、操作系统、浏览器类型等。</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">1.2 我们如何使用您的个人信息</h3>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<h3 className="mb-3">1.2 我们如何使用您的个人信息</h3>
|
||||
<ul className="space-y-2">
|
||||
<li>提供产品和服务:向您提供我们的产品和服务,处理您的请求和订单。</li>
|
||||
<li>客户服务:与您联系,提供客户支持,回复您的咨询和反馈。</li>
|
||||
<li>改进产品和服务:分析使用情况,改进我们的产品和服务质量。</li>
|
||||
@@ -49,33 +49,33 @@ function PrivacyContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">二、我们如何共享、转让、公开披露您的个人信息</h2>
|
||||
<h2 className="mb-4">二、我们如何共享、转让、公开披露您的个人信息</h2>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">2.1 共享</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">2.1 共享</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们不会向其他任何公司、组织和个人分享您的个人信息,但以下情况除外:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2 mb-4">
|
||||
<ul className="space-y-2 mb-4">
|
||||
<li>在获取明确同意的情况下分享:获得您的明确同意后,我们会与其他方共享您的个人信息。</li>
|
||||
<li>根据法律法规、法律程序、强制性的行政或司法要求所必须的情况进行提供。</li>
|
||||
<li>在涉及合并、收购或破产清算时,如涉及到个人信息转让,我们会要求新的持有您个人信息的公司、组织继续受本隐私政策的约束。</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">2.2 转让</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">2.2 转让</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们不会将您的个人信息转让给任何公司、组织和个人,但以下情况除外:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2 mb-4">
|
||||
<ul className="space-y-2 mb-4">
|
||||
<li>在获取明确同意的情况下转让。</li>
|
||||
<li>根据适用的法律法规、法律程序、强制性的行政或司法要求所必须的情况进行提供。</li>
|
||||
<li>在涉及合并、收购或破产清算时,如涉及到个人信息转让,我们会要求新的持有您个人信息的公司、组织继续受本隐私政策的约束。</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">2.3 公开披露</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<h3 className="mb-3">2.3 公开披露</h3>
|
||||
<p className="leading-relaxed">
|
||||
我们仅会在以下情况下,公开披露您的个人信息:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="space-y-2">
|
||||
<li>获得您的明确同意。</li>
|
||||
<li>基于法律法规或法律程序的要求。</li>
|
||||
<li>在涉及合并、收购或破产清算时。</li>
|
||||
@@ -84,11 +84,11 @@ function PrivacyContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">三、我们如何保护您的个人信息</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">三、我们如何保护您的个人信息</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们已使用符合业界标准的安全防护措施保护您提供的个人信息,防止数据遭到未经授权访问、公开披露、使用、修改、损坏或丢失。我们会采取一切合理可行的措施,保护您的个人信息。
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="space-y-2">
|
||||
<li>使用加密技术确保数据传输和存储安全。</li>
|
||||
<li>限制访问权限,仅授权人员可访问个人信息。</li>
|
||||
<li>定期进行安全审计和风险评估。</li>
|
||||
@@ -98,11 +98,11 @@ function PrivacyContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">四、您的权利</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">四、您的权利</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
按照中国相关的法律、法规、标准,以及其他国家、地区的通行做法,我们保障您对自己的个人信息行使以下权利:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="space-y-2">
|
||||
<li>访问您的个人信息。</li>
|
||||
<li>更正您的个人信息。</li>
|
||||
<li>删除您的个人信息。</li>
|
||||
@@ -110,30 +110,30 @@ function PrivacyContent() {
|
||||
<li>注销您的账户。</li>
|
||||
<li>获取您的个人信息副本。</li>
|
||||
</ul>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mt-4">
|
||||
<p className="leading-relaxed mt-4">
|
||||
如您需要行使上述权利,请通过本隐私政策提供的联系方式与我们联系。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">五、未成年人保护</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<h2 className="mb-4">五、未成年人保护</h2>
|
||||
<p className="leading-relaxed">
|
||||
我们非常重视对未成年人个人信息的保护。如果您是18周岁以下的未成年人,在使用我们的产品和服务前,应事先取得您家长或法定监护人的同意。如您是未成年人的监护人,当您对您所监护的未成年人的个人信息处理存在疑问时,请通过本隐私政策提供的联系方式与我们联系。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">六、隐私政策的更新</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<h2 className="mb-4">六、隐私政策的更新</h2>
|
||||
<p className="leading-relaxed">
|
||||
我们可能适时更新本隐私政策的条款,该等更新构成本隐私政策的一部分。如该等更新造成您在本隐私政策下权利的实质减少,我们将在更新生效前通过在主页上显著位置提示或向您发送电子邮件或其他方式通知您,在该种情况下,若您继续使用我们的服务,即表示同意受经修订的本隐私政策的约束。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">七、Cookie 和网站分析工具</h2>
|
||||
<h2 className="mb-4">七、Cookie 和网站分析工具</h2>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">7.1 Cookie 使用说明</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">7.1 Cookie 使用说明</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们使用 Cookie 和类似技术来提供、保护和改进我们的服务。Cookie 是存储在您设备上的小型文本文件,帮助我们识别您的设备、记住您的偏好设置。
|
||||
</p>
|
||||
<div className="overflow-x-auto mb-6">
|
||||
@@ -169,23 +169,23 @@ function PrivacyContent() {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">7.2 Google Analytics 使用说明</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">7.2 Google Analytics 使用说明</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们使用 Google Analytics 4(由 Google LLC 提供)分析网站使用情况,帮助我们了解访客如何使用网站,从而改进用户体验。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-2">
|
||||
<p className="leading-relaxed mb-2">
|
||||
<strong>收集的数据包括:</strong>
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-1 mb-4">
|
||||
<ul className="space-y-1 mb-4">
|
||||
<li>访问的页面和停留时间</li>
|
||||
<li>设备类型、浏览器类型</li>
|
||||
<li>地理位置(国家/城市级别,IP 地址已匿名化)</li>
|
||||
<li>访问来源(直接访问、搜索引擎、外部链接)</li>
|
||||
</ul>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-2">
|
||||
<p className="leading-relaxed mb-2">
|
||||
<strong>我们已采取的保护措施:</strong>
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-1 mb-4">
|
||||
<ul className="space-y-1 mb-4">
|
||||
<li>IP 地址匿名化</li>
|
||||
<li>数据保留期限设为 14 个月</li>
|
||||
<li>禁用广告个性化功能</li>
|
||||
@@ -193,29 +193,29 @@ function PrivacyContent() {
|
||||
<li>不与 Google 其他服务共享数据用于广告目的</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">7.3 您的选择</h3>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2 mb-4">
|
||||
<h3 className="mb-3">7.3 您的选择</h3>
|
||||
<ul className="space-y-2 mb-4">
|
||||
<li>您可以在首次访问时选择接受或拒绝分析 Cookie</li>
|
||||
<li>您可以点击页面右下角的“Cookie 设置”按钮随时更改偏好</li>
|
||||
<li>您可以通过浏览器设置删除或阻止 Cookie(可能影响网站功能)</li>
|
||||
</ul>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">7.4 数据删除请求</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<h3 className="mb-3">7.4 数据删除请求</h3>
|
||||
<p className="leading-relaxed">
|
||||
如您希望删除我们持有的您的个人数据,或撤回您的同意,请通过以下方式联系我们:
|
||||
</p>
|
||||
<ul className="list-none text-[var(--color-text-muted)] space-y-1 mt-2">
|
||||
<ul className="list-none space-y-1 mt-2">
|
||||
<li>隐私邮箱:privacy@novalon.cn</li>
|
||||
<li>联系地址:中国四川省成都市龙泉驿区幸福路12号</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">八、如何联系我们</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">八、如何联系我们</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
如果您对本隐私政策有任何疑问、意见或建议,或需要行使您的权利,请通过以下方式与我们联系:
|
||||
</p>
|
||||
<ul className="list-none text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="list-none space-y-2">
|
||||
<li>公司名称:四川睿新致远科技有限公司</li>
|
||||
<li>联系邮箱:contact@novalon.cn</li>
|
||||
<li>隐私邮箱:privacy@novalon.cn</li>
|
||||
@@ -264,7 +264,7 @@ export default async function PrivacyPolicyPage() {
|
||||
<div className="max-w-4xl">
|
||||
{cmsContent ? (
|
||||
<div
|
||||
className="max-w-none"
|
||||
className="prose max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: sanitizeRichText(cmsContent) }}
|
||||
/>
|
||||
) : (
|
||||
|
||||
+43
-43
@@ -13,50 +13,50 @@ export const revalidate = 3600;
|
||||
|
||||
function TermsContent() {
|
||||
return (
|
||||
<div className="max-w-none">
|
||||
<div className="prose max-w-none">
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">引言</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">引言</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
欢迎使用四川睿新致远科技有限公司(以下简称“我们”、“公司”)提供的产品和服务。在使用我们的产品和服务之前,请您仔细阅读并理解本服务条款。如果您不同意本服务条款的任何内容,请停止使用我们的产品和服务。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
本服务条款是您与四川睿新致远科技有限公司之间就使用我们的产品和服务所订立的协议。我们有权根据需要不时修改本服务条款,修改后的条款一旦公布即代替原条款,恕不另行通知。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">一、服务内容</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">一、服务内容</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们提供的产品和服务包括但不限于:软件开发、云服务、数据分析、信息安全、企业级软件产品(如ERP、CRM、后台管理系统、BI等)等。具体服务内容以我们官方网站或产品文档为准。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
我们保留随时修改、暂停或终止部分或全部服务的权利,无需事先通知。对于因服务修改、暂停或终止而给您造成的任何损失,我们不承担任何责任,除非法律另有规定。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">二、用户注册与账户</h2>
|
||||
<h2 className="mb-4">二、用户注册与账户</h2>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">2.1 注册资格</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">2.1 注册资格</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
您确认,在您完成注册程序或以其他方式实际使用本服务时,您应当是具备完全民事权利能力和完全民事行为能力的自然人、法人或其他组织。若您不具备前述主体资格,则您及您的监护人应承担因此而导致的一切后果,且我们有权注销或永久冻结您的账户。
|
||||
</p>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">2.2 账户安全</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">2.2 账户安全</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
您有责任维护您账户的安全性和保密性。您不得向任何第三方泄露您的账户信息,也不得与他人共享您的账户。如果您发现任何未经授权使用您账户的情况,应立即通知我们。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
您对您账户下发生的所有活动负责。我们对因您未能维护账户安全而造成的任何损失不承担责任。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">三、用户行为规范</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">三、用户行为规范</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
在使用我们的产品和服务时,您同意遵守以下行为规范:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2 mb-4">
|
||||
<ul className="space-y-2 mb-4">
|
||||
<li>遵守所有适用的法律法规和本服务条款。</li>
|
||||
<li>不得利用我们的产品和服务进行任何违法或不当活动。</li>
|
||||
<li>不得干扰或破坏我们的产品和服务或与我们的产品和服务相连的服务器和网络。</li>
|
||||
@@ -65,52 +65,52 @@ function TermsContent() {
|
||||
<li>不得进行任何形式的商业欺诈或诈骗活动。</li>
|
||||
<li>不得恶意收集或获取其他用户的信息。</li>
|
||||
</ul>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
如果我们认定您违反了本服务条款或任何适用法律,我们有权在不事先通知的情况下,暂停或终止您的账户,并拒绝您现在或将来使用我们的产品和服务。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">四、知识产权</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">四、知识产权</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们的产品和服务中包含的所有内容,包括但不限于软件、设计、文字、图片、音频、视频、商标、服务标识等,均受著作权法、商标法、专利法或其他适用法律的保护。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<p className="leading-relaxed mb-4">
|
||||
除非另有明确说明,我们拥有或持有我们产品和服务中所有内容的所有知识产权。您不得以任何形式复制、修改、传播、展示、执行、创作衍生作品、转让、出售或以其他方式使用这些内容,除非获得我们的明确书面许可。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<p className="leading-relaxed">
|
||||
您在使用我们的产品和服务时产生的任何内容,您仍保留其知识产权,但您授予我们全球性、非独占性、免版税的许可,以使用、复制、修改、传播、展示和执行这些内容,仅限于提供和改进我们的产品和服务。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">五、服务费用与支付</h2>
|
||||
<h2 className="mb-4">五、服务费用与支付</h2>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">5.1 费用标准</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">5.1 费用标准</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们的产品和服务可能需要支付费用。具体费用标准以我们官方网站或产品文档公布的价格为准。我们保留随时调整价格的权利,调整后的价格适用于调整后的新订单或续费。
|
||||
</p>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">5.2 支付方式</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h3 className="mb-3">5.2 支付方式</h3>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们接受多种支付方式,包括但不限于银行转账、支付宝、微信支付等。具体支付方式以我们官方网站或产品文档为准。
|
||||
</p>
|
||||
|
||||
<h3 className="text-xl font-semibold text-[var(--color-text-primary)] mb-3">5.3 退款政策</h3>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed">
|
||||
<h3 className="mb-3">5.3 退款政策</h3>
|
||||
<p className="leading-relaxed">
|
||||
除非另有明确说明,我们提供的产品和服务一经售出,不予退款。如因我们的原因导致产品或服务无法正常使用,我们将根据实际情况提供相应的补偿或解决方案。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">六、免责声明</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">六、免责声明</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们的产品和服务按“现状”和“可用”基础提供,不提供任何明示或暗示的保证,包括但不限于对适销性、适用性、非侵权性或准确性、可靠性的保证。
|
||||
</p>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<p className="leading-relaxed mb-4">
|
||||
我们不对以下情况承担责任:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="space-y-2">
|
||||
<li>因您违反本服务条款或任何适用法律而导致的任何损失或损害。</li>
|
||||
<li>因不可抗力、网络故障、设备故障等不可控因素导致的服务中断或数据丢失。</li>
|
||||
<li>因第三方服务或内容导致的任何损失或损害。</li>
|
||||
@@ -119,11 +119,11 @@ function TermsContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">七、服务终止</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">七、服务终止</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
您可以随时停止使用我们的产品和服务,并注销您的账户。我们也有权在不事先通知的情况下,因以下原因暂停或终止您的账户:
|
||||
</p>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="space-y-2">
|
||||
<li>您违反本服务条款或任何适用法律。</li>
|
||||
<li>我们出于安全、法律或商业考虑,认为有必要终止您的账户。</li>
|
||||
<li>您长时间未使用您的账户。</li>
|
||||
@@ -132,15 +132,15 @@ function TermsContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">八、争议解决</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">八、争议解决</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
本服务条款的订立、执行、解释及争议解决均适用中华人民共和国法律。如就本服务条款发生任何争议,双方应首先通过友好协商解决;协商不成的,任何一方均可向公司所在地有管辖权的人民法院提起诉讼。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">九、其他条款</h2>
|
||||
<ul className="list-disc pl-6 text-[var(--color-text-muted)] space-y-2">
|
||||
<h2 className="mb-4">九、其他条款</h2>
|
||||
<ul className="space-y-2">
|
||||
<li>本服务条款构成您与我们就使用我们的产品和服务所达成的完整协议,取代之前的所有口头或书面协议。</li>
|
||||
<li>如本服务条款的任何条款被认定为无效或不可执行,该条款应被限制或排除,以使其有效和可执行,其余条款继续有效。</li>
|
||||
<li>我们未行使或延迟行使本服务条款项下的任何权利或规定,不构成对该权利或规定的放弃。</li>
|
||||
@@ -149,11 +149,11 @@ function TermsContent() {
|
||||
</section>
|
||||
|
||||
<section className="mb-12">
|
||||
<h2 className="text-2xl font-bold text-[var(--color-text-primary)] mb-4">十、联系我们</h2>
|
||||
<p className="text-[var(--color-text-muted)] leading-relaxed mb-4">
|
||||
<h2 className="mb-4">十、联系我们</h2>
|
||||
<p className="leading-relaxed mb-4">
|
||||
如果您对本服务条款有任何疑问、意见或建议,请通过以下方式与我们联系:
|
||||
</p>
|
||||
<ul className="list-none text-[var(--color-text-muted)] space-y-2">
|
||||
<ul className="list-none space-y-2">
|
||||
<li>公司名称:四川睿新致远科技有限公司</li>
|
||||
<li>联系邮箱:contact@novalon.cn</li>
|
||||
<li>联系地址:中国四川省成都市龙泉驿区幸福路12号</li>
|
||||
@@ -209,7 +209,7 @@ export default async function TermsOfServicePage() {
|
||||
<div className="max-w-4xl">
|
||||
{cmsContent ? (
|
||||
<div
|
||||
className="max-w-none"
|
||||
className="prose max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: sanitizeRichText(cmsContent) }}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* seed 写策略(2026-11-25,为 §17.2 那类「跑一次 seed 冲掉 CMS 人工编辑」而写)。
|
||||
*
|
||||
* 判据只认**是否存在 + 是否显式 --force**,不猜「这行有没有被人工编辑过」:
|
||||
* 仓里没有编辑指纹这一状态源,凭空比对内容只会造出第二个真相。
|
||||
*/
|
||||
import {
|
||||
parseSeedMode,
|
||||
decideSeedWrite,
|
||||
createSeedWriteCounts,
|
||||
recordSeedWrite,
|
||||
formatSeedSummary,
|
||||
formatSeedMode,
|
||||
shouldPruneSeededRows,
|
||||
} from './seed-write-policy';
|
||||
|
||||
describe('parseSeedMode', () => {
|
||||
it('无参数 ⇒ 默认非 force(破坏性动作默认关闭)', () => {
|
||||
expect(parseSeedMode([])).toEqual({ force: false, unknown: [] });
|
||||
});
|
||||
|
||||
it('--force ⇒ 开启覆盖', () => {
|
||||
expect(parseSeedMode(['--force'])).toEqual({ force: true, unknown: [] });
|
||||
});
|
||||
|
||||
it('未知参数不静默吞掉 ⇒ 交回调用方报错(--forced 这类手滑会变成「看起来生效了」)', () => {
|
||||
expect(parseSeedMode(['--forced', '--force'])).toEqual({ force: true, unknown: ['--forced'] });
|
||||
});
|
||||
|
||||
it('npm run db:seed -- --force 传入的形态(前置 -- 已被 npm 吃掉)也要认', () => {
|
||||
expect(parseSeedMode(['--', '--force'])).toEqual({ force: true, unknown: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('decideSeedWrite', () => {
|
||||
it('行不存在 ⇒ 新建(force 与否都一样)', () => {
|
||||
expect(decideSeedWrite({ exists: false, force: false }).action).toBe('create');
|
||||
expect(decideSeedWrite({ exists: false, force: true }).action).toBe('create');
|
||||
});
|
||||
|
||||
it('行已存在且未带 --force ⇒ 跳过,保留库里的人工编辑', () => {
|
||||
const decision = decideSeedWrite({ exists: true, force: false });
|
||||
expect(decision.action).toBe('skip');
|
||||
expect(decision.reason).toContain('--force');
|
||||
});
|
||||
|
||||
it('行已存在且带 --force ⇒ 覆盖', () => {
|
||||
const decision = decideSeedWrite({ exists: true, force: true });
|
||||
expect(decision.action).toBe('update');
|
||||
expect(decision.reason).toContain('--force');
|
||||
});
|
||||
|
||||
it('决策是全函数的:同输入同输出(无隐式全局状态)', () => {
|
||||
expect(decideSeedWrite({ exists: true, force: false })).toEqual(
|
||||
decideSeedWrite({ exists: true, force: false }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldPruneSeededRows', () => {
|
||||
it('非 force 时永不删除——即使种子集合为空(deleteMany 是破坏性动作)', () => {
|
||||
expect(shouldPruneSeededRows({ force: false, desiredCount: 0 })).toBe(false);
|
||||
});
|
||||
|
||||
it('force + 种子集合为空 ⇒ 允许清理历史种子遗留行', () => {
|
||||
expect(shouldPruneSeededRows({ force: true, desiredCount: 0 })).toBe(true);
|
||||
});
|
||||
|
||||
it('force 且种子非空 ⇒ 不删(清理由覆盖语义完成)', () => {
|
||||
expect(shouldPruneSeededRows({ force: true, desiredCount: 3 })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('计数与汇总', () => {
|
||||
it('计数按动作累加,汇总行能区分「新建 / 覆盖 / 跳过」', () => {
|
||||
const counts = createSeedWriteCounts();
|
||||
recordSeedWrite(counts, 'create');
|
||||
recordSeedWrite(counts, 'create');
|
||||
recordSeedWrite(counts, 'update');
|
||||
recordSeedWrite(counts, 'skip');
|
||||
recordSeedWrite(counts, 'skip');
|
||||
recordSeedWrite(counts, 'skip');
|
||||
|
||||
expect(counts).toEqual({ created: 2, updated: 1, skipped: 3 });
|
||||
|
||||
const summary = formatSeedSummary(counts);
|
||||
expect(summary).toContain('新建 2');
|
||||
expect(summary).toContain('覆盖 1');
|
||||
expect(summary).toContain('跳过 3');
|
||||
});
|
||||
|
||||
it('全跳过时汇总必须显式提示「未写入」——否则读日志的人会以为 seed 生效了', () => {
|
||||
const counts = createSeedWriteCounts();
|
||||
recordSeedWrite(counts, 'skip');
|
||||
expect(formatSeedSummary(counts)).toContain('未写任何一行');
|
||||
});
|
||||
|
||||
it('汇总带上当前模式,日志一行即可看出是补缺还是覆盖', () => {
|
||||
expect(formatSeedMode({ force: false, unknown: [] })).toContain('不覆盖');
|
||||
expect(formatSeedMode({ force: true, unknown: [] })).toContain('覆盖');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* seed 的写策略(2026-11-25)。
|
||||
*
|
||||
* 背景:2026-11-24 那次 seed 事故(qa-tracker §17.2)不是「seed 写错了值」,而是
|
||||
* **seed 依据「种子文件是唯一真相」这一隐含假设无条件覆盖** —— `upsert` 的 update 分支
|
||||
* 把 CMS 里人工改过的正文冲回种子版本,`deleteMany` 更是无条件删。事故前没有任何一道闸
|
||||
* 能区分「我想初始化」与「我想重置」。
|
||||
*
|
||||
* 本模块把这条边界变成**显式的、可单测的纯函数**:
|
||||
* - 默认 = 补缺(缺行才写,已有行不碰)
|
||||
* - `--force` = 覆盖(明确表达「我要把库重置成种子状态」)
|
||||
*
|
||||
* 刻意**不做**内容指纹/时间戳比对:仓里没有「人工编辑」这一状态源,凭 `updatedAt` 猜
|
||||
* 会把「上一次 seed 自己写的行」误判成人工编辑,等于造出第二个真相源。
|
||||
* 判据只认两件可观测的事实:行是否存在、命令行是否显式 --force。
|
||||
*/
|
||||
|
||||
export type SeedWriteAction = 'create' | 'update' | 'skip';
|
||||
|
||||
export interface SeedMode {
|
||||
force: boolean;
|
||||
/** 未识别的参数。调用方必须报错:`--forced` 这类手滑不能退化成「看起来生效了」。 */
|
||||
unknown: string[];
|
||||
}
|
||||
|
||||
export interface SeedWriteDecision {
|
||||
action: SeedWriteAction;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface SeedWriteCounts {
|
||||
created: number;
|
||||
updated: number;
|
||||
skipped: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 seed 的 CLI 参数。`npm run db:seed -- --force` 在 npm 层会把 `--` 保留在
|
||||
* `process.argv` 里,故显式忽略它(否则每次带 --force 都变成「未知参数」)。
|
||||
*/
|
||||
export function parseSeedMode(argv: readonly string[]): SeedMode {
|
||||
let force = false;
|
||||
const unknown: string[] = [];
|
||||
|
||||
for (const arg of argv) {
|
||||
if (arg === '--') continue;
|
||||
if (arg === '--force') {
|
||||
force = true;
|
||||
continue;
|
||||
}
|
||||
unknown.push(arg);
|
||||
}
|
||||
|
||||
return { force, unknown };
|
||||
}
|
||||
|
||||
/** 单行该新建、覆盖还是跳过。纯函数:同输入同输出。 */
|
||||
export function decideSeedWrite(input: { exists: boolean; force: boolean }): SeedWriteDecision {
|
||||
if (!input.exists) {
|
||||
return { action: 'create', reason: '库中缺行 ⇒ 新建' };
|
||||
}
|
||||
if (input.force) {
|
||||
return { action: 'update', reason: '--force ⇒ 覆盖已有行' };
|
||||
}
|
||||
return {
|
||||
action: 'skip',
|
||||
reason: '已存在且未带 --force ⇒ 保留库中内容(如需重置请显式 --force)',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否清理「种子集合已为空」的历史遗留行(如当前 `case-study`)。
|
||||
* 删除是破坏性动作,故只在 --force 下成立;非 force 时宁可留旧行也不猜。
|
||||
*/
|
||||
export function shouldPruneSeededRows(input: { force: boolean; desiredCount: number }): boolean {
|
||||
return input.force && input.desiredCount === 0;
|
||||
}
|
||||
|
||||
export function createSeedWriteCounts(): SeedWriteCounts {
|
||||
return { created: 0, updated: 0, skipped: 0 };
|
||||
}
|
||||
|
||||
export function recordSeedWrite(counts: SeedWriteCounts, action: SeedWriteAction): void {
|
||||
if (action === 'create') counts.created += 1;
|
||||
else if (action === 'update') counts.updated += 1;
|
||||
else counts.skipped += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收尾汇总。刻意在「一行都没写」时显式说出来 —— 否则读日志的人会把
|
||||
* 「全部跳过」误读成「seed 成功执行」。
|
||||
*/
|
||||
export function formatSeedSummary(counts: SeedWriteCounts): string {
|
||||
const total = counts.created + counts.updated + counts.skipped;
|
||||
const head = `种子写入汇总:新建 ${counts.created} / 覆盖 ${counts.updated} / 跳过 ${counts.skipped}(共 ${total} 行)`;
|
||||
if (counts.created + counts.updated === 0) {
|
||||
return `${head} ⇒ 未写任何一行(库中已有全部种子行;要重置请显式 --force)`;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
/** 启动日志用的一行模式说明。 */
|
||||
export function formatSeedMode(mode: SeedMode): string {
|
||||
return mode.force
|
||||
? '--force 覆盖模式(会改写库中已有同 slug 行)'
|
||||
: '补缺模式(已存在的行不覆盖,保护 CMS 人工编辑)';
|
||||
}
|
||||
Reference in new issue
Block a user