diff --git a/CHANGELOG.md b/CHANGELOG.md index 6655ee3..cc470b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project follows the structure from Keep a Changelog and intends to use Sema ### Fixed +- **CLI flags no longer open the TUI:** `github-usage --export` / `--no-interactive` (and any other dashed argv, including `github-usage -v`) stay on the CLI when stdin and stdout are TTYs. Only a bare `github-usage` in a terminal launches the Textual app. `./start.sh -v` is unchanged because `start.sh` already maps `-v` to `--version` before Python routing. - **Artifact storage partial failures:** a per-repo artifact API error no longer blanks the whole Actions Artifact Storage section — successfully scanned repos still render, and failed repos are listed as skipped in the text/HTML email and PDF exports. - **Email Actions section:** plain-text and HTML emails show **private-repo quota** against the 2,000 min / 500 MB free tier (with public usage labeled free) instead of comparing combined account totals to the private quota. When no visibility split is available, the report says so explicitly rather than implying the total is all quota-counted. - **Copilot AI credits:** email report data now reads GitHub's `…/billing/ai_credit/usage` endpoint (preferred over legacy premium-request usage after Copilot's 2026 metering change) and labels the email Copilot section and forecast row accordingly; org-licensed Copilot without personal usage gets an explanatory note. Usage displays **credit quantities** (`grossQuantity`) rather than dollar `netAmount`, which is often zero on included allowance. Failed usage API calls surface as report errors or notes instead of looking like zero usage. Forecast exports (CSV/XLSX/PDF/legacy) use the same Copilot metric label as email. diff --git a/scripts/check b/scripts/check index 2600f8f..87b00a5 100755 --- a/scripts/check +++ b/scripts/check @@ -8,7 +8,30 @@ echo "==> Python syntax" scripts/python -m py_compile github-usage src/github_usage/*.py echo "==> Unit tests" -PYTHONPATH=src scripts/python -m unittest discover -s tests -v +unit_pid="" +cleanup_unit() { + if [ -n "${unit_pid}" ]; then + kill -9 "$unit_pid" 2>/dev/null || true + fi +} +trap cleanup_unit EXIT +PYTHONPATH=src scripts/python -m unittest discover -s tests -v /dev/null; do + if [ "$i" -ge 180 ]; then + echo "unit tests exceeded 180s" >&2 + kill -9 "$unit_pid" 2>/dev/null || true + wait "$unit_pid" 2>/dev/null || true + unit_pid="" + exit 1 + fi + sleep 1 + i=$((i + 1)) +done +wait "$unit_pid" +unit_pid="" +trap - EXIT echo "==> CLI smoke" test -x start.sh diff --git a/scripts/coverage-check b/scripts/coverage-check index 2e110c1..df8252d 100755 --- a/scripts/coverage-check +++ b/scripts/coverage-check @@ -15,7 +15,7 @@ TOTAL_MIN="${COVERAGE_TOTAL_MIN:-75}" FILE_MIN="${COVERAGE_FILE_MIN:-82}" echo "==> Running tests under coverage (src only)" -PYTHONPATH=src scripts/python -m coverage run --source="$SRC" -m unittest discover -s tests +PYTHONPATH=src scripts/python -m coverage run --source="$SRC" -m unittest discover -s tests Coverage report" PYTHONPATH=src scripts/python -m coverage report diff --git a/src/github_usage/cli_gui.py b/src/github_usage/cli_gui.py index fd59f4c..2dcb8b0 100644 --- a/src/github_usage/cli_gui.py +++ b/src/github_usage/cli_gui.py @@ -76,7 +76,7 @@ def route_entry(argv: Sequence[str]) -> RouteResult: if cli_mode: return RouteResult(handled=False, argv=stripped) - if sys.stdin.isatty() and sys.stdout.isatty(): + if not stripped and sys.stdin.isatty() and sys.stdout.isatty(): return RouteResult(handled=True, argv=[], exit_code=run_tui()) if not stripped: diff --git a/tests/test_gui_models.py b/tests/test_gui_models.py index 4cf6f7a..6d303b1 100644 --- a/tests/test_gui_models.py +++ b/tests/test_gui_models.py @@ -64,6 +64,19 @@ def test_tty_default_launches_tui(self) -> None: self.assertEqual(result.exit_code, 0) run_tui.assert_called_once() + def test_dashed_argv_on_tty_skips_tui(self) -> None: + argv = ["--export", "json", "--no-interactive"] + with ( + mock.patch("github_usage.cli_gui.run_tui", return_value=0) as run_tui, + mock.patch("sys.stdin.isatty", return_value=True), + mock.patch("sys.stdout.isatty", return_value=True), + mock.patch.dict(os.environ, {}, clear=True), + ): + result = route_entry(argv) + self.assertFalse(result.handled) + self.assertEqual(result.argv, argv) + run_tui.assert_not_called() + def test_missing_gui_message_contains_venv_python(self) -> None: self.assertIn("uv pip install --python .venv -e '.[gui]'", _MISSING_GUI_MESSAGE)