Stevesolun commited on
Commit
760d1fe
·
verified ·
1 Parent(s): 5f38379

Sync ctx c83b16e

Browse files

GitHub commit: c83b16ee716a7c8319b8c8e39939e6930bf717ba

.github/workflows/test.yml CHANGED
@@ -169,6 +169,8 @@ jobs:
169
 
170
  browser-security:
171
  name: "Browser monitor security"
 
 
172
  runs-on: ubuntu-latest
173
  steps:
174
  - name: Checkout
@@ -183,11 +185,30 @@ jobs:
183
  cache: pip
184
  cache-dependency-path: pyproject.toml
185
 
186
- - name: Install browser test dependencies
187
  run: |
188
  python -m pip install --upgrade pip
189
  python -m pip install ".[dev,browser]"
190
- python -m playwright install --with-deps chromium
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  - name: Run browser security tests
193
  run: pytest -q --no-cov -m browser src/tests/test_ctx_monitor_browser.py
 
169
 
170
  browser-security:
171
  name: "Browser monitor security"
172
+ needs: classify
173
+ if: ${{ github.event_name == 'push' || needs.classify.outputs.browser_changed == 'true' }}
174
  runs-on: ubuntu-latest
175
  steps:
176
  - name: Checkout
 
185
  cache: pip
186
  cache-dependency-path: pyproject.toml
187
 
188
+ - name: Install browser Python dependencies
189
  run: |
190
  python -m pip install --upgrade pip
191
  python -m pip install ".[dev,browser]"
192
+
193
+ - name: Detect Playwright version
194
+ id: playwright
195
+ run: |
196
+ python - <<'PY' >> "$GITHUB_OUTPUT"
197
+ from importlib.metadata import version
198
+
199
+ print(f"version={version('playwright')}")
200
+ PY
201
+
202
+ - name: Cache Playwright browsers
203
+ uses: actions/cache@v4
204
+ with:
205
+ path: ~/.cache/ms-playwright
206
+ key: playwright-${{ runner.os }}-${{ steps.playwright.outputs.version }}
207
+
208
+ - name: Install browser runtime
209
+ run: |
210
+ python -m playwright install-deps chromium
211
+ python -m playwright install chromium
212
 
213
  - name: Run browser security tests
214
  run: pytest -q --no-cov -m browser src/tests/test_ctx_monitor_browser.py
