fix(pipeline): repair token tracker CLI summary (#622)
Some checks failed
Smoke Test / smoke (pull_request) Failing after 24s
Architecture Lint / Linter Tests (pull_request) Successful in 29s
Validate Config / YAML Lint (pull_request) Failing after 16s
Validate Config / JSON Validate (pull_request) Successful in 21s
Validate Config / Shell Script Lint (pull_request) Failing after 1m8s
Validate Config / Python Syntax & Import Check (pull_request) Failing after 1m21s
Validate Config / Python Test Suite (pull_request) Has been skipped
Validate Config / Cron Syntax Check (pull_request) Successful in 15s
Validate Config / Deploy Script Dry Run (pull_request) Successful in 15s
Validate Config / Playbook Schema Validation (pull_request) Successful in 30s
Architecture Lint / Lint Repository (pull_request) Failing after 28s
PR Checklist / pr-checklist (pull_request) Successful in 5m18s
Some checks failed
Smoke Test / smoke (pull_request) Failing after 24s
Architecture Lint / Linter Tests (pull_request) Successful in 29s
Validate Config / YAML Lint (pull_request) Failing after 16s
Validate Config / JSON Validate (pull_request) Successful in 21s
Validate Config / Shell Script Lint (pull_request) Failing after 1m8s
Validate Config / Python Syntax & Import Check (pull_request) Failing after 1m21s
Validate Config / Python Test Suite (pull_request) Has been skipped
Validate Config / Cron Syntax Check (pull_request) Successful in 15s
Validate Config / Deploy Script Dry Run (pull_request) Successful in 15s
Validate Config / Playbook Schema Validation (pull_request) Successful in 30s
Architecture Lint / Lint Repository (pull_request) Failing after 28s
PR Checklist / pr-checklist (pull_request) Successful in 5m18s
Fix the hyphenated token-tracker entrypoint and normalize SQLite time filtering so same-day usage appears in the summary dashboard.
This commit is contained in:
@@ -5,11 +5,12 @@ Tests for scripts/token_tracker.py — Token Budget Tracker.
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
|
||||
from token_tracker import (
|
||||
get_db,
|
||||
@@ -155,5 +156,37 @@ class TestBudgets(unittest.TestCase):
|
||||
self.assertIn("p1", loaded)
|
||||
|
||||
|
||||
class TestWrapperScript(unittest.TestCase):
|
||||
def test_hyphen_wrapper_summary_works_with_custom_db(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
db_path = Path(tmpdir) / "wrapper.db"
|
||||
budgets_path = Path(tmpdir) / "budgets.json"
|
||||
budgets_path.write_text(json.dumps({"knowledge-mine": 200_000_000}))
|
||||
conn = get_db(db_path)
|
||||
try:
|
||||
record_usage(conn, "knowledge-mine", "worker-1", 123456)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
repo_root = Path(__file__).parent.parent
|
||||
wrapper = repo_root / "scripts" / "token-tracker.py"
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(wrapper),
|
||||
"--summary",
|
||||
"--db", str(db_path),
|
||||
"--budgets-file", str(budgets_path),
|
||||
],
|
||||
cwd=str(repo_root),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("DAILY SUMMARY", result.stdout)
|
||||
self.assertIn("knowledge-mine", result.stdout)
|
||||
self.assertIn("123.5K", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user