Skip to content

Commit 08e20a5

Browse files
authored
fix: harden hk strategies audit gate and CI (#60)
1 parent e9e3058 commit 08e20a5

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ jobs:
5151
run: |
5252
set -euo pipefail
5353
python -m pip install --upgrade pip
54-
python -m pip install -e . pandas pytest pytest-cov ruff
54+
python -m pip install -e . pandas pytest pytest-cov ruff build
5555
python -m pip install --no-deps -e external/QuantPlatformKit
5656
57+
- name: Verify dependencies
58+
run: |
59+
set -euo pipefail
60+
python -m pip check
61+
5762
- name: Run Ruff
5863
run: |
5964
set -euo pipefail
@@ -63,3 +68,8 @@ jobs:
6368
run: |
6469
set -euo pipefail
6570
PYTHONPATH=src python -m pytest -q tests --cov --cov-report=term --cov-report=xml
71+
72+
- name: Build package
73+
run: |
74+
set -euo pipefail
75+
python -m build

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ package-dir = {"" = "src"}
2323
where = ["src"]
2424

2525
[tool.ruff]
26-
ignore = ["E701", "E702", "E741", "F841", "F821", "B008", "F401", "F601", "E402"]
2726
target-version = "py311"
2827
line-length = 120
2928

29+
[tool.ruff.lint]
30+
ignore = ["E701", "E702", "E741", "F841", "F821", "B008", "F401", "F601", "E402"]
31+
3032
[tool.coverage.run]
3133
branch = true
3234
source = ["src"]

scripts/gate_codex_app_review.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def compile_patterns(policy: dict[str, Any]) -> list[re.Pattern[str]]:
9393
# ─── static guard ────────────────────────────────────────────────────────────
9494

9595
_SENSITIVE = re.compile(
96-
r'(?:api[_\s]?key|secret|password|token|credential|private[_\s]?key)\s*[:=]\s*["\']'
96+
r'(?P<field>api[_\s]?key|secret|password|token|credential|private[_\s]?key)\s*[:=]\s*["\']'
9797
r'(?!\$\{\{|{{|example|placeholder|test|your[-_\s]|xxx|TODO|CHANGEME)[^"\']{12,}["\']',
9898
re.IGNORECASE,
9999
)
@@ -115,7 +115,8 @@ def scan_diff(diff_text: str, path_patterns: list[re.Pattern[str]]) -> list[str]
115115
if not line.startswith("+") or line.startswith("+++"): continue
116116
m = _SENSITIVE.search(line[1:])
117117
if m:
118-
violations.append(f"**Hardcoded secret** in `{current}`: `{m.group(0)[:100]}`")
118+
field = re.sub(r"\s+", "_", m.group("field").strip().lower())
119+
violations.append(f"**Hardcoded secret** in `{current}`: `{field}=<redacted>`")
119120
return list(dict.fromkeys(violations))
120121

121122

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
import unittest
4+
5+
from scripts.gate_codex_app_review import scan_diff
6+
7+
8+
class GateCodexAppReviewTests(unittest.TestCase):
9+
def test_scan_diff_redacts_hardcoded_secret_values(self) -> None:
10+
secret_field = "API" + "_KEY"
11+
secret_value = "super" + "secretvalue123456"
12+
diff_text = (
13+
"diff --git a/example.env b/example.env\n"
14+
"--- a/example.env\n"
15+
"+++ b/example.env\n"
16+
f'+{secret_field} = "{secret_value}"\n'
17+
)
18+
19+
violations = scan_diff(diff_text, [])
20+
21+
self.assertEqual(len(violations), 1)
22+
self.assertIn("<redacted>", violations[0])
23+
self.assertIn("api_key", violations[0])
24+
self.assertNotIn(secret_value, violations[0])
25+
26+
27+
if __name__ == "__main__":
28+
unittest.main()

0 commit comments

Comments
 (0)