endofmodel 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {endofmodel-0.2.0 → endofmodel-0.3.0}/CHANGELOG.md +7 -0
  2. {endofmodel-0.2.0 → endofmodel-0.3.0}/PKG-INFO +57 -3
  3. {endofmodel-0.2.0 → endofmodel-0.3.0}/README.md +56 -2
  4. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/__init__.py +1 -1
  5. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/cli.py +89 -30
  6. endofmodel-0.3.0/src/endofmodel/report.py +141 -0
  7. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/scan.py +13 -11
  8. endofmodel-0.3.0/tests/fixtures/scan-project/NOTES.md +1 -0
  9. endofmodel-0.3.0/tests/fixtures/scan-project/app.py +4 -0
  10. endofmodel-0.3.0/tests/test_report.py +91 -0
  11. {endofmodel-0.2.0 → endofmodel-0.3.0}/.gitignore +0 -0
  12. {endofmodel-0.2.0 → endofmodel-0.3.0}/CONTRIBUTING.md +0 -0
  13. {endofmodel-0.2.0 → endofmodel-0.3.0}/LICENSE +0 -0
  14. {endofmodel-0.2.0 → endofmodel-0.3.0}/examples/README.md +0 -0
  15. {endofmodel-0.2.0 → endofmodel-0.3.0}/pyproject.toml +0 -0
  16. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/__main__.py +0 -0
  17. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/core.py +0 -0
  18. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/anthropic.json +0 -0
  19. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/gemini.json +0 -0
  20. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/microsoft.json +0 -0
  21. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/mistral.json +0 -0
  22. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/moonshot.json +0 -0
  23. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/openai.json +0 -0
  24. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/openrouter.json +0 -0
  25. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/schema.json +0 -0
  26. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/upstage.json +0 -0
  27. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/data/zai.json +0 -0
  28. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/exceptions.py +0 -0
  29. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/guard.py +0 -0
  30. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/integrations/__init__.py +0 -0
  31. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/integrations/langchain.py +0 -0
  32. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/integrations/litellm.py +0 -0
  33. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/py.typed +0 -0
  34. {endofmodel-0.2.0 → endofmodel-0.3.0}/src/endofmodel/registry.py +0 -0
  35. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/conftest.py +0 -0
  36. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_core.py +0 -0
  37. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_examples.py +0 -0
  38. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_guard.py +0 -0
  39. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_integration_langchain.py +0 -0
  40. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_integration_litellm.py +0 -0
  41. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_openrouter.py +0 -0
  42. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_registry.py +0 -0
  43. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_scan_cli.py +0 -0
  44. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_sdks.py +0 -0
  45. {endofmodel-0.2.0 → endofmodel-0.3.0}/tests/test_sync_openrouter.py +0 -0
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2026-12-02)
4
+
5
+ - GitHub Action (`uses: Agentdrops/endofmodel@v0.3.0`): annotates the exact lines in pull requests, writes a job summary, and can upload SARIF to code scanning (`upload-sarif: true`). Outputs `failed`, `findings`, `sarif-file`.
6
+ - pre-commit hook (`id: endofmodel`): scans staged files.
7
+ - `endofmodel scan`: `--format sarif` (SARIF 2.1.0, validated against the official schema) and `--format github` (workflow annotations), `-o/--output FILE`, several paths at once. Paths are reported relative to the current directory (`scan src` reports `src/app.py`).
8
+ - `endofmodel.scan.fails()`: whether a single finding fails the gate.
9
+
3
10
  ## 0.2.0 (2026-12-02)
4
11
 
5
12
  - LiteLLM callback (`endofmodel.integrations.litellm`): `install()`, or `handler` for the LiteLLM proxy. Warns before each call and flags silent redirects, for every provider LiteLLM routes to; OpenRouter routing gets OpenRouter's schedule. Extra: `endofmodel[litellm]`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: endofmodel
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Know before your LLM model dies: warnings, CI checks and silent-redirect detection for deprecated OpenAI, Anthropic and Gemini models.
5
5
  Project-URL: Homepage, https://github.com/Agentdrops/endofmodel
6
6
  Project-URL: Issues, https://github.com/Agentdrops/endofmodel/issues
