Skip to content

Commit 8119c2a

Browse files
committed
fix: align qmt internal pins and lint gate
1 parent c0f3209 commit 8119c2a

3 files changed

Lines changed: 54 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"flask>=3.0",
1515
"pandas>=2.0",
1616
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@e86554b",
17-
"cn-equity-strategies @ git+https://github.com/QuantStrategyLab/CnEquityStrategies.git@357dba7e8896a7f488a484d4a3eea33894708ab9",
17+
"cn-equity-strategies @ git+https://github.com/QuantStrategyLab/CnEquityStrategies.git@f9a0009d55e71d37c037d5787193226c3acb0d1a",
1818
]
1919

2020
[project.optional-dependencies]

scripts/gate_codex_app_review.py

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def env(name: str, default: str = "") -> str:
3333

3434

3535
def env_int(name: str, default: int) -> int:
36-
try: return int(env(name, str(default)))
37-
except ValueError: return default
36+
try:
37+
return int(env(name, str(default)))
38+
except ValueError:
39+
return default
3840

3941

4042
def github_request(token: str, method: str, path: str,
@@ -47,7 +49,8 @@ def github_request(token: str, method: str, path: str,
4749
"X-GitHub-Api-Version": "2022-11-28",
4850
"User-Agent": "codex-review-gate",
4951
}
50-
if payload: headers["Content-Type"] = "application/json"
52+
if payload:
53+
headers["Content-Type"] = "application/json"
5154
req = urllib.request.Request(url, data=data, method=method, headers=headers)
5255
try:
5356
with urllib.request.urlopen(req, timeout=30) as resp:
@@ -69,8 +72,10 @@ def step_summary(text: str) -> None:
6972

7073
def load_policy() -> dict[str, Any]:
7174
if POLICY_PATH.exists():
72-
try: return json.loads(POLICY_PATH.read_text(encoding="utf-8"))
73-
except (OSError, json.JSONDecodeError): pass
75+
try:
76+
return json.loads(POLICY_PATH.read_text(encoding="utf-8"))
77+
except (OSError, json.JSONDecodeError):
78+
pass
7479
return {
7580
"version": 1,
7681
"blocked_path_patterns": [
@@ -85,8 +90,10 @@ def compile_patterns(policy: dict[str, Any]) -> list[re.Pattern[str]]:
8590
pp: list[re.Pattern[str]] = []
8691
for p in policy.get("blocked_path_patterns", []):
8792
if isinstance(p, str) and p.strip():
88-
try: pp.append(re.compile(p, re.IGNORECASE))
89-
except re.error: pass
93+
try:
94+
pp.append(re.compile(p, re.IGNORECASE))
95+
except re.error:
96+
pass
9097
return pp
9198

9299

@@ -111,8 +118,11 @@ def scan_diff(diff_text: str, path_patterns: list[re.Pattern[str]]) -> list[str]
111118
violations.append(f"**Blocked file**: `{current}` matches `{pat.pattern}`")
112119
break
113120
continue
114-
if line.startswith("+++ b/"): current = line[6:]; continue
115-
if not line.startswith("+") or line.startswith("+++"): continue
121+
if line.startswith("+++ b/"):
122+
current = line[6:]
123+
continue
124+
if not line.startswith("+") or line.startswith("+++"):
125+
continue
116126
m = _SENSITIVE.search(line[1:])
117127
if m:
118128
violations.append(f"**Hardcoded secret** in `{current}`: `{m.group(0)[:100]}`")
@@ -128,8 +138,10 @@ def check_metadata(files: list[dict[str, Any]], policy: dict[str, Any]) -> list[
128138
for f in files:
129139
fn = f.get("filename", "?")
130140
st = (f.get("status") or "").lower().strip()
131-
if st == "removed": issues.append(f"**File deleted**: `{fn}` — verify intentional")
132-
elif st == "renamed": issues.append(f"**File renamed**: `{f.get('previous_filename', '?')}` → `{fn}`")
141+
if st == "removed":
142+
issues.append(f"**File deleted**: `{fn}` — verify intentional")
143+
elif st == "renamed":
144+
issues.append(f"**File renamed**: `{f.get('previous_filename', '?')}` → `{fn}`")
133145
if len(files) > mx_f:
134146
issues.append(f"**Too many files**: {len(files)} changed (limit {mx_f})")
135147
if ta + td > mx_l:
@@ -146,10 +158,13 @@ def run_static_guard(token: str, repo: str, pr_number: int) -> int:
146158
try:
147159
batch = github_request(token, "GET",
148160
f"/repos/{repo}/pulls/{pr_number}/files?per_page=100&page={page}")
149-
except RuntimeError: break
150-
if not isinstance(batch, list) or not batch: break
161+
except RuntimeError:
162+
break
163+
if not isinstance(batch, list) or not batch:
164+
break
151165
files.extend(batch)
152-
if len(batch) < 100: break
166+
if len(batch) < 100:
167+
break
153168
page += 1
154169

155170
diff_text = ""
@@ -165,13 +180,16 @@ def run_static_guard(token: str, repo: str, pr_number: int) -> int:
165180
)
166181
with urllib.request.urlopen(req, timeout=30) as resp:
167182
diff_text = resp.read().decode("utf-8", errors="replace")
168-
except Exception: pass
183+
except Exception:
184+
pass
169185

170186
issues = check_metadata(files, policy) + scan_diff(diff_text, compile_patterns(policy))
171-
if not issues: return 0
187+
if not issues:
188+
return 0
172189

173190
print(f"STATIC → BLOCKED: {len(issues)} issue(s)")
174-
for i in issues: print(f" • {i}")
191+
for i in issues:
192+
print(f" • {i}")
175193
step_summary(f"## Merge blocked: {len(issues)} static issue(s)\n\n" +
176194
"\n".join(f"- {i}" for i in issues))
177195
return 1
@@ -181,7 +199,8 @@ def run_static_guard(token: str, repo: str, pr_number: int) -> int:
181199

182200
def get_codex_review(token: str, repo: str, pr_number: int) -> dict[str, Any] | None:
183201
reviews = github_request(token, "GET", f"/repos/{repo}/pulls/{pr_number}/reviews?per_page=100")
184-
if not isinstance(reviews, list): return None
202+
if not isinstance(reviews, list):
203+
return None
185204
for r in reversed(reviews):
186205
if isinstance(r, dict) and (r.get("user") or {}).get("login") == BOT_LOGIN:
187206
return r
@@ -228,16 +247,20 @@ def main() -> int:
228247
pr_number = pr.get("number")
229248
head_sha = (pr.get("head") or {}).get("sha")
230249
if not pr_number or not head_sha:
231-
print(f"::warning::Cannot resolve PR context"); return 0
250+
print("::warning::Cannot resolve PR context")
251+
return 0
232252

233253
print(f"PR #{pr_number} sha={head_sha[:12]} event={event_name}")
234254

235255
# ── Phase 1: Static guard (skip on review-only events) ────────────
236256
if event_name != "pull_request_review":
237-
try: rc = run_static_guard(token, repo, pr_number)
257+
try:
258+
rc = run_static_guard(token, repo, pr_number)
238259
except RuntimeError as exc:
239-
print(f"::warning::Static guard error: {exc}"); rc = 0
240-
if rc != 0: return 1
260+
print(f"::warning::Static guard error: {exc}")
261+
rc = 0
262+
if rc != 0:
263+
return 1
241264
print("STATIC → clean")
242265

243266
# ── Phase 2: App review ───────────────────────────────────────────
@@ -250,8 +273,10 @@ def main() -> int:
250273
return rc
251274

252275
# WAIT: poll for existing or upcoming review
253-
try: existing = get_codex_review(token, repo, pr_number)
254-
except RuntimeError: existing = None
276+
try:
277+
existing = get_codex_review(token, repo, pr_number)
278+
except RuntimeError:
279+
existing = None
255280

256281
if existing is not None:
257282
rc, title, summary = app_decision(existing)
@@ -266,8 +291,10 @@ def main() -> int:
266291

267292
while time.time() < deadline:
268293
time.sleep(poll_s)
269-
try: review = get_codex_review(token, repo, pr_number)
270-
except RuntimeError: continue
294+
try:
295+
review = get_codex_review(token, repo, pr_number)
296+
except RuntimeError:
297+
continue
271298
if review is not None:
272299
rc, title, summary = app_decision(review)
273300
print(f"WAIT → found review → exit={rc}: {title}")

strategy_registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
CN_EQUITY_DOMAIN,
1818
get_platform_runtime_adapter,
1919
get_qmt_rollout_allowlist,
20-
get_runtime_enabled_profiles,
2120
get_strategy_catalog,
2221
)
2322

0 commit comments

Comments
 (0)