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:
zhangxiang committed 2026-11-25 16:29:42 +08:00
1 parent 683f693b48
commit 9d144f623f
20 files changed
+1091 -250

No files matched your search

+15 -1
View File
@@ -24,6 +24,14 @@
**通过标准**: **0 error**。warning **不判红**——这是本项目的显式裁定(见 `CONTEXT.md`「lint warning 分级与门禁判定口径」);把 warning 清零不是门禁前置条件,但**不得**为凑绿而把它们调成 `off`。
**warning 数量口径(本文件为版本库内的权威记录位)**:
> **2026-11-25 第二轮复测(seed 写策略 / `prose` 排版层 / 写库 E2E 隔离,分支 `feat/porsche-ui-replica`)**:
> `npm run lint` ⇒ **EXIT=0,`✖ 88 problems (0 errors, 88 warnings)`**。
> 分项(`npx eslint . --format json` 按 `ruleId` 聚合):**60** `no-console` / **14** `react-hooks/set-state-in-effect` /
> **8** `@next/next/no-img-element` / **4** `@typescript-eslint/no-explicit-any` / 各 1 `@next/next/no-html-link-for-pages`、`@next/next/no-sync-scripts`(60+14+8+4+1+1 = 88 ✓)。
> 与上一行 84 的**差额 +4 全部来自 `prisma/seed.ts` 新增的 4 条 `console.log`**(写入模式行、汇总行等)——
> 该文件不在任何 override 内,`no-console` 是「种子脚本进度日志」的有意容忍项(见本节末尾「已知例外」),
> 不是把闸调松。其余新增文件(`src/lib/seed-write-policy.ts` 及其测试、`src/app/__tests__/prose-layer.test.ts`)逐个
> `npx eslint --format json` 查均为 0 条。
> **2026-11-25 收尾轮复测(全项目未收口事项收尾,分支 `feat/porsche-ui-replica`)**:
> `npm run lint` ⇒ **EXIT=0,`✖ 84 problems (0 errors, 84 warnings)`**(与 Batch 2 同数,本轮零新增)。
> 分项(`npx eslint . --format json` 按 `ruleId` 聚合):**56** `no-console` / **14** `react-hooks/set-state-in-effect` /
@@ -226,6 +234,7 @@ Closes #123
|---|---|---|
| `npm run test` / `test:functional` / `test:e2e` | `npm run dev` | 日常回归。**GA4 的 4 个 `@critical` 用例 × 4 project = 16 个实例是 skipped**(GA ID 只在 `.env.production`,dev 下不注入 gtag,`test.skip` 触发)。证据 `docs/acceptance/2026-09-21-gates/skipped-tests-final-tree.json` |
| `npm run test:e2e:prod` | `E2E_TARGET=production` ⇒ `HOSTNAME=localhost PORT=3000 node dist/standalone/server.js`(`e2e/playwright.config.ts:132-135`) | **唯一**真正断言 GA4(生产响应头不在此集合,属 `@security`)/ 预渲染与 ISR 的口径;用例集是 `@smoke\|@critical\|@journey` × 4 project,`reuseExistingServer` 在此目标下为 false(`:139`)。产物是 `output: 'standalone'`(`next.config.mjs:44`),Next 16 下 `next start` 明确不受支持,故不能写成 `npm run start`;harness 不代跑构建,须先 `npm run build` 并按 `Jenkinsfile:353-355` 把 `dist/static` 与 `public` 拷进 `dist/standalone/`(standalone 不自含这两者,缺了 `/_next/static/**` 全 404) |
| `npm run test:e2e:write-db` | `scripts/e2e/serve-temp-db.sh` ⇒ `/tmp` 一次性 SQLite(`migrate deploy` → `seed` → 路由预热 → `next dev -p 3101`),host 固定 `localhost` | **写库型 11 例的授权口径**(`cms-workflow.spec.ts` 3 例 + `user-journey.spec.ts` 8 例)= AUTH-D4 的闭合方式:真写库,但**不写 `prisma/dev.db`**。判据:`11 passed / 0 failed / EXIT=0`,且脚本首行打印的 `dev.db` 指纹(inode+size+mtime)跑前跑后不变。三条踩坑记录见 `docs/lessons-learned.md` §5.66。⚠ **残差抖动**:3 次运行中 1 次出现 2 红(两个 spec 同时停在 `submitForReview`),复跑即绿 ⇒ 宣称前须连续两次 EXIT=0,且出现红时先 `cp -R e2e/test-results` 再复跑 |
| `Jenkinsfile`「🌐 E2E 测试」(仅 main) | build + `test:e2e:prod` | CI 在 main 上执行产物口径;功能分支本地跑 `npm run test` 不覆盖它 |
**结论**:以 `npm run test` 的绿灯宣称"GA4/生产头已验证"属口径错误;引用时必须指明目标。
@@ -233,13 +242,18 @@ Closes #123
#### 6.1 产物口径的三条实操陷阱(2026-09-30 封版轮在 `a0328a6` 上实测)
1. **`test:e2e:prod` 默认集合会写真库**:它的 grep 是 `@smoke|@critical|@journey`,**不排除** `e2e/cms-workflow.spec.ts`(`@critical`)与 `e2e/user-journey.spec.ts`(`@journey`),二者对 `/api/admin/items|media` 发真实写请求 ⇒ "prod" 不等于"只读安全"。要拿写库-free 凭据必须自己加:
`--grep-invert 'cms-workflow\.spec\.ts|user-journey\.spec\.ts'`(`--grep-invert` 匹配的是含**文件路径**的 title path,先 `--list` 自证排除生效再实跑)。封版树实测:排除后 **92 例 → 91 passed / 1 failed**,`prisma/dev.db` 的 inode/size/mtime 跑前后完全一致。唯一红是 `[firefox] uj-09:124` 的并发墙钟(隔离与 4-project 复跑均绿),已登记 `docs/acceptance/qa-tracker.md` §2.4。
`--grep-invert 'cms-workflow\.spec\.ts|user-journey\.spec\.ts'`(`--grep-invert` 匹配的是含**文件路径**的 title path,先 `--list` 自证排除生效再实跑)。封版树实测:排除后 **92 例 → 91 passed / 1 failed**,`prisma/dev.db` 的 inode/size/mtime 跑前后完全一致。唯一红是 `[firefox] uj-09:124` 的并发墙钟(隔离与 4-project 复跑均绿),已登记 `docs/acceptance/qa-tracker.md` §2.4。**2026-11-25 起有第三条路**:想真跑这 11 例而不脏本地库,用 `npm run test:e2e:write-db`(临时库口径,见上表;`docs/lessons-learned.md` §5.66 记了三个踩坑)。
2. **视觉比对必须显式关写入**:**不带 `--update-snapshots` 旗标**时 Playwright 取 `missing`(`node_modules/playwright/lib/common/index.js:584`),会**静默创建**缺失参照;而**裸 `--update-snapshots`(带旗标不带值)取 `changed`**(`node_modules/playwright/lib/program.js:202` 的 `preset: "changed"`),只写「缺失 / 比对不符」两种,**不会重写通过的参照**——所以「覆盖了多少张」可以直接当作「判红多少张」。只读比对必须显式写 `--update-snapshots=none`,并先确认 `:3000` 无残留服务(`reuseExistingServer` 在 dev 目标下为 true,会静默复用旧构建)。**读数口径**:`--update-snapshots=none` 在封版树(2026-09-30)实测 **94 passed / 31 failed**(20 例缺参照 + 11 例已过时,归因见 `docs/acceptance/2026-09-30-seal/final-verdict.md` §2.2);AUTH-D3 于 **2026-10-08 闭合**(写入 38 张 = 25 新 + 13 覆盖;**38 是文件数、31 是用例数**,一例可多 shot),随后独立只读复跑 **125 passed / 0 failed / EXIT=0**,取证见 `docs/acceptance/2026-10-08-baselines/`。**判红归因的参照系是「基线采集树 vs 当前树」**(`git log -1 -- <参照路径>` 现取采集树),「本轮相对上一轮零源码改动」只支撑绿灯平移、不支撑参照同源——详见 `docs/lessons-learned.md` §5.33。
3. **安全头不必打线上**:`scripts/utils/check-security-headers.ts:28-35` 支持 `--url`,因此可以对着本分支产物跑(`--url http://localhost:3100/` ⇒ 实测 7 PASS / 1 WARN / 0 FAIL,WARN 是 HSTS,由 nginx/CDN 边缘注入,http 目标本就不下发)。只有 `test:all` 的默认值指向 `https://novalon.cn`,那条在分支产物上结构上不可能全绿,两者不可混用。
### 7. 一键门禁 `npm run test:all`
`type-check` → `lint` → `test:coverage` → **`test:integration:real`** → **`check:a11y`** → **`check:visual`** → `test:e2e:fast` → `test:security:headers`(`package.json` 的 `test:all` 原文即此八段,勿凭记忆省略 `test:integration:real`。2026-10-17 新增 `check:visual` = `check:grammar:selftest` → `check:grammar` → `check:accents:selftest` → `check:accents`,**自证先跑**:自证失败的闸不许用它的绿灯出结论。见 §5.2)。注意最后一项 E2E 仍是 **dev 目标**(`@smoke|@critical`),GA4 的 16 个实例同样 skipped,故 `test:all` 绿之后仍需按 §6 补 `test:e2e:prod`。
⚠ **`check:visual` 当前在 HEAD 上整段判红,且与本轮改动无关**:它的第二段 `check:accents:selftest`
在 `git worktree add /tmp/pristine-head HEAD` 上原样复现 8/10 红(`[A]` 三个情景报「夹具串维」、
`[B]` 五个报「违规 2≠应 1 / 腐化 1≠应 0」),而判据本体 `npm run check:accents` 单跑 **EXIT=0**。
⇒ 「`test:all` 全绿」这条结论在修好该自证之前**不可能成立**,引用门禁读数时要分段写
(判据本体 / 自证),登记见 `docs/acceptance/qa-tracker.md` §19 的 OPEN-15。
## 提交与 PR 流程(PR-First)