Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Quality gates(typecheck + 严格 lint + vitest,含演示数据合理性与 CSP 一致性)
run: pnpm check

- name: Coverage gate(vitest --coverage,阈值见 vitest.config.ts)
# Q1:`pnpm check` 只跑 `vitest run`,vitest.config.ts 里的 thresholds 从不被执行 = 形同虚设。
# 这里用带 --coverage 的命令再跑一次,阈值(statements 60 / branches 50 / functions 60 / lines 60)
# 才真正拦得住回归。注意 include 是**选定域**(utils / services / demo + 安全相关页面逻辑),
# 日志里的百分比不是全项目覆盖率(全项目口径见 vitest.config.ts 注释)。
- name: Quality gates(typecheck + 严格 lint)
run: pnpm typecheck && pnpm lint

- name: Test & coverage gate(vitest --coverage 单次执行,阈值见 vitest.config.ts)
# Q1 的初衷是让 coverage 阈值真正被执行。此前 `pnpm check`(内含一轮全量 vitest)+
# `pnpm test:coverage`(再来一轮)把全部用例跑了两遍;现在 lint 之后只跑一次带
# --coverage 的 vitest,用例与阈值在同一次执行里生效。本地/pre-commit 的
# `pnpm check` 入口不受影响。include 仍是**选定域**(utils / services / demo +
# 安全相关页面逻辑),日志里的百分比不是全项目覆盖率。
run: pnpm test:coverage

- name: Dependency audit(全量公告、真实源码补丁和攻击回归;不忽略公告)
- name: Dependency audit(运行时公告零忽略 + 真实源码补丁与攻击回归;仅构建链可达的公告为非阻塞告警,分层政策见 SECURITY.md)
run: pnpm audit:security

build:
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Type check
run: pnpm run typecheck

- name: Test
run: pnpm test

- name: Lint
run: pnpm run lint

- name: Dependency audit(全量公告与真实源码补丁验证)
run: pnpm audit:security
# 质量门禁(typecheck / test / lint / audit)不在 master 部署上重跑:推到 master 的
# commit 即 PR 上被 ci.yml 逐项检查过的同一 commit(分支保护要求 check/build/e2e 全绿),
# 重复执行只增加约 6-8 分钟纯冗余。本工作流保留的是部署特有的门禁:凭据注入构建、
# SPA 404 回退、dist 密钥扫描与完整性清单(扫描过的字节 = 发布的字节)。
# 直推 master(不经 PR)的提交没有这道重复防线——分支保护已要求 PR 流程。

