guard release code against redaction placeholders

This commit is contained in:
732642856
2026-07-13 22:53:04 +08:00
parent 67b217efd7
commit 7ae756f97b
5 changed files with 32 additions and 3 deletions
+1
View File
@@ -82,6 +82,7 @@ For large architecture or release work, also read:
| ERR-049 | PyJHora benchmark runner executed on `--help`, used a wrong repository-root path in `run_skill_baseline.py`, and failed when reused without pre-created output directories. | mitigated 2026-07-12 | Keep `tests/test_pyjhora_compare_cli.py`; require explicit `--build-local`, safe argparse help, correct repo root, and directory creation inside `run_sample()`. |
| ERR-050 | Prashna CLI/API/UI could synthesize or accept a non-question chart; legacy Tajika/Saham/Sphuta/Kunda paths also exposed approximate values as usable evidence. | mitigated 2026-07-12 | Require backend Swiss `PrashnaContext` with question text/time/location/timezone; reject client planets/ascendant. Block legacy Sphuta/Kunda/Gulika/Panchavargiya and no-location Saham paths; keep seven-planet Tajika interactions partial until named-yoga golden cases and formula parity exist. |
| ERR-051 | Privacy redaction can replace executable numeric test fixtures with bare placeholder identifiers such as `REDACTED_YEAR`, causing `NameError` before a regression reaches its target. | observed 2026-07-12 | Public tests must use generic fixtures (for example 1990) or quoted placeholders only; run `rg -n "REDACTED_YEAR" tests` before release and repair executable occurrences. |
| ERR-052 | Text-only privacy scanning cannot distinguish a harmless quoted placeholder from a bare Python identifier that will fail at runtime. | mitigated 2026-07-13 | `public_release_privacy_scan.py` parses shipped Python files and rejects executable `REDACTED_*` names; keep the AST regression test. |
## Fragment Sweep Command Set
+1 -1
View File
@@ -404,7 +404,7 @@ if __name__ == '__main__':
print(f"行星经度: { {k: f'{v:.1f}' for k,v in test_planets.items()} }")
print()
result = narayana_dasha_full_report(test_lagna, test_planets, test_age, REDACTED_YEAR)
result = narayana_dasha_full_report(test_lagna, test_planets, test_age, 1990)
print("=== 大运序列 ===")
for p in result['mahadasha_sequence']:
+21
View File
@@ -4,6 +4,7 @@
from __future__ import annotations
import argparse
import ast
import json
import os
import re
@@ -120,6 +121,25 @@ def scan_text(
return findings
def scan_executable_redaction_names(path: Path, text: str) -> list[dict[str, object]]:
"""Reject unquoted privacy placeholders that would raise at runtime."""
if path.suffix.lower() != ".py":
return []
try:
tree = ast.parse(text, filename=str(path))
except SyntaxError:
return []
try:
display_path = path.relative_to(ROOT).as_posix()
except ValueError:
display_path = path.as_posix()
return [
{"rule_id": "executable_redaction_placeholder", "path": display_path, "line": node.lineno}
for node in ast.walk(tree)
if isinstance(node, ast.Name) and node.id.startswith("REDACTED_")
]
def build_report(root: Path = ROOT) -> dict[str, object]:
findings: list[dict[str, object]] = []
scanned = 0
@@ -131,6 +151,7 @@ def build_report(root: Path = ROOT) -> dict[str, object]:
text = path.read_text(encoding="utf-8", errors="ignore")
scanned += 1
findings.extend(scan_text(path, text, patterns))
findings.extend(scan_executable_redaction_names(path, text))
return {
"scope": "public_release_privacy_scan",
"scanned_files": scanned,
+2 -2
View File
@@ -630,8 +630,8 @@ if __name__ == '__main__':
print(f" swisseph可用: {HAS_SWE}")
print()
# 测试:private birth datetime +8 的出生盘,计算 2026 年太阳返照
test_birth_year, test_birth_month, test_birth_day = REDACTED_YEAR, 4, 17
# Generic public smoke fixture, calculating the 2026 solar return.
test_birth_year, test_birth_month, test_birth_day = 1990, 4, 17
test_birth_hour, test_birth_minute = 14, 45
test_lat, test_lon, test_tz = 36.4667, 114.2, 8.0
test_target_year = 2026
@@ -31,6 +31,13 @@ def test_public_release_privacy_scan_supports_unpacked_zip_without_git(tmp_path:
assert report["status"] == "pass", report["findings"]
def test_public_release_privacy_scan_rejects_executable_redaction_placeholder(tmp_path: Path) -> None:
(tmp_path / "unsafe.py").write_text("year = REDACTED_YEAR\n", encoding="utf-8")
report = build_report(tmp_path)
assert report["status"] == "fail"
assert report["findings"][0]["rule_id"] == "executable_redaction_placeholder"
def test_private_workspace_directories_are_gitignored() -> None:
gitignore = (Path(__file__).resolve().parents[1] / ".gitignore").read_text(encoding="utf-8").splitlines()
assert "/scratch/" in gitignore