From c4fb0c1b783abba006a77c0888aead21a7526c42 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 14:56:15 +0800 Subject: [PATCH 1/4] docs(adr): propose ADR 025 for verification tiers and CI governance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add proposed ADR 025 defining the five verification tiers (L0–L4, including event-driven formal model verification), test coverage and placement discipline, and CI governance rules, along with its mirrored Chinese translation, index entries and a routing pointer in AGENTS.md. Refs #1938 --- AGENTS.md | 1 + docs/INDEX.md | 1 + ...25-verification-tiers-and-ci-governance.md | 133 ++++++++++++++++++ docs/adr/README.md | 1 + ...25-verification-tiers-and-ci-governance.md | 79 +++++++++++ 5 files changed, 215 insertions(+) create mode 100644 docs/adr/025-verification-tiers-and-ci-governance.md create mode 100644 docs/zh/adr/025-verification-tiers-and-ci-governance.md diff --git a/AGENTS.md b/AGENTS.md index 2460a29789..e58cb555a8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,6 +66,7 @@ Every public service is a data face. The contract is [service faces](docs/design ## Testing +- Follow [ADR 025](docs/adr/025-verification-tiers-and-ci-governance.md) for verification tiers (L0–L4, including when formal models run), test placement and CI governance. - Verify that the remaining necessary changes satisfy the user flow, reusing relevant tests first; after integration, check the interfaces and flows actually affected. Reuse evidence that still applies; only expand or repeat verification for new changes, failures or unresolved doubts. Progress is not measured by test count, failure count or number of runs. - Automated tests only protect architectural flows, public interfaces, cross-crate contracts, persistence formats, user flows and release artifacts. Assertions about private modules, helper functions, single functions, internal call order or mock configuration belong in the nearest flow test, not in standalone tests. - Scenarios involving security, data loss, data migration, protocol compatibility or release artifacts may keep a dedicated test if they cannot be triggered reliably in a flow test. diff --git a/docs/INDEX.md b/docs/INDEX.md index a974bf8787..59e935a8d1 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -49,6 +49,7 @@ This index is navigation. Delivery status lives in issues, not here. - [Architecture decisions](adr/README.md) - [ADR 022 — Timeline 属性查询与正文重建](adr/022-event-property-queries.md)(中文):目标 API 与模块结构、属性查询、业务状态恢复和正文释放 - [ADR 023 — 上下文用量由独立分支部件维护](adr/023-context-usage.md)(中文):ContextUsage 的职责、增量统计、服务商校准及后续设计边界 +- [ADR 025 — Verification tiers, test coverage and CI governance](adr/025-verification-tiers-and-ci-governance.md)([中文](zh/adr/025-verification-tiers-and-ci-governance.md)):verification tiers (L0–L4, including formal models), test coverage discipline and CI governance rules (#1938) - [Resume:按业务对象设计计算与读取](design/resume-read-design.md)(中文,草案):usage、输入队列、Prompt、显示详情、SQL 执行和恢复校验的分项设计与成本验收 - [当前状态字段索引](design/appserver/timeline-state-read-indexes.md)(中文,草案):现有API缺口、完整索引键、源位置前驱和SQL扫描验收 - [状态保存与恢复读取](design/owner-state-indexed-reads.md)(中文,草案):按业务对象决定持久化;当前队列点查、Prompt有效引用、Usage数字和真实流程读写数量 diff --git a/docs/adr/025-verification-tiers-and-ci-governance.md b/docs/adr/025-verification-tiers-and-ci-governance.md new file mode 100644 index 0000000000..a3608c9e34 --- /dev/null +++ b/docs/adr/025-verification-tiers-and-ci-governance.md @@ -0,0 +1,133 @@ +# 025: Verification tiers, test coverage and CI governance + +Decision status: Proposed. + +## Context + +Repository verification tends to grow monotonically when every discovered defect or new check is +appended directly to the pull-request gate. Over time, two distinct concepts get conflated: + +- **Repository verification coverage**: every check, formal model, suite, benchmark and acceptance + procedure the repository maintains. +- **Pull-request gate execution**: the bounded subset that must complete synchronously before a + change merges. + +When those two are treated as identical, slow suites, cross-platform checks, compile-time rebuild +loops and pure static scans all pile onto one flat, serial gate. When execution approaches the job +limit, raising timeouts hides the degradation until queues, cache eviction and mutual cancellations +undermine both contributor turnaround and `main` signal quality. + +## Decision + +### D1. Verification is tiered by change nature and feedback cycle + +Verification assets are assigned to five tiers according to what failure class they catch, what +triggers them and how fast they must answer: + +| Tier | Question answered | Scope | Trigger | +| --- | --- | --- | --- | +| **L0 — Design & formal** | Do the state-machine, protocol and handover invariants hold in the abstract? | Formal models (e.g. TLA+ specifications and `.cfg` properties), ADR immutability checks | **Event-driven on design/contract change**: when a formal model, protocol/event contract, recovery boundary or handover invariant changes. Not run on ordinary implementation PRs. | +| **L1 — Static & contract** | Are formatting, dependency boundaries, public schemas/wire types, static source rules and license/advisory policies intact? | Formatters, linters, pure static repository scans, frontend typecheck/lint, wire/schema contracts, dependency advisory/license checks | **Every PR**, scoped to the changed surface (dependency scans only on manifest, lockfile or policy changes). Fast fail-first gate. | +| **L2 — Affected business flows** | Do the modified modules and their direct dependents preserve behavioral contracts? | Unit tests and in-process or loopback flow tests for the affected crates and their downstream consumers | **Every PR** on the primary high-throughput platform; expands to the full workspace only when shared foundational crates or workspace-wide configuration change. | +| **L3 — Real environment & cross-platform** | Do real OS primitives, process/plugin wiring, terminal interaction and external protocol boundaries work? | OS-native boundary slices, real daemon + plugin runtime flows, interactive terminal E2E suites, external registry acceptance | **Split by cost**: narrow OS-native boundary slices run on PRs that touch platform/client code; full cross-platform runs and external-registry checks run asynchronously on `main` or on a schedule; interactive terminal E2E runs locally on demand and before release. | +| **L4 — Quality, performance & release** | Have model quality, resource budgets, executable layout or distribution artifacts regressed? | Evaluation harnesses, memory/startup measurements, native code-layout builds, multi-platform release builds and registry/image acceptance | **Scheduled (nightly), manual dispatch or release train only**. Never gates an ordinary feature PR. | + +Formal models (L0) verify that an abstract state machine satisfies safety and conditional liveness +invariants within a finite state space; they do not compile or test implementation code. Ordinary +implementation changes rely on L2 flow tests to guard that code still refines the model's actions. +If a code change alters a modelled handover or ordering guarantee, it is a design change and returns +to L0 before merging. + +### D2. Test coverage follows lowest-layer, single-owner and build-hygiene rules + +Coverage quality is measured by contract protection per unit of cost, not by test count at the top +layer. + +- **Test at the lowest layer that proves the contract**: logic, state transitions, rendering rules, + validation errors and edge-case matrices belong in component, state-machine or in-process flow + tests — never in process-spawning, PTY or binary-copying E2E tests. End-to-end suites cover + wiring and real OS interaction on representative happy and failure paths rather than exhaustive + combinations. +- **One owning layer per behavior**: once a lower layer (or a dedicated suite such as the local + terminal E2E suite) proves a behavior, higher layers verify only connectivity and do not duplicate + its failure matrix. Migrating coverage to a better carrier requires retiring or disabling the + superseded CI case in the same change or tracked migration. +- **Inject testability at runtime boundaries instead of recompiling**: test variants (release + stamps, build IDs, clocks, endpoints, fault injection) must be configurable at the binary or test + boundary without flipping build-time environment variables that recompile upstream crates in CI. +- **Treat test executables as build artifacts**: organize integration tests into a bounded number + of balanced entry binaries per crate to avoid linker and compiler-cache amplification from + dozens of single-file test executables, while splitting oversized test binaries that create + single-process scheduling tails or linker pressure. + +### D3. CI gates operate under explicit budgets and light/heavy isolation + +- **Hard latency and resource budgets**: every synchronous tier maintains an explicit wall-clock + ceiling (target: L1 ≤ 2 min; PR end-to-end median ≤ 8 min, p90 ≤ 15 min; OS-native PR slice + ≤ 3 min). Approaching or hitting a timeout is a regression to fix by narrowing scope, optimizing + slow tests, improving parallelism or moving work to L3/L4 — **never** by raising job or target + timeouts alone. +- **Cost disclosure for gate additions**: any change that adds a required PR check or widens path + selection must state its incremental runtime, added compile dependencies and target runner pool. +- **Physical isolation of light checks from heavy builds**: pure static repository checks (boundary, + link, literal, packaging metadata) must not depend on compiling business runtime crates. Docs, + frontend, script and static checks run in lightweight jobs and never contend for heavy build or + scarce platform runner pools. + +### D4. Impact-scoped routing is the default, backed by scheduled full sweeps + +- **Consistent routing on PRs and `main`**: both pull requests and pushes to `main` select only the + groups their changed paths affect. `main` pushes run to completion without cancelling earlier + `main` pushes, so every merged commit produces an honest pass/fail signal without non-code or + frontend merges starving backend runners. +- **Scheduled full sweeps cover cross-cutting drift**: periodic scheduled runs (and release-train + verification) execute the full cross-platform and cross-workspace matrix so implicit coupling + cannot accumulate unnoticed. +- **Explicit path classification**: new top-level repository directories and non-code assets must + be classified explicitly in the change router rather than silently falling through to the + most expensive full-workspace fallback. + +### D5. Scarce platform pools verify platform-native boundaries only + +- **Primary platform for platform-neutral work**: full workspace compilation and platform-neutral + L1/L2 verification run on the highest-throughput, lowest-queue runner pool (Linux). +- **Minimal, mechanically checked secondary OS slices**: scarce OS pools (macOS, Windows) run only + checks that exercise platform-specific code paths (`cfg(target_os = ...)`), native OS APIs or + target packaging boundaries on pull requests. The platform-native selection is verified against + the source rather than maintained as an unchecked manual list. +- **Periodic telemetry and pruning**: CI health (queue p90, execution p90, cache write/eviction + volume, slowest test targets, zero-match dead steps and cancellation waste) is reviewed + periodically to retire obsolete checks and trim new long tails. + +## Consequences + +- Adding a new test, static scan or formal model requires declaring its tier (L0–L4) and owner + before wiring it into CI. +- Pure static checks are decoupled from workspace-coupled tooling so frontend, docs and script + changes stay fast. +- Build-time flags that vary only for testing are replaced by boundary/runtime injection so CI + never triggers cascading crate recompiles. +- Test binary layout and cache footprint become reviewable engineering concerns alongside runtime + code. +- Concrete workflow changes, runner migrations, test-binary consolidation and slow-test cleanups + are tracked in separate implementation issues rather than here. + +## Non-goals + +- Lowering overall defect detection or deleting coverage without an owning replacement at a more + appropriate tier. +- Prescribing specific CI vendor syntax, runner hostnames or crate-by-crate path tables (those live + in workflow files, architecture guides and issues). +- Replacing code review or design review with automated checks. + +## Supersession + +Does not supersede any prior ADR. Extends [ADR 008](008-documentation-ownership.md) by separating +verification policy rules (here) from current CI implementation details (`docs/architecture/build.md`, +`docs/release/README.md`) and delivery status (issues). + +References: [ADR 008](008-documentation-ownership.md), +[Timeline finite model checking](../design/examples/capability-models/README.md), +[Build environment](../architecture/build.md), +[Terminal end-to-end suite](../architecture/tui-e2e.md), +[#1938](https://github.com/arcships/dim/issues/1938). diff --git a/docs/adr/README.md b/docs/adr/README.md index f6bdba0811..13b66870e2 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -32,6 +32,7 @@ original text. | [022 — Timeline 属性查询与正文重建](022-event-property-queries.md) | Proposed | Supersedes 019's event-only results, skip-based paging and start-only positions, and 020's single-predicate limit; retains 021's read ownership | | [023 — 上下文用量由独立分支部件维护](023-context-usage.md) | Accepted | Follows 021 and 022; separates context usage statistics from request preparation | | [024 — Web 抓取层使用请求库,地址策略在请求之前执行](024-web-fetch-transport.md) | Proposed | Follows 006 D1; replaces the hand-written transport and narrows the address policy to a pre-request check | +| [025 — Verification tiers, test coverage and CI governance](025-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; separates verification tiers (L0–L4), test placement and CI governance rules | Source baseline: [initial foundation parent](https://github.com/arcships/dim/commit/aaaffa5768e031d781abb73e45b1915b05dc2aa0). This baseline includes lifecycle fixes not necessarily present on the default branch. diff --git a/docs/zh/adr/025-verification-tiers-and-ci-governance.md b/docs/zh/adr/025-verification-tiers-and-ci-governance.md new file mode 100644 index 0000000000..5f60944ffe --- /dev/null +++ b/docs/zh/adr/025-verification-tiers-and-ci-governance.md @@ -0,0 +1,79 @@ +# 025: 验证分层、测试覆盖与 CI 治理原则 + +决策状态:Proposed(提案)。 + +## 背景 + +每当主干出现回归或新增一种检查手段,如果习惯性地把它直接挂进 PR 必跑门禁,仓库的验证体系就会单调膨胀。时间一长,两个本应分开的概念会被混为一谈: + +- **仓库的验证覆盖面**:仓库维护的全部检查、形式化模型、测试套件、基准评估与发布验收手段。 +- **PR 门禁的执行面**:每次合入前必须同步跑完的有界子集。 + +一旦把两者画上等号,慢速集成测试、跨平台检查、为测试而触发的重复编译以及纯静态扫描就会全部堆在同一条串行门禁里。耗时逼近上限时,如果只靠不断调大超时时间来兜底,真正的问题会被掩盖,最终演变为长队列等待、编译缓存写爆淘汰、任务相互取消,反过来同时伤害开发反馈速度与 `main` 主干信号质量。 + +## 决策 + +### D1. 按变动性质与反馈周期将验证分为五层(L0–L4) + +所有验证资产按「守卫的问题类型、触发条件、预期反馈周期」归入五层,各司其职,不再平铺混跑: + +| 层级 | 守卫的核心问题 | 范围 | 触发时机 | +| --- | --- | --- | --- | +| **L0 — 设计与形式化层** | 抽象状态机、协议与交接不变量本身是否存在反例? | 形式化模型(如 TLA+ 规约及 `.cfg` 性质)、ADR 不可变检查 | **仅设计/契约变动时触发**:当形式化模型、协议/事件契约、恢复边界或交接不变量变更时运行;普通实现 PR **不跑**。 | +| **L1 — 静态与契约层** | 格式、依赖边界、公开 schema / wire 类型、静态源码规则及依赖合规是否破坏? | 格式化、Lint、纯静态仓库扫描、前端类型检查/Lint、wire/schema 契约、依赖漏洞与许可证扫描 | **每次 PR 按改动面精准触发**(依赖合规仅在 manifest、lockfile 或策略文件变更时跑),作为最快失败门禁。 | +| **L2 — 影响面业务流层** | 改动模块及其直接下游的业务行为契约是否保持正确? | 受影响 crate 及直接下游的单元测试、进程内或 loopback 流程测试 | **每次 PR 在主力高吞吐平台运行**;仅在公共底层 crate 或全局构建配置改动时扩大至全 workspace。 | +| **L3 — 真实环境与跨平台层** | 真实 OS 原语、真实进程/插件接线、终端交互与外部协议边界是否正常? | 平台专属边界窄集、真实 daemon + 插件运行时流、交互式终端 E2E、外部注册表验收 | **按成本拆分**:仅触及平台/客户端代码时在 PR 跑对应的 OS 专属窄集;全量跨平台与外部注册表检查在 `main` 异步或定时运行;交互式终端 E2E 在本地按需及发版前运行。 | +| **L4 — 效果、性能与发布层** | 模型效果、资源预算、可执行文件布局或分发包是否退化? | 评测套件(eval)、内存/启动测量、原生代码布局构建、多平台发布包构建与注册表/镜像验收 | **仅定时(Nightly)、手动触发或发版流程运行**,绝不阻塞普通功能 PR。 | + +形式化模型(L0)验证的是「抽象状态机在有限状态空间内满足安全性与条件活性」,不是代码编译检查。普通代码改动依靠 L2 流程测试守住「实现依然精化模型动作」。如果某次实现修改破坏了模型假设的交接或先后序承诺,它本质上属于设计变更,必须回到 L0 更新并重跑模型后再合入。 + +### D2. 测试覆盖遵循「最低层证明、单一归属、运行期注入、产物治理」四条规则 + +测试质量取决于单位成本下对契约的保护力,而不是在最高层堆积用例数量: + +- **最低层证明原则**:纯逻辑、状态转换、渲染规则、参数校验与错误分支矩阵必须下沉到组件、状态机或进程内流程测试,禁止写成起真实进程、PTY 或拷贝二进制的端到端测试。E2E 套件只覆盖跨进程接线与真实 OS 交互的代表性路径,不做排列组合穷举。 +- **单一归属原则**:同一行为只在一个最合适的层级做完整覆盖,上层仅验证链路接通,不重复下层的异常矩阵。当行为迁移到更合适的载体(例如组件测试或本地终端 E2E 套件)后,必须在同一改动或对应迁移任务中同步退役旧 CI 用例。 +- **运行期边界注入替代重编译**:测试所需的构建态差异(如 release 标记、build ID、时钟、外部端点、故障注入)应在二进制或测试边界支持运行期注入,禁止为了测试几个分支而切换编译环境变量、迫使 CI 重编上游依赖图。 +- **把测试二进制当作工程产物治理**:按 crate 将集成测试聚合为少量均衡的入口二进制,避免大量单文件测试可执行文件重复全图链接、写爆编译缓存;同时对过大的单一测试二进制做均衡拆分,避免形成单进程调度长尾或链接器压力。 + +### D3. CI 门禁实行硬预算制与轻重物理隔离 + +- **明确耗时与资源预算**:每个同步门禁层设定清晰上限(目标:L1 ≤ 2 分钟;PR 端到端中位 ≤ 8 分钟、p90 ≤ 15 分钟;OS 专属 PR 窄集 ≤ 3 分钟)。逼近或触发超时视为需要修复的工程退化,必须通过收敛范围、优化慢测、提升并行度或调整分层来压回预算内,**禁止**以单纯调大超时阈值作为解决方案。 +- **门禁增量成本显式化**:任何向 PR 必跑门禁新增检查或扩大路径匹配规则的变更,必须写明增量耗时、新增编译依赖及落入的 runner 池。 +- **轻量静态检查与重型构建物理隔离**:纯静态仓库检查(依赖边界、链接、字面量、打包元数据等)不得依赖编译业务运行时 crate。文档、前端、脚本与纯静态检查运行在轻量作业中,不得抢占重型编译或稀缺平台 runner 池。 + +### D4. 默认按影响面路由,由定时全量兜底 + +- **PR 与 `main` 保持一致的影响面路由**:PR 与 `main` 推送均只运行受改动路径影响的检查组。`main` 推送各自独立跑完、不相互取消,既保证每次合入都有真实的绿/红结果,又避免前端或非后端合入拖垮后端 runner。 +- **定时全量兜底跨模块隐式耦合**:通过周期性定时运行(Nightly)及发版前全量门禁覆盖全 workspace 与全平台矩阵,防止跨模块隐式依赖退化漏网。 +- **显式路径分类**:新增顶层目录或非代码资产时,必须在路径路由规则中显式归类,不得静默落入最昂贵的全量兜底组。 + +### D5. 稀缺平台仅验证平台专属边界,且定期度量和做减法 + +- **平台无关验证集中在主力高吞吐平台**:全量编译及平台无关的 L1/L2 验证集中在高并发、低排队的单一主平台(Linux)执行。 +- **稀缺平台窄集且由代码核对**:稀缺 OS runner 池(macOS、Windows)在 PR 阶段仅运行触及平台专属代码路径(`cfg(target_os = ...)`)、原生 OS API 或目标打包边界的检查;专属清单应通过代码属性或静态检查核对,不依赖易漂移的人工白名单。 +- **周期性可观测与减法维护**:定期复盘 CI 指标(排队 p90、执行 p90、缓存写入/淘汰体积、Top 最慢测试目标、0 匹配死步骤与取消浪费率),持续淘汰过时检查并治理新增慢测长尾。 + +## 影响 + +- 新增测试、静态扫描或形式化模型时,需先明确其所属层级(L0–L4)与归属,再决定是否接入 PR 门禁。 +- 纯静态检查将与依赖全后端的研发工具解耦,保持文档、前端与脚本类 PR 的秒级/分钟级反馈。 +- 仅服务于测试的编译期开关将改为边界/运行期注入,消除 CI 中的级联重编。 +- 测试二进制形态与编译缓存体积成为与业务代码同等重要的工程审查对象。 +- 具体的 workflow 调整、runner 迁移、测试二进制合并与慢测治理分别在独立实现 issue 中跟踪,不写入本 ADR。 + +## 非目标 + +- 降低仓库整体缺陷检出能力,或在没有合适层级替代覆盖的情况下删除测试。 +- 规定具体的 CI 平台语法、runner 主机名或逐 crate 路径表(这些属于 workflow 文件、架构文档与 issue 范畴)。 +- 用自动化检查替代设计评审与代码审查。 + +## 替代关系 + +不替代任何既有 ADR。本决策承接 [ADR 008](../../adr/008-documentation-ownership.md) 的分层边界:本文件仅定义验证与 CI 治理原则,当前 CI 实现细节留在 `docs/architecture/build.md` 与 `docs/release/README.md`,推进状态留在 issues。 + +参考:[ADR 008](../../adr/008-documentation-ownership.md)、 +[Timeline 承诺的有限模型检查](../../design/examples/capability-models/README.md)、 +[Build environment](../../architecture/build.md)、 +[Terminal end-to-end suite](../../architecture/tui-e2e.md)、 +[#1938](https://github.com/arcships/dim/issues/1938)。 From 32d3d15a5104fa88dbd6132fde44a80efa99cb91 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 16:03:05 +0800 Subject: [PATCH 2/4] docs(adr): refine ADR 025 with three operational states and form-only doc checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Incorporate review feedback from #1940: - Frame D1 around three operational test states (Active gate, Retained on-demand/sweep, Dev/exploratory) with L0–L4 mapped onto them, keeping ADR freeze checks in L1, splitting L0 triggers into model-file changes and review checklists, scoping L2 to reverse-dependency closures, and distinguishing L4 execution from L4 harness self-checks. - Add D2 stating that documentation guides and carries semantic contracts while automated checks enforce deterministic form and structural invariants without business compilation or prose/literal guessing. - Reconcile D3 with AGENTS.md Testing (lowest flow or contract layer) and add a release-unreachability bound for runtime test injection. - Move numeric latency budgets out of the immutable ADR (D4) and require an active scheduled sweep with triage/bisection ownership before narrowing main pushes (D5). - Revert the AGENTS.md edit until ADR 025 is accepted. Refs #1938 --- AGENTS.md | 1 - docs/INDEX.md | 2 +- ...25-verification-tiers-and-ci-governance.md | 184 ++++++++++-------- docs/adr/README.md | 2 +- ...25-verification-tiers-and-ci-governance.md | 82 ++++---- 5 files changed, 152 insertions(+), 119 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e58cb555a8..2460a29789 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,7 +66,6 @@ Every public service is a data face. The contract is [service faces](docs/design ## Testing -- Follow [ADR 025](docs/adr/025-verification-tiers-and-ci-governance.md) for verification tiers (L0–L4, including when formal models run), test placement and CI governance. - Verify that the remaining necessary changes satisfy the user flow, reusing relevant tests first; after integration, check the interfaces and flows actually affected. Reuse evidence that still applies; only expand or repeat verification for new changes, failures or unresolved doubts. Progress is not measured by test count, failure count or number of runs. - Automated tests only protect architectural flows, public interfaces, cross-crate contracts, persistence formats, user flows and release artifacts. Assertions about private modules, helper functions, single functions, internal call order or mock configuration belong in the nearest flow test, not in standalone tests. - Scenarios involving security, data loss, data migration, protocol compatibility or release artifacts may keep a dedicated test if they cannot be triggered reliably in a flow test. diff --git a/docs/INDEX.md b/docs/INDEX.md index 59e935a8d1..f99be5b4ef 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -49,7 +49,7 @@ This index is navigation. Delivery status lives in issues, not here. - [Architecture decisions](adr/README.md) - [ADR 022 — Timeline 属性查询与正文重建](adr/022-event-property-queries.md)(中文):目标 API 与模块结构、属性查询、业务状态恢复和正文释放 - [ADR 023 — 上下文用量由独立分支部件维护](adr/023-context-usage.md)(中文):ContextUsage 的职责、增量统计、服务商校准及后续设计边界 -- [ADR 025 — Verification tiers, test coverage and CI governance](adr/025-verification-tiers-and-ci-governance.md)([中文](zh/adr/025-verification-tiers-and-ci-governance.md)):verification tiers (L0–L4, including formal models), test coverage discipline and CI governance rules (#1938) +- [ADR 025 — Verification tiers, test coverage and CI governance](adr/025-verification-tiers-and-ci-governance.md)([中文](zh/adr/025-verification-tiers-and-ci-governance.md)):three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance (#1938) - [Resume:按业务对象设计计算与读取](design/resume-read-design.md)(中文,草案):usage、输入队列、Prompt、显示详情、SQL 执行和恢复校验的分项设计与成本验收 - [当前状态字段索引](design/appserver/timeline-state-read-indexes.md)(中文,草案):现有API缺口、完整索引键、源位置前驱和SQL扫描验收 - [状态保存与恢复读取](design/owner-state-indexed-reads.md)(中文,草案):按业务对象决定持久化;当前队列点查、Prompt有效引用、Usage数字和真实流程读写数量 diff --git a/docs/adr/025-verification-tiers-and-ci-governance.md b/docs/adr/025-verification-tiers-and-ci-governance.md index a3608c9e34..62946d42a1 100644 --- a/docs/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/adr/025-verification-tiers-and-ci-governance.md @@ -4,127 +4,153 @@ Decision status: Proposed. ## Context -Repository verification tends to grow monotonically when every discovered defect or new check is -appended directly to the pull-request gate. Over time, two distinct concepts get conflated: +Repository verification grows monotonically when every discovered defect or new check is appended +directly to the pull-request gate. Over time, two distinct concepts get conflated: - **Repository verification coverage**: every check, formal model, suite, benchmark and acceptance procedure the repository maintains. -- **Pull-request gate execution**: the bounded subset that must complete synchronously before a - change merges. +- **Active pull-request gate**: the bounded subset that must complete synchronously before a change + merges. When those two are treated as identical, slow suites, cross-platform checks, compile-time rebuild -loops and pure static scans all pile onto one flat, serial gate. When execution approaches the job -limit, raising timeouts hides the degradation until queues, cache eviction and mutual cancellations -undermine both contributor turnaround and `main` signal quality. +loops and brittle text scans all pile onto one flat gate. Raising timeouts when jobs approach the +ceiling hides the degradation until queues, compiler-cache eviction and mutual cancellations erode +both contributor turnaround and `main` signal quality. ## Decision -### D1. Verification is tiered by change nature and feedback cycle +### D1. Verification separates into three operational states; tiers (L0–L4) map assets to states -Verification assets are assigned to five tiers according to what failure class they catch, what -triggers them and how fast they must answer: +Every verification asset has an explicit operational state that governs its lifecycle and CI cost: -| Tier | Question answered | Scope | Trigger | +1. **Active gate**: runs automatically on pull requests under explicit wall-clock budgets, guarding + high-frequency contracts and the affected dependency closure. +2. **Retained (on-demand & sweep)**: stays in the repository without gating ordinary pull requests. + Runs on scheduled full sweeps, before release, when diagnosing or reproducing a failure, or when + a design/protocol review calls for it. Retained Rust tests remain compiled (for example, + consolidated with `#[ignore]`) so they do not bitrot; external-toolchain checks (TLC/Java, + local tmux E2E, standalone profiling scripts) stay out of everyday build toolchains. +3. **Dev / exploratory**: temporary probes or fine-grained local tests created while developing or + debugging. Ablated before merge: enduring contract coverage moves into the active gate (D3), + reusable diagnostic reproducers move into Retained, and throwaway scaffolding is removed. + +Verification tiers (L0–L4) map each class of asset to its default operational state and trigger: + +| Tier | Question answered | Scope | Default state & trigger | | --- | --- | --- | --- | -| **L0 — Design & formal** | Do the state-machine, protocol and handover invariants hold in the abstract? | Formal models (e.g. TLA+ specifications and `.cfg` properties), ADR immutability checks | **Event-driven on design/contract change**: when a formal model, protocol/event contract, recovery boundary or handover invariant changes. Not run on ordinary implementation PRs. | -| **L1 — Static & contract** | Are formatting, dependency boundaries, public schemas/wire types, static source rules and license/advisory policies intact? | Formatters, linters, pure static repository scans, frontend typecheck/lint, wire/schema contracts, dependency advisory/license checks | **Every PR**, scoped to the changed surface (dependency scans only on manifest, lockfile or policy changes). Fast fail-first gate. | -| **L2 — Affected business flows** | Do the modified modules and their direct dependents preserve behavioral contracts? | Unit tests and in-process or loopback flow tests for the affected crates and their downstream consumers | **Every PR** on the primary high-throughput platform; expands to the full workspace only when shared foundational crates or workspace-wide configuration change. | -| **L3 — Real environment & cross-platform** | Do real OS primitives, process/plugin wiring, terminal interaction and external protocol boundaries work? | OS-native boundary slices, real daemon + plugin runtime flows, interactive terminal E2E suites, external registry acceptance | **Split by cost**: narrow OS-native boundary slices run on PRs that touch platform/client code; full cross-platform runs and external-registry checks run asynchronously on `main` or on a schedule; interactive terminal E2E runs locally on demand and before release. | -| **L4 — Quality, performance & release** | Have model quality, resource budgets, executable layout or distribution artifacts regressed? | Evaluation harnesses, memory/startup measurements, native code-layout builds, multi-platform release builds and registry/image acceptance | **Scheduled (nightly), manual dispatch or release train only**. Never gates an ordinary feature PR. | +| **L0 — Design & formal** | Do abstract state-machine, protocol and handover invariants hold? | Formal models (e.g. TLA+ specifications and `.cfg` properties) | **Retained**: (a) triggered on formal model file changes (with tool cost disclosed under D4 if wired into CI), and (b) enforced via PR checklist/review whenever an implementation change alters a modelled handover, recovery or ordering guarantee. Not run on ordinary implementation PRs. | +| **L1 — Static form & contract** | Are formatting, dependency boundaries, ADR immutability, public schemas/wire types and license/advisory policies intact? | Formatters, linters, pure static form/structure checks (including ADR freeze checks on every PR / ADR edit), frontend typecheck/lint, wire/schema contracts, dependency advisory/license scans | **Active gate**: fast fail-first on every PR, scoped to the changed surface (dependency scans only on manifest, lockfile or policy changes). | +| **L2 — Business flows** | Do modified modules and their transitive consumers preserve behavioral contracts? | Unit and in-process or loopback flow tests | **Active gate** on the primary high-throughput platform for the **reverse-dependency closure** of changed crates (expanding to the full workspace when foundational crates or workspace-wide configuration change). Heavy historical, soak or low-frequency flows belong in **Retained**. | +| **L3 — Real environment & cross-platform** | Do real OS primitives, process/plugin wiring, terminal interaction and external protocol boundaries work? | OS-native boundary slices, real daemon + plugin runtime flows, interactive terminal E2E suites, external registry acceptance | **Split**: narrow OS-native boundary slices run in the **Active gate** only on PRs touching platform/client code; full cross-platform runs, external-registry acceptance and interactive terminal E2E are **Retained** (asynchronous `main`/scheduled sweeps, pre-release or local on-demand). | +| **L4 — Quality, performance & release** | Have model quality, resource budgets, executable layout or distribution artifacts regressed? | Evaluation harnesses, memory/startup measurements, native code-layout builds, multi-platform release builds and registry/image acceptance | **Execution is always Retained** (scheduled, manual or release train only — never gates ordinary feature PRs). Changes to an L4 harness itself run the harness's own L1/L2 checks in the **Active gate** on that PR. | Formal models (L0) verify that an abstract state machine satisfies safety and conditional liveness invariants within a finite state space; they do not compile or test implementation code. Ordinary implementation changes rely on L2 flow tests to guard that code still refines the model's actions. If a code change alters a modelled handover or ordering guarantee, it is a design change and returns -to L0 before merging. +to L0 through review before merging. + +### D2. Documentation guides and states semantic contracts; automated checks enforce form, not prose semantics + +Documentation exists to guide contributors and state semantic contracts. Automated checks over +documentation and source conventions enforce only **deterministic, low-false-positive form and +structural invariants**: + +- **In scope for automated checks (L1, zero business compilation)**: lifecycle/immutability form + (such as accepted-ADR freeze checks), link and template structure, and deterministic + code-to-document structural projections (such as dependency graphs or service declarations) that + do not parse natural-language prose. +- **Out of scope for automated checks**: semantic correctness of prose, design quality, and + judgement calls such as whether an edit alters a modelled invariant. Avoid brittle cross-language + text scanners that try to infer semantics from raw literals and rely on growing manual + allowlists; enforce invariants through types, boundaries, review checklists, L0 models and L2 + behavioral tests instead. -### D2. Test coverage follows lowest-layer, single-owner and build-hygiene rules +### D3. Test coverage follows lowest flow/contract layer, single owner, release-safe injection and build hygiene Coverage quality is measured by contract protection per unit of cost, not by test count at the top layer. -- **Test at the lowest layer that proves the contract**: logic, state transitions, rendering rules, - validation errors and edge-case matrices belong in component, state-machine or in-process flow - tests — never in process-spawning, PTY or binary-copying E2E tests. End-to-end suites cover - wiring and real OS interaction on representative happy and failure paths rather than exhaustive - combinations. +- **Lowest flow or contract layer that proves the contract**: assertions about private modules, + helpers or single functions belong in the nearest flow or contract test rather than standalone + unit tests, while state transitions, rendering rules, validation errors and edge matrices stay + out of process-spawning, PTY or binary-copying E2E tests. End-to-end suites cover wiring and real + OS interaction on representative paths rather than exhaustive combinations. - **One owning layer per behavior**: once a lower layer (or a dedicated suite such as the local terminal E2E suite) proves a behavior, higher layers verify only connectivity and do not duplicate - its failure matrix. Migrating coverage to a better carrier requires retiring or disabling the - superseded CI case in the same change or tracked migration. -- **Inject testability at runtime boundaries instead of recompiling**: test variants (release - stamps, build IDs, clocks, endpoints, fault injection) must be configurable at the binary or test - boundary without flipping build-time environment variables that recompile upstream crates in CI. -- **Treat test executables as build artifacts**: organize integration tests into a bounded number - of balanced entry binaries per crate to avoid linker and compiler-cache amplification from - dozens of single-file test executables, while splitting oversized test binaries that create - single-process scheduling tails or linker pressure. - -### D3. CI gates operate under explicit budgets and light/heavy isolation - -- **Hard latency and resource budgets**: every synchronous tier maintains an explicit wall-clock - ceiling (target: L1 ≤ 2 min; PR end-to-end median ≤ 8 min, p90 ≤ 15 min; OS-native PR slice - ≤ 3 min). Approaching or hitting a timeout is a regression to fix by narrowing scope, optimizing - slow tests, improving parallelism or moving work to L3/L4 — **never** by raising job or target + its failure matrix. Migrating coverage to a better carrier requires retiring or demoting the + superseded active CI case in the same change or tracked migration. +- **Release-safe runtime injection instead of recompiling**: test variants (release stamps, build + IDs, clocks, endpoints, fault injection) must be injectable at runtime or test boundaries without + flipping build-time flags that recompile upstream crates in CI. **Production-safety bound**: every + test-only override must be unreachable in release builds (compiled only under debug/test builds) + or confined to test-harness entry points so test injection never widens what a shipped binary + accepts. +- **Treat test executables as build artifacts**: consolidate integration tests into a bounded number + of balanced entry binaries per crate to avoid linker and compiler-cache amplification from dozens + of single-file executables, while splitting oversized binaries that create single-process + scheduling tails or linker pressure. + +### D4. Active gates operate under recorded budgets and physical light/heavy isolation + +- **Recorded wall-clock and resource budgets**: every synchronous active-gate tier declares a + recorded latency and resource budget (maintained alongside runner measurements in + `docs/architecture/build.md` and tracking issues, not hardcoded as immutable constants in this + ADR). Approaching or hitting a budget is a regression fixed by narrowing scope, optimizing slow + tests, improving parallelism or demoting cases to Retained — **never** by raising job or target timeouts alone. - **Cost disclosure for gate additions**: any change that adds a required PR check or widens path selection must state its incremental runtime, added compile dependencies and target runner pool. -- **Physical isolation of light checks from heavy builds**: pure static repository checks (boundary, - link, literal, packaging metadata) must not depend on compiling business runtime crates. Docs, - frontend, script and static checks run in lightweight jobs and never contend for heavy build or - scarce platform runner pools. - -### D4. Impact-scoped routing is the default, backed by scheduled full sweeps - -- **Consistent routing on PRs and `main`**: both pull requests and pushes to `main` select only the - groups their changed paths affect. `main` pushes run to completion without cancelling earlier - `main` pushes, so every merged commit produces an honest pass/fail signal without non-code or - frontend merges starving backend runners. -- **Scheduled full sweeps cover cross-cutting drift**: periodic scheduled runs (and release-train - verification) execute the full cross-platform and cross-workspace matrix so implicit coupling - cannot accumulate unnoticed. +- **Physical isolation of light checks from heavy builds**: pure static repository checks must not + depend on compiling business runtime crates. Docs, frontend, script and static checks run in + lightweight jobs and never contend for heavy build or scarce platform runner pools. + +### D5. Impact-scoped routing and platform minimalism require scheduled full sweeps and periodic pruning + +- **Impact-scoped routing with sweep prerequisite**: both pull requests and pushes to `main` route + by changed paths, and `main` pushes run to completion without cancelling earlier ones. Narrowing + `main` pushes is permitted **only while an active scheduled full sweep is running** to catch + cross-group drift; a sweep failure must have defined triage ownership and commit-range bisection + back to the regressing merge on `main`. - **Explicit path classification**: new top-level repository directories and non-code assets must be classified explicitly in the change router rather than silently falling through to the most expensive full-workspace fallback. - -### D5. Scarce platform pools verify platform-native boundaries only - -- **Primary platform for platform-neutral work**: full workspace compilation and platform-neutral - L1/L2 verification run on the highest-throughput, lowest-queue runner pool (Linux). -- **Minimal, mechanically checked secondary OS slices**: scarce OS pools (macOS, Windows) run only - checks that exercise platform-specific code paths (`cfg(target_os = ...)`), native OS APIs or - target packaging boundaries on pull requests. The platform-native selection is verified against - the source rather than maintained as an unchecked manual list. +- **Scarce platforms run platform-native boundaries only**: full workspace compilation and + platform-neutral L1/L2 verification run on the highest-throughput primary platform (Linux). + Secondary OS pools (macOS, Windows) run only checks covering platform-specific code paths + (`cfg(target_os = ...)`), native OS APIs or packaging boundaries on pull requests, verified + mechanically against the source rather than maintained as an unchecked manual list. - **Periodic telemetry and pruning**: CI health (queue p90, execution p90, cache write/eviction volume, slowest test targets, zero-match dead steps and cancellation waste) is reviewed - periodically to retire obsolete checks and trim new long tails. + periodically to retire obsolete checks and demote emerging long tails to Retained. ## Consequences -- Adding a new test, static scan or formal model requires declaring its tier (L0–L4) and owner - before wiring it into CI. -- Pure static checks are decoupled from workspace-coupled tooling so frontend, docs and script - changes stay fast. -- Build-time flags that vary only for testing are replaced by boundary/runtime injection so CI - never triggers cascading crate recompiles. -- Test binary layout and cache footprint become reviewable engineering concerns alongside runtime - code. -- Concrete workflow changes, runner migrations, test-binary consolidation and slow-test cleanups - are tracked in separate implementation issues rather than here. +- Every new test, static check or formal model declares its operational state (Active / Retained / + Dev), tier (L0–L4) and owner before wiring into CI. +- Once accepted, `AGENTS.md` (`## Testing`) can consolidate its testing rules onto this ADR so the + rule is stated once; until accepted, `AGENTS.md` keeps the current operational commands unchanged. +- Pure static form checks are decoupled from workspace-coupled tooling so docs, frontend and script + PRs stay fast. +- Test-only build flags move to release-unreachable runtime/harness injection, eliminating + cascading CI recompiles without weakening production boundaries. +- Concrete workflow changes, runner migrations, scheduled sweeps, test-binary consolidation and + numeric budgets live in `docs/architecture/build.md`, `docs/release/README.md` and tracking + issues rather than here. ## Non-goals - Lowering overall defect detection or deleting coverage without an owning replacement at a more - appropriate tier. -- Prescribing specific CI vendor syntax, runner hostnames or crate-by-crate path tables (those live - in workflow files, architecture guides and issues). -- Replacing code review or design review with automated checks. + appropriate layer or operational state. +- Freezing numeric latency targets, runner hostnames, workflow syntax or crate-by-crate routing + tables in an immutable ADR. +- Replacing design review or code review with automated checks. ## Supersession Does not supersede any prior ADR. Extends [ADR 008](008-documentation-ownership.md) by separating -verification policy rules (here) from current CI implementation details (`docs/architecture/build.md`, -`docs/release/README.md`) and delivery status (issues). +verification and CI governance principles (here) from numeric budgets and current CI implementation +(`docs/architecture/build.md`, `docs/release/README.md`) and delivery status (issues). References: [ADR 008](008-documentation-ownership.md), [Timeline finite model checking](../design/examples/capability-models/README.md), diff --git a/docs/adr/README.md b/docs/adr/README.md index 13b66870e2..8c01f95881 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -32,7 +32,7 @@ original text. | [022 — Timeline 属性查询与正文重建](022-event-property-queries.md) | Proposed | Supersedes 019's event-only results, skip-based paging and start-only positions, and 020's single-predicate limit; retains 021's read ownership | | [023 — 上下文用量由独立分支部件维护](023-context-usage.md) | Accepted | Follows 021 and 022; separates context usage statistics from request preparation | | [024 — Web 抓取层使用请求库,地址策略在请求之前执行](024-web-fetch-transport.md) | Proposed | Follows 006 D1; replaces the hand-written transport and narrows the address policy to a pre-request check | -| [025 — Verification tiers, test coverage and CI governance](025-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; separates verification tiers (L0–L4), test placement and CI governance rules | +| [025 — Verification tiers, test coverage and CI governance](025-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; defines three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance | Source baseline: [initial foundation parent](https://github.com/arcships/dim/commit/aaaffa5768e031d781abb73e45b1915b05dc2aa0). This baseline includes lifecycle fixes not necessarily present on the default branch. diff --git a/docs/zh/adr/025-verification-tiers-and-ci-governance.md b/docs/zh/adr/025-verification-tiers-and-ci-governance.md index 5f60944ffe..3dc2bd218f 100644 --- a/docs/zh/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/zh/adr/025-verification-tiers-and-ci-governance.md @@ -7,70 +7,78 @@ 每当主干出现回归或新增一种检查手段,如果习惯性地把它直接挂进 PR 必跑门禁,仓库的验证体系就会单调膨胀。时间一长,两个本应分开的概念会被混为一谈: - **仓库的验证覆盖面**:仓库维护的全部检查、形式化模型、测试套件、基准评估与发布验收手段。 -- **PR 门禁的执行面**:每次合入前必须同步跑完的有界子集。 +- **活跃 PR 门禁**:每次合入前必须同步跑完的有界子集。 -一旦把两者画上等号,慢速集成测试、跨平台检查、为测试而触发的重复编译以及纯静态扫描就会全部堆在同一条串行门禁里。耗时逼近上限时,如果只靠不断调大超时时间来兜底,真正的问题会被掩盖,最终演变为长队列等待、编译缓存写爆淘汰、任务相互取消,反过来同时伤害开发反馈速度与 `main` 主干信号质量。 +一旦把两者画上等号,慢速集成测试、跨平台检查、为测试而触发的重复编译以及脆弱的文本扫描就会全部堆在同一条门禁里。耗时逼近上限时,靠调大超时阈值只会掩盖退化,最终演变为长队列等待、编译缓存写爆淘汰、任务相互取消,反过来同时伤害开发反馈速度与 `main` 主干信号质量。 ## 决策 -### D1. 按变动性质与反馈周期将验证分为五层(L0–L4) +### D1. 测试按执行角色分为三态,验证分层(L0–L4)映射到对应状态 -所有验证资产按「守卫的问题类型、触发条件、预期反馈周期」归入五层,各司其职,不再平铺混跑: +每项验证资产必须明确其执行态,以决定生命周期与 CI 成本归属: -| 层级 | 守卫的核心问题 | 范围 | 触发时机 | +1. **活跃门禁(Active Gate)**:PR 每次自动运行并受明确耗时预算约束,守卫高频契约与受影响依赖闭包。 +2. **保留按需(Retained / On-demand & Sweep)**:保留在仓库中,**不阻塞日常 PR**;在定时全量扫、发版前、排障复现或设计/协议评审要求时拉起。保留的 Rust 测试继续参与编译检查(例如聚合后标注 `#[ignore]`)以防编译腐烂;依赖外部工具链的检查(TLC/Java、本地 tmux E2E、独立性能脚本)不绑入日常构建链。 +3. **开发调试(Dev / Exploratory)**:开发或排障期间编写的临时探针与细粒度局部测试。合入前必须消融:具持久契约价值的进入活跃门禁(D3),具长期复现诊断价值的转为保留按需,其余随分支清理,不入主干长期背债。 + +五层验证资产(L0–L4)的默认执行态与触发方式如下: + +| 层级 | 守卫的核心问题 | 范围 | 默认执行态与触发方式 | | --- | --- | --- | --- | -| **L0 — 设计与形式化层** | 抽象状态机、协议与交接不变量本身是否存在反例? | 形式化模型(如 TLA+ 规约及 `.cfg` 性质)、ADR 不可变检查 | **仅设计/契约变动时触发**:当形式化模型、协议/事件契约、恢复边界或交接不变量变更时运行;普通实现 PR **不跑**。 | -| **L1 — 静态与契约层** | 格式、依赖边界、公开 schema / wire 类型、静态源码规则及依赖合规是否破坏? | 格式化、Lint、纯静态仓库扫描、前端类型检查/Lint、wire/schema 契约、依赖漏洞与许可证扫描 | **每次 PR 按改动面精准触发**(依赖合规仅在 manifest、lockfile 或策略文件变更时跑),作为最快失败门禁。 | -| **L2 — 影响面业务流层** | 改动模块及其直接下游的业务行为契约是否保持正确? | 受影响 crate 及直接下游的单元测试、进程内或 loopback 流程测试 | **每次 PR 在主力高吞吐平台运行**;仅在公共底层 crate 或全局构建配置改动时扩大至全 workspace。 | -| **L3 — 真实环境与跨平台层** | 真实 OS 原语、真实进程/插件接线、终端交互与外部协议边界是否正常? | 平台专属边界窄集、真实 daemon + 插件运行时流、交互式终端 E2E、外部注册表验收 | **按成本拆分**:仅触及平台/客户端代码时在 PR 跑对应的 OS 专属窄集;全量跨平台与外部注册表检查在 `main` 异步或定时运行;交互式终端 E2E 在本地按需及发版前运行。 | -| **L4 — 效果、性能与发布层** | 模型效果、资源预算、可执行文件布局或分发包是否退化? | 评测套件(eval)、内存/启动测量、原生代码布局构建、多平台发布包构建与注册表/镜像验收 | **仅定时(Nightly)、手动触发或发版流程运行**,绝不阻塞普通功能 PR。 | +| **L0 — 设计与形式化层** | 抽象状态机、协议与交接不变量本身是否存在反例? | 形式化模型(如 TLA+ 规约及 `.cfg` 性质) | **保留按需**:(a) 修改形式化模型文件时触发(若接入 CI 须按 D4 披露工具链成本);(b) 当实现改动影响已建模的交接、恢复或先后序承诺时,通过 PR 清单与评审强制触发。普通实现 PR **不跑**。 | +| **L1 — 静态形式与契约层** | 格式、依赖边界、ADR 不可变形式、公开 schema / wire 类型及依赖合规是否破坏? | 格式化、Lint、纯静态形式/结构检查(含每个 PR / ADR 变动必跑的 ADR 冻结检查)、前端类型检查/Lint、wire/schema 契约、依赖漏洞与许可证扫描 | **活跃门禁**:每个 PR 最快失败门禁,按改动面精准触发(依赖合规仅在 manifest、lockfile 或策略文件变更时跑)。 | +| **L2 — 业务流层** | 改动模块及其传递下游的业务行为契约是否保持正确? | 单元测试与进程内或 loopback 流程测试 | **活跃门禁**:在主力高吞吐平台运行改动 crate 的**反向依赖闭包**(公共底层 crate 或全局构建配置改动时扩大至全 workspace)。重型历史、长时压测或低频流程归入**保留按需**。 | +| **L3 — 真实环境与跨平台层** | 真实 OS 原语、真实进程/插件接线、终端交互与外部协议边界是否正常? | 平台专属边界窄集、真实 daemon + 插件运行时流、交互式终端 E2E、外部注册表验收 | **拆档**:仅触及平台/客户端代码时,极窄的 OS 专属原语边界进**活跃门禁**;全量跨平台、外部注册表验收与交互式终端 E2E 归**保留按需**(`main` 异步/定时扫、发版前或本地按需)。 | +| **L4 — 效果、性能与发布层** | 模型效果、资源预算、可执行文件布局或分发包是否退化? | 评测套件(eval)、内存/启动测量、原生代码布局构建、多平台发布包构建与注册表/镜像验收 | **执行始终归保留按需**(仅定时、手动或发版流程,绝不阻塞普通功能 PR);修改 L4 工具链自身时,该工具自身的 L1/L2 自检作为**活跃门禁**在其 PR 上运行。 | -形式化模型(L0)验证的是「抽象状态机在有限状态空间内满足安全性与条件活性」,不是代码编译检查。普通代码改动依靠 L2 流程测试守住「实现依然精化模型动作」。如果某次实现修改破坏了模型假设的交接或先后序承诺,它本质上属于设计变更,必须回到 L0 更新并重跑模型后再合入。 +形式化模型(L0)验证的是「抽象状态机在有限状态空间内满足安全性与条件活性」,不是代码编译检查。普通代码改动依靠 L2 流程测试守住「实现依然精化模型动作」;若实现改动改变了模型假设的交接或先后序承诺,本质上属于设计变更,须通过评审回到 L0 更新并重跑模型后再合入。 -### D2. 测试覆盖遵循「最低层证明、单一归属、运行期注入、产物治理」四条规则 +### D2. 文档承担引导与语义约束;自动化检查只控形式与结构边界,不控内容语义 -测试质量取决于单位成本下对契约的保护力,而不是在最高层堆积用例数量: +文档的职责是引导贡献者并陈述语义契约。针对文档和源码约定的自动化检查只应约束**确定性、低误报的形式与结构不变量**: -- **最低层证明原则**:纯逻辑、状态转换、渲染规则、参数校验与错误分支矩阵必须下沉到组件、状态机或进程内流程测试,禁止写成起真实进程、PTY 或拷贝二进制的端到端测试。E2E 套件只覆盖跨进程接线与真实 OS 交互的代表性路径,不做排列组合穷举。 -- **单一归属原则**:同一行为只在一个最合适的层级做完整覆盖,上层仅验证链路接通,不重复下层的异常矩阵。当行为迁移到更合适的载体(例如组件测试或本地终端 E2E 套件)后,必须在同一改动或对应迁移任务中同步退役旧 CI 用例。 -- **运行期边界注入替代重编译**:测试所需的构建态差异(如 release 标记、build ID、时钟、外部端点、故障注入)应在二进制或测试边界支持运行期注入,禁止为了测试几个分支而切换编译环境变量、迫使 CI 重编上游依赖图。 -- **把测试二进制当作工程产物治理**:按 crate 将集成测试聚合为少量均衡的入口二进制,避免大量单文件测试可执行文件重复全图链接、写爆编译缓存;同时对过大的单一测试二进制做均衡拆分,避免形成单进程调度长尾或链接器压力。 +- **允许自动化检查(L1,零业务编译)**:生命周期与不可变形式(如已接受 ADR 冻结检查)、链接与模板结构完整性,以及不解析自然语言散文的确定性「代码到文档」结构投影(如依赖图、服务声明表)。 +- **不以自动化测试强控**:文档散文的语义正确性、设计优劣,以及“某次实现改动是否触及已建模不变量”这类语义判断。避免新增试图从源码字面量推断语义、依赖不断膨胀的人工白名单维系的跨语言文本扫描;语义约束通过类型系统、模块边界、评审清单、L0 模型与 L2 行为测试保障。 -### D3. CI 门禁实行硬预算制与轻重物理隔离 +### D3. 测试覆盖遵循最低流程/契约层、单一归属、生产不可达注入与产物治理 + +测试质量取决于单位成本下对契约的保护力,而不是在最高层堆积用例数量: -- **明确耗时与资源预算**:每个同步门禁层设定清晰上限(目标:L1 ≤ 2 分钟;PR 端到端中位 ≤ 8 分钟、p90 ≤ 15 分钟;OS 专属 PR 窄集 ≤ 3 分钟)。逼近或触发超时视为需要修复的工程退化,必须通过收敛范围、优化慢测、提升并行度或调整分层来压回预算内,**禁止**以单纯调大超时阈值作为解决方案。 -- **门禁增量成本显式化**:任何向 PR 必跑门禁新增检查或扩大路径匹配规则的变更,必须写明增量耗时、新增编译依赖及落入的 runner 池。 -- **轻量静态检查与重型构建物理隔离**:纯静态仓库检查(依赖边界、链接、字面量、打包元数据等)不得依赖编译业务运行时 crate。文档、前端、脚本与纯静态检查运行在轻量作业中,不得抢占重型编译或稀缺平台 runner 池。 +- **能证明契约的最低流程层或契约层**:关于私有模块、helper 或单个函数的断言应落在最近的流程测试或契约测试中,不鼓励为内部实现写孤立单测;同时状态转换、渲染规则、参数校验与错误矩阵不得写成起真实进程、PTY 或拷贝二进制的端到端测试。E2E 只覆盖代表性接线与真实 OS 交互路径,不做排列组合穷举。 +- **单一归属原则**:下层(或专用套件,如本地终端 E2E)已证明的行为,上层仅验证链路接通,不重复异常矩阵。覆盖迁移到更合适的载体后,须在同一改动或对应迁移任务中同步退役或降级原活跃 CI 用例。 +- **生产安全的运行期注入替代重编译**:测试态差异(release 标记、build ID、时钟、端点、故障注入)应在运行期或测试边界注入,避免通过切换编译期环境变量迫使 CI 级联重编上游 crate。**生产安全红线**:所有仅用于测试的覆写入口**在 release 构建中必须不可达**(仅在 debug/test 构建编译),或严格限定在测试夹具入口内,绝不扩大生产二进制可接受的外部输入面。 +- **把测试二进制当作工程产物治理**:按 crate 将集成测试聚合为少量均衡的入口二进制,避免大量单文件测试可执行文件重复全图链接、放大编译缓存写盘体积;同时拆分过大的单一测试二进制,消除单进程调度长尾与链接器压力。 -### D4. 默认按影响面路由,由定时全量兜底 +### D4. 活跃门禁实行有记录预算制与轻重物理隔离 -- **PR 与 `main` 保持一致的影响面路由**:PR 与 `main` 推送均只运行受改动路径影响的检查组。`main` 推送各自独立跑完、不相互取消,既保证每次合入都有真实的绿/红结果,又避免前端或非后端合入拖垮后端 runner。 -- **定时全量兜底跨模块隐式耦合**:通过周期性定时运行(Nightly)及发版前全量门禁覆盖全 workspace 与全平台矩阵,防止跨模块隐式依赖退化漏网。 -- **显式路径分类**:新增顶层目录或非代码资产时,必须在路径路由规则中显式归类,不得静默落入最昂贵的全量兜底组。 +- **有记录的耗时与资源预算**:每个同步活跃门禁层声明明确的耗时与资源预算(随 runner 实测数据记录在 `docs/architecture/build.md` 与追踪 issue 中,不在不可变 ADR 内写死具体分钟数)。逼近或触发预算上限视为退化,须通过收敛范围、优化慢测、提升并行度或降级到保留按需来压回预算,**禁止**以单纯调大作业或单目标超时作为解决方案。 +- **门禁增量成本显式化**:任何向 PR 必跑门禁新增检查或扩大路径匹配规则的变更,必须写明增量耗时、新增编译依赖与目标 runner 池。 +- **轻量检查与重型构建物理隔离**:纯静态仓库检查不得依赖编译业务运行时 crate。文档、前端、脚本与静态检查运行在轻量作业中,不得抢占重型编译或稀缺平台 runner 池。 -### D5. 稀缺平台仅验证平台专属边界,且定期度量和做减法 +### D5. 影响面路由与稀缺平台最小化,以定时全量扫和周期减法为前提 -- **平台无关验证集中在主力高吞吐平台**:全量编译及平台无关的 L1/L2 验证集中在高并发、低排队的单一主平台(Linux)执行。 -- **稀缺平台窄集且由代码核对**:稀缺 OS runner 池(macOS、Windows)在 PR 阶段仅运行触及平台专属代码路径(`cfg(target_os = ...)`)、原生 OS API 或目标打包边界的检查;专属清单应通过代码属性或静态检查核对,不依赖易漂移的人工白名单。 -- **周期性可观测与减法维护**:定期复盘 CI 指标(排队 p90、执行 p90、缓存写入/淘汰体积、Top 最慢测试目标、0 匹配死步骤与取消浪费率),持续淘汰过时检查并治理新增慢测长尾。 +- **影响面路由与全量扫前置条件**:PR 与 `main` 推送均按改动路径选择检查组,且 `main` 推送各自独立跑完、不相互取消。**只有在定时全量扫已上线运行时,才允许收窄 `main` 推送**,以兜底跨组隐式耦合;全量扫失败须有明确的分诊归属与针对区间合并提交的二分定位流程。 +- **显式路径分类**:新增顶层目录或非代码资产时,必须在路径路由器中显式归类,不得静默落入最昂贵的全量兜底组。 +- **稀缺平台仅验证平台专属边界**:全量编译与平台无关的 L1/L2 验证集中在高吞吐主力平台(Linux)。稀缺 OS 池(macOS、Windows)在 PR 阶段仅运行触及平台专属代码路径(`cfg(target_os = ...)`)、原生 OS API 或目标打包边界的检查,且专属清单应由源码机制核对,不依赖易漂移的人工白名单。 +- **周期性可观测与减法维护**:定期复盘 CI 指标(排队 p90、执行 p90、缓存写入/淘汰体积、最慢测试目标、0 匹配死步骤与取消浪费率),持续淘汰过时检查并将新长尾降级至保留按需。 ## 影响 -- 新增测试、静态扫描或形式化模型时,需先明确其所属层级(L0–L4)与归属,再决定是否接入 PR 门禁。 -- 纯静态检查将与依赖全后端的研发工具解耦,保持文档、前端与脚本类 PR 的秒级/分钟级反馈。 -- 仅服务于测试的编译期开关将改为边界/运行期注入,消除 CI 中的级联重编。 -- 测试二进制形态与编译缓存体积成为与业务代码同等重要的工程审查对象。 -- 具体的 workflow 调整、runner 迁移、测试二进制合并与慢测治理分别在独立实现 issue 中跟踪,不写入本 ADR。 +- 新增测试、静态检查或形式化模型接入 CI 前,须先明确其执行态(活跃/保留/调试)、层级(L0–L4)与归属。 +- 本 ADR 被正式接受后,可将 `AGENTS.md`(`## Testing`)的测试规则统一收口指向本决策以避免重复;接受前 `AGENTS.md` 保持现行操作命令不变。 +- 纯静态形式检查与依赖全后端的研发工具解耦,保持文档、前端与脚本 PR 的快速反馈。 +- 仅服务于测试的编译期开关改为生产不可达的运行期/夹具注入,消除级联重编且不放松生产安全边界。 +- 具体 workflow 调整、runner 迁移、定时全量扫、测试二进制聚合与具体预算数值均落在 `docs/architecture/build.md`、`docs/release/README.md` 与追踪 issue 中。 ## 非目标 -- 降低仓库整体缺陷检出能力,或在没有合适层级替代覆盖的情况下删除测试。 -- 规定具体的 CI 平台语法、runner 主机名或逐 crate 路径表(这些属于 workflow 文件、架构文档与 issue 范畴)。 +- 降低仓库整体缺陷检出能力,或在没有合适层级或执行态替代覆盖的情况下删除测试。 +- 在不可变 ADR 中写死具体分钟数阈值、runner 主机名、workflow 语法或逐 crate 路由表。 - 用自动化检查替代设计评审与代码审查。 ## 替代关系 -不替代任何既有 ADR。本决策承接 [ADR 008](../../adr/008-documentation-ownership.md) 的分层边界:本文件仅定义验证与 CI 治理原则,当前 CI 实现细节留在 `docs/architecture/build.md` 与 `docs/release/README.md`,推进状态留在 issues。 +不替代任何既有 ADR。本决策承接 [ADR 008](../../adr/008-documentation-ownership.md) 的分层边界:本文件仅定义验证与 CI 治理原则,预算数值与当前 CI 实现留在 `docs/architecture/build.md` 与 `docs/release/README.md`,推进状态留在 issues。 参考:[ADR 008](../../adr/008-documentation-ownership.md)、 [Timeline 承诺的有限模型检查](../../design/examples/capability-models/README.md)、 From e2a5a2c36928b1849f9c38d9c6076e1573f08661 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 16:08:29 +0800 Subject: [PATCH 3/4] docs(adr): add generated-snapshot restraint rule to ADR 025 D2 Clarify under D2 that generated files are committed and freshness-checked only when downstream code consumes them or when they serve as concise, actively referenced public summaries; fine-grained internal graphs used for boundary enforcement are verified live in memory and generated on demand instead of committed to Git. Refs #1938 --- docs/adr/025-verification-tiers-and-ci-governance.md | 9 +++++++-- docs/zh/adr/025-verification-tiers-and-ci-governance.md | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/adr/025-verification-tiers-and-ci-governance.md b/docs/adr/025-verification-tiers-and-ci-governance.md index 62946d42a1..2e0ee9eef7 100644 --- a/docs/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/adr/025-verification-tiers-and-ci-governance.md @@ -58,8 +58,13 @@ structural invariants**: - **In scope for automated checks (L1, zero business compilation)**: lifecycle/immutability form (such as accepted-ADR freeze checks), link and template structure, and deterministic - code-to-document structural projections (such as dependency graphs or service declarations) that - do not parse natural-language prose. + code-to-document structural projections (such as public service catalogs or crate-level overviews) + that do not parse natural-language prose. +- **Keep generated snapshots minimal**: commit and freshness-check a generated file only when + downstream code consumes it (e.g. cross-language type declarations) or when it is a concise, + actively referenced public summary. Fine-grained internal dependency graphs computed for boundary + checks are verified live in memory and generated on demand rather than committed to Git as + conflict-prone snapshots. - **Out of scope for automated checks**: semantic correctness of prose, design quality, and judgement calls such as whether an edit alters a modelled invariant. Avoid brittle cross-language text scanners that try to infer semantics from raw literals and rely on growing manual diff --git a/docs/zh/adr/025-verification-tiers-and-ci-governance.md b/docs/zh/adr/025-verification-tiers-and-ci-governance.md index 3dc2bd218f..c3ed31e820 100644 --- a/docs/zh/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/zh/adr/025-verification-tiers-and-ci-governance.md @@ -37,7 +37,8 @@ 文档的职责是引导贡献者并陈述语义契约。针对文档和源码约定的自动化检查只应约束**确定性、低误报的形式与结构不变量**: -- **允许自动化检查(L1,零业务编译)**:生命周期与不可变形式(如已接受 ADR 冻结检查)、链接与模板结构完整性,以及不解析自然语言散文的确定性「代码到文档」结构投影(如依赖图、服务声明表)。 +- **允许自动化检查(L1,零业务编译)**:生命周期与不可变形式(如已接受 ADR 冻结检查)、链接与模板结构完整性,以及不解析自然语言散文的确定性「代码到文档」结构投影(如公开服务目录或 crate 级总览)。 +- **克制入库自动生成文件**:只有当生成文件被下游代码直接消费(如跨语言类型声明),或是精简且被文档实际引用的公开摘要时,才应提交进 Git 并做过期校验;纯用于依赖边界校验的细粒度内部图谱应在内存中实时检查、本地按需生成,不提交进 Git 制造合并冲突。 - **不以自动化测试强控**:文档散文的语义正确性、设计优劣,以及“某次实现改动是否触及已建模不变量”这类语义判断。避免新增试图从源码字面量推断语义、依赖不断膨胀的人工白名单维系的跨语言文本扫描;语义约束通过类型系统、模块边界、评审清单、L0 模型与 L2 行为测试保障。 ### D3. 测试覆盖遵循最低流程/契约层、单一归属、生产不可达注入与产物治理 From e417fb7501620d6910319e1c44b38ad846118d5e Mon Sep 17 00:00:00 2001 From: eric8810 Date: Fri, 20 Nov 2026 16:45:04 +0800 Subject: [PATCH 4/4] docs(adr): renumber to ADR 026 and resolve second-round review findings Address all findings from PR #1940 review: - Renumber from ADR 025 to ADR 026 across English/Chinese ADRs and indexes so PR #1941 retains 025 without collision. - Split D2 automated checks into pure static L1 checks (zero business compilation) and runtime-assembled structural projections (workspace- coupled alongside L2), and scope the literal-scanner rule to introducing new scanners. - Mark interactive terminal E2E in L3 as Retained (local-only), run locally on demand or before release and never invoked by CI workflows. - Add asset-file edits (such as formal model changes) to D1's Retained definition and state that the tier table trigger column is authoritative. - Clarify in Consequences that AGENTS.md and docs/architecture/ remain authoritative for current commands and committed snapshots until this ADR is accepted and follow-up tooling changes land. Refs #1938 --- docs/INDEX.md | 2 +- ...6-verification-tiers-and-ci-governance.md} | 45 +++++++++++-------- docs/adr/README.md | 2 +- ...6-verification-tiers-and-ci-governance.md} | 17 +++---- 4 files changed, 38 insertions(+), 28 deletions(-) rename docs/adr/{025-verification-tiers-and-ci-governance.md => 026-verification-tiers-and-ci-governance.md} (78%) rename docs/zh/adr/{025-verification-tiers-and-ci-governance.md => 026-verification-tiers-and-ci-governance.md} (80%) diff --git a/docs/INDEX.md b/docs/INDEX.md index f99be5b4ef..9c4a23473a 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -49,7 +49,7 @@ This index is navigation. Delivery status lives in issues, not here. - [Architecture decisions](adr/README.md) - [ADR 022 — Timeline 属性查询与正文重建](adr/022-event-property-queries.md)(中文):目标 API 与模块结构、属性查询、业务状态恢复和正文释放 - [ADR 023 — 上下文用量由独立分支部件维护](adr/023-context-usage.md)(中文):ContextUsage 的职责、增量统计、服务商校准及后续设计边界 -- [ADR 025 — Verification tiers, test coverage and CI governance](adr/025-verification-tiers-and-ci-governance.md)([中文](zh/adr/025-verification-tiers-and-ci-governance.md)):three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance (#1938) +- [ADR 026 — Verification tiers, test coverage and CI governance](adr/026-verification-tiers-and-ci-governance.md)([中文](zh/adr/026-verification-tiers-and-ci-governance.md)):three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance (#1938) - [Resume:按业务对象设计计算与读取](design/resume-read-design.md)(中文,草案):usage、输入队列、Prompt、显示详情、SQL 执行和恢复校验的分项设计与成本验收 - [当前状态字段索引](design/appserver/timeline-state-read-indexes.md)(中文,草案):现有API缺口、完整索引键、源位置前驱和SQL扫描验收 - [状态保存与恢复读取](design/owner-state-indexed-reads.md)(中文,草案):按业务对象决定持久化;当前队列点查、Prompt有效引用、Usage数字和真实流程读写数量 diff --git a/docs/adr/025-verification-tiers-and-ci-governance.md b/docs/adr/026-verification-tiers-and-ci-governance.md similarity index 78% rename from docs/adr/025-verification-tiers-and-ci-governance.md rename to docs/adr/026-verification-tiers-and-ci-governance.md index 2e0ee9eef7..4dbafa4b4f 100644 --- a/docs/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/adr/026-verification-tiers-and-ci-governance.md @@ -1,4 +1,4 @@ -# 025: Verification tiers, test coverage and CI governance +# 026: Verification tiers, test coverage and CI governance Decision status: Proposed. @@ -26,10 +26,12 @@ Every verification asset has an explicit operational state that governs its life 1. **Active gate**: runs automatically on pull requests under explicit wall-clock budgets, guarding high-frequency contracts and the affected dependency closure. 2. **Retained (on-demand & sweep)**: stays in the repository without gating ordinary pull requests. - Runs on scheduled full sweeps, before release, when diagnosing or reproducing a failure, or when - a design/protocol review calls for it. Retained Rust tests remain compiled (for example, - consolidated with `#[ignore]`) so they do not bitrot; external-toolchain checks (TLC/Java, - local tmux E2E, standalone profiling scripts) stay out of everyday build toolchains. + Runs when the asset's own source files change (for example, formal model edits), on scheduled + full sweeps, before release, when diagnosing or reproducing a failure, or when a design/protocol + review calls for it — with the tier table's "Default state & trigger" column authoritative for + each tier. Retained Rust tests remain compiled (for example, consolidated with `#[ignore]`) so + they do not bitrot; external-toolchain checks (TLC/Java, local tmux E2E, standalone profiling + scripts) stay out of everyday build toolchains. 3. **Dev / exploratory**: temporary probes or fine-grained local tests created while developing or debugging. Ablated before merge: enduring contract coverage moves into the active gate (D3), reusable diagnostic reproducers move into Retained, and throwaway scaffolding is removed. @@ -39,9 +41,9 @@ Verification tiers (L0–L4) map each class of asset to its default operational | Tier | Question answered | Scope | Default state & trigger | | --- | --- | --- | --- | | **L0 — Design & formal** | Do abstract state-machine, protocol and handover invariants hold? | Formal models (e.g. TLA+ specifications and `.cfg` properties) | **Retained**: (a) triggered on formal model file changes (with tool cost disclosed under D4 if wired into CI), and (b) enforced via PR checklist/review whenever an implementation change alters a modelled handover, recovery or ordering guarantee. Not run on ordinary implementation PRs. | -| **L1 — Static form & contract** | Are formatting, dependency boundaries, ADR immutability, public schemas/wire types and license/advisory policies intact? | Formatters, linters, pure static form/structure checks (including ADR freeze checks on every PR / ADR edit), frontend typecheck/lint, wire/schema contracts, dependency advisory/license scans | **Active gate**: fast fail-first on every PR, scoped to the changed surface (dependency scans only on manifest, lockfile or policy changes). | -| **L2 — Business flows** | Do modified modules and their transitive consumers preserve behavioral contracts? | Unit and in-process or loopback flow tests | **Active gate** on the primary high-throughput platform for the **reverse-dependency closure** of changed crates (expanding to the full workspace when foundational crates or workspace-wide configuration change). Heavy historical, soak or low-frequency flows belong in **Retained**. | -| **L3 — Real environment & cross-platform** | Do real OS primitives, process/plugin wiring, terminal interaction and external protocol boundaries work? | OS-native boundary slices, real daemon + plugin runtime flows, interactive terminal E2E suites, external registry acceptance | **Split**: narrow OS-native boundary slices run in the **Active gate** only on PRs touching platform/client code; full cross-platform runs, external-registry acceptance and interactive terminal E2E are **Retained** (asynchronous `main`/scheduled sweeps, pre-release or local on-demand). | +| **L1 — Static form & contract** | Are formatting, dependency boundaries, ADR immutability, public schemas/wire types and license/advisory policies intact? | Formatters, linters, pure static form/structure checks (including ADR freeze checks on every PR / ADR edit), frontend typecheck/lint, source-derived wire/schema contracts, dependency advisory/license scans | **Active gate**: fast fail-first on every PR, scoped to the changed surface (dependency scans only on manifest, lockfile or policy changes). | +| **L2 — Business flows** | Do modified modules and their transitive consumers preserve behavioral contracts? | Unit and in-process or loopback flow tests (plus runtime-assembled structural checks that require compiling the workspace) | **Active gate** on the primary high-throughput platform for the **reverse-dependency closure** of changed crates (expanding to the full workspace when foundational crates or workspace-wide configuration change). Heavy historical, soak or low-frequency flows belong in **Retained**. | +| **L3 — Real environment & cross-platform** | Do real OS primitives, process/plugin wiring, terminal interaction and external protocol boundaries work? | OS-native boundary slices, real daemon + plugin runtime flows, interactive terminal E2E suites, external registry acceptance | **Split**: narrow OS-native boundary slices run in the **Active gate** only on PRs touching platform/client code; full cross-platform runs and external-registry acceptance are **Retained** (asynchronous `main`/scheduled sweeps, pre-release or on-demand); interactive terminal E2E is **Retained (local-only)** — run locally on demand or before release, **never** invoked by a CI workflow. | | **L4 — Quality, performance & release** | Have model quality, resource budgets, executable layout or distribution artifacts regressed? | Evaluation harnesses, memory/startup measurements, native code-layout builds, multi-platform release builds and registry/image acceptance | **Execution is always Retained** (scheduled, manual or release train only — never gates ordinary feature PRs). Changes to an L4 harness itself run the harness's own L1/L2 checks in the **Active gate** on that PR. | Formal models (L0) verify that an abstract state machine satisfies safety and conditional liveness @@ -56,20 +58,25 @@ Documentation exists to guide contributors and state semantic contracts. Automat documentation and source conventions enforce only **deterministic, low-false-positive form and structural invariants**: -- **In scope for automated checks (L1, zero business compilation)**: lifecycle/immutability form - (such as accepted-ADR freeze checks), link and template structure, and deterministic - code-to-document structural projections (such as public service catalogs or crate-level overviews) - that do not parse natural-language prose. +- **Pure static form checks (L1, zero business compilation)**: lifecycle/immutability form (such as + accepted-ADR freeze checks), link and template structure, and manifest- or AST-derived structural + checks (such as crate/module dependency boundaries and source-parsed type declarations) that do + not compile business runtime crates and do not parse natural-language prose. +- **Runtime-assembled structural projections (workspace-coupled, alongside L2)**: deterministic + code-to-document projections that inherently require compiling and assembling the runtime (such + as a live public service catalog) run on the workspace-coupled build/verify path rather than + blocking pure-static docs, frontend or script PRs. - **Keep generated snapshots minimal**: commit and freshness-check a generated file only when downstream code consumes it (e.g. cross-language type declarations) or when it is a concise, actively referenced public summary. Fine-grained internal dependency graphs computed for boundary checks are verified live in memory and generated on demand rather than committed to Git as conflict-prone snapshots. - **Out of scope for automated checks**: semantic correctness of prose, design quality, and - judgement calls such as whether an edit alters a modelled invariant. Avoid brittle cross-language - text scanners that try to infer semantics from raw literals and rely on growing manual - allowlists; enforce invariants through types, boundaries, review checklists, L0 models and L2 - behavioral tests instead. + judgement calls such as whether an edit alters a modelled invariant. Avoid introducing new brittle + cross-language text scanners that try to infer semantics from raw literals and rely on growing + manual allowlists (existing allowlist-backed scanners are kept only until replaced by types, + boundaries or behavioral tests rather than imitated); enforce invariants through types, + boundaries, review checklists, L0 models and L2 behavioral tests instead. ### D3. Test coverage follows lowest flow/contract layer, single owner, release-safe injection and build hygiene @@ -133,8 +140,10 @@ layer. - Every new test, static check or formal model declares its operational state (Active / Retained / Dev), tier (L0–L4) and owner before wiring into CI. -- Once accepted, `AGENTS.md` (`## Testing`) can consolidate its testing rules onto this ADR so the - rule is stated once; until accepted, `AGENTS.md` keeps the current operational commands unchanged. +- Until this ADR is accepted and its follow-up tooling changes land, `AGENTS.md` and + `docs/architecture/` remain the authoritative reference for today's commands and committed + snapshots; once aligned, `AGENTS.md` (`## Testing`) can consolidate its testing rules onto this + ADR so the rule is stated once. - Pure static form checks are decoupled from workspace-coupled tooling so docs, frontend and script PRs stay fast. - Test-only build flags move to release-unreachable runtime/harness injection, eliminating diff --git a/docs/adr/README.md b/docs/adr/README.md index 8c01f95881..ab7e972b0d 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -32,7 +32,7 @@ original text. | [022 — Timeline 属性查询与正文重建](022-event-property-queries.md) | Proposed | Supersedes 019's event-only results, skip-based paging and start-only positions, and 020's single-predicate limit; retains 021's read ownership | | [023 — 上下文用量由独立分支部件维护](023-context-usage.md) | Accepted | Follows 021 and 022; separates context usage statistics from request preparation | | [024 — Web 抓取层使用请求库,地址策略在请求之前执行](024-web-fetch-transport.md) | Proposed | Follows 006 D1; replaces the hand-written transport and narrows the address policy to a pre-request check | -| [025 — Verification tiers, test coverage and CI governance](025-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; defines three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance | +| [026 — Verification tiers, test coverage and CI governance](026-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; defines three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance | Source baseline: [initial foundation parent](https://github.com/arcships/dim/commit/aaaffa5768e031d781abb73e45b1915b05dc2aa0). This baseline includes lifecycle fixes not necessarily present on the default branch. diff --git a/docs/zh/adr/025-verification-tiers-and-ci-governance.md b/docs/zh/adr/026-verification-tiers-and-ci-governance.md similarity index 80% rename from docs/zh/adr/025-verification-tiers-and-ci-governance.md rename to docs/zh/adr/026-verification-tiers-and-ci-governance.md index c3ed31e820..fba9e8756f 100644 --- a/docs/zh/adr/025-verification-tiers-and-ci-governance.md +++ b/docs/zh/adr/026-verification-tiers-and-ci-governance.md @@ -1,4 +1,4 @@ -# 025: 验证分层、测试覆盖与 CI 治理原则 +# 026: 验证分层、测试覆盖与 CI 治理原则 决策状态:Proposed(提案)。 @@ -18,7 +18,7 @@ 每项验证资产必须明确其执行态,以决定生命周期与 CI 成本归属: 1. **活跃门禁(Active Gate)**:PR 每次自动运行并受明确耗时预算约束,守卫高频契约与受影响依赖闭包。 -2. **保留按需(Retained / On-demand & Sweep)**:保留在仓库中,**不阻塞日常 PR**;在定时全量扫、发版前、排障复现或设计/协议评审要求时拉起。保留的 Rust 测试继续参与编译检查(例如聚合后标注 `#[ignore]`)以防编译腐烂;依赖外部工具链的检查(TLC/Java、本地 tmux E2E、独立性能脚本)不绑入日常构建链。 +2. **保留按需(Retained / On-demand & Sweep)**:保留在仓库中,**不阻塞日常 PR**;在资产自身文件变动(如形式化模型编辑)、定时全量扫、发版前、排障复现或设计/协议评审要求时拉起,各层级的具体触发条件以下表「默认执行态与触发方式」列为准。保留的 Rust 测试继续参与编译检查(例如聚合后标注 `#[ignore]`)以防编译腐烂;依赖外部工具链的检查(TLC/Java、本地 tmux E2E、独立性能脚本)不绑入日常构建链。 3. **开发调试(Dev / Exploratory)**:开发或排障期间编写的临时探针与细粒度局部测试。合入前必须消融:具持久契约价值的进入活跃门禁(D3),具长期复现诊断价值的转为保留按需,其余随分支清理,不入主干长期背债。 五层验证资产(L0–L4)的默认执行态与触发方式如下: @@ -26,9 +26,9 @@ | 层级 | 守卫的核心问题 | 范围 | 默认执行态与触发方式 | | --- | --- | --- | --- | | **L0 — 设计与形式化层** | 抽象状态机、协议与交接不变量本身是否存在反例? | 形式化模型(如 TLA+ 规约及 `.cfg` 性质) | **保留按需**:(a) 修改形式化模型文件时触发(若接入 CI 须按 D4 披露工具链成本);(b) 当实现改动影响已建模的交接、恢复或先后序承诺时,通过 PR 清单与评审强制触发。普通实现 PR **不跑**。 | -| **L1 — 静态形式与契约层** | 格式、依赖边界、ADR 不可变形式、公开 schema / wire 类型及依赖合规是否破坏? | 格式化、Lint、纯静态形式/结构检查(含每个 PR / ADR 变动必跑的 ADR 冻结检查)、前端类型检查/Lint、wire/schema 契约、依赖漏洞与许可证扫描 | **活跃门禁**:每个 PR 最快失败门禁,按改动面精准触发(依赖合规仅在 manifest、lockfile 或策略文件变更时跑)。 | -| **L2 — 业务流层** | 改动模块及其传递下游的业务行为契约是否保持正确? | 单元测试与进程内或 loopback 流程测试 | **活跃门禁**:在主力高吞吐平台运行改动 crate 的**反向依赖闭包**(公共底层 crate 或全局构建配置改动时扩大至全 workspace)。重型历史、长时压测或低频流程归入**保留按需**。 | -| **L3 — 真实环境与跨平台层** | 真实 OS 原语、真实进程/插件接线、终端交互与外部协议边界是否正常? | 平台专属边界窄集、真实 daemon + 插件运行时流、交互式终端 E2E、外部注册表验收 | **拆档**:仅触及平台/客户端代码时,极窄的 OS 专属原语边界进**活跃门禁**;全量跨平台、外部注册表验收与交互式终端 E2E 归**保留按需**(`main` 异步/定时扫、发版前或本地按需)。 | +| **L1 — 静态形式与契约层** | 格式、依赖边界、ADR 不可变形式、公开 schema / wire 类型及依赖合规是否破坏? | 格式化、Lint、纯静态形式/结构检查(含每个 PR / ADR 变动必跑的 ADR 冻结检查)、前端类型检查/Lint、源码静态提取的 wire/schema 契约、依赖漏洞与许可证扫描 | **活跃门禁**:每个 PR 最快失败门禁,按改动面精准触发(依赖合规仅在 manifest、lockfile 或策略文件变更时跑)。 | +| **L2 — 业务流层** | 改动模块及其传递下游的业务行为契约是否保持正确? | 单元测试与进程内或 loopback 流程测试(以及须编译 workspace 才能运行的运行时装配结构校验) | **活跃门禁**:在主力高吞吐平台运行改动 crate 的**反向依赖闭包**(公共底层 crate 或全局构建配置改动时扩大至全 workspace)。重型历史、长时压测或低频流程归入**保留按需**。 | +| **L3 — 真实环境与跨平台层** | 真实 OS 原语、真实进程/插件接线、终端交互与外部协议边界是否正常? | 平台专属边界窄集、真实 daemon + 插件运行时流、交互式终端 E2E、外部注册表验收 | **拆档**:仅触及平台/客户端代码时,极窄的 OS 专属原语边界进**活跃门禁**;全量跨平台与外部注册表验收归**保留按需**(`main` 异步/定时扫、发版前或按需);交互式终端 E2E 归**保留按需(仅限本地)**——只在本地按需或发版前运行,**绝不**由任何 CI workflow 触发。 | | **L4 — 效果、性能与发布层** | 模型效果、资源预算、可执行文件布局或分发包是否退化? | 评测套件(eval)、内存/启动测量、原生代码布局构建、多平台发布包构建与注册表/镜像验收 | **执行始终归保留按需**(仅定时、手动或发版流程,绝不阻塞普通功能 PR);修改 L4 工具链自身时,该工具自身的 L1/L2 自检作为**活跃门禁**在其 PR 上运行。 | 形式化模型(L0)验证的是「抽象状态机在有限状态空间内满足安全性与条件活性」,不是代码编译检查。普通代码改动依靠 L2 流程测试守住「实现依然精化模型动作」;若实现改动改变了模型假设的交接或先后序承诺,本质上属于设计变更,须通过评审回到 L0 更新并重跑模型后再合入。 @@ -37,9 +37,10 @@ 文档的职责是引导贡献者并陈述语义契约。针对文档和源码约定的自动化检查只应约束**确定性、低误报的形式与结构不变量**: -- **允许自动化检查(L1,零业务编译)**:生命周期与不可变形式(如已接受 ADR 冻结检查)、链接与模板结构完整性,以及不解析自然语言散文的确定性「代码到文档」结构投影(如公开服务目录或 crate 级总览)。 +- **纯静态形式检查(L1,零业务编译)**:生命周期与不可变形式(如已接受 ADR 冻结检查)、链接与模板结构完整性,以及基于 manifest 或 AST 的静态结构校验(如 crate/模块依赖边界、源码解析的类型声明),既不编译业务运行时 crate,也不解析自然语言散文。 +- **需组装运行时的结构投影(随 L2 编译路径)**:固有需要编译并装配运行时才能计算的确定性「代码到文档」投影(如实时公开服务目录)归入依赖 workspace 编译的校验路径,不阻塞纯文档、前端或脚本 PR。 - **克制入库自动生成文件**:只有当生成文件被下游代码直接消费(如跨语言类型声明),或是精简且被文档实际引用的公开摘要时,才应提交进 Git 并做过期校验;纯用于依赖边界校验的细粒度内部图谱应在内存中实时检查、本地按需生成,不提交进 Git 制造合并冲突。 -- **不以自动化测试强控**:文档散文的语义正确性、设计优劣,以及“某次实现改动是否触及已建模不变量”这类语义判断。避免新增试图从源码字面量推断语义、依赖不断膨胀的人工白名单维系的跨语言文本扫描;语义约束通过类型系统、模块边界、评审清单、L0 模型与 L2 行为测试保障。 +- **不以自动化测试强控**:文档散文的语义正确性、设计优劣,以及“某次实现改动是否触及已建模不变量”这类语义判断。避免新增试图从源码字面量推断语义、依赖不断膨胀的人工白名单维系的跨语言文本扫描(既有白名单扫描器仅过渡保留至被类型、边界或行为测试替代,不再效仿);语义约束通过类型系统、模块边界、评审清单、L0 模型与 L2 行为测试保障。 ### D3. 测试覆盖遵循最低流程/契约层、单一归属、生产不可达注入与产物治理 @@ -66,7 +67,7 @@ ## 影响 - 新增测试、静态检查或形式化模型接入 CI 前,须先明确其执行态(活跃/保留/调试)、层级(L0–L4)与归属。 -- 本 ADR 被正式接受后,可将 `AGENTS.md`(`## Testing`)的测试规则统一收口指向本决策以避免重复;接受前 `AGENTS.md` 保持现行操作命令不变。 +- 在本 ADR 被正式接受且配套工具变更落地前,`AGENTS.md` 与 `docs/architecture/` 仍是现行命令与入库快照的权威依据;对齐后可将 `AGENTS.md`(`## Testing`)的测试规则统一收口指向本决策以避免重复。 - 纯静态形式检查与依赖全后端的研发工具解耦,保持文档、前端与脚本 PR 的快速反馈。 - 仅服务于测试的编译期开关改为生产不可达的运行期/夹具注入,消除级联重编且不放松生产安全边界。 - 具体 workflow 调整、runner 迁移、定时全量扫、测试二进制聚合与具体预算数值均落在 `docs/architecture/build.md`、`docs/release/README.md` 与追踪 issue 中。