@@ -177,12 +177,65 @@ FAILED: retired models or models retiring within 30 days.
177
177
  ```
178
178
 
179
179
  Exit code is `1` when the gate fails, so CI blocks the merge. Mentions in `.md`/`.txt` files are
180
- reported but never fail the build. GitHub Actions:
180
+ reported but never fail the build. `scan` takes several files or folders, and
181
+ `--format json | sarif | github` (with `-o FILE`) for machine-readable output.
182
+
183
+ #### GitHub Action
184
+
185
+ Findings show up as annotations on the exact lines of the pull request, plus a summary on
186
+ the run page:
181
187
 
182
188
  ```yaml
183
- - run: pipx run endofmodel scan . --fail-under-days 30
189
+ # .github/workflows/endofmodel.yml
190
+ name: endofmodel
191
+ on: [pull_request]
192
+ jobs:
193
+ scan:
194
+ runs-on: ubuntu-latest
195
+ steps:
196
+ - uses: actions/checkout@v4
197
+ - uses: Agentdrops/endofmodel@v0.3.0
198
+ with:
199
+ path: . # files or folders, space-separated
200
+ fail-under-days: 30
184
201
  ```
185
202
 
203
+ To get the findings as **code scanning alerts** as well (a Security tab, alerts on PRs,
204
+ dismiss/track per alert), upload the SARIF report. This needs code scanning: public repos,
205
+ or GitHub Advanced Security on private ones.
206
+
207
+ ```yaml
208
+ permissions:
209
+ contents: read
210
+ security-events: write
211
+ steps:
212
+ - uses: actions/checkout@v4
213
+ - uses: Agentdrops/endofmodel@v0.3.0
214
+ with:
215
+ upload-sarif: true
216
+ ```
217
+
218
+ Inputs: `path`, `fail-under-days`, `fail-on-findings` (`false` = report only), `annotations`,
219
+ `sarif-file`, `upload-sarif`, `version`, `python-version`. Outputs: `failed`, `findings`,
220
+ `sarif-file`. The action runs endofmodel in its own virtualenv and doesn't touch your Python.
221
+ Other CI systems: `pipx run endofmodel scan . --format sarif -o endofmodel.sarif`.
222
+
223
+ #### pre-commit
224
+
225
+ Stop a retired model from being committed in the first place:
226
+
227
+ ```yaml
228
+ # .pre-commit-config.yaml
229
+ repos:
230
+ - repo: https://github.com/Agentdrops/endofmodel
231
+ rev: v0.3.0
232
+ hooks:
233
+ - id: endofmodel
234
+ # args: [--fail-under-days, "14"]
235
+ ```
236
+
237
+ Only the staged files are scanned, so it's fast.
238
+
186
239
  ### List what's retiring soon
187
240
 
188
241
  ```bash
@@ -272,6 +325,7 @@ at a folder of JSON files in the same format. Entries there override the bundled
272
325
  - [ ] v0.2: scrape official provider deprecation pages for OpenAI / Anthropic / Gemini
273
326
  - [ ] v0.3: Azure OpenAI, Amazon Bedrock, Vertex AI, Groq
274
327
  - [x] v0.2: LangChain and LiteLLM callbacks
328
+ - [x] v0.3: GitHub Action (PR annotations, SARIF / code scanning) and pre-commit hook
275
329
  - [ ] v0.4: google-genai SDK adapter, Slack & OpenTelemetry notifiers
276
330
  - [ ] v0.5: optional `endofmodel update` to fetch the latest registry (cached)
277
331
 
@@ -134,12 +134,65 @@ FAILED: retired models or models retiring within 30 days.
134
134
  ```
135
135
 
136
136
  Exit code is `1` when the gate fails, so CI blocks the merge. Mentions in `.md`/`.txt` files are
137
- reported but never fail the build. GitHub Actions:
137
+ reported but never fail the build. `scan` takes several files or folders, and
138
+ `--format json | sarif | github` (with `-o FILE`) for machine-readable output.
139
+
140
+ #### GitHub Action
141
+
142
+ Findings show up as annotations on the exact lines of the pull request, plus a summary on
143
+ the run page:
138
144
 
139
145
  ```yaml
