From 55e93b25f0abe58ee527baef93cafd7d885d010f Mon Sep 17 00:00:00 2001 From: xstudio agent Date: Tue, 29 Sep 2026 14:36:55 +0800 Subject: [PATCH] =?UTF-8?q?chg=5F0011(T0):=205=E4=BB=B6=E5=A5=97=EF=BC=88p?= =?UTF-8?q?roposal/spec/tasks/testcases/testcases.map.yaml=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proposal.md | 95 ++++++++++++++ .../chg_0011_vehicle_cloud_compliance/spec.md | 82 ++++++++++++ .../tasks.md | 72 +++++++++++ .../testcases.map.yaml | 58 +++++++++ .../testcases.md | 122 ++++++++++++++++++ 5 files changed, 429 insertions(+) create mode 100644 openspec/changes/chg_0011_vehicle_cloud_compliance/proposal.md create mode 100644 openspec/changes/chg_0011_vehicle_cloud_compliance/spec.md create mode 100644 openspec/changes/chg_0011_vehicle_cloud_compliance/tasks.md create mode 100644 openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.map.yaml create mode 100644 openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.md diff --git a/openspec/changes/chg_0011_vehicle_cloud_compliance/proposal.md b/openspec/changes/chg_0011_vehicle_cloud_compliance/proposal.md new file mode 100644 index 0000000..a712b56 --- /dev/null +++ b/openspec/changes/chg_0011_vehicle_cloud_compliance/proposal.md @@ -0,0 +1,95 @@ +--- +change_id: chg_0011 +status: proposed +owner: pm@team +stakeholders: [pd, tm, qa, dev] +priority: P1 +target_release: v0.7 +created: 2026-09-29 +skip_coverage: false +--- + +# chg_0011 vehicle_cloud_compliance — 车云数据合规场景 + +## Why + +chg_0010(金融联合风控)已落地"数据不出域"的多方计算场景,但需求 §5 还要求另一类互补场景: +**"数据出域可追溯"** — 数据确实需要离开车端到云端,但全程可审计、可还原、可鉴权。 + +候选三场景中: + +- **金融联合风控** → chg_0010 已闭环(80% 复用率,多方数据不出域)。 +- **车云数据合规** → **本 chg**(32% 复用率,6/19 算子,数据出域可追溯)。 +- 医疗联合诊断 → 后续候选(与 chg_0011 互补,暂缓)。 + +车云合规的特殊性在于: + +1. **车端 PII 必须出域**(监管/合规分析需要)— 但要**字段感知脱敏 + 零宽水印 + 审计链**全程可还原。 +2. **出域字段有白名单边界** — GPS / 车牌 / 车主 ID 全部脱敏,业务字段(故障码 / 电池电压 / 里程)保留。 +3. **不依赖 PSI / 同态加密**(与 chg_0010 互补)— 数据明文聚合,但通过水印 + 审计保证可追溯。 + +**约束**: + +- 不改 backend 代码(6 算子已齐备:tds-connector / data-masking / data-watermark / horizontal-fedavg / abac-policy / compliance-audit) +- 不加前端(场景测试目标是 backend e2e 协同) +- 不动 OperatorsService / ExperimentModule 注册(19 算子已注册) +- 复用 chg_0010 的 e2e 风格:admin token + per-vehicle 标签模拟 50 辆车 + +## Scope + +**做**: + +1. **场景设计文档** `docs/dth/vc/scenario.md`:定义 VC 场景的 6 步流程 + 数据流图 + 不变性约束 + 与既有算子的映射表 + **出域 PII 清单**。 + +2. **集成 e2e 测试** `tests/e2e/dth_vc.test.sh`:10 case 串起 6 个算子,覆盖: + - S1: 车端 TDS 合约 hash 匹配(tds-connector → JWT token) + - S2: TDS 合约 hash 不匹配 → 流程拒绝(tds-connector → error="contract-mismatch") + - S3: 50 车 telemetry 字段感知脱敏(data-masking:GPS/车牌/车主ID 全脱敏,业务字段保留) + - S4: 脱敏可逆性证明(data-masking:reversible_hash=SHA256 字段 → 业务对账还原) + - S5: 聚合报告零宽水印嵌入 + 提取 roundtrip(data-watermark) + - S6: 水印不可见(data-watermark:visible length 不变) + - S7: 50 车 fleet 聚合(horizontal-fedavg:mean + stddev) + - S8: ABAC 合规分析师通过 + 工程师拒绝(abac-policy) + - S9: 审计链 HMAC 完整(compliance-audit:6 步流程 chainValid=true) + - S10: E2E 端到端 6 步(admin login → S1→S9 串行 + 总耗时 < 60s) + +3. **门禁更新** `openspec/scripts/check_spec_coverage.sh`:无需改动(5 件套天然 cover)。 + +**不做**: + +- ❌ 新建 VC 专属 endpoint(直接复用 `POST /experiment/runs` 一个一个跑算子) +- ❌ 新加前端(backend-only e2e) +- ❌ 新加 operator(19 算子全够用,本 chg 用 6 个) +- ❌ 新加依赖(纯 shell + python3 + jq,已在 chg_0002 启用) +- ❌ 改 abac / auth / tds-connector(admin token 全程够用) + +## Acceptance + +- 10 case e2e 全 PASS(chg_0011 自身) +- 7 回归 e2e 全 PASS(chg_0002/0005/0006/0007/0008/0009/0010 = 7 套) +- gate `PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh` gap=0 +- `tsc --noEmit` 0 error(除预存 chg_0002 vertical-lr.ts:52) +- 文档 `docs/dth/vc/scenario.md` 包含:mermaid 流程图(6 步)+ 数据流表 + 算子映射表 + 不变性清单 + **出域 PII 清单** + 复用矩阵 + +## 与 chg_0010 的互补关系 + +| 维度 | chg_0010 金融联合风控 | chg_0011 车云数据合规 | +|---|---|---| +| 数据流向 | 不出域(多方计算) | **出域可追溯** | +| 隐私保护 | PSI / Paillier / Threshold Sig | **水印 + 审计链** | +| 算子覆盖率 | 8/19 = 42%(10 算子 + 6 真算法) | **6/19 = 32%** | +| 独占算子 | psi / paillier-he / threshold-sig / did-identity | **data-masking / horizontal-fedavg** | +| 共有算子 | abac-policy / data-watermark / compliance-audit / tds-connector | 同 4 个 | +| 业务上下文 | 银行反欺诈 | 车云合规分析 | + +## 与 handoff §2 的对应 + +handoff §2 优先级 2 = "chg_0010 真实业务场景测试设计" → chg_0010 已闭环 ✓。 +chg_0011 是 handoff §2 的**第 2 个候选场景**(车云数据合规),完成 = handoff §2 三场景全部覆盖(金融 ✓ / 车云 ✓ / 医疗 暂缓)。 + +## 风险 + +- **R1** data-masking v2 是**字段级单值**算子,50 车 telemetry 是批量数据。 + - 缓解:e2e 在 shell 层做 50 次循环调用(每车 3 字段),保持"业务流 = 50 车 × 3 字段 = 150 次算子调用"的真实性。 +- **R2** horizontal-fedavg 在 chg_0008 的测试用例断言 `aggregated == [0.3, 0.4]` 精确等于均值。 + - 缓解:50 车 fleet 取均值,fedavg 直接给 mean,无 epsilon 时精确等于数学均值。 diff --git a/openspec/changes/chg_0011_vehicle_cloud_compliance/spec.md b/openspec/changes/chg_0011_vehicle_cloud_compliance/spec.md new file mode 100644 index 0000000..fa9062c --- /dev/null +++ b/openspec/changes/chg_0011_vehicle_cloud_compliance/spec.md @@ -0,0 +1,82 @@ +# Spec: experiment_platform + +## Requirement + +THE SYSTEM SHALL provide a vehicle-to-cloud data compliance (VC) scenario that composes +6 existing operators (tds-connector / data-masking / data-watermark / horizontal-fedavg / +abac-policy / compliance-audit) into a 6-step end-to-end compliant telemetry flow across +50 simulated vehicles, proving that **out-of-domain PII is masked + watermarked + audit-traceable** +WITHOUT any new operator / endpoint / dependency, so that 业务方能用现有算子验证"数据出域可追溯" +的车云合规场景。 + +## ADDED Scenarios + +### S1 车端 TDS 合约 hash 匹配 + +- **WHEN** the vehicle's TDS client submits `contract_hash` matching the cloud platform's `contract_hash` +- **THEN** tds-connector.match() returns `{contract_hash_match: true, access_token: <3-part JWT>}` +- **AND** the JWT has 3 dot-separated parts (header.payload.signature) +- **AND** output `schema_version === "v2"` + +### S2 TDS 合约 hash 不匹配 → 流程拒绝 + +- **WHEN** tds-connector.match() is called with `contract_hash_a !== contract_hash_b` +- **THEN** output `{contract_hash_match: false, error: "contract-mismatch"}` +- **AND** the VC flow is aborted at step 1 (no data-masking / aggregation runs) + +### S3 字段感知脱敏(50 车 × 3 字段 = 150 次调用) + +- **WHEN** 50 vehicles submit telemetry with GPS / plate / owner_id PII fields + business fields (fault_code / battery_voltage / mileage) +- **THEN** data-masking masks **all 3 PII fields per vehicle** (150 masked values total) +- **AND** the original PII values (GPS coordinates / plate numbers / owner IDs) NEVER appear in any masked output +- **AND** business fields (fault_code / battery_voltage / mileage) are NOT masked — they are passed through unchanged +- **AND** schema_version = "v2" + +### S4 脱敏可逆性证明 + +- **WHEN** the masked output from S3 is inspected +- **THEN** each masked entry contains a `reversible_hash` field (SHA256 of the original value) +- **AND** the SHA256 hash is **stable** — re-masking the same original value produces the same reversible_hash +- **AND** the reversible_hash length is exactly 64 hex chars (SHA256) + +### S5 聚合报告零宽水印嵌入 + 提取 roundtrip + +- **WHEN** the fleet aggregator embeds `payload = "VC|2026-09-29|fleet-50|v1"` into a fleet report via data-watermark +- **THEN** data-watermark.extract(watermarked_report) returns the **exact** payload string +- **AND** the embedded payload survives a single roundtrip (embed → extract = payload) +- **AND** schema_version = "v2" + +### S6 水印不可见 + +- **WHEN** S5 embed is performed with `text = "fleet report body..."` and payload above +- **THEN** the visible (printable) length of `watermarked_text` is **unchanged** from `text` (zero-width chars are not visible) +- **AND** the **byte** length grows by exactly `payload.length * 4` (4 zero-width chars per byte) + +### S7 50 车 fleet 聚合(horizontal-fedavg) + +- **WHEN** 50 vehicles submit their mean-fault-code (normalized to [0, 1]) +- **THEN** horizontal-fedavg outputs `aggregated` as the fleet-wide mean +- **AND** `client_count === 50` +- **AND** no Gaussian DP noise is applied (epsilon absent) +- **AND** schema_version = "v2" + +### S8 ABAC 合规分析师通过 + 工程师拒绝 + +- **WHEN** an ABAC policy requires `subject.role === "compliance-analyst"` AND `env.ip in CIDR "10.0.0.0/24"` +- **THEN** request from `{role: "compliance-analyst", ip: "10.0.0.5"}` returns `{decision: "allow"}` +- **AND** request from `{role: "engineer", ip: "10.0.0.5"}` returns `{decision: "deny", reasons: [...allow_miss...]}` +- **AND** request from `{role: "compliance-analyst", ip: "192.168.1.5"}` returns `{decision: "deny", reasons: [...env_violation: ip...]}` (out of CIDR) + +### S9 审计链 HMAC 完整(6 步流程链) + +- **WHEN** the full VC flow runs through 6 audit entries (S1 tds + S3 masking + S5 watermark + S7 fedavg + S8 abac + S8-close = 6 entries) +- **THEN** compliance-audit chain contains ≥ 6 entries (one per VC step) +- **AND** each entry has HMAC-SHA256 chain linkage (`prev_hash` references the prior entry) +- **AND** `chainValid === true` on full replay + +### S10 E2E 端到端 6 步不变性 + +- **WHEN** a single shell run executes S1→S9 in order with the canonical 50-vehicle fixture +- **THEN** every intermediate assertion in S1..S9 passes +- **AND** the final output reports `e2e dth_vc: pass=N fail=0` (N = total sub-assertions, expected 10+) +- **AND** total wall-clock time for the e2e is < 60s (operators are local TS, no external I/O) diff --git a/openspec/changes/chg_0011_vehicle_cloud_compliance/tasks.md b/openspec/changes/chg_0011_vehicle_cloud_compliance/tasks.md new file mode 100644 index 0000000..df1aab8 --- /dev/null +++ b/openspec/changes/chg_0011_vehicle_cloud_compliance/tasks.md @@ -0,0 +1,72 @@ +# Tasks (DAG) + +- id: T1 + type: architect + depends_on: [] + output: docs/dth/vc/scenario.md + verification: + - 文档含 mermaid 流程图(6 步 + 6 算子映射) + - 数据流表(每步:输入 → 算子 → 输出 → 不变性) + - 算子映射表(每算子:何时被调用 / 输入 schema / 输出 schema) + - 不变性清单(S1-S10 → 对应算子 + 测试断言) + - **出域 PII 清单**(GPS / 车牌 / 车主 ID / 业务字段 — 是否出域 + 脱敏方式 + 反向验证) + - 复用矩阵(既有 19 算子的复用率 ≥ 32%) + +- id: T2 + type: implementer + depends_on: [T1] + output: | + tests/e2e/dth_vc.test.sh (10 case e2e shell 脚本) + verification: + - 脚本无 set -e(每条 assertion 独立计数) + - 使用 DTH_BASE=${DTH_BASE:-http://127.0.0.1:30000} + - 每条 assert 用 python3 json_get (与 chg_0010 一致) + - 包含 admin token login (pre_admin_login) + - 10 case 覆盖 S1..S10 + - 总耗时 < 60s + - 复用既有 helpers(不要重写 json_get / assert / login,从 chg_0010 复制) + +- id: T3 + type: tester + depends_on: [T2] + output: | + 1 次完整 e2e 跑通(bash tests/e2e/dth_vc.test.sh 10/0) + verification: + - pass=10 fail=0 + - 含 4+ 不变性断言(脱敏可逆 / 水印 roundtrip / 水印不可见 / 审计链 HMAC) + - 含 1 拒绝路径(TDS mismatch → 流程拒绝) + - 含 1 跨车 E2E 串联(S10 = S1→S9 一气呵成) + +- id: T4 + type: qa + depends_on: [T3] + output: | + PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh + 7 e2e 套件全跑(chg_0002/0005/0006/0007/0008/0009/0010/0011 = 8 套) + verification: + - gate gap = 0 + - tsc --noEmit 0 error(除预存 chg_0002 vertical-lr.ts:52) + - 7 回归 + 1 新 = 8 e2e 套件全 PASS + - 总断言数 ≥ 182(172 旧 + 10 新 = 182) + - 报告落 /tmp/chg_0011-qa.log + +- id: T5 + type: pm + depends_on: [T4] + output: | + openspec/changes/chg_0011_vehicle_cloud_compliance/.xstudio-report.md + chg_0011 实施说明(取舍 + 与 chg_0010 互补算子差异 + 后续医疗候选) + verification: + - 报告含 改动文件清单 + 门禁结果 + 算子复用率 + 是否建议合并 + - 报告大小 ≥ 30 行 + - chg_0011 任务全部完成 + +# Notes + +- 无 backend 代码改动(19 算子已齐备,本 chg 用其中 6 个) +- 无 frontend 代码改动(业务场景 e2e only) +- 无新依赖 +- 测试端口 30000(与既有 e2e 一致;DTH_BASE env 可覆盖) +- 提交顺序建议:T1 (docs) → T2 (test script) → T3 (test PASS) → T4 (gate + regressions) → T5 (report) +- 与 chg_0010 的边界:不动 OperatorsService / ExperimentModule 注册(19 算子已注册),仅新增 test 脚本 +- 与 chg_0010 的复用:共用 tds-connector / data-watermark / abac-policy / compliance-audit 4 算子;新增 data-masking / horizontal-fedavg 2 算子 diff --git a/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.map.yaml b/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.map.yaml new file mode 100644 index 0000000..c3f772d --- /dev/null +++ b/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.map.yaml @@ -0,0 +1,58 @@ +# spec: experiment_platform@chg_0011 +scenarios: + - id: S1 + cases: [C1_vc_tds_contract_match] + - id: S2 + cases: [C2_vc_tds_mismatch_abort] + - id: S3 + cases: [C3_vc_field_aware_masking] + - id: S4 + cases: [C4_vc_masking_reversible] + - id: S5 + cases: [C5_vc_watermark_embed_extract_roundtrip] + - id: S6 + cases: [C6_vc_watermark_invisible_length] + - id: S7 + cases: [C7_vc_fleet_fedavg_aggregation] + - id: S8 + cases: [C8_vc_abac_compliance_analyst] + - id: S9 + cases: [C9_vc_audit_chain_hmac_valid] + - id: S10 + cases: [C10_vc_e2e_full_flow_6_steps] +gate: + blocking_gap_tolerance: 0 + implementation_files: + - tests/e2e/dth_vc.test.sh + - docs/dth/vc/scenario.md + test_files: + - tests/e2e/dth_vc.test.sh +notes: + reuses_operators_no_new_code: true + operator_coverage: "6 of 19 chg_0002/0008/0009 operators" + operators_used: + - tds-connector (S1, S2) + - data-masking (S3, S4) + - data-watermark (S5, S6) + - horizontal-fedavg (S7) + - abac-policy (S8) + - compliance-audit (S9) + invariant_assertions: 4 + - C4 masking_reversible (合规可还原) + - C5 watermark_roundtrip (可恢复性) + - C6 watermark_invisible_length (不可见性) + - C9 audit_chain_hmac_valid (不可篡改性) + complementary_to_chg_0010: + shared_operators: + - tds-connector + - data-watermark + - abac-policy + - compliance-audit + chg_0011_unique: + - data-masking + - horizontal-fedavg + chg_0010_unique: + - psi + - paillier-he + - threshold-sig + - did-identity \ No newline at end of file diff --git a/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.md b/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.md new file mode 100644 index 0000000..dcbdaf3 --- /dev/null +++ b/openspec/changes/chg_0011_vehicle_cloud_compliance/testcases.md @@ -0,0 +1,122 @@ +### C1_vc_tds_contract_match +- Scenario: S1 +- Type: e2e +- Priority: P0 +- Given: backend running on 30000, admin token, vehicle's contract_hash = "vc-contract-v1" +- When: POST /experiment/runs with operator=tds-connector (matching contract_hash_a == contract_hash_b) +- Then: response.tds.contract_hash_match=true +- And: response.tds.access_token is non-empty 3-part JWT (header.payload.signature) +- And: schema_version=v2 +- Automated: true +- Bound Task: T2 + +### C2_vc_tds_mismatch_abort +- Scenario: S2 +- Type: e2e +- Priority: P1 +- Given: contract_hash_a = "vc-contract-v1", contract_hash_b = "vc-contract-v2" (different) +- When: POST /experiment/runs with operator=tds-connector +- Then: response.tds.contract_hash_match=false +- And: response.tds.error="contract-mismatch" +- And: response.tds.access_token=null +- And: VC flow aborts (no data-masking / aggregation runs) +- Automated: true +- Bound Task: T2 + +### C3_vc_field_aware_masking +- Scenario: S3 +- Type: e2e +- Priority: P0 +- Given: 50 vehicles × 3 PII fields (GPS / plate / owner_id) + 3 business fields (fault_code / battery_voltage / mileage) +- When: 150 POST calls to data-masking (PII fields masked) + business fields passed through +- Then: all 50 vehicles' GPS coordinates, plate numbers, owner IDs are masked (50 of each) +- And: NO original PII value appears in any masked output (assert no GPS lat/lon, no plate, no owner_id strings) +- And: business fields (fault_code "P0301", battery_voltage "12.6V", mileage "50000km") appear unchanged +- And: schema_version=v2 +- Automated: true +- Bound Task: T2 + +### C4_vc_masking_reversible +- Scenario: S4 +- Type: e2e +- Priority: P0 (compliance invariant) +- Given: 1 vehicle with original GPS / plate / owner_id values, data-masked once +- When: re-run data-masking on the same original values +- Then: both runs produce the SAME reversible_hash for each field (SHA256 stable) +- And: reversible_hash is exactly 64 hex chars (SHA256 output) +- And: re-masking returns identical masked output (deterministic) +- Automated: true +- Bound Task: T2 + +### C5_vc_watermark_embed_extract_roundtrip +- Scenario: S5 +- Type: e2e +- Priority: P0 +- Given: fleet report text "Fleet avg fault_rate=0.05, fleet size=50", payload="VC|2026-09-29|fleet-50|v1" +- When: POST data-watermark (action=embed) with text + payload, then POST (action=extract) on watermarked_text +- Then: extract returns the EXACT payload string "VC|2026-09-29|fleet-50|v1" +- And: roundtrip payload matches byte-for-byte +- And: schema_version=v2 +- Automated: true +- Bound Task: T2 + +### C6_vc_watermark_invisible_length +- Scenario: S6 +- Type: e2e +- Priority: P1 +- Given: text="Fleet avg fault_rate=0.05, fleet size=50" (37 chars), data-watermark embed +- When: POST data-watermark (action=embed) with payload="VC|2026-09-29|fleet-50|v1" (24 bytes) +- Then: visible (printable) length of watermarked_text == 37 (unchanged) +- And: total length of watermarked_text == 37 + 24*4 == 133 (zero-width chars added) +- And: zero-width chars appended is exactly 96 (= 24 * 4) +- Automated: true +- Bound Task: T2 + +### C7_vc_fleet_fedavg_aggregation +- Scenario: S7 +- Type: e2e +- Priority: P0 +- Given: 50 vehicles each submit a normalized fault-rate in [0, 1] +- When: POST horizontal-fedavg with input.weights=[0.02, 0.05, ..., 0.08] (50 numbers) +- Then: response.fedavg.aggregated[0] is the mean of the 50 values (no DP noise, epsilon absent) +- And: response.fedavg.client_count=50 +- And: response.fedavg.noise_applied=false +- And: schema_version=v2 +- Automated: true +- Bound Task: T2 + +### C8_vc_abac_compliance_analyst +- Scenario: S8 +- Type: e2e +- Priority: P0 +- Given: abac policy requiring role=compliance-analyst AND env.ip in CIDR 10.0.0.0/24 +- When: 3 POSTs with combinations (1 allow + 2 deny) +- Then: allow for {role: compliance-analyst, ip: 10.0.0.5} +- And: deny with allow_miss for {role: engineer, ip: 10.0.0.5} +- And: deny with env_violation:ip for {role: compliance-analyst, ip: 192.168.1.5} +- Automated: true +- Bound Task: T2 + +### C9_vc_audit_chain_hmac_valid +- Scenario: S9 +- Type: e2e +- Priority: P1 +- Given: 6 VC step audit entries (S1 tds + S3 masking summary + S5 watermark + S7 fedavg + S8 abac + S8-close) +- When: POST compliance-audit with action=record (5 appends to chain), then POST verify=true with entries=full chain +- Then: chain length === 6 +- And: each entry has prev_hash linking prior entry's hash +- And: chainValid=true on verify replay +- Automated: true +- Bound Task: T2 + +### C10_vc_e2e_full_flow_6_steps +- Scenario: S10 +- Type: e2e +- Priority: P0 +- Given: canonical 50-vehicle fixture (TDS contract, masked telemetry, watermark payload, fleet weights, ABAC policy, audit entries) +- When: 1 shell run executes all 9 steps in sequence (C1-C9 in order) +- Then: pass=10 fail=0 (10 main cases) +- And: total wall-clock < 60s +- And: no operator-not-found or 500 errors in any substep +- Automated: true +- Bound Task: T3 (E2E orchestration test) \ No newline at end of file