## 根因 `apps.api.src.*` 需倉庫根目錄在 sys.path 才能透過 PEP 420 namespace package 解析(因 apps/ 和 apps/api/ 無 __init__.py)。 - CI rootdir=repo root → 可解析(但脆弱依賴) - 本地 pytest rootdir=apps/api → 解析失敗 → 整個 src.models.__init__ 炸 - CI 錯誤: `test_secret_redactor.py` 無法 import module ## 修復 src.models.__init__ 的 3 處 `apps.api.src.*` 改 `src.*` src.models.incident 的 1 處 `apps.api.src.*` 改 `src.*` tests/test_aider_event_models.py import path 統一 tests/test_secret_redactor.py import path 統一 ## 驗證 138 個 pytest test 全過(drift + rule_engine + approval_execution + aider_event + incident + secret_redactor) 所有 test 都用 `from src.*` 風格(codebase 既有慣例,pytest rootdir=apps/api 提供 src/ 作 import root) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
# 2026-04-20 @ Asia/Taipei
|
||
# Import root 由 pytest rootdir=apps/api 提供(見 pyproject.toml),因此不得用 `apps.api.src.*` 絕對路徑
|
||
from src.utils.secret_redactor import redact
|
||
|
||
|
||
def test_openrouter_key_redacted():
|
||
assert "<redacted:openrouter>" in redact("sk-or-v1-abcdef0123456789ABCDEFghijklmnopqrstuv")
|
||
|
||
|
||
def test_anthropic_key_redacted():
|
||
assert "<redacted:anthropic>" in redact("sk-ant-api03-abcDEF_123-xyz")
|
||
|
||
|
||
def test_github_token_redacted():
|
||
assert "<redacted:github>" in redact("ghp_abcdef0123456789ABCDEFghijklmnopqrst")
|
||
|
||
|
||
def test_google_key_redacted():
|
||
assert "<redacted:google>" in redact("AIzaSyABCDEFGHIJKLMNOPQRSTUVWXYZ1234567")
|
||
|
||
|
||
def test_telegram_bot_token_redacted():
|
||
assert "<redacted:telegram>" in redact("8474499448:AAFqu_i4-PN4zGFOK5ea8o0Ud56qqEtCMeI")
|
||
|
||
|
||
def test_aws_key_redacted():
|
||
assert "<redacted:aws>" in redact("key=AKIAIOSFODNN7EXAMPLE")
|
||
|
||
|
||
def test_clean_passthrough():
|
||
assert redact("normal text here") == "normal text here"
|
||
|
||
|
||
def test_nested_dict():
|
||
d = {"a": "ghp_abcdef0123456789ABCDEFghijklmnopqrst", "b": {"c": "AIzaSyABCDEFGHIJKLMNOPQRSTUVWXYZ1234567"}}
|
||
out = redact(d)
|
||
assert "ghp_abc" not in str(out)
|
||
assert "AIzaSy" not in str(out)
|