- name: Build
# 注入本产线会用到的全部凭据;扫描步骤必须看到同一组环境变量(否则「构建期配置了凭据」
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pnpm start:demo
- **Permission points are single-source.** Add a new point to `PERMISSION_TREE` in `src/constants/permissions.ts`, then wire it in the same PR: `access` in `config/routes.ts` for pages, `src/access.ts` for buttons, the demo backend route in `src/demo/server/routes.ts`, and the API→permission table in [docs/demo/role-matrix.md](./docs/demo/role-matrix.md). Do not re-derive a role's permissions anywhere else — the matrix reproduces `DEFAULT_ROLE_PERMISSIONS` item by item and must stay exact.
- **Never describe demo mode as real authorization.** The in-browser demo backend demonstrates the contract; every check runs in the user's own browser, so the docs must always say that a real backend has to implement it. The same applies to audit logs, the role-assignment rules and coordinate precision.
- **New build-time credential.** Register it in `CREDENTIAL_DECLARATIONS` in `scripts/check-dist-secrets.mjs`, give it a typed `EXPECTED_*` declaration and a shape check, and declare it in every pipeline that injects it (Vercel env, Cloudflare Pages env, Docker build args, the Pages workflow's scan step). An injected-but-undeclared credential fails the scan by design.
- **Do not weaken a gate to land a change.** Thresholds, allowlists, CSP sources and security tests must not be relaxed; if a gate blocks you, fix the cause or raise it in the PR description.
- **Do not weaken a gate to land a change.** Thresholds, allowlists, CSP sources and security tests must not be relaxed; if a gate blocks you, fix the cause or raise it in the PR description. (The one deliberate amendment on record: dependency-advisory tiering, 2026-11-01 — runtime stays zero-ignore, build-chain-only advisories warn; rationale and scope in SECURITY.md.)

## Testing

- Unit tests: `src/**/*.test.ts` (vitest) — demo data sanity, demo backend endpoints, request layer, geo math, import/export
- Repo-level: `scripts/*.test.ts` — repository hygiene, CSP and security-header consistency across Vercel, nginx and Cloudflare Pages, AMap loader-host pinning, route table (components exist, legacy paths resolve, bilingual menu keys), deploy-routing fail-closed behaviour, Dockerfile frontend pinning, integrity manifest
- Browser: `e2e/` (Playwright, 112 cases green against the new contract) — every page free of errors / CSP violations, English UI without leftover Chinese, key business flows; cases tagged `@smoke` re-run against the live site after each deployment
- Accessibility: `e2e/a11y.spec.ts` injects axe-core from the existing transitive install (no new dependency; served same-origin because the CSP has no `unsafe-inline`) and runs **24 cases** in three groups — 10 routes × light (cold start), 10 routes × realDark (cold start), and 4 routes (`/`, `/ops/devices`, `/ops/alarms`, `/ops/tickets`) × realDark reached by **clicking** the header theme toggle. The toggle group exists because umi's `setAntdConfig` deep-merges and the light/dark token sets were previously asymmetric, leaving light seeds behind on a hot switch; both sets now hold the same 13 keys and the toggle path was measured to produce byte-identical tokens to a cold-start dark across 17 CSS variables. Command `pnpm exec playwright test e2e/a11y.spec.ts --workers=1` → 24 passed, with **0 critical and 0 serious in all 24 cases** and the exclusion list empty (no rule excluded, no threshold lowered, nothing reclassified). This is **not** "axe clean": the moderate/minor findings are reported and stay non-gating — `landmark-no-duplicate-banner` and `landmark-unique` (moderate, 2 per route, ProLayout header/banner), Calendar `heading-order` (moderate) and FullCalendar's `empty-table-header` (minor ×7), plus a `region` moderate on the empty portal `<div>` antd creates when the toggle's tooltip opens (toggle cases only). Treat any newly appearing critical/serious result as a regression to fix, not to exclude.
- Accessibility: `e2e/a11y.spec.ts` injects axe-core from the existing transitive install (no new dependency; served same-origin because the CSP has no `unsafe-inline`) and runs **27 cases** in three groups — 11 routes × light (cold start), 11 routes × realDark (cold start), and 5 routes (`/login`, `/`, `/ops/devices`, `/ops/alarms`, `/ops/tickets`) × realDark reached by **clicking** the header theme toggle. The toggle group exists because umi's `setAntdConfig` deep-merges and the light/dark token sets were previously asymmetric, leaving light seeds behind on a hot switch; both sets now hold the same 13 keys and the toggle path was measured to produce byte-identical tokens to a cold-start dark across 17 CSS variables. Command `pnpm exec playwright test e2e/a11y.spec.ts --workers=1`; the gate is **0 critical and 0 serious across all cases** with the exclusion list empty (no rule excluded, no threshold lowered, nothing reclassified). This is **not** "axe clean": the moderate/minor findings are reported and stay non-gating — `landmark-no-duplicate-banner` and `landmark-unique` (moderate, 2 per route, ProLayout header/banner), Calendar `heading-order` (moderate) and FullCalendar's `empty-table-header` (minor ×7), plus a `region` moderate on the empty portal `<div>` antd creates when the toggle's tooltip opens (toggle cases only). Treat any newly appearing critical/serious result as a regression to fix, not to exclude.
- Coverage: `pnpm test:coverage` — the percentage is measured over the **selected include set** in `vitest.config.ts` (`src/utils`, `src/services`, `src/demo`, `src/pages/Login`, `src/pages/System/Users`, `src/pages/System/Roles`), not the whole project; thresholds (statements 60 / branches 50 / functions 60 / lines 60) gate that set in CI and must not be lowered. Final local figure: statements 79.38% / branches 74.48% / functions 75.55% / lines 81.51% over 54 files (644 passed, 5 skipped — the skips are the mode-conditional branches of `scripts/real-mode-artifact.test.ts`), against roughly 47.87% statements for whole-project `src/**`
- Lint: `react-hooks/exhaustive-deps` is an error and unused-disable reporting is on (an unused disable directive is itself an error). A disable line must carry a concrete written reason on the same or preceding line; the one remaining `exhaustive-deps` disable in `src/` is `src/hooks/useApi.ts` (its reason is on the line, because the dependency array is supplied by the caller and the rule cannot verify it statically).
- Lint: `react-hooks/exhaustive-deps` is an error and unused-disable reporting is on (an unused disable directive is itself an error). A disable line must carry a concrete written reason on the same or preceding line; the 6 `exhaustive-deps` disables currently in `src/` (`src/hooks/useApi.ts` plus five Cesium scene pages' clock/pure-function effects) each carry their reason on the line.
6 changes: 3 additions & 3 deletions CONTRIBUTING.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pnpm start:demo
- **权限点只有一个来源。** 新增权限点要在 `src/constants/permissions.ts` 的 `PERMISSION_TREE` 里登记,并在同一个 PR 内接好:页面用 `config/routes.ts` 的 `access`,按钮用 `src/access.ts`,演示后端路由用 `src/demo/server/routes.ts`,并同步 [docs/demo/role-matrix.md](./docs/demo/role-matrix.md) 的接口 → 权限点对照。角色权限不允许在别处另算一套——矩阵文档逐项复刻 `DEFAULT_ROLE_PERMISSIONS`,必须保持精确一致。
- **绝不把演示模式描述成真实授权。** 浏览器内演示后端演示的是契约;一切校验都在用户自己的浏览器里执行,文档必须始终写明真实后端要自行实现。操作日志、角色分配规则与坐标精度同理。
- **新增构建期凭据。** 要在 `scripts/check-dist-secrets.mjs` 的 `CREDENTIAL_DECLARATIONS` 登记,配一个类型化的 `EXPECTED_*` 声明与形态校验,并在所有注入它的产线里声明(Vercel 环境变量、Cloudflare Pages 环境变量、Docker build-arg、Pages workflow 的扫描步骤)。注入了却没声明会按设计判失败。
- **不得为了合入而放松门禁。** 阈值、白名单、CSP 来源与安全测试都不许放宽;被门禁挡住时请修根因,或在 PR 描述里提出。
- **不得为了合入而放松门禁。** 阈值、白名单、CSP 来源与安全测试都不许放宽;被门禁挡住时请修根因,或在 PR 描述里提出。(有记录的唯一一次主动修订:2026-11-01 依赖公告分层——运行时维持零忽略,仅构建链可达的公告降为告警;理由与范围见 SECURITY.md。)

## 测试

- 单元测试:`src/**/*.test.ts`(vitest)——演示数据合理性、演示后端接口、请求层、地理计算、导入导出
- 仓库级:`scripts/*.test.ts`——仓库卫生、CSP 与安全响应头在 Vercel / nginx / Cloudflare Pages 三处一致、高德加载器主机固定、路由表(组件存在、旧路径可达、菜单双语)、部署路由闭合失败行为、Dockerfile frontend 固定、完整性清单
- 浏览器:`e2e/`(Playwright,当前按新契约全绿 112 例)——每个页面无异常 / 无 CSP 违规、英文界面无遗漏中文、关键业务流程;`@smoke` 标签的用例在部署后对线上地址再跑一遍
- 无障碍:`e2e/a11y.spec.ts` 从既有传递依赖注入 axe-core(不新增依赖;因为 CSP 没有 `unsafe-inline`,改为同源 URL 注入),共跑 **24 例**,分三组——10 条路由 × 浅色(冷启动)、10 条路由 × realDark(冷启动)、以及 4 条路由(`/`、`/ops/devices`、`/ops/alarms`、`/ops/tickets`)× realDark 且经**点击顶栏主题开关**到达。切换组存在的原因:umi 的 `setAntdConfig` 是深合并,而此前浅色与暗色 token 键集不对称,热切换会残留浅色种子值;现在两套键集都是同样的 13 个键,且实测切换路径与冷启动暗色在 17 个 CSS 变量上逐字节一致。命令 `pnpm exec playwright test e2e/a11y.spec.ts --workers=1` → 24 例全过,**24 例的 critical 与 serious 均为 0**,排除清单为空(没有排除任何规则、没有放宽阈值、没有重新分级)。这不等于「axe 无告警」:moderate / minor 结果照常输出但不作为门禁——ProLayout 头部的 `landmark-no-duplicate-banner`、`landmark-unique`(moderate,每路由 2 个),Calendar 的 `heading-order`(moderate),FullCalendar 内部的 `empty-table-header`(minor ×7),以及切换用例里 antd 在开关 tooltip 打开时创建的空 portal `<div>` 上的 `region`(moderate,仅切换组)。新出现的 critical / serious 一律按回归修复,不允许加进排除清单。
- 无障碍:`e2e/a11y.spec.ts` 从既有传递依赖注入 axe-core(不新增依赖;因为 CSP 没有 `unsafe-inline`,改为同源 URL 注入),共跑 **27 例**,分三组——11 条路由 × 浅色(冷启动)、11 条路由 × realDark(冷启动)、以及 5 条路由(`/login`、`/`、`/ops/devices`、`/ops/alarms`、`/ops/tickets`)× realDark 且经**点击顶栏主题开关**到达。切换组存在的原因:umi 的 `setAntdConfig` 是深合并,而此前浅色与暗色 token 键集不对称,热切换会残留浅色种子值;现在两套键集都是同样的 13 个键,且实测切换路径与冷启动暗色在 17 个 CSS 变量上逐字节一致。命令 `pnpm exec playwright test e2e/a11y.spec.ts --workers=1`;门禁要求**全部用例 critical 与 serious 均为 0**,排除清单为空(没有排除任何规则、没有放宽阈值、没有重新分级)。这不等于「axe 无告警」:moderate / minor 结果照常输出但不作为门禁——ProLayout 头部的 `landmark-no-duplicate-banner`、`landmark-unique`(moderate,每路由 2 个),Calendar 的 `heading-order`(moderate),FullCalendar 内部的 `empty-table-header`(minor ×7),以及切换用例里 antd 在开关 tooltip 打开时创建的空 portal `<div>` 上的 `region`(moderate,仅切换组)。新出现的 critical / serious 一律按回归修复,不允许加进排除清单。
- 覆盖率:`pnpm test:coverage`——百分比统计的是 `vitest.config.ts` 的**选定域**(`src/utils`、`src/services`、`src/demo`、`src/pages/Login`、`src/pages/System/Users`、`src/pages/System/Roles`),不是全项目口径;阈值(statements 60 / branches 50 / functions 60 / lines 60)在 CI 上只对域内生效,不得下调。最终本机数字:54 个文件上 statements 79.38% / branches 74.48% / functions 75.55% / lines 81.51%(644 passed、5 skipped,skip 全部来自 `scripts/real-mode-artifact.test.ts` 的模式分支),同口径全项目 `src/**` 约 statements 47.87%
- Lint:`react-hooks/exhaustive-deps` 已提到 error,未使用 disable 的上报已开启。disable 行必须在本行或上一行写明具体理由;`src/` 内仅剩 1 处 `exhaustive-deps` disable,在 `src/hooks/useApi.ts`(理由写在同一行:依赖数组由调用方提供,规则无法静态校验展开项)。
- Lint:`react-hooks/exhaustive-deps` 已提到 error,未使用 disable 的上报已开启。disable 行必须在本行或上一行写明具体理由;`src/` 内现存 6 处 `exhaustive-deps` disable(`src/hooks/useApi.ts` 与五个 Cesium 场景页的时钟/纯函数 effect),理由均已写在同一行。
Loading
Loading