38 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""raw 凭据过滤的离线回归测试。"""
import pathlib
import sys
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[3]
SCRIPT_DIR = PROJECT_ROOT / "muse" / "authority" / "evidence" / "skills" / "记录运行证据" / "scripts"
sys.path.insert(0, str(SCRIPT_DIR))
from persist_raw import _check_no_secrets # noqa: E402
def test_normal_prompt_words_are_allowed():
_check_no_secrets("输出不超过 4000 字;token budget 只用于篇幅估算。")
def test_secret_assignments_are_rejected():
for text in (
"api_key=sk-example-secret-value",
"token: abcdefghijklmnop",
"Authorization: Bearer abcdefghijklmnop",
"-----BEGIN PRIVATE KEY-----",
):
try:
_check_no_secrets(text)
except ValueError:
continue
raise AssertionError(f"凭据未被拒绝: {text}")
def main():
test_normal_prompt_words_are_allowed()
test_secret_assignments_are_rejected()
print("全部通过")
if __name__ == "__main__":
main()