From 8e333c20303894a59560352d6e85f4e349d61e47 Mon Sep 17 00:00:00 2001 From: brovatten Date: Wed, 10 Jun 2026 01:23:17 +0200 Subject: [PATCH] Add telemetry source attribution --- scripts/cb_engine.py | 2 ++ tests/test_cb_engine.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/scripts/cb_engine.py b/scripts/cb_engine.py index 842fb69..6f89f20 100644 --- a/scripts/cb_engine.py +++ b/scripts/cb_engine.py @@ -20,6 +20,7 @@ import argparse import json +import os import shutil from pathlib import Path @@ -142,6 +143,7 @@ def run_health(artifact_dir: str, repo: str, name: str) -> int: def main(argv=None) -> int: + os.environ.setdefault("CODEBOARDING_SOURCE", "github_action") p = argparse.ArgumentParser(description=__doc__) sub = p.add_subparsers(dest="cmd", required=True) diff --git a/tests/test_cb_engine.py b/tests/test_cb_engine.py index 523db5d..cc1c912 100644 --- a/tests/test_cb_engine.py +++ b/tests/test_cb_engine.py @@ -1,6 +1,7 @@ """Smoke tests for scripts/cb_engine.py — verify it calls the engine API correctly, using stub modules so no real engine venv is needed.""" +import os import sys import tempfile import types @@ -8,6 +9,7 @@ from contextlib import redirect_stderr from io import StringIO from pathlib import Path +from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts")) import cb_engine # noqa: E402 @@ -92,6 +94,21 @@ def test_main_parses_depth_as_int(self): ]) self.assertEqual(rf.calls[0]["depth_level"], 2) + def test_main_sets_github_action_source(self): + rf = _Rec() + self._install(run_full=rf) + with patch.dict(os.environ, {}, clear=True): + cb_engine.main([ + "base", + "--repo", "/repo", + "--out", "/out", + "--name", "myrepo", + "--run-id", "rid-base", + "--depth", "2", + "--source-sha", "abc123", + ]) + self.assertEqual(os.environ["CODEBOARDING_SOURCE"], "github_action") + def test_main_rejects_invalid_depth(self): for depth in ("0", "4", "x"): with self.subTest(depth=depth):