140
- - run: pipx run endofmodel scan . --fail-under-days 30
146
+ # .github/workflows/endofmodel.yml
147
+ name: endofmodel
148
+ on: [pull_request]
149
+ jobs:
150
+ scan:
151
+ runs-on: ubuntu-latest
152
+ steps:
153
+ - uses: actions/checkout@v4
154
+ - uses: Agentdrops/endofmodel@v0.3.0
155
+ with:
156
+ path: . # files or folders, space-separated
157
+ fail-under-days: 30
141
158
  ```
142
159
 
160
+ To get the findings as **code scanning alerts** as well (a Security tab, alerts on PRs,
161
+ dismiss/track per alert), upload the SARIF report. This needs code scanning: public repos,
162
+ or GitHub Advanced Security on private ones.
163
+
164
+ ```yaml
165
+ permissions:
166
+ contents: read
167
+ security-events: write
168
+ steps:
169
+ - uses: actions/checkout@v4
170
+ - uses: Agentdrops/endofmodel@v0.3.0
171
+ with:
172
+ upload-sarif: true
173
+ ```
174
+
175
+ Inputs: `path`, `fail-under-days`, `fail-on-findings` (`false` = report only), `annotations`,
176
+ `sarif-file`, `upload-sarif`, `version`, `python-version`. Outputs: `failed`, `findings`,
177
+ `sarif-file`. The action runs endofmodel in its own virtualenv and doesn't touch your Python.
178
+ Other CI systems: `pipx run endofmodel scan . --format sarif -o endofmodel.sarif`.
179
+
180
+ #### pre-commit
181
+
182
+ Stop a retired model from being committed in the first place:
183
+
184
+ ```yaml
185
+ # .pre-commit-config.yaml
186
+ repos:
187
+ - repo: https://github.com/Agentdrops/endofmodel
188
+ rev: v0.3.0
189
+ hooks:
190
+ - id: endofmodel
191
+ # args: [--fail-under-days, "14"]
192
+ ```
193
+
194
+ Only the staged files are scanned, so it's fast.
195
+
143
196
  ### List what's retiring soon
144
197
 
145
198
  ```bash
@@ -229,6 +282,7 @@ at a folder of JSON files in the same format. Entries there override the bundled
229
282
  - [ ] v0.2: scrape official provider deprecation pages for OpenAI / Anthropic / Gemini
230
283
  - [ ] v0.3: Azure OpenAI, Amazon Bedrock, Vertex AI, Groq
231
284
  - [x] v0.2: LangChain and LiteLLM callbacks
285
+ - [x] v0.3: GitHub Action (PR annotations, SARIF / code scanning) and pre-commit hook
232
286
  - [ ] v0.4: google-genai SDK adapter, Slack & OpenTelemetry notifiers
233
287
  - [ ] v0.5: optional `endofmodel update` to fetch the latest registry (cached)
234
288
 
@@ -13,7 +13,7 @@ Quick start::
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
- __version__ = "0.2.0"
16
+ __version__ = "0.3.0"
17
17
 
18
18
  from .core import ModelStatus, Status, assert_models_ok, check
