Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ jobs:
run: |
set -euo pipefail
python -m pip install --upgrade pip
python -m pip install -e . pandas pytest pytest-cov ruff
python -m pip install -e . pandas pytest pytest-cov ruff build
python -m pip install --no-deps -e external/QuantPlatformKit

- name: Verify dependencies
run: |
set -euo pipefail
python -m pip check

- name: Run Ruff
run: |
set -euo pipefail
Expand All @@ -63,3 +68,8 @@ jobs:
run: |
set -euo pipefail
PYTHONPATH=src python -m pytest -q tests --cov --cov-report=term --cov-report=xml

- name: Build package
run: |
set -euo pipefail
python -m build
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ package-dir = {"" = "src"}
where = ["src"]

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

[tool.ruff.lint]
ignore = ["E701", "E702", "E741", "F841", "F821", "B008", "F401", "F601", "E402"]

[tool.coverage.run]
branch = true
source = ["src"]
Expand Down
5 changes: 3 additions & 2 deletions scripts/gate_codex_app_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def compile_patterns(policy: dict[str, Any]) -> list[re.Pattern[str]]:
# ─── static guard ────────────────────────────────────────────────────────────

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


Expand Down
28 changes: 28 additions & 0 deletions tests/test_gate_codex_app_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import unittest

from scripts.gate_codex_app_review import scan_diff


class GateCodexAppReviewTests(unittest.TestCase):
def test_scan_diff_redacts_hardcoded_secret_values(self) -> None:
secret_field = "API" + "_KEY"
secret_value = "super" + "secretvalue123456"
diff_text = (
"diff --git a/example.env b/example.env\n"
"--- a/example.env\n"
"+++ b/example.env\n"
f'+{secret_field} = "{secret_value}"\n'
)

violations = scan_diff(diff_text, [])

self.assertEqual(len(violations), 1)
self.assertIn("<redacted>", violations[0])
self.assertIn("api_key", violations[0])
self.assertNotIn(secret_value, violations[0])


if __name__ == "__main__":
unittest.main()
Loading