README.md CHANGED
@@ -18,7 +18,7 @@ tags:
18
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
19
  [![Python 3.11+](https://img.shields.io/badge/Python-3.11+-green.svg)](https://python.org)
20
  [![PyPI](https://img.shields.io/pypi/v/claude-ctx.svg)](https://pypi.org/project/claude-ctx/)
21
- [![Tests](https://img.shields.io/badge/Tests-3479_collected-brightgreen.svg)](#)
22
  [![Graph](https://img.shields.io/badge/Graph-104%2C079_nodes_/_3.0M_edges-red.svg)](graph/)
23
  [![Docs](https://img.shields.io/badge/docs-MkDocs_Material-blue.svg)](https://stevesolun.github.io/ctx/)
24
 
 
18
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
19
  [![Python 3.11+](https://img.shields.io/badge/Python-3.11+-green.svg)](https://python.org)
20
  [![PyPI](https://img.shields.io/pypi/v/claude-ctx.svg)](https://pypi.org/project/claude-ctx/)
21
+ [![Tests](https://img.shields.io/badge/Tests-3481_collected-brightgreen.svg)](#)
22
  [![Graph](https://img.shields.io/badge/Graph-104%2C079_nodes_/_3.0M_edges-red.svg)](graph/)
23
  [![Docs](https://img.shields.io/badge/docs-MkDocs_Material-blue.svg)](https://stevesolun.github.io/ctx/)
24
 
scripts/ci_required.py CHANGED
@@ -7,6 +7,18 @@ import os
7
  from typing import Any
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def failed_required_jobs(
11
  needs: dict[str, dict[str, Any]],
12
  *,
@@ -23,6 +35,13 @@ def failed_required_jobs(
23
  and result == "skipped"
24
  ):
25
  continue
 
 
 
 
 
 
 
26
  failures[name] = result
27
  return failures
28
 
 
7
  from typing import Any
8
 
9
 
10
+ def _job_output(
11
+ needs: dict[str, dict[str, Any]],
12
+ job_name: str,
13
+ output_name: str,
14
+ ) -> str | None:
15
+ outputs = needs.get(job_name, {}).get("outputs", {})
16
+ if not isinstance(outputs, dict):
17
+ return None
18
+ output = outputs.get(output_name)
19
+ return output if isinstance(output, str) else None
20
+
21
+
22
  def failed_required_jobs(
23
  needs: dict[str, dict[str, Any]],
24
  *,
 
35
  and result == "skipped"
36
  ):
37
  continue
38
+ if (
39
+ event_name == "pull_request"
40
+ and name == "browser-security"
41
+ and result == "skipped"
42
+ and _job_output(needs, "classify", "browser_changed") == "false"
43
+ ):
44
+ continue
45
  failures[name] = result
46
  return failures
47
 
src/tests/test_ci_classifier.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from pathlib import Path
 
4
 
5
  from scripts.ci_classifier import classify_paths, main
6
  from scripts.ci_required import failed_required_jobs
@@ -59,7 +60,7 @@ def test_main_writes_github_outputs(tmp_path: Path, monkeypatch) -> None:
59
 
60
 
61
  def test_ci_required_allows_pr_policy_skip_on_push_only() -> None:
62
- needs = {
63
  "static": {"result": "success"},
64
  "no-test-no-merge": {"result": "skipped"},
65
  }
@@ -71,9 +72,32 @@ def test_ci_required_allows_pr_policy_skip_on_push_only() -> None:
71
 
72
 
73
  def test_ci_required_rejects_failed_dependency() -> None:
74
- needs = {
75
  "static": {"result": "success"},
76
  "test": {"result": "failure"},
77
  }
78
 
79
  assert failed_required_jobs(needs, event_name="push") == {"test": "failure"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
 
3
  from pathlib import Path
4
+ from typing import Any
5
 
6
  from scripts.ci_classifier import classify_paths, main
7
  from scripts.ci_required import failed_required_jobs
 
60
 
61
 
62
  def test_ci_required_allows_pr_policy_skip_on_push_only() -> None:
63
+ needs: dict[str, dict[str, Any]] = {
64
  "static": {"result": "success"},
65
  "no-test-no-merge": {"result": "skipped"},
66
  }
 
72
 
73
 
74
  def test_ci_required_rejects_failed_dependency() -> None:
75
+ needs: dict[str, dict[str, Any]] = {
76
  "static": {"result": "success"},
77
  "test": {"result": "failure"},
78
  }
79
 
80
  assert failed_required_jobs(needs, event_name="push") == {"test": "failure"}
81
+
82
+
83
+ def test_ci_required_allows_browser_skip_for_unrelated_pr_only() -> None:
84
+ needs: dict[str, dict[str, Any]] = {
85
+ "classify": {"result": "success", "outputs": {"browser_changed": "false"}},
86
+ "browser-security": {"result": "skipped"},
87
+ }
88
+
89
+ assert failed_required_jobs(needs, event_name="pull_request") == {}
90
+ assert failed_required_jobs(needs, event_name="push") == {
91
+ "browser-security": "skipped",
92
+ }
93
+
94
+
95
+ def test_ci_required_rejects_browser_skip_when_classifier_requests_it() -> None:
96
+ needs: dict[str, dict[str, Any]] = {
97
+ "classify": {"result": "success", "outputs": {"browser_changed": "true"}},
98
+ "browser-security": {"result": "skipped"},
99
+ }
100
+
101
+ assert failed_required_jobs(needs, event_name="pull_request") == {
102
+ "browser-security": "skipped",
103
+ }