feat(clients): optional project_slug and gitea_repo on ingest context
PHP + Node reporters read ERROR_REPORTING_* env; ingest-api tests run contract on clients/. Paperclip-Agent: 11179220-3cec-4f0f-880d-2771ff64fce8 Paperclip-Issue: BIT-1310 Paperclip-Run: 35ce1c21-9862-4c60-8b58-441d53b4b3bd
This commit is contained in:
1 parent
54645842f7
commit
a51b3e987a
4 files changed
+132
-1
No files matched your search
@@ -12,6 +12,9 @@
|
||||
* ERROR_REPORTING_TOKEN — ingest API key (Bearer token)
|
||||
* ERROR_REPORTING_ENDPOINT — base URL (default: https://errors.bitreport.pt)
|
||||
* ERROR_REPORTING_DISABLED — set to "1" to disable
|
||||
* ERROR_REPORTING_PROJECT_NAME — display name in ingest context (optional)
|
||||
* ERROR_REPORTING_PROJECT_SLUG — stable product slug (optional)
|
||||
* ERROR_REPORTING_GITEA_REPO — canonical owner/repo on Gitea (optional)
|
||||
*/
|
||||
|
||||
let _token = '';
|
||||
|
||||
@@ -14,6 +14,8 @@ declare(strict_types=1);
|
||||
* ERROR_REPORTING_TOKEN — ingest API key (required)
|
||||
* ERROR_REPORTING_ENDPOINT — base URL (default: https://errors.bitreport.pt)
|
||||
* ERROR_REPORTING_DISABLED — set to "1" to disable
|
||||
* ERROR_REPORTING_PROJECT_SLUG — stable product slug for ERRSIG / Paperclip routing (optional)
|
||||
* ERROR_REPORTING_GITEA_REPO — canonical owner/repo on Gitea, e.g. BitReport.pt/my-product (optional)
|
||||
*/
|
||||
|
||||
namespace BitReport;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"build": "tsc",
|
||||
"start": "node dist/server.js",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test": "vitest run && python3 ../tools/ci/check_error_reporter_context_contract.py --path ../clients",
|
||||
"test:watch": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CI gate: shipped ingest clients must document project_slug + gitea_repo routing."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
SCAN_EXTENSIONS = {".php", ".js", ".mjs", ".cjs", ".ts", ".py"}
|
||||
EXCLUDE_PATTERNS = (
|
||||
".git/*",
|
||||
"node_modules/*",
|
||||
"vendor/*",
|
||||
".venv/*",
|
||||
"venv/*",
|
||||
"__pycache__/*",
|
||||
"dist/*",
|
||||
"build/*",
|
||||
)
|
||||
|
||||
REPORTER_MARKERS = (
|
||||
"php-error",
|
||||
"js-error",
|
||||
"error-monitoring",
|
||||
"reporterror(",
|
||||
"reportmessage(",
|
||||
"sendtoingestapi",
|
||||
"/v1/ingest/events",
|
||||
)
|
||||
|
||||
SLUG_MARKERS = (
|
||||
"project_slug",
|
||||
"projectslug",
|
||||
"error_monitoring_project_slug",
|
||||
"error_reporting_project_slug",
|
||||
)
|
||||
|
||||
REPO_MARKERS = (
|
||||
"gitea_repo",
|
||||
"gitearepo",
|
||||
"error_monitoring_gitea_repo",
|
||||
"error_reporting_gitea_repo",
|
||||
)
|
||||
|
||||
|
||||
def _is_excluded(rel_path: str) -> bool:
|
||||
norm = rel_path.replace("\\", "/")
|
||||
if "/node_modules/" in norm or norm.startswith("node_modules/"):
|
||||
return True
|
||||
if "/vendor/" in norm or norm.startswith("vendor/"):
|
||||
return True
|
||||
return any(fnmatch.fnmatch(rel_path, pattern) for pattern in EXCLUDE_PATTERNS)
|
||||
|
||||
|
||||
def _is_candidate_file(rel_path: str, text_lower: str) -> bool:
|
||||
if _is_excluded(rel_path):
|
||||
return False
|
||||
if Path(rel_path).suffix.lower() not in SCAN_EXTENSIONS:
|
||||
return False
|
||||
name = Path(rel_path).name.lower()
|
||||
has_reporter_naming = (
|
||||
"reporter" in name
|
||||
or "errorreporter" in text_lower
|
||||
or "errormonitoringreporter" in text_lower
|
||||
)
|
||||
if not has_reporter_naming:
|
||||
return False
|
||||
return any(marker in text_lower for marker in REPORTER_MARKERS)
|
||||
|
||||
|
||||
def _contract_ok(text_lower: str) -> tuple[bool, bool]:
|
||||
has_slug = any(marker in text_lower for marker in SLUG_MARKERS)
|
||||
has_repo = any(marker in text_lower for marker in REPO_MARKERS)
|
||||
return has_slug, has_repo
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Verify error reporter context contract in repository files.")
|
||||
parser.add_argument(
|
||||
"--path",
|
||||
default=str(REPO_ROOT),
|
||||
help="Repository root to scan.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
root = Path(args.path).resolve()
|
||||
if not root.is_dir():
|
||||
print(f"error: scan root does not exist: {root}")
|
||||
return 2
|
||||
|
||||
failures: list[tuple[str, bool, bool]] = []
|
||||
candidates = 0
|
||||
|
||||
for file_path in root.rglob("*"):
|
||||
if not file_path.is_file():
|
||||
continue
|
||||
rel = file_path.relative_to(root).as_posix()
|
||||
if _is_excluded(rel):
|
||||
continue
|
||||
try:
|
||||
content = file_path.read_text(encoding="utf-8", errors="ignore")
|
||||
except OSError:
|
||||
continue
|
||||
low = content.lower()
|
||||
if not _is_candidate_file(rel, low):
|
||||
continue
|
||||
candidates += 1
|
||||
has_slug, has_repo = _contract_ok(low)
|
||||
if not (has_slug and has_repo):
|
||||
failures.append((rel, has_slug, has_repo))
|
||||
|
||||
print(f"reporter_contract_candidates={candidates}")
|
||||
if not failures:
|
||||
print("reporter_context_contract=ok")
|
||||
return 0
|
||||
|
||||
print("reporter_context_contract=failed")
|
||||
for rel, has_slug, has_repo in failures:
|
||||
print(f"- {rel}: has_project_slug={int(has_slug)} has_gitea_repo={int(has_repo)}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user