# Novalon Website 开发工作流指南 本文件定义 AI 代理与开发者在参与本项目时应遵循的标准工作流。核心目标是**在需求清晰、文档一致、测试覆盖的前提下交付可验证的代码变更**。 ## 1. 工作流总览 新功能或复杂变更按以下流水线执行: ``` /入口判断 ↓ /grill-with-docs → 需求梳理:在项目语境中通过结构化问答形成文档化共识 ↓ /context7 → 官方实践:涉及第三方库 / 框架 / API 时查询官方文档与最佳实践 ↓ /to-prd → 需求文档化:将澄清后的需求综合为结构化 PRD (必须包含 mermaid 架构/数据流/时序图) ↓ /to-issues → 任务拆解:按 tracer-bullet 垂直切片将 PRD 拆为独立 Issues ↓ /tdd → TDD 实现:RED-GREEN-REFACTOR 循环逐个实现 ↓ /systematic-debugging → 系统调试:遇到 bug 时收集症状→形成假设→验证→修复根因 ↓ /verification → 验证门禁:类型检查、Lint、单元测试、E2E、可访问性、Lighthouse ↓ /文档同步 → 更新 README.md / CONTEXT.md / AGENTS.md 及受影响的设计文档 ``` ## 2. 入口判断 ### 2.1 必须使用 - 新功能开发 - 跨模块变更(如同时修改组件、API、测试) - 涉及数据模型 / API 变更 - 设计 DNA、HSI 架构、四层叙事模型相关的页面重构 ### 2.2 建议使用 - 需求不清晰的变更 - 需要多人协作的功能 - 涉及第三方库升级或替换 - 性能优化、可访问性改进等横向改造 ### 2.3 可跳过 - 单行修复 - 文档更新(仍需满足「文档同步」要求) - 配置变更 - 明显的拼写 / 类型错误 ## 3. 核心原则 | 原则 | 含义 | |------|------| | **不跳步** | 不要在需求不清晰时直接编码(跳过 grill-with-docs)。 | | **不猜测** | PRD 未形成共识前,不进行任务拆解。 | | **不偷懒** | TDD 循环中必须先写失败测试再看实现。 | | **不掩饰** | 遇到 bug 时先诊断根因再修复,不要随机尝试。 | | **零编造** | 禁止凭空创造 API / 数据结构 / 未经验证的配置。所有产出必须有至少一个可信来源支撑。 | | **文档同步** | 任何变更必须同步更新相关文档(注释、README.md、CONTEXT.md、AGENTS.md、docs/ 下受影响文件)。 | | **交叉验证** | 关键决策须从至少两个独立可信源(官方文档 + 既有代码库模式 / 设计规范)比对求证。 | | **双归零** | 任何错误立即暂停,执行技术归零(定位机理、复现、修复)与管理归零(追溯流程漏洞、更新检查清单)。 | ## 4. 阶段详解 ### 4.1 /grill-with-docs — 需求梳理 **目标**:将模糊需求转化为基于项目共享语言的文档化共识。 **必须引用**: - [CONTEXT.md](CONTEXT.md) — 领域术语表与关键决策 - [AGENTS.md](AGENTS.md) §9 — 命令速查与架构(原 CLAUDE.md 正文,已并入) - [README.md](README.md) — 项目规划与进度 **输出**: - 更新后的 `CONTEXT.md`(若引入新术语或变更决策) - 问题清单与决策记录 **关键问题**: 1. 变更属于哪种页面类型?(首页 / Hub / Spoke / Independent / 详情页) 2. 是否涉及四层叙事模型(Hero → 价值 → 信任 → CTA)调整? 3. 是否引入新的设计令牌、动画或第三方依赖? 4. 是否需要同步更新跨页面链接(产品 ↔ 方案 ↔ 服务)? ### 4.2 /context7 — 官方实践 **目标**:在涉及第三方库 / 框架 / API 时,获取官方文档与最佳实践。 **触发条件**: - 使用新依赖(如 Radix UI、Framer Motion、Zod、Prisma 的新特性) - Next.js App Router、React Server Components、API Routes 相关变更 - Tailwind CSS、shadcn/ui 组件模式变更 **输出**: - 引用来源清单 - 关键 API 用法示例 - 与项目现有模式的差异说明 ### 4.3 /to-prd — 需求文档化 **目标**:将澄清后的需求综合为结构化 PRD。 **PRD 必须包含**: - 背景与目标 - 范围与不在范围内 - 用户故事或验收标准 - 受影响的页面 / 组件 / API / 数据模型 - 设计约束(品牌红、动效四原则、Mobile First、standalone 混合渲染下「API/ISR 需 Node 运行时、图片 unoptimized」等) - 风险与依赖 - 验证方式 ### 4.4 /to-issues — 任务拆解 **目标**:按 tracer-bullet 垂直切片将 PRD 拆为独立可追踪的 Issues。 **切片原则**: - 每个 Issue 可独立开发、独立测试、独立交付 - 优先完成一条端到端 tracer-bullet(如一个页面的 Hero → 价值 → 信任 → CTA) - 标注优先级、依赖关系、信源与验证命令 ### 4.5 /tdd — TDD 实现 **目标**:RED-GREEN-REFACTOR 循环逐个实现。 **适用层级**: - 单元测试:工具函数、Hooks、CMS 渲染器、组件行为 - E2E 测试:关键用户路径(导航、表单、Hero 区域可见性) - 视觉回归:涉及 UI 样式调整的变更 **纪律**: 1. 先写 failing test 2. 用最简单实现让测试通过 3. 重构并确保测试仍通过 ### 4.6 /systematic-debugging — 系统调试 **目标**:遇到 bug、测试失败或异常行为时,先诊断根因再修复。 **流程**: 1. 收集症状(日志、截图、复现步骤) 2. 形成假设 3. 最小化验证 4. 修复根因 5. 补充回归测试 ## 5. 质量门禁 变更提交前必须通过以下检查: | 检查项 | 命令 | 通过标准 | |--------|------|---------| | 类型检查 | `npm run type-check` | 无类型错误 | | 代码风格 | `npm run lint` | 0 error(warning 不判红;**实测 105 条**,2026-09-23 最终树复测):55 `no-console`、25 `@typescript-eslint/no-explicit-any`、12 `react-hooks/set-state-in-effect`、10 `@next/next/no-img-element`、1 `@next/next/no-sync-scripts`、1 `@next/next/no-html-link-for-pages`、1 `Unused eslint-disable directive`(死抑制)。分项相加 = 105,口径自洽。**2026-10-08 本树复测**:`npm run lint` EXIT=0、**0 error / 104 warning**(`npm run type-check` 同 EXIT=0)⇒ 本行 105 为 2026-09-23 历史读数,现行权威位在 `docs/development/quality-gates.md`,引用计数须附复算命令 | | 单元测试 | `npm run test:unit` | 全部通过 | | 单元覆盖率 | `npm run test:coverage` | 阈值单一真源为 [config/test/jest.config.js](config/test/jest.config.js) 的 `coverageThreshold`(根 `jest.config.js` 仅转发):global 门限 branches 82 / functions 75 / lines 75 / statements 75,**2026-09-23 收尾树复测 134 套件 / 1697 例全通过,EXIT=0,0 条阈值告警**;global 实测 **stmts 85.59 / branch 87.5 / funcs 80.67 / lines 85.59**(目录级:`components/content` 100×4、`components/sections` 72.77/90.79/73.8/72.77、`lib/cms` 91.93/92.77/92.68/91.93)。⚠ global 实测已高于门限 5.6–12.5 个点,棘轮当前偏松,上调须作为独立动作 | | E2E 测试 | `npm run test` | 全部通过。**但默认 webServer 是 `npm run dev`,16 个 `@critical` GA4 用例(TC-GA4-001..004 × 4 project)在这一轮里是 skipped 而不是 passed**——`NEXT_PUBLIC_GA_MEASUREMENT_ID` 只存在于 `.env.production`,dev 下 `GoogleAnalytics.tsx` 提前返回 null,用例内 `test.skip` 触发(证据 `docs/acceptance/2026-09-21-gates/skipped-tests-final-tree.json`:28 skipped 中该组恰为 16)。故 `npm run test` 绿 **不等于** GA4 覆盖已验证 | | E2E 测试(产物目标) | `npm run test:e2e:prod` | `E2E_TARGET=production` → harness 新起 `node dist/standalone/server.js`(**不是** `npm run start`;standalone 下 `next start` 不受支持)。那 16 个 GA4 用例只在这里真正断言(2026-09-23 实测:`@smoke\|@critical\|@journey` 排除 2 个写库 spec 后 **92 例通过 / 0 skipped / EXIT=0**)。⚠ **生产响应头不在该 grep 集合里**——它在 `@security`(`security-headers.spec.ts`)下,别把两者混为一谈。**须先自行 `npm run build`(harness 不代跑),且 `postbuild` 须已装配 `dist/static` + `public`** | | 视觉回归 | `npm run test:visual:all -- --update-snapshots=none`(**只读比对**,不写参照;缺省不带 `--update-snapshots=none` 时 Playwright 会**静默创建**缺失基线) | ⚠ **2026-09-23 最终树实测 EXIT=1,21 失败 / 104 通过,其中 0 例是像素不符**。红因全部是测试装配缺陷(记为 N-15,见 `docs/acceptance/2026-09-23-gates/final-verdict.md` §3 与 `docs/lessons-learned.md` §5.29):10 例基线文件从不存在(`/products/erp-upgrade`、`/about/brand` × 5 project)、10 例死在选择器(`[class*="card"]` 零匹配;`input[type="text"]` 的 `.first()` 命中按设计隐藏的**反垃圾蜜罐**字段)、1 例移动端窄视口按钮不可见。**判读必须分层**:现存参照层面 104 例全绿(含 `/contact` 全页)⇒ 本轮修复无视觉外溢;装配层面转绿需 §5.1 的基线写授权 + 修 N-15 选择器,二者缺一不可。另注:磁盘上 85 张基线 PNG 相对 HEAD 处于 modified(2026-09-22 重生成、未提交),故"绿"依赖未提交状态。**2026-10-08 复核更正**:`git ls-files e2e/visual-snapshots` 现取为 **107 张、全部已入库且工作树干净**,「85 张未提交」不成立(同 `docs/lessons-learned.md:505`),本行原文仅作 2026-09-23 当时的叙述保留。**2026-10-08 同日再更(AUTH-D3 已闭合)**:写入 38 张(25 新 + 13 覆盖,逐张读图追认)后独立只读复跑 **125 passed / 0 failed / EXIT=0**,参照现取 **132 张**(5 project 各 26 + `manual-acceptance/` 2)⇒ 本行的 21 失败 / 104 通过 / 94-31 系列读数全部作废,改以 `docs/acceptance/qa-tracker.md` §9 与 `docs/acceptance/2026-10-08-baselines/attribution.md` 为准。另更正机制描述:**裸 `--update-snapshots`(带旗标不带值)取 `changed`** 而非 `missing`(`node_modules/playwright/lib/program.js:202` 的 `preset`),只写缺失/不符、不重写通过项;「静默创建缺失基线」对应的是**完全不带该旗标**时的缺省 `missing`(`common/index.js:584`)。 | | 可访问性 | `npm run check:a11y`(= `check:contrast` + `check:headings` + `check:brand-token`) | WCAG AA 通过;`check:a11y` 已并入 `npm run test:all` | | Landing 门禁 | `npm run test:landing` | 四道门禁(`e2e/landing/{layout,motion,demo,a11y}.spec.ts`,2026-12-03 从 `novavis-authority` 的四个 python 脚本移植):布局几何与焦点 / 渐进生长与 reduced-motion / 首屏剧本与无 JS 降级(四层真实可见性 + 徽标一一对应)/ 结构与全量对比度(同色无条件阻断 + axe critical/serious=0)。**已并入 `test:all`**;独立 config `e2e/playwright.landing.config.ts`(单引擎单 project,串行)。口径与判别性取证见 [docs/landing.md](docs/landing.md) §3 | | 全量门禁 | `npm run test:all` | type-check + **check:package-keys** + **type-check:e2e** + lint + test:coverage + test:integration:real + check:a11y + **test:landing** + **check:visual** + test:e2e:fast + test:security:headers。⚠ 以 `package.json` 的 `scripts.test:all` 为唯一真源;本行曾漏记后三项,导致 `check:visual` 恒红期间「`test:all` 全绿」的宣称无法被核对(2026-11-26 补齐) | | 真库集成层 | `npm run test:integration:real` | `config/test/jest.integration.config.js` → `tests-integration/*.itest.ts`,一次性临时 SQLite(`/tmp/novalon-itest.db`),teardown 以 inode+size+mtime 守卫 `prisma/dev.db` 未被写入。原 `test:integration`(跑 mock 版 `src/app/api/**` 路由单测)已改名 `test:integration:mocked`,A-8 的「命名误导」由此收口 | | 性能 | `npm run lighthouse` | 满足 lhci 断言 | > ✅ **2026-09-23 最终树数字已回填**:type-check EXIT=0(0 error)、lint EXIT=0(0 error / 105 warning)、`test:coverage` EXIT=0(134 套件 / 1697 例,global 85.56/86.86/80.59/85.56)。本轮另把 **axe 全站节点计数**与 **Lighthouse** 在**装配后的 standalone 产物**上跑通:axe `PASSED=true`(`chromium|firefox × light|dark` 各 34 页,`bgMismatch=0`、`contrastNodes=0`、`violationNodes=0`),Lighthouse 27 次运行断言全通过、**a11y 9/9 URL 均为 100**、对比度与 `aria-required-children` 失败节点 **0**(上一轮为 92-97 分 + 10 个失败节点)。前提是先修掉 N-9:standalone 产物不含 `dist/static`,此前两条门禁是在全站 CSS 404 的裸 HTML 上出数的。另修掉 N-11:`/contact` 的 CSP 违规源自 Zod 的 eval 能力探测,以 `z.config({ jitless: true })` 消除后 Lighthouse best-practices 由「8/9 齐平 + `/contact` 96」变为 **9/9 均为 100**。完整证据、未闭环项与待授权清单见 `docs/acceptance/2026-09-23-gates/final-verdict.md`;另见 `docs/acceptance/2026-09-21-gates/final-tree-results.md` 与 `CONTEXT.md` 决策表末尾新增行。 > > **axe 节点计数门禁已于本轮落地**(2026-09-23 复核):`check:axe:routes` / `check:axe` 现指向真实存在的 `scripts/accessibility/{crawl-routes,axe-node-count}.mjs`(由 `docs/acceptance/2026-09-21-axe/` 平移而来),判定升级为**退出码** 0 通过 / 1 判红 / 2 清单缺失或 0 条;CI 在 `Jenkinsfile`「♿♿ 全站 axe 节点计数」阶段(仅 `main`)用 `node dist/standalone/server.js` 在专用端口 3100 跑,路由清单 = sitemap ∪ 预渲染产物 ∪ BFS。两条仍**不在** `test:all` 内,本地需手动跑。详见 `docs/testing.md` ⑤ 节与 `docs/development/quality-gates.md` §5。 > 提交信息须符合 Conventional Commits 规范,详见 [docs/development/quality-gates.md](docs/development/quality-gates.md)。 ### 5.1 提交流程(PR-First,2026-09-20 对齐 novavis §27) `dev`/`main` 一律经功能分支 + PR 合入,执行顺序固定:**同步 dev → rebase → push → PR 门禁 → rebase 合并**。 ```bash git fetch origin dev && git rebase origin/dev # ⚠️ 以 origin/dev 为准,本地 dev 可能陈旧 git push -u origin # 改写历史后仅用 --force-with-lease,禁裸 --force bash scripts/check-pr-checklist.sh # 未通过不得创建 PR ``` - PR 模板:[.gitea/PULL_REQUEST_TEMPLATE.md](.gitea/PULL_REQUEST_TEMPLATE.md);功能分支合并方式选 Gitea 的 **Rebase**(保持线性历史),不选 merge commit。 - 门禁校验模板三节完整(全链路检查 / 测试分层检查 / 质量门禁)+ checklist 子项 ≥ 20 + 描述文件所有子项已勾选。不适用项**仍须勾选**并注明 `N/A:理由`。 - 破坏性/共享状态动作(seed 重跑、DB 写入、force push、合并、删分支、部署)须单独取得授权,不夹带在常规变更里。 ## 6. 文档同步清单 任何非单行变更都必须评估并同步更新以下文档: - [ ] [README.md](README.md) — 规划、进度、技术栈、脚本 - [ ] [CONTEXT.md](CONTEXT.md) — 新增或变更的术语、决策 - [ ] [AGENTS.md](AGENTS.md) §9 — 新命令、架构变化、约束更新 - [ ] 受影响的设计 / 测试 / 部署文档(`docs/` 目录) - [ ] 代码注释(说明关键决策的佐证来源) ## 7. 循环控制与错误处理 ### 7.1 循环检测 若连续步骤出现以下情况,判定为循环风险: - 输出内容实质性重复(语义相同,仅措辞变化) - 引用的信源或推理路径与前一步完全相同,且未引入新信息 - 结论已包含在上一轮已知结论集中 ### 7.2 退出流程 一旦检测到循环: 1. 立即停止当前推理链,不回退至更早步骤重试。 2. 提取当前已验证的稳定结论。 3. 生成终结性输出,标题为「基于交叉验证的最终结论」。 4. 列出未解决的歧义(不超过 2 条)。 5. 严禁在终结输出后再追加「进一步思考」或「另一种可能」。 ### 7.3 双归零 任何错误立即暂停: - **技术归零**:定位机理、复现、修复。 - **管理归零**:追溯流程漏洞、更新检查清单(如本文件或 `docs/lessons-learned.md`)。 ## 8. 关键约束速查 | 约束 | 来源 | |------|------| | 渲染模式为 `output: 'standalone'` 混合渲染(`output: 'export'` 已移除并被 standalone 取代):营销页预渲染/ISR,`/api/*` 与 `/admin/*` 需 Node 运行时 | `next.config.mjs:85`、本文件 §9 `Build Output` | | 静态资源走 Nginx + CDN,`images.unoptimized: true` 是部署形态的要求(无 Node 接管 `/_next/image` 时改回 `false` 会导致图片全量 404) | `next.config.mjs:8-14` | | `next start`(= `npm run start`/`preview`)在 standalone 下会打 `"next start" does not work with "output: standalone"` 警告;受支持启动方式是 `node dist/standalone/server.js` | `node_modules/next/dist/server/next.js`、本文件 §9 `Build Output` | | **standalone 产物不自带静态资源**:`next build` 只产出 `dist/standalone/{server.js,dist/server}`,`dist/static` 与 `public` 必须拷入 `dist/standalone/dist/static`、`dist/standalone/public`(镜像由 `Dockerfile:53-57` 的 `COPY` 完成)。本地/CI 直跑 `node dist/standalone/server.js` 前必须执行 `npm run build`(`postbuild` 钩子自动拷贝),否则全站 CSS/JS 404,`check:axe` 会以 `bgMismatch` 报红而 **Lighthouse 仍错误地 exit 0**。复验时换端口——残留 server 会给出修复前的假 404 | `Dockerfile:5-9,53-57`、`docs/acceptance/2026-09-23-gates/final-verdict.md` N-9 | | 默认 E2E 打 dev server;GA4 与生产头只在 `npm run test:e2e:prod` 下真正断言 | `e2e/playwright.config.ts:130` | | 品牌红 `#C41E3A` 每页 ≥ 3 处触达点,面积 ≤ 10% | `CONTEXT.md` | | 动效时长**按类别分档**(AGENTS.md 早期把三档压成一句「180–280ms」,与 `CONTEXT.md:76` 冲突 ⇒ 已按原文改正):入场 **180–280ms**(`--transition-fast`…`--transition-normal`)、hover **150ms**、反馈 **100ms**;且**禁止超过 700ms 的入场动效**(`CONTEXT.md:82`)。缓动统一 `ease-ink` [0.22, 1, 0.36, 1] | `CONTEXT.md` §动效设计四原则 | | 所有字体使用本地文件,禁止外部字体 CDN | 项目记忆 | | `experimental.webpackBuildWorker` 必须禁用 | 项目记忆 | | 组件旧版本归档到 `_archive/`,排除 TypeScript 编译 | 本文件 §9 `Archiving Convention` | ## 9. 命令速查与架构(原 CLAUDE.md 正文,2026-12-03 并入) > 本节内容原在 `CLAUDE.md`。按 `novavis-desktop` 的口径(该仓只有 `AGENTS.md` 一份 agent 文档、`git ls-files` 无 `CLAUDE.md`),本仓 2026-12-03 收敛为单文档:`AGENTS.md` 是唯一真源,`CLAUDE.md` 已删除。历史文档里对 `CLAUDE.md` 的引用一律改指本文件对应小节。 ### Common Commands ```bash # Development npm run dev # Start dev server on port 3000 npm run dev:clean # Clean .next/dist then start dev server # Build & Preview npm run build # Build production files to dist/ npm run build:clean # Clean then build npm run start # next start -p 3000 — serve the built output npm run preview # ALIAS of `start` (identical `next start -p 3000`); it is NOT `npx serve` # 说明(2026-09-23 文档同步轮核实):`next start` 与 `output: 'standalone'` 组合下 Next 16 会打印 # `"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" # instead.`(实测见 `docs/acceptance/2026-09-21-gates/ga4-production-run.txt`;抛出点 # `node_modules/next/dist/server/next.js` 的 `getServer()`)。它是 **warn 而非 throw**——服务照常起来, # 但走的是不受支持的降级路径,所以门禁脚本正逐步脱离 `next start`:`test:e2e:prod` 已改为直接 # `node dist/standalone/server.js`(`e2e/playwright.config.ts:132-135`);`check:headings` 也已脱离 # `next start` —— `scripts/utils/check-heading-hierarchy.ts:55-66` 现为「存在 dist/standalone/server.js 就直接 # 起 standalone(注入 HOSTNAME/PORT/NODE_ENV),仅当产物缺失才回退 `npm run preview` 并打印告警」, # 见验收报告 N-24③。至此门禁脚本不再依赖不受支持的 `next start` 路径。 # standalone 的受支持启动方式是 `node dist/standalone/server.js`,且服务启动前 `public/` # 与 `dist/static` 必须已在 standalone 根目录下(server.js 启动时缓存静态索引,缺资源会让 # /_next/static/** 全 404)。**这一步由 `package.json:9` 的 `postbuild` 自动完成**(`npm run build` # 结尾 `rm -rf` + `cp -R dist/static → dist/standalone/dist/static`、`cp -R public → dist/standalone/public`), # 所以正常路径下"先 build 再起 standalone"即可,不必手工拷;仅当产物来自别处或要复用旧 dist 时才参照 # `Jenkinsfile:353-355`(axe 阶段复用上一阶段产物时的同套拷贝)与 `scripts/deploy.sh:162-175` # (发布侧把 `public/` 与 `dist/static → dist/_next/static` 同步进 Nginx 站点根)。npm 侧没有包一层的启动脚本。 # Deploy (统一发布脚本) ./scripts/deploy.sh build # 构建静态产物 ./scripts/deploy.sh deploy # 构建并发布到生产服务器 ./scripts/deploy.sh deploy --skip-build # 使用现有 dist/ 直接发布 ./scripts/deploy.sh rollback # 回滚到最近一次远程备份 ./scripts/deploy.sh status # 查看生产环境发布状态 # Linting & Type Checking npm run lint # ESLint flat config at repo root (`eslint.config.mjs`; `config/lint/.eslintrc.json` no longer exists) npm run type-check # tsc --noEmit npm run type-check:e2e # tsc --noEmit -p e2e/tsconfig.json(DEC-N6:e2e/** 不在根 tsconfig 内, # 重复声明类错误只有这条能静态抓到) npm run check:package-keys # JSON 重复键守卫(按父路径+键名;0 无重复 / 1 判红 / 2 未能度量, # --selftest 三条各测一维)。背景:重复键被后者静默覆盖,不报错也不判红 # E2E Testing (Playwright) npm run test # 全链路 E2E:先 test:functional(4 功能 project),再 test:visual:all(5 视觉 project),串行以免写库用例与截图并发污染基线 npm run test:functional # 仅功能 project(chromium / chromium-mobile / firefox / webkit) npm run test:e2e # Same as test:functional npm run test:smoke # Only @smoke-tagged tests npm run test:e2e:prod # @smoke+@critical+@journey 打构建产物(E2E_TARGET=production → node dist/standalone/server.js,CI 门禁) npm run test:e2e:write-db # 写库型 11 例(cms-workflow 3 + user-journey 8):目标库是 /tmp 一次性 SQLite,prisma/dev.db 全程不被写 npm run test:visual # Visual regression (Desktop Chrome) npm run test:visual:all # Visual regression (all projects) npm run test:visual:update # Update visual snapshots npx playwright test --grep "test name" # Run a single E2E test by name npm run test:landing # Landing 四道门禁(layout/motion/demo/a11y);独立 config,单引擎串行;已并入 test:all # ⚠ E2E 目标口径(默认跑的是 dev server,不是产物) # `npm run test` / `test:functional` 的 webServer 是 `npm run dev`(`e2e/playwright.config.ts:132-135`), # 因此 **16 个 @critical GA4 用例(TC-GA4-001..004 × 4 project)在这一轮里是 skipped,不是 passed**: # `NEXT_PUBLIC_GA_MEASUREMENT_ID` 只写在 `.env.production`,dev 读不到 → `GoogleAnalytics.tsx:81,119` # 提前 return null → 用例内 `test.skip(measurementId === null, …)` 触发。证据: # `docs/acceptance/2026-09-21-gates/skipped-tests-final-tree.json`(28 skipped 中该组恰为 16)。 # 它们真正断言的唯一入口是 `npm run test:e2e:prod`(`E2E_TARGET=production` → 直接 # `HOSTNAME=localhost PORT=3000 node dist/standalone/server.js`,非 `next start`;须先 `npm run build` # 并把 `dist/static` + `public` 并入 standalone 根目录,见 Build & Preview 段的装配口径), # 见同目录 `ga4-production-run.txt` 的 4 passed。故「`npm run test` 全绿」不等于 GA4 覆盖已验证。 # Unit Testing (Jest) npm run test:unit # Run all unit tests npm run test:coverage # Coverage report(阈值以 jest.config.js 的 coverageThreshold 为准;根配置 re-export config/test/jest.config.js 以免双份漂移) npx jest --testPathPattern="button" # Run a single test file matching pattern # Quality Checks npm run check:a11y # 可访问性静态门禁伞(= check:contrast + check:headings + check:brand-token,已并入 test:all) npm run check:contrast # 令牌对比度审计(读 globals.css 令牌表,浅色+暗色双主题、含 alpha 组,缺令牌即红) npm run check:headings # 标题层级审计(有 dist/standalone/server.js 时直起 standalone;产物缺失才回退 `npm run preview` 并打印告警 —— scripts/utils/check-heading-hierarchy.ts:52-67) npm run check:brand-token # 品牌红文字必须走 text-brand-ink* 令牌(DESIGN.md 双通道红规则) npm run check:motion # 动效契约门禁(N-29 收口):R1 令牌档位(instant 100ms / fast·normal 180–280ms,CONTEXT.md:76)、 # R2 时长 ≤700ms(CSS 声明、framer transition 对象的 duration、Tailwind duration-* 类、tailwind.config 的 animation; # infinite 循环与 *-delay 豁免)、R3 transition 时长必须走 var(--transition-*)、 # R4 写死的 cubic-bezier 必须属于令牌层 --ease-*(允许集合从 CSS 解析,不硬编码)且 --ease-ink==[0.22,1,0.36,1]。 # 退出码 0 干净 / 1 违规 / 2 未能度量(空扫描、缺令牌文件)—— 空扫描不读作干净。 # ⚠ 当前树 23 处违规(EXIT=1),故**尚未**并入 check:a11y,详见 docs/development/quality-gates.md §5.1 npm run check:motion:test # 上述门禁的自证伪测试(19 例,双向:合规夹具判 0 + 违规夹具判对应规则红); # 测试在 scripts/ 下,jest 默认 roots 只含 src,故该脚本显式传 --roots npm run check:axe:routes # 全站路由清单(sitemap ∪ 预渲染产物 ∪ 站内链接 BFS)→ /tmp/axe-routes.xml # 同样需要 :3100 的生产服务(SEED 默认取 ${BASE}/sitemap.xml) npm run check:axe # 双引擎(chromium/firefox)×双主题(light/dark)逐页 axe 节点计数 + 三条规则级 # 规则(autocomplete-valid/presentation-role-conflict/svg-img-alt)的分母断言; # 退出码 0 通过 / 1 判红 / 2 清单缺失或 0 条(假绿熔断)。证据落 # docs/acceptance/2026-09-21-axe/axe-evidence.json。需一个生产服务在 :3100: # PORT=3100 HOSTNAME=127.0.0.1 node dist/standalone/server.js(先拷 dist/static 与 public,见上文) # CI 侧由 Jenkinsfile「♿♿ 全站 axe 节点计数」阶段(仅 main)自动串起 npm run test:all # type-check + check:package-keys + type-check:e2e + lint + test:coverage + test:integration:real + check:a11y + test:landing + check:visual + test:e2e:fast + test:security:headers npm run test:e2e:prod # E2E_TARGET=production(构建产物目标);harness **不代跑构建**,须先 `npm run build` # (standalone 根目录的 dist/static + public 由 postbuild 自动装配,见上文) npm run lighthouse # Lighthouse CI(配置 config/test/lighthouserc.json;axe critical/serious 逐条 minScore:1;inspector-issues 亦判红——CSP/弃用类问题只走 DevTools issue 通道,errors-in-console 与 0.9 分类阈值都看不见它;报告落 lighthouse-reports/) # Database (Prisma + SQLite) npm run db:seed # Seed the dev database npm run db:reset # Reset database with migrations ``` ### Architecture #### Tech Stack - **Next.js 16.3**(App Router)混合渲染 — SSG/ISR 静态页 + API routes;`output: 'standalone'`(`next.config.mjs:44`)、`distDir: 'dist'`(`:46`)。standalone 入口是 `node dist/standalone/server.js`,需另拷 `dist/static` 与 `public`;`npm run start`(= `next start`)在 standalone 下只算不受支持的降级路径,见下文 Build Output - **中间件命名为 `proxy.ts`**(Next 16 起 `middleware.ts` 更名);其 matcher 排除 `/api/*`,因此每个 API 路由必须自行做鉴权 - **React 18**, **TypeScript 5** (strict mode with `noUncheckedIndexedAccess`) - **Tailwind CSS 3** with design tokens exposed as CSS custom properties (all tokenized via `var()` references in `tailwind.config.js`) - **Framer Motion** for animations, **Lucide React** for icons, **Zod** for validation - **shadcn/ui** pattern (Radix UI + class-variance-authority + tailwind-merge) - **Prisma** with SQLite for backend data (admin, auth, CMS) #### Path Alias `@/` maps to `src/` — configured in both `tsconfig.json` (`paths`) and `jest.config.js` (`moduleNameMapper`). #### TypeScript Strictness Beyond `strict: true`, the project enables: - `noUncheckedIndexedAccess: true` — array/object index access returns `T | undefined`, requiring null checks. This is a significant constraint to be aware of when writing code. - `noImplicitReturns`, `noFallthroughCasesInSwitch`, `noUnusedLocals`, `noUnusedParameters` #### Route Structure (App Router) ``` src/app/ ├── layout.tsx # Root layout: fonts, metadata, theme, analytics, SEO schemas ├── (marketing)/ # Route group — all public marketing pages │ ├── layout.tsx # Shared: Header + Footer + PageTransition + ErrorBoundary │ ├── page.tsx # Home: server component, CMS zones via `lib/cms/data-server` → `home-content-v15.tsx` │ ├── about/ # About page (client.tsx) │ ├── news/ # News list + [slug] detail │ ├── contact/ # Contact form │ ├── products/ # Products hub (HSI model) │ │ ├── page.tsx # Product listing (enterprise suites + standalone) │ │ ├── [id]/ # Product detail (four-layer narrative) │ │ ├── standalone/[id]/ # Standalone product detail │ │ ├── erp-upgrade/ # Specific product landing pages │ │ └── erp-upgrade-v3/ │ ├── services/ # Services list + [id] detail │ ├── solutions/ # Solutions list + [id] detail (cross-references products) │ ├── cases/ # Case studies │ └── team/ # Team page ├── api/ │ ├── admin/ # Admin API │ ├── auth/ # Authentication API │ ├── cms/ # CMS API routes (draft mode, revalidation) │ └── contact/ # Contact form submission ├── privacy/, terms/ # Legal pages └── fonts/ # Local font files (Geist Sans/Mono) ``` #### Archiving Convention When replacing a page or component with a new version, move the old one to an `_archive/` subdirectory (e.g., `src/app/(marketing)/_archive/` for old homepage iterations). The archive is excluded from TypeScript compilation via `tsconfig.json`. #### Dark Mode Dark mode uses the `data-theme="dark"` HTML attribute (not Tailwind's `dark:` class). Tailwind is configured with `darkMode: ['variant', '[data-theme="dark"] &']` — use the **variant** form, not `['selector', ...]`, because the selector form is accepted by the config but JIT emits zero `dark:` rules under Turbopack + Next.js 16. **Three-state preference model** (`src/lib/theme.ts` is the single source of truth): | Stored value (`localStorage['novalon-theme']`) | Meaning | |---|---| | `'light'` / `'dark'` | Explicit user choice — always wins over the OS | | `'system'` / absent | Follow OS `prefers-color-scheme` (**default for new visitors**) | - `src/app/layout.tsx` has an inline `