STEP 1380 — TS/Python 決定表 drift 検知 CI
1. 契機
STEP 1377 (2026-08-23) で discovery-worker Python fdr_gate.spec_table() を rei-aios TypeScript d8MultiTrialSpecTable() の Python 移植として 実装。 決定表 8 rule M1-M8 は 「一字一句同じ」 と 明示したが、 現時点は manual 同期 = 実装 lag / drift risk。
本 STEP: **subprocess ベースで TS 実行時に Python spec 実測 + 差分 diff** の CI test を 追加、 drift 発生時 test fail で 即検出。
2. 実装
2.1 Python 側 (discovery-worker/worker/fdr_gate.py)
CLI に --spec-json flag 追加 (spec table のみを JSON dump、 他 output なし):
if args.spec_json:
print(json.dumps(spec_table(), ensure_ascii=False, indent=2))
return
2.2 TS 側 (rei-aios test/step1380-ts-python-drift-check-test.ts)
spawnSync('python', [DISCOVERY_WORKER_PATH, '--spec-json'])で Python spec 取得d8MultiTrialSpecTable()と 比較- Semantic contract 比較: rule name (M1-M8) + verdict (D-FUMT₈ 8 値) + reason (payload key)
- Documentation-only warning: condition string (language variations は 許可、 fail しない)
2.3 SKIP conditions (graceful degradation)
- Python 未 install → SKIP
- discovery-worker path 未 present → SKIP
- Python invocation 失敗 → SKIP (exit 0)
- Python
--spec-jsonexit 非 0 → FAIL (旧 version、 sync 必要 marker)
3. Verify 実測 (52/52 PASS)
3.1 Semantic contract 一致
[6] rule 名 M1-M8 全一致: TS ↔ Python [7] verdict (D-FUMT₈ name) 全 8 rule 一致 [8] reason (payload key) 全 8 rule 一致 [10] activation subset 一致: 5 値 (TRUE / FALSE / NEITHER / ZERO / BOTH) [11] reason set 一致: 8 reason 全部 双方向 subset check
3.2 Condition variations (documented allowed diffs)
| Rule | TS condition | Python condition |
|---|---|---|
| M1 | trials.length === 0 | trials.length == 0 |
| M2 | fdrQ null / NaN / ≤0 / ≥1 | fdr_q null / NaN / <=0 / >=1 |
| M3 | alpha null / NaN / ≤0 / ≥1 | alpha null / NaN / <=0 / >=1 |
| M4 | 全 trial の pValue が invalid | all p_value invalid |
| M5 | naive_significant_count === 0 | naive_significant_count == 0 |
| M6 | fdr_survivors === 0 かつ naive_significant > 0 | fdr_survivors == 0 and naive > 0 |
| M7 | 0 < fdr_survivors < naive_significant | 0 < fdr_survivors < naive |
| M8 | fdr_survivors > 0 かつ === naive_significant | fdr_survivors == naive > 0 |
Documented parity: 0/8 exact match, 8 language variations (allowed): === vs ==、 ≤ vs <=、 かつ vs and、 camelCase vs snake_case、 Japanese vs English 混在。 「documentation 差」 として test 内で warn 出力、 fail しない。
4. Design rationale
4.1 「Semantic contract」 vs 「documentation」 分離
- Semantic contract (must match): rule name / verdict / reason = caller が payload から parse する 実データ (drift → caller 破壊)
- Documentation (allowed to differ): condition strings = human-readable spec dump (drift → 意味変わらず、 language convention の 反映)
4.2 SKIP graceful design
CI 環境が Python missing / discovery-worker absent 場合、 test は SKIP (exit 0)、 fail しない。 rei-aios は Python 依存を hard requirement 化しない。 但し 存在するなら full parity 検証。
4.3 Drift 発生時の 挙動
- rule name / verdict / reason が 1 個でも 不一致 → test FAIL、 detail 出力 (どの rule の どの field が どう違うか)
- Condition string 不一致 → warn (実測 8/8 が 「documented variation」 として fail しない)
- Python spec 数 vs TS spec 数 不一致 → test FAIL (rule 追加 lag / 削除 lag 検出)
5. Honest scope
- 「世界初」 主張ゼロ、 cross-language contract testing は 30+ 年前既知 pattern (Contract Testing / Consumer-Driven Contracts、 Fowler 2011 等)、 novelty は Rei stack 内 TS/Python parity 初 CI arc のみ
- subprocess spawnSync 依存 = Python 環境 hard requirement、 但し SKIP graceful で mitigation
- Condition parity は intentional差 が 主 (language variation)、 exact match 期待は 非現実的 → warn-only。 v0.2 で shared spec source (ex: JSON schema) から 両実装 生成する option candidate
- drift 検出 rule 名一字違い (M1 → M01 等) は catch する、 但し **意味は同じで 名前だけ変更** も FAIL 扱い (breaking change の 明示)
- Python 側 fdr_gate.py に
--spec-jsonflag 追加は minor CLI 追加のみ、 既存 CLI (normal mode) と 排他 (両方 required なら error)、 backward compat 維持 - 本 CI test は npm run test:step1380 で 実行、 GitHub Actions 統合 は 別 STEP (Rei stack は 現状 CI service 未 setup)
6. 関連
- STEP 1371 (2026-08-23) — rei-aios TypeScript d8MultiTrialSpecTable() origin
- STEP 1377 (2026-08-23) — discovery-worker Python fdr_gate.spec_table() origin (Python 移植)
- STEP 1378 (2026-08-23) — MCP tool count auto-count (同 「発見手法 = 防止手法」 対称性 pattern)
- STEP 1379 (2026-08-23) — Cohen's d BOTH 経路 (別 primitive、 本 CI test の scope 外だが 同型 CI 追加 candidate)
feedback_super_naming_siren_family_pattern— 「一字一句同じ」 claim vs 実装 lag drift の 「果たせない約束」 回避feedback_all_research_site_reflection_default— 2026-08-06 protocol 継続