19
19
  from .exceptions import (
@@ -4,14 +4,17 @@ from __future__ import annotations
4
4
 
5
5
  import argparse
6
6
  import json
7
+ import os
7
8
  import sys
8
9
  from collections.abc import Sequence
10
+ from dataclasses import replace
9
11
  from datetime import date
10
12
 
11
13
  from . import __version__
12
14
  from .core import Status, check
13
15
  from .registry import get_registry
14
- from .scan import gate, scan
16
+ from .report import to_github_annotations, to_sarif
17
+ from .scan import Finding, gate, scan
15
18
 
16
19
  _ICON = {"retired": "✖", "critical": "!", "warn": "~", "info": "·"}
17
20
 
@@ -41,11 +44,58 @@ def cmd_check(args) -> int:
41
44
  return 1 if bad else 0
42
45
 
43
46
 
47
+ def _display_path(root: str, finding_path: str) -> str:
48
+ """Path relative to the current directory when possible, so editors, CI annotations and
49
+ SARIF can find the file (``scan src`` reports ``src/app.py``, not ``app.py``)."""
50
+ full = os.path.join(root, finding_path) if os.path.isdir(root) else finding_path
51
+ full = os.path.normpath(full)
52
+ try:
53
+ rel = os.path.relpath(full)
54
+ except ValueError: # different drive on Windows
55
+ return full
56
+ return full if rel.startswith("..") else rel.replace(os.sep, "/")
57
+
58
+
59
+ def _scan_paths(paths: list) -> list[Finding]:
60
+ findings: list[Finding] = []
61
+ seen = set()
62
+ for root in paths:
63
+ for f in scan(root):
64
+ f = replace(f, path=_display_path(root, f.path))
65
+ key = (f.path, f.line, f.column)
66
+ if key not in seen:
67
+ seen.add(key)
68
+ findings.append(f)
69
+ order = {"retired": 0, "critical": 1, "warn": 2, "info": 3}
70
+ findings.sort(key=lambda f: (order[f.severity], f.path, f.line))
71
+ return findings
72
+
73
+
44
74
  def cmd_scan(args) -> int:
45
- findings = scan(args.path)
75
+ findings = _scan_paths(args.paths or ["."])
46
76
  failed = gate(findings, args.fail_under_days)
47
- if args.json:
48
- print(
77
+ fmt = "json" if args.json else args.format
78
+ out = open(args.output, "w", encoding="utf-8") if args.output else sys.stdout
79
+ try:
80
+ _print_scan(fmt, findings, failed, args.fail_under_days, out)
81
+ finally:
82
+ if args.output:
83
+ out.close()
84
+ return 1 if failed else 0
85
+
86
+
87
+ def _print_scan(fmt: str, findings: list, failed: bool, days: int, out) -> None:
88
+ def emit(text: str = "") -> None:
89
+ print(text, file=out)
90
+
91
+ if fmt == "sarif":
92
+ emit(json.dumps(to_sarif(findings, days, __version__), indent=2))
93
+ elif fmt == "github":
94
+ for line in to_github_annotations(findings, days):
95
+ emit(line)
96
+ _print_text(findings, failed, days, emit)
97
+ elif fmt == "json":
98
+ emit(
49
99
  json.dumps(
50
100
  {
51
101
  "failed": failed,
@@ -64,29 +114,30 @@ def cmd_scan(args) -> int:
64
114
  )
65
115
  )
66
116
  else:
67
- if not findings:
68
- print("No deprecated or retired model IDs found.")
69
- for f in findings:
70
- s = f.status
71
- when = (
72
- f"retires {s.retires_on} ({s.days_left}d)"
73
- if s.status is Status.DEPRECATED
74
- else f"{s.status.value} {s.retires_on or ''}".strip()
75
- )
76
- repl = f" -> {s.replacement}" if s.replacement else ""
77
- doc = " [docs]" if f.is_doc else ""
78
- print(f"{_icon(f)} {f.path}:{f.line}:{f.column} {f.model} {when}{repl}{doc}")
79
- if findings:
80
- counts: dict = {}
81
- for f in findings:
82
- counts[f.severity] = counts.get(f.severity, 0) + 1
83
- summary = ", ".join(f"{v} {k}" for k, v in counts.items())
84
- print(f"\n{len(findings)} finding(s): {summary}")
85
- if failed:
86
- print(
87
- f"FAILED: retired models or models retiring within {args.fail_under_days} days."
88
- )
89
- return 1 if failed else 0
117
+ _print_text(findings, failed, days, emit)
118
+
119
+
120
+ def _print_text(findings: list, failed: bool, days: int, emit) -> None:
121
+ if not findings:
122
+ emit("No deprecated or retired model IDs found.")
123
+ return
124
+ for f in findings:
125
+ s = f.status
126
+ when = (
127
+ f"retires {s.retires_on} ({s.days_left}d)"
128
+ if s.status is Status.DEPRECATED
129
+ else f"{s.status.value} {s.retires_on or ''}".strip()
130
+ )
131
+ repl = f" -> {s.replacement}" if s.replacement else ""
132
+ doc = " [docs]" if f.is_doc else ""
133
+ emit(f"{_icon(f)} {f.path}:{f.line}:{f.column} {f.model} {when}{repl}{doc}")
134
+ counts: dict = {}
135
+ for f in findings:
136
+ counts[f.severity] = counts.get(f.severity, 0) + 1
137
+ summary = ", ".join(f"{v} {k}" for k, v in counts.items())
138
+ emit(f"\n{len(findings)} finding(s): {summary}")
139
+ if failed:
140
+ emit(f"FAILED: retired models or models retiring within {days} days.")
90
141
 
91
142
 
92
143
  def _icon(f) -> str:
@@ -151,15 +202,23 @@ def build_parser() -> argparse.ArgumentParser:
151
202
  c.add_argument("--json", action="store_true")
152
203
  c.set_defaults(func=cmd_check)
153
204
 
154
- s = sub.add_parser("scan", help="scan a folder for deprecated/retired model IDs (CI gate)")
155
- s.add_argument("path", nargs="?", default=".")
205
+ s = sub.add_parser("scan", help="scan files/folders for deprecated/retired model IDs (CI gate)")
206
+ s.add_argument("paths", nargs="*", metavar="PATH", help="files or folders (default: .)")
156
207
  s.add_argument(
157
208
  "--fail-under-days",
158
209
  type=int,
159
210
  default=30,
160
211
  help="fail if a model retires within N days (default 30)",
161
212
  )
162
- s.add_argument("--json", action="store_true")
213
+ s.add_argument(
214
+ "--format",
215
+ choices=["text", "json", "sarif", "github"],
216
+ default="text",
217
+ help="text (default), json, sarif (GitHub code scanning etc.), "
218
+ "github (workflow annotations on the PR diff, plus the text report)",
219
+ )
220
+ s.add_argument("--json", action="store_true", help="same as --format json")
221
+ s.add_argument("-o", "--output", metavar="FILE", help="write the report to FILE")
163
222
  s.set_defaults(func=cmd_scan)
164
223
 
165
224
  ls = sub.add_parser("list", help="list registry entries")
@@ -0,0 +1,141 @@
1
+ """Machine-readable scan output: SARIF 2.1.0 and GitHub Actions workflow annotations.
2
+
3
+ SARIF is what GitHub code scanning (and most other code-review tools) ingest; uploaded
4
+ results appear as alerts on the exact lines of a pull request. Workflow annotations need no
5
+ setup at all: GitHub shows them inline in the PR's "Files changed" view.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from .core import Status
11
+ from .scan import Finding, fails
12
+
13
+ SARIF_SCHEMA = "https://json.schemastore.org/sarif-2.1.0.json"
14
+ HELP_URI = "https://github.com/Agentdrops/endofmodel#ci-gate"
15
+
16
+ RULES = {
17
+ "retired-model": {
18
+ "name": "RetiredModel",
19
+ "short": "Retired LLM model",
20
+ "full": "This model ID has been retired by its provider: requests fail, or are "
21
+ "silently served by a different model.",
22
+ "level": "error",
23
+ },
24
+ "deprecated-model": {
25
+ "name": "DeprecatedModel",
26
+ "short": "Deprecated LLM model",
27
+ "full": "This model ID is deprecated and has a retirement date (or one is coming). "
28
+ "Migrate to the replacement before it stops working.",
29
+ "level": "warning",
30
+ },
31
+ }
32
+
33
+
34
+ def rule_id(f: Finding) -> str:
35
+ retired = f.status.status in (Status.RETIRED, Status.REDIRECTED)
36
+ return "retired-model" if retired else "deprecated-model"
37
+
38
+
39
+ def level(f: Finding, fail_under_days: int) -> str:
40
+ """``error`` if it fails the gate, ``note`` for docs, ``warning`` otherwise."""
41
+ if fails(f, fail_under_days):
42
+ return "error"
43
+ return "note" if f.is_doc else "warning"
44
+
45
+
46
+ def _uri(path: str) -> str:
47
+ return path.replace("\\", "/").removeprefix("./")
48
+
49
+
50
+ def to_sarif(findings: list[Finding], fail_under_days: int, version: str) -> dict:
51
+ rules = [
52
+ {
53
+ "id": rid,
54
+ "name": r["name"],
55
+ "shortDescription": {"text": r["short"]},
56
+ "fullDescription": {"text": r["full"]},
57
+ "helpUri": HELP_URI,
58
+ "defaultConfiguration": {"level": r["level"]},
59
+ "properties": {"tags": ["llm", "deprecation", "maintainability"]},
60
+ }
61
+ for rid, r in RULES.items()
62
+ ]
63
+ results = []
64
+ for f in findings:
65
+ s = f.status
66
+ results.append(
67
+ {
68
+ "ruleId": rule_id(f),
69
+ "level": level(f, fail_under_days),
70
+ "message": {"text": s.describe()},
71
+ "locations": [
72
+ {
73
+ "physicalLocation": {
74
+ "artifactLocation": {"uri": _uri(f.path), "uriBaseId": "%SRCROOT%"},
75
+ "region": {
76
+ "startLine": f.line,
77
+ "startColumn": f.column,
78
+ "endColumn": f.column + len(f.model),
79
+ },
80
+ }
81
+ }
82
+ ],
83
+ "properties": {
84
+ "model": f.model,
85
+ "provider": s.provider,
86
+ "status": s.status.value,
87
+ "retires_on": s.retires_on.isoformat() if s.retires_on else None,
88
+ "days_left": s.days_left,
89
+ "replacement": s.replacement,
90
+ },
91
+ }
92
+ )
93
+ return {
94
+ "$schema": SARIF_SCHEMA,
95
+ "version": "2.1.0",
96
+ "runs": [
97
+ {
98
+ "tool": {
99
+ "driver": {
100
+ "name": "endofmodel",
101
+ "version": version,
102
+ "informationUri": "https://github.com/Agentdrops/endofmodel",
103
+ "rules": rules,
104
+ }
105
+ },
106
+ "results": results,
107
+ }
108
+ ],
109
+ }
110
+
111
+
112
+ def _escape_data(value: str) -> str:
113
+ return value.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
114
+
115
+
116
+ def _escape_property(value: str) -> str:
117
+ return _escape_data(value).replace(":", "%3A").replace(",", "%2C")
118
+
119
+
120
+ _COMMAND = {"error": "error", "warning": "warning", "note": "notice"}
121
+
122
+
123
+ def to_github_annotations(findings: list[Finding], fail_under_days: int) -> list[str]:
124
+ """One ``::error file=...,line=...::message`` workflow command per finding."""
125
+ lines = []
126
+ for f in findings:
127
+ s = f.status
128
+ title = f"{'Retired' if rule_id(f) == 'retired-model' else 'Deprecated'} model: {f.model}"
129
+ props = ",".join(
130
+ f"{k}={_escape_property(str(v))}"
131
+ for k, v in (
132
+ ("file", _uri(f.path)),
133
+ ("line", f.line),
134
+ ("col", f.column),
135
+ ("endColumn", f.column + len(f.model)),
136
+ ("title", title),
137
+ )
138
+ )
139
+ cmd = _COMMAND[level(f, fail_under_days)]
140
+ lines.append(f"::{cmd} {props}::{_escape_data(s.describe())}")
141
+ return lines
@@ -143,15 +143,17 @@ def scan(
143
143
  return findings
144
144
 
145
145
 
146
+ def fails(finding: Finding, fail_under_days: int) -> bool:
147
+ """True if this finding should fail the build: a retired model, or one retiring within
148
+ ``fail_under_days``. Documentation-only mentions never fail."""
149
+ if finding.is_doc:
150
+ return False
151
+ s = finding.status
152
+ if s.status in (Status.RETIRED, Status.REDIRECTED):
153
+ return True
154
+ return s.days_left is not None and s.days_left <= fail_under_days
155
+
156
+
146
157
  def gate(findings: list[Finding], fail_under_days: int) -> bool:
147
- """True if the build should fail: a retired model, or one retiring within the window.
148
- Documentation-only mentions never fail the gate."""
149
- for f in findings:
150
- if f.is_doc:
151
- continue
152
- s = f.status
153
- if s.status in (Status.RETIRED, Status.REDIRECTED):
154
- return True
155
- if s.days_left is not None and s.days_left <= fail_under_days:
156
- return True
157
- return False
158
+ """True if the build should fail (see :func:`fails`)."""
159
+ return any(fails(f, fail_under_days) for f in findings)
@@ -0,0 +1 @@
1
+ We migrated away from gpt-4o-2024-05-13.
@@ -0,0 +1,4 @@
1
+ # Test fixture for the GitHub Action self-test. Do not "fix" these model IDs.
2
+ CHAT_MODEL = "gpt-4o-2024-05-13" # retired
3
+ SUMMARY_MODEL = "claude-opus-4-5-20251101" # deprecated
4
+ CURRENT = "gpt-6-luna" # fine
@@ -0,0 +1,91 @@
1
+ import json
2
+
3
+ import pytest
4
+
5
+ from endofmodel import scan
6
+ from endofmodel.cli import main
7
+ from endofmodel.report import to_github_annotations, to_sarif
8
+
9
+
10
+ @pytest.fixture
11
+ def project(tmp_path, monkeypatch):
12
+ root = tmp_path / "repo"
13
+ (root / "src").mkdir(parents=True)
14
+ (root / "src" / "app.py").write_text(
15
+ 'A = "test-retired-model"\nB = "test-deprecated-model"\nC = "fine-model"\n'
16
+ )
17
+ (root / "README.md").write_text("Old: test-retired-model\n")
18
+ monkeypatch.chdir(root)
19
+ return root
20
+
21
+
22
+ def _results(sarif):
23
+ return [
24
+ (
25
+ r["ruleId"],
26
+ r["level"],
27
+ r["locations"][0]["physicalLocation"]["artifactLocation"]["uri"],
28
+ r["locations"][0]["physicalLocation"]["region"]["startLine"],
29
+ )
30
+ for r in sarif["runs"][0]["results"]
31
+ ]
32
+
33
+
34
+ def test_sarif_levels_follow_the_gate(project):
35
+ sarif = to_sarif(scan("."), fail_under_days=30, version="9.9.9")
36
+ assert sarif["version"] == "2.1.0"
37
+ driver = sarif["runs"][0]["tool"]["driver"]
38
+ assert driver["name"] == "endofmodel" and driver["version"] == "9.9.9"
39
+ assert {r["id"] for r in driver["rules"]} == {"retired-model", "deprecated-model"}
40
+ assert sorted(_results(sarif)) == [
41
+ ("deprecated-model", "warning", "src/app.py", 2), # retires in 2999: not failing
42
+ ("retired-model", "error", "src/app.py", 1),
43
+ ("retired-model", "note", "README.md", 1), # docs never fail
44
+ ]
45
+ region = sarif["runs"][0]["results"][0]["locations"][0]["physicalLocation"]["region"]
46
+ assert region["endColumn"] > region["startColumn"]
47
+
48
+
49
+ def test_sarif_deprecated_becomes_error_inside_window(project):
50
+ sarif = to_sarif(scan("."), fail_under_days=10**6, version="x")
51
+ assert ("deprecated-model", "error", "src/app.py", 2) in _results(sarif)
52
+
53
+
54
+ def test_github_annotations_and_escaping(project):
55
+ lines = to_github_annotations(scan("."), fail_under_days=30)
56
+ assert any(
57
+ line.startswith("::error file=src/app.py,line=1,col=6,endColumn=24,") for line in lines
58
+ )
59
+ assert any(line.startswith("::notice file=README.md,") for line in lines)
60
+ assert any(line.startswith("::warning ") for line in lines)
61
+ for line in lines:
62
+ props = line.split("::")[1]
63
+ assert "title=Retired model%3A " in props or "title=Deprecated model%3A " in props
64
+ assert "\n" not in line
65
+
66
+
67
+ def test_cli_sarif_to_file(project, capsys):
68
+ assert main(["scan", "--format", "sarif", "-o", "out.sarif"]) == 1 # gate still applies
69
+ assert capsys.readouterr().out == ""
70
+ sarif = json.loads((project / "out.sarif").read_text())
71
+ assert len(sarif["runs"][0]["results"]) == 3
72
+
73
+
74
+ def test_cli_github_format_prints_annotations_and_report(project, capsys):
75
+ assert main(["scan", "src", "--format", "github"]) == 1
76
+ out = capsys.readouterr().out
77
+ assert "::error file=src/app.py,line=1" in out # path relative to cwd, not to "src"
78
+ assert "FAILED" in out
79
+
80
+
81
+ def test_cli_multiple_paths_for_pre_commit(project, capsys):
82
+ assert main(["scan", "README.md"]) == 0 # docs only: reported, never fails
83
+ assert main(["scan", "README.md", "src/app.py"]) == 1
84
+ out = capsys.readouterr().out
85
+ assert "src/app.py:1:" in out and "README.md:1:" in out
86
+
87
+
88
+ def test_cli_same_file_twice_is_reported_once(project, capsys):
89
+ main(["scan", "src", "src/app.py", "--json"])
90
+ data = json.loads(capsys.readouterr().out)
91
+ assert len(data["findings"]) == 2
File without changes
File without changes
File without changes
File without changes
File without changes