memindex 1.4.5 → 1.5.0
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.qoder-plugin/plugin.json +1 -1
- package/README.md +8 -2
- package/dist/bug-report/index.js +94 -83
- package/dist/npx-cli/index.js +300 -299
- package/dist/opencode-plugin/index.js +40 -40
- package/dist/pi-extension/TYPEBOX-PROVENANCE.json +4 -4
- package/dist/pi-extension/index.js +9 -9
- package/integrations/dsh/lib/index.js +19 -19
- package/integrations/dsh/package.json +1 -1
- package/integrations/openclaw/install.sh +16 -10
- package/integrations/openclaw/openclaw.plugin.json +1 -5
- package/integrations/openclaw/test-install.sh +20 -13
- package/integrations/pi/TYPEBOX-PROVENANCE.json +4 -4
- package/package.json +5 -5
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.qoder-plugin/plugin.json +1 -1
- package/plugin/hooks/codex-hooks.json +12 -0
- package/plugin/package.json +1 -1
- package/plugin/scripts/context-generator.cjs +65 -63
- package/plugin/scripts/context-generator.cjs.map +3 -3
- package/plugin/scripts/mcp-server.cjs +71 -70
- package/plugin/scripts/mcp-server.cjs.map +3 -3
- package/plugin/scripts/statusline.cjs +1 -1
- package/plugin/scripts/transcript-watcher.cjs +36 -35
- package/plugin/scripts/transcript-watcher.cjs.map +3 -3
- package/plugin/scripts/worker-service.cjs +714 -674
- package/plugin/scripts/worker-service.cjs.map +3 -3
- package/plugin/skills/cloud-sync/SKILL.md +5 -5
- package/plugin/skills/distill/SKILL.md +22 -0
- package/plugin/skills/how-it-works/SKILL.md +1 -1
- package/plugin/skills/how-it-works/onboarding-explainer.md +1 -1
- package/plugin/skills/import-chats/SKILL.md +22 -0
- package/plugin/skills/import-jira/SKILL.md +22 -0
- package/plugin/skills/import-reviews/SKILL.md +22 -0
- package/plugin/skills/mode-creator/SKILL.md +7 -1
- package/plugin/skills/pin/SKILL.md +26 -0
- package/plugin/skills/savings/SKILL.md +22 -0
- package/plugin/skills/timeline-report/SKILL.md +8 -8
- package/plugin/skills/weekly-digests/SKILL.md +5 -5
- package/plugin/skills/worker-request.mjs +45 -0
- package/plugin/sqlite/SessionStore.js +109 -109
- package/plugin/sqlite/SessionStore.js.map +3 -3
- package/plugin/sqlite/observations/files.js +12 -9
- package/plugin/sqlite/observations/files.js.map +3 -3
- package/plugin/ui/viewer-bundle.js +18 -18
- package/integrations/openclaw/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/integrations/openclaw/skills/agent-cost-report/SKILL.md +0 -241
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr.py +0 -219
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/plugin/skills/agent-cost-report/SKILL.md +0 -241
- package/plugin/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/plugin/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/plugin/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/plugin/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/plugin/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/plugin/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/plugin/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/plugin/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/plugin/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/plugin/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/plugin/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/plugin/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/plugin/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/plugin/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/plugin/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/plugin/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/plugin/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/plugin/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/plugin/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/plugin/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/plugin/skills/agent-cost-report/scripts/acr.py +0 -219
- package/plugin/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/plugin/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/plugin/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/plugin/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/plugin/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/plugin/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/plugin/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/plugin/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/plugin/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/plugin/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/plugin/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/plugin/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/plugin/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/plugin/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/babysit/SKILL.md +0 -87
- package/plugin/skills/design-is/SKILL.md +0 -312
- package/plugin/skills/do/SKILL.md +0 -45
- package/plugin/skills/learn-codebase/SKILL.md +0 -21
- package/plugin/skills/make-plan/SKILL.md +0 -67
- package/plugin/skills/oh-my-issues/SKILL.md +0 -226
- package/plugin/skills/pathfinder/SKILL.md +0 -111
- package/plugin/skills/screenpipe/SKILL.md +0 -78
- package/plugin/skills/screenpipe/screenpipe.mjs +0 -196
- package/plugin/skills/smart-explore/SKILL.md +0 -193
- package/plugin/skills/standup/SKILL.md +0 -142
- package/plugin/skills/standup/agent-brief.md +0 -47
- package/plugin/skills/standup/standup.mjs +0 -586
- package/plugin/skills/what-the/SKILL.md +0 -6
- package/plugin/skills/wowerpoint/SKILL.md +0 -205
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"""Native PDF controls for the ordinary Windows Chrome installation."""
|
|
2
|
-
import os
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
import shutil
|
|
5
|
-
import sys
|
|
6
|
-
import tempfile
|
|
7
|
-
import unittest
|
|
8
|
-
from unittest.mock import patch
|
|
9
|
-
|
|
10
|
-
import _paths # noqa: F401
|
|
11
|
-
from acr import render
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@unittest.skipUnless(sys.platform == "win32", "requires actual Windows Chrome installation")
|
|
15
|
-
class WindowsChromePdf(unittest.TestCase):
|
|
16
|
-
def setUp(self):
|
|
17
|
-
candidates = [Path(os.environ[key]) / "Google/Chrome/Application/chrome.exe"
|
|
18
|
-
for key in ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA")
|
|
19
|
-
if key in os.environ]
|
|
20
|
-
self.chrome = next((p for p in candidates if p.is_file()), None)
|
|
21
|
-
if self.chrome is None:
|
|
22
|
-
if os.environ.get("ACR_EXPECT_WINDOWS_CHROME") == "1":
|
|
23
|
-
self.fail("Windows CI must provide Chrome for the native PDF regressions")
|
|
24
|
-
self.skipTest("Chrome is optional and is not installed in a standard Windows location")
|
|
25
|
-
print("native Chrome:", self.chrome, "google-chrome on PATH:", shutil.which("google-chrome"))
|
|
26
|
-
self.tmp = tempfile.TemporaryDirectory(prefix="acr-native-pdf-")
|
|
27
|
-
self.addCleanup(self.tmp.cleanup)
|
|
28
|
-
self.out = Path(self.tmp.name)
|
|
29
|
-
(self.out / "report.print.html").write_text("<!doctype html><html><body>Native agent report</body></html>", encoding="utf-8")
|
|
30
|
-
|
|
31
|
-
def test_default_discovers_installed_chrome_and_produces_pdf(self):
|
|
32
|
-
system_path = str(Path(os.environ["SystemRoot"]) / "System32")
|
|
33
|
-
with patch.dict(os.environ, {"PATH": system_path}):
|
|
34
|
-
self.assertIsNone(shutil.which("google-chrome"))
|
|
35
|
-
self.assertIsNone(shutil.which("chrome"))
|
|
36
|
-
path, message = render.pdf(str(self.out))
|
|
37
|
-
self.assertIsNotNone(path, message)
|
|
38
|
-
self.assertTrue(Path(path).read_bytes().startswith(b"%PDF-"))
|
|
39
|
-
self.assertFalse((self.out / ".chrome-profile").exists())
|
|
40
|
-
|
|
41
|
-
def test_explicit_missing_browser_does_not_substitute_installed_chrome(self):
|
|
42
|
-
path, message = render.pdf(str(self.out), chrome="acr-browser-that-does-not-exist")
|
|
43
|
-
self.assertIsNone(path)
|
|
44
|
-
self.assertIn("PDF skipped", message)
|
|
45
|
-
self.assertFalse((self.out / "report.pdf").exists())
|
|
46
|
-
|
|
47
|
-
def test_explicit_chrome_path_still_produces_pdf(self):
|
|
48
|
-
path, message = render.pdf(str(self.out), chrome=str(self.chrome))
|
|
49
|
-
self.assertIsNotNone(path, message)
|
|
50
|
-
self.assertTrue(Path(path).read_bytes().startswith(b"%PDF-"))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if __name__ == "__main__":
|
|
54
|
-
unittest.main()
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import builtins
|
|
2
|
-
import datetime as dt
|
|
3
|
-
import os
|
|
4
|
-
import re
|
|
5
|
-
import subprocess
|
|
6
|
-
import sys
|
|
7
|
-
import unittest
|
|
8
|
-
from unittest.mock import patch
|
|
9
|
-
from zoneinfo import ZoneInfoNotFoundError
|
|
10
|
-
|
|
11
|
-
import _paths # noqa: F401
|
|
12
|
-
from acr import period
|
|
13
|
-
from acr.period import PT
|
|
14
|
-
|
|
15
|
-
H = 3600 * 1000
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MissingTimezoneData(unittest.TestCase):
|
|
19
|
-
def test_cli_explains_how_to_install_timezone_data(self):
|
|
20
|
-
env = dict(os.environ, PYTHONTZPATH="")
|
|
21
|
-
result = subprocess.run(
|
|
22
|
-
[sys.executable, "-S", _paths.ACR_PY, "--help"],
|
|
23
|
-
env=env, capture_output=True, text=True, timeout=10,
|
|
24
|
-
)
|
|
25
|
-
self.assertEqual(result.returncode, 1)
|
|
26
|
-
self.assertIn("America/Los_Angeles", result.stderr)
|
|
27
|
-
self.assertNotIn("Traceback", result.stderr)
|
|
28
|
-
command = re.search(r'^"(.+)" -m pip install tzdata$', result.stderr, re.MULTILINE)
|
|
29
|
-
self.assertIsNotNone(command)
|
|
30
|
-
self.assertTrue(os.path.samefile(command.group(1), sys.executable))
|
|
31
|
-
powershell_line = f'PowerShell: & "{command.group(1)}" -m pip install tzdata'
|
|
32
|
-
self.assertEqual(powershell_line in result.stderr.splitlines(), os.name == "nt")
|
|
33
|
-
self.assertIn("PYTHONTZPATH", result.stderr)
|
|
34
|
-
|
|
35
|
-
def test_windows_install_command_handles_spaces_in_interpreter_path(self):
|
|
36
|
-
with open(_paths.ACR_PY, encoding="utf-8") as script:
|
|
37
|
-
code = compile(script.read(), _paths.ACR_PY, "exec")
|
|
38
|
-
real_import = builtins.__import__
|
|
39
|
-
|
|
40
|
-
def missing_timezone_import(name, *args, **kwargs):
|
|
41
|
-
if name == "acr":
|
|
42
|
-
raise ZoneInfoNotFoundError("America/Los_Angeles")
|
|
43
|
-
return real_import(name, *args, **kwargs)
|
|
44
|
-
|
|
45
|
-
interpreter = r"C:\Program Files\Python\python.exe"
|
|
46
|
-
with patch("builtins.__import__", side_effect=missing_timezone_import), \
|
|
47
|
-
patch("os.name", "nt"), patch("sys.executable", interpreter):
|
|
48
|
-
with self.assertRaises(SystemExit) as error:
|
|
49
|
-
exec(code, {"__file__": _paths.ACR_PY, "__name__": "__main__"})
|
|
50
|
-
lines = str(error.exception).splitlines()
|
|
51
|
-
plain_line = '"C:\\Program Files\\Python\\python.exe" -m pip install tzdata'
|
|
52
|
-
self.assertIn(plain_line, lines)
|
|
53
|
-
self.assertIn("PowerShell: & " + plain_line, lines)
|
|
54
|
-
self.assertIn("PYTHONTZPATH", lines[-1])
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class DefaultWindow(unittest.TestCase):
|
|
58
|
-
def test_default_last_7_full_pt_days_fixed_clock(self):
|
|
59
|
-
now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
|
|
60
|
-
w = period.resolve_window(now=now)
|
|
61
|
-
self.assertEqual(w.start_pt, "2026-09-18")
|
|
62
|
-
self.assertEqual(w.end_exclusive_pt, "2026-09-25")
|
|
63
|
-
self.assertFalse(w.partial_last_day)
|
|
64
|
-
self.assertEqual(w.generated_at_pt, "2026-09-25 16:42 PT")
|
|
65
|
-
self.assertEqual(w.start.utcoffset(), dt.timedelta(hours=-7))
|
|
66
|
-
self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 7 * 24 * H)
|
|
67
|
-
b = w.block()
|
|
68
|
-
self.assertEqual(set(b), {"start_pt", "end_exclusive_pt", "start_epoch_ms", "end_epoch_ms",
|
|
69
|
-
"generated_at_pt", "partial_last_day"})
|
|
70
|
-
self.assertEqual(b["start_epoch_ms"], int(dt.datetime(2026, 9, 18, tzinfo=PT).timestamp() * 1000))
|
|
71
|
-
|
|
72
|
-
def test_default_accepts_a_utc_clock(self):
|
|
73
|
-
now = dt.datetime(2026, 9, 26, 3, 0, tzinfo=dt.timezone.utc)
|
|
74
|
-
w = period.resolve_window(now=now)
|
|
75
|
-
self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-09-18", "2026-09-25"))
|
|
76
|
-
|
|
77
|
-
def test_explicit_end_after_today_is_partial(self):
|
|
78
|
-
now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
|
|
79
|
-
w = period.resolve_window("2026-09-18", "2026-09-26", now=now)
|
|
80
|
-
self.assertTrue(w.partial_last_day)
|
|
81
|
-
self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 8 * 24 * H)
|
|
82
|
-
|
|
83
|
-
def test_explicit_end_equal_today_is_not_partial(self):
|
|
84
|
-
now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
|
|
85
|
-
self.assertFalse(period.resolve_window("2026-09-18", "2026-09-25", now=now).partial_last_day)
|
|
86
|
-
|
|
87
|
-
def test_only_start_given_defaults_end_to_today(self):
|
|
88
|
-
now = dt.datetime(2026, 9, 25, 9, 0, tzinfo=PT)
|
|
89
|
-
w = period.resolve_window(start="2026-09-01", now=now)
|
|
90
|
-
self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-09-01", "2026-09-25"))
|
|
91
|
-
|
|
92
|
-
def test_bad_inputs(self):
|
|
93
|
-
now = dt.datetime(2026, 9, 25, 9, 0, tzinfo=PT)
|
|
94
|
-
with self.assertRaises(ValueError):
|
|
95
|
-
period.resolve_window("2026-09-25", "2026-09-25", now=now)
|
|
96
|
-
with self.assertRaises(ValueError):
|
|
97
|
-
period.parse_day("2026-09-25T10:00")
|
|
98
|
-
with self.assertRaises(ValueError):
|
|
99
|
-
period.parse_day("2026-09-25+00:00")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
class DstBoundary(unittest.TestCase):
|
|
103
|
-
"""US DST ends Sunday 2026-11-01 02:00 PT; PT windows are calendar days, so epoch spans change."""
|
|
104
|
-
|
|
105
|
-
def test_default_window_across_fall_back(self):
|
|
106
|
-
now = dt.datetime(2026, 11, 4, 10, 0, tzinfo=PT)
|
|
107
|
-
w = period.resolve_window(now=now)
|
|
108
|
-
self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-10-28", "2026-11-04"))
|
|
109
|
-
self.assertEqual(w.start.utcoffset(), dt.timedelta(hours=-7))
|
|
110
|
-
self.assertEqual(w.end.utcoffset(), dt.timedelta(hours=-8))
|
|
111
|
-
self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, (7 * 24 + 1) * H)
|
|
112
|
-
self.assertFalse(w.partial_last_day)
|
|
113
|
-
|
|
114
|
-
def test_single_day_containing_fall_back_is_25_hours(self):
|
|
115
|
-
w = period.resolve_window("2026-11-01", "2026-11-02", now=dt.datetime(2026, 11, 5, tzinfo=PT))
|
|
116
|
-
self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 25 * H)
|
|
117
|
-
self.assertEqual(w.start.isoformat(), "2026-11-01T00:00:00-07:00")
|
|
118
|
-
self.assertEqual(w.end.isoformat(), "2026-11-02T00:00:00-08:00")
|
|
119
|
-
|
|
120
|
-
def test_default_window_ending_on_dst_day(self):
|
|
121
|
-
now = dt.datetime(2026, 11, 1, 12, 0, tzinfo=PT)
|
|
122
|
-
w = period.resolve_window(now=now)
|
|
123
|
-
self.assertEqual((w.start_pt, w.end_exclusive_pt), ("2026-10-25", "2026-11-01"))
|
|
124
|
-
self.assertEqual(w.end.utcoffset(), dt.timedelta(hours=-7))
|
|
125
|
-
self.assertEqual(w.end_epoch_ms - w.start_epoch_ms, 7 * 24 * H)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
class SessionBlock(unittest.TestCase):
|
|
129
|
-
def test_session_block_has_null_bounds(self):
|
|
130
|
-
b = period.session_block("abc", now=dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT))
|
|
131
|
-
self.assertIsNone(b["start_pt"]); self.assertIsNone(b["end_epoch_ms"])
|
|
132
|
-
self.assertEqual(b["session"], "abc"); self.assertFalse(b["partial_last_day"])
|
|
133
|
-
self.assertEqual(b["generated_at_pt"], "2026-09-25 16:42 PT")
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if __name__ == "__main__":
|
|
137
|
-
unittest.main()
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
import shutil
|
|
4
|
-
import subprocess
|
|
5
|
-
import sys
|
|
6
|
-
import tempfile
|
|
7
|
-
import unittest
|
|
8
|
-
|
|
9
|
-
import _paths
|
|
10
|
-
from acr import prices
|
|
11
|
-
|
|
12
|
-
SAMPLE = os.path.join(_paths.FIXTURES, "prices_sample.json")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Norm(unittest.TestCase):
|
|
16
|
-
def test_norm_rules(self):
|
|
17
|
-
self.assertEqual(prices.norm("claude-fable-5-1"), "anthropic/claude-fable-5.1")
|
|
18
|
-
self.assertEqual(prices.norm("claude-sonnet-4-5-20250929"), "anthropic/claude-sonnet-4.5")
|
|
19
|
-
self.assertEqual(prices.norm("gpt-5-codex"), "openai/gpt-5-codex")
|
|
20
|
-
self.assertEqual(prices.norm("gemini-2.5-pro"), "google/gemini-2.5-pro")
|
|
21
|
-
self.assertEqual(prices.norm("anthropic/claude-opus-5.5"), "anthropic/claude-opus-5.5")
|
|
22
|
-
self.assertEqual(prices.norm("alias-x", aliases={"alias-x": "vendor/real"}), "vendor/real")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class Rate(unittest.TestCase):
|
|
26
|
-
@classmethod
|
|
27
|
-
def setUpClass(cls):
|
|
28
|
-
cls.models = prices.load(SAMPLE)["models"]
|
|
29
|
-
|
|
30
|
-
def test_explicit_cache_write_1h_is_used(self):
|
|
31
|
-
r = prices.rate("anthropic/claude-opus-5.5", self.models)
|
|
32
|
-
self.assertEqual(r["cache_write_1h"], 30.0)
|
|
33
|
-
self.assertEqual(r["price_source"]["cache_write_1h"], "listed")
|
|
34
|
-
self.assertEqual(r["price_source"], {"cache_read": "listed", "cache_write": "listed", "cache_write_1h": "listed"})
|
|
35
|
-
|
|
36
|
-
def test_cache_write_1h_falls_back_to_2x_input(self):
|
|
37
|
-
r = prices.rate("claude-fable-5-1", self.models)
|
|
38
|
-
self.assertEqual(r["key"], "anthropic/claude-fable-5.1")
|
|
39
|
-
self.assertEqual(r["input_usd_per_mtok"], 10.0)
|
|
40
|
-
self.assertEqual(r["output_usd_per_mtok"], 50.0)
|
|
41
|
-
self.assertEqual(r["cache_read"], 0.25)
|
|
42
|
-
self.assertEqual(r["cache_write"], 12.5)
|
|
43
|
-
self.assertEqual(r["cache_write_1h"], 20.0)
|
|
44
|
-
self.assertEqual(r["price_source"]["cache_write_1h"], "input*2")
|
|
45
|
-
self.assertEqual(r["source"], "openrouter-public-list")
|
|
46
|
-
|
|
47
|
-
def test_cache_read_and_write_fallbacks(self):
|
|
48
|
-
r = prices.rate("claude-sonnet-4-5-20250929", self.models)
|
|
49
|
-
self.assertAlmostEqual(r["cache_read"], 0.3)
|
|
50
|
-
self.assertAlmostEqual(r["cache_write"], 3.75)
|
|
51
|
-
self.assertEqual(r["cache_write_1h"], 6.0)
|
|
52
|
-
self.assertEqual(r["price_source"], {"cache_read": "input*0.1", "cache_write": "input*1.25", "cache_write_1h": "input*2"})
|
|
53
|
-
|
|
54
|
-
def test_unpriced(self):
|
|
55
|
-
self.assertIsNone(prices.rate("<synthetic>", self.models))
|
|
56
|
-
self.assertIsNone(prices.rate("", self.models))
|
|
57
|
-
self.assertIsNone(prices.rate(None, self.models))
|
|
58
|
-
self.assertIsNone(prices.rate("unknown-model-9", self.models))
|
|
59
|
-
self.assertIsNone(prices.rate("gpt-5-codex", self.models))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class Files(unittest.TestCase):
|
|
63
|
-
def setUp(self):
|
|
64
|
-
self.tmp = tempfile.mkdtemp(prefix="acr-prices-")
|
|
65
|
-
|
|
66
|
-
def tearDown(self):
|
|
67
|
-
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
68
|
-
|
|
69
|
-
def test_ensure_with_saved_prices_writes_outdir_copy(self):
|
|
70
|
-
path, p = prices.ensure(self.tmp, prices_file=SAMPLE)
|
|
71
|
-
self.assertEqual(path, os.path.join(self.tmp, "prices.json"))
|
|
72
|
-
with open(path) as fh:
|
|
73
|
-
d = json.load(fh)
|
|
74
|
-
self.assertEqual(d["models"]["anthropic/claude-fable-5.1"]["input"], 10.0)
|
|
75
|
-
self.assertEqual(d["source"], prices.SOURCE_URL)
|
|
76
|
-
self.assertEqual(d["loaded_from"], os.path.abspath(SAMPLE))
|
|
77
|
-
|
|
78
|
-
def test_offline_fetch_is_an_error_not_zero(self):
|
|
79
|
-
with self.assertRaises(prices.PriceError):
|
|
80
|
-
prices.ensure(self.tmp, url="http://127.0.0.1:9/models")
|
|
81
|
-
self.assertFalse(os.path.exists(os.path.join(self.tmp, "prices.json")))
|
|
82
|
-
|
|
83
|
-
def test_bad_prices_file(self):
|
|
84
|
-
bad = os.path.join(self.tmp, "bad.json")
|
|
85
|
-
with open(bad, "w") as fh:
|
|
86
|
-
fh.write('{"nope": 1}')
|
|
87
|
-
with self.assertRaises(prices.PriceError):
|
|
88
|
-
prices.load(bad)
|
|
89
|
-
with self.assertRaises(prices.PriceError):
|
|
90
|
-
prices.load(os.path.join(self.tmp, "missing.json"))
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class Cli(unittest.TestCase):
|
|
94
|
-
def setUp(self):
|
|
95
|
-
self.tmp = tempfile.mkdtemp(prefix="acr-cli-")
|
|
96
|
-
|
|
97
|
-
def tearDown(self):
|
|
98
|
-
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
99
|
-
|
|
100
|
-
def run_acr(self, *argv):
|
|
101
|
-
return subprocess.run([sys.executable, _paths.ACR_PY, *argv], capture_output=True, text=True)
|
|
102
|
-
|
|
103
|
-
def test_prices_offline_exits_nonzero_with_clear_error(self):
|
|
104
|
-
r = self.run_acr("prices", "--out", self.tmp, "--url", "http://127.0.0.1:9/models")
|
|
105
|
-
self.assertNotEqual(r.returncode, 0)
|
|
106
|
-
self.assertIn("could not fetch", r.stderr)
|
|
107
|
-
self.assertIn("--prices", r.stderr)
|
|
108
|
-
|
|
109
|
-
def test_prices_from_saved_file(self):
|
|
110
|
-
r = self.run_acr("prices", "--out", self.tmp, "--prices", SAMPLE)
|
|
111
|
-
self.assertEqual(r.returncode, 0, r.stderr)
|
|
112
|
-
self.assertIn("4 models", r.stdout)
|
|
113
|
-
self.assertTrue(os.path.exists(os.path.join(self.tmp, "prices.json")))
|
|
114
|
-
|
|
115
|
-
def test_every_subcommand_is_wired(self):
|
|
116
|
-
r = self.run_acr("--help")
|
|
117
|
-
for cmd in ("collect", "prices", "rollup", "review", "render", "pdf", "measure-openrouter", "sync-check"): self.assertIn(cmd, r.stdout, cmd)
|
|
118
|
-
|
|
119
|
-
def test_collect_rejects_session_with_period(self):
|
|
120
|
-
r = self.run_acr("collect", "--session", "x", "--start", "2026-09-18", "--out", self.tmp)
|
|
121
|
-
self.assertNotEqual(r.returncode, 0)
|
|
122
|
-
self.assertIn("--session", r.stderr)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if __name__ == "__main__":
|
|
126
|
-
unittest.main()
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"""Phase 3 tests (plan 3.6, 3.7, 3.8): the renderer against the five report fixtures."""
|
|
2
|
-
import glob
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import re
|
|
6
|
-
import shutil
|
|
7
|
-
import tempfile
|
|
8
|
-
import unittest
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from unittest.mock import patch
|
|
11
|
-
|
|
12
|
-
import _paths # noqa: F401
|
|
13
|
-
from acr import render
|
|
14
|
-
|
|
15
|
-
FIXTURES = sorted(glob.glob(os.path.join(_paths.FIXTURES, "report-*.json")))
|
|
16
|
-
MONEY = re.compile(r"\$[0-9,]*\.[0-9]*")
|
|
17
|
-
TWO_DEC = re.compile(r"\$[0-9,]*\.[0-9][0-9]")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def load(path):
|
|
21
|
-
with open(path) as fh: return json.load(fh)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class Fixtures(unittest.TestCase):
|
|
25
|
-
def setUp(self):
|
|
26
|
-
self.assertEqual(len(FIXTURES), 5, FIXTURES)
|
|
27
|
-
self.pages = {os.path.basename(f): render.page(load(f)) for f in FIXTURES}
|
|
28
|
-
|
|
29
|
-
def test_no_script_or_external_resources(self):
|
|
30
|
-
for name, h in self.pages.items():
|
|
31
|
-
self.assertNotRegex(h, r"<script|<link|@import|url\(http|src=\"http", name)
|
|
32
|
-
self.assertEqual(h.count("url("), h.count("url(#"), name)
|
|
33
|
-
|
|
34
|
-
def test_dollars_two_decimals_no_cent_sign(self):
|
|
35
|
-
for name, h in self.pages.items():
|
|
36
|
-
body = re.sub(r'<span class="ex">.*?</span>', "", h)
|
|
37
|
-
bad = [m for m in MONEY.findall(body) if not TWO_DEC.fullmatch(m)]
|
|
38
|
-
self.assertEqual(bad, [], name); self.assertNotIn(chr(0xA2), h, name)
|
|
39
|
-
self.assertIn("Measured provider spend: unavailable", h, name)
|
|
40
|
-
|
|
41
|
-
def test_layout_order_tiles_and_links(self):
|
|
42
|
-
for name, h in self.pages.items():
|
|
43
|
-
i_hero, i_wm, i_rib = h.find('class="hero'), h.find('class="wins-mistakes'), h.find('class="ribbon')
|
|
44
|
-
self.assertTrue(0 <= i_hero < i_wm, name)
|
|
45
|
-
self.assertTrue(i_rib == -1 or i_wm < i_rib, name)
|
|
46
|
-
self.assertLessEqual(h.count('class="behavior-tile'), 4, name)
|
|
47
|
-
self.assertEqual(h.count("Cost of mistakes"), 1, name)
|
|
48
|
-
for frag in set(re.findall(r'href="#((?:win|mistakes)-[^"]+)"', h)): self.assertIn(f'id="{frag}"', h, f"{name}: {frag}")
|
|
49
|
-
d = h.find('<details id="details"'); u = h.find("Upper bound")
|
|
50
|
-
self.assertTrue(u == -1 or u > d, name)
|
|
51
|
-
|
|
52
|
-
def test_day_chart_and_empty_days(self):
|
|
53
|
-
one, empty, thirty = self.pages["report-1day.json"], self.pages["report-empty.json"], self.pages["report-30day.json"]
|
|
54
|
-
self.assertEqual(one.count('class="cax"'), 1 + 1)
|
|
55
|
-
self.assertIn("no agent work", empty); self.assertIn("Nothing finished yet", empty)
|
|
56
|
-
self.assertIn("No merged PR or published version found", empty)
|
|
57
|
-
self.assertGreater(thirty.count("no agent work"), 20)
|
|
58
|
-
|
|
59
|
-
def test_every_money_figure_in_hero_has_a_tag(self):
|
|
60
|
-
for name, h in self.pages.items():
|
|
61
|
-
hero = h[h.find('class="hero'): h.find('class="wins-mistakes')]
|
|
62
|
-
self.assertGreaterEqual(hero.count('class="est'), len(MONEY.findall(hero)) - 1, name)
|
|
63
|
-
|
|
64
|
-
def test_deterministic(self):
|
|
65
|
-
for f in FIXTURES: self.assertEqual(render.page(load(f)), render.page(load(f)))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
class SavedReports(unittest.TestCase):
|
|
69
|
-
def test_report_saved_under_an_older_minutes_name_renders_its_numbers(self):
|
|
70
|
-
new = load(os.path.join(_paths.FIXTURES, "report-30day.json"))
|
|
71
|
-
new["spend"]["mistakes_user_minutes"] = 12.5; new["timeline"]["mistakes_by_day"][0]["user_minutes"] = 3.5
|
|
72
|
-
old = json.loads(json.dumps(new).replace("user_minutes", "owner_minutes"))
|
|
73
|
-
self.assertNotIn("user_minutes", json.dumps(old))
|
|
74
|
-
render.upgrade_minutes(old)
|
|
75
|
-
self.assertEqual(old["spend"]["mistakes_user_minutes"], 12.5)
|
|
76
|
-
self.assertEqual(old["timeline"]["mistakes_by_day"][0]["user_minutes"], 3.5)
|
|
77
|
-
self.assertEqual(old["spend"]["mistakes_user_minutes_known_n"], new["spend"]["mistakes_user_minutes_known_n"])
|
|
78
|
-
self.assertEqual(render.page(old, False), render.page(new, False))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class Files(unittest.TestCase):
|
|
82
|
-
def setUp(self):
|
|
83
|
-
self.tmp = tempfile.mkdtemp()
|
|
84
|
-
|
|
85
|
-
def tearDown(self):
|
|
86
|
-
shutil.rmtree(self.tmp)
|
|
87
|
-
|
|
88
|
-
def test_render_file_and_print_mode(self):
|
|
89
|
-
p = render.render_file(FIXTURES[0], self.tmp)
|
|
90
|
-
self.assertTrue(p.endswith("report.html")); self.assertIn('<details id="details" >', open(p).read())
|
|
91
|
-
q = render.render_file(FIXTURES[0], self.tmp, print_mode=True)
|
|
92
|
-
self.assertTrue(q.endswith("report.print.html")); self.assertIn('<details id="details" open>', open(q).read())
|
|
93
|
-
|
|
94
|
-
def test_failed_render_keeps_the_previous_report(self):
|
|
95
|
-
p = render.render_file(FIXTURES[0], self.tmp)
|
|
96
|
-
with open(p, "rb") as fh: before = fh.read()
|
|
97
|
-
self.assertIn(b"<!doctype html>", before)
|
|
98
|
-
d = load(FIXTURES[0]); del d["line_items"]
|
|
99
|
-
bad = os.path.join(self.tmp, "broken.json")
|
|
100
|
-
with open(bad, "w", encoding="utf-8") as fh: json.dump(d, fh)
|
|
101
|
-
with self.assertRaises(KeyError): render.render_file(bad, self.tmp)
|
|
102
|
-
with open(p, "rb") as fh: self.assertEqual(fh.read(), before)
|
|
103
|
-
|
|
104
|
-
def test_pdf_skipped_without_chrome(self):
|
|
105
|
-
render.render_file(FIXTURES[0], self.tmp, print_mode=True)
|
|
106
|
-
path, msg = render.pdf(self.tmp, chrome="no-such-browser-xyz")
|
|
107
|
-
self.assertIsNone(path); self.assertIn("PDF skipped, HTML is canonical", msg)
|
|
108
|
-
|
|
109
|
-
def test_usd2_is_the_only_formatter(self):
|
|
110
|
-
src = open(os.path.join(_paths.SCRIPTS, "acr", "render.py")).read()
|
|
111
|
-
self.assertNotIn("def " + "cen" + "ts", src); self.assertNotIn(chr(0xA2), src); self.assertEqual(render.usd2(1234.5), "$1,234.50")
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
def posix(path):
|
|
115
|
-
return os.fspath(path).replace("\\", "/")
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
MAC_APP = "Google Chrome.app/Contents/MacOS/Google Chrome"
|
|
119
|
-
PDF = b"%PDF-1.4\n1 0 obj\n<<>>\nendobj\ntrailer\n<<>>\n%%EOF\n"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
class FakeChrome:
|
|
123
|
-
"""subprocess.Popen stand-in: prints `pdf` to the --print-to-pdf= path (nothing when None), writes `stderr`, then
|
|
124
|
-
exits with `exit_code`, or, like Chrome on macOS, keeps running until it is terminated (`exits=False`)."""
|
|
125
|
-
def __init__(self, pdf=PDF, stderr=b"", exit_code=0, exits=True):
|
|
126
|
-
self.pdf, self.stderr, self.exit_code, self.exits = pdf, stderr, exit_code, exits
|
|
127
|
-
self.cmds, self.terminated, self.returncode = [], False, None
|
|
128
|
-
|
|
129
|
-
def __call__(self, cmd, stdout=None, stderr=None):
|
|
130
|
-
self.cmds.append(cmd); self.returncode = None
|
|
131
|
-
if self.pdf is not None:
|
|
132
|
-
with open(next(a for a in cmd if a.startswith("--print-to-pdf="))[len("--print-to-pdf="):], "wb") as fh: fh.write(self.pdf)
|
|
133
|
-
stderr.write(self.stderr)
|
|
134
|
-
return self
|
|
135
|
-
|
|
136
|
-
def poll(self):
|
|
137
|
-
if self.returncode is None and self.exits: self.returncode = self.exit_code
|
|
138
|
-
return self.returncode
|
|
139
|
-
|
|
140
|
-
def wait(self, timeout=None):
|
|
141
|
-
return self.poll()
|
|
142
|
-
|
|
143
|
-
def terminate(self):
|
|
144
|
-
self.terminated, self.returncode = True, -15
|
|
145
|
-
|
|
146
|
-
kill = terminate
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
class ChromeLookup(unittest.TestCase):
|
|
150
|
-
"""pdf() on every OS with sys.platform, PATH, the install check and the Chrome process patched: the default
|
|
151
|
-
lookup per platform, and how a Chrome that exits, fails, hangs or keeps running after printing is handled."""
|
|
152
|
-
def setUp(self):
|
|
153
|
-
self.tmp = tempfile.mkdtemp(prefix="acr pdf #")
|
|
154
|
-
self.addCleanup(shutil.rmtree, self.tmp, True)
|
|
155
|
-
with open(os.path.join(self.tmp, "report.print.html"), "w", encoding="utf-8") as fh: fh.write("<p>report</p>")
|
|
156
|
-
|
|
157
|
-
def pdf(self, platform, on_path=(), installed=(), env=None, chrome="google-chrome", fake=None):
|
|
158
|
-
fake = fake or FakeChrome()
|
|
159
|
-
with patch("sys.platform", platform), patch("shutil.which", lambda name: "/usr/bin/" + name if name in on_path else None), \
|
|
160
|
-
patch("os.path.isfile", lambda p: posix(p) in installed), patch.dict(os.environ, env or {}), patch("subprocess.Popen", fake), \
|
|
161
|
-
patch.object(render, "CHROME_EXIT_GRACE_S", 0.05), patch.object(render, "CHROME_TIMEOUT_S", 0.3):
|
|
162
|
-
path, msg = render.pdf(self.tmp, chrome=chrome)
|
|
163
|
-
return path, msg, [posix(cmd[0]) for cmd in fake.cmds], fake
|
|
164
|
-
|
|
165
|
-
def mac(self, **kw):
|
|
166
|
-
return self.pdf("darwin", installed=("/Applications/" + MAC_APP,), **kw)
|
|
167
|
-
|
|
168
|
-
def test_linux_default_is_google_chrome_on_path(self):
|
|
169
|
-
self.assertEqual(self.pdf("linux", on_path=("google-chrome",))[2], ["/usr/bin/google-chrome"])
|
|
170
|
-
path, msg, exes, _ = self.pdf("linux", installed=("/Applications/" + MAC_APP,))
|
|
171
|
-
self.assertEqual((path, exes), (None, [])); self.assertIn("PDF skipped, HTML is canonical", msg)
|
|
172
|
-
|
|
173
|
-
def test_macos_default_finds_the_app_bundle_off_path(self):
|
|
174
|
-
self.assertEqual(self.mac()[2], ["/Applications/" + MAC_APP])
|
|
175
|
-
user_app = posix(os.path.join(os.path.expanduser("~"), "Applications", *MAC_APP.split("/")))
|
|
176
|
-
self.assertEqual(self.pdf("darwin", installed=(user_app,))[2], [user_app])
|
|
177
|
-
self.assertEqual(self.pdf("darwin", on_path=("google-chrome",), installed=("/Applications/" + MAC_APP,))[2], ["/usr/bin/google-chrome"])
|
|
178
|
-
|
|
179
|
-
def test_windows_default_finds_installed_chrome_off_path(self):
|
|
180
|
-
env = {"PROGRAMFILES": r"C:\Program Files", "PROGRAMFILES(X86)": r"C:\Program Files (x86)", "LOCALAPPDATA": r"C:\Users\u\AppData\Local"}
|
|
181
|
-
local = "C:/Users/u/AppData/Local/Google/Chrome/Application/chrome.exe"
|
|
182
|
-
self.assertEqual(self.pdf("win32", installed=(local,), env=env)[2], [local])
|
|
183
|
-
self.assertEqual(self.pdf("win32", on_path=("chrome",), installed=(local,), env=env)[2], ["/usr/bin/chrome"])
|
|
184
|
-
|
|
185
|
-
def test_explicit_chrome_is_never_substituted(self):
|
|
186
|
-
path, msg, exes, _ = self.mac(chrome="no-such-browser-xyz")
|
|
187
|
-
self.assertEqual((path, exes), (None, [])); self.assertIn("PDF skipped", msg)
|
|
188
|
-
|
|
189
|
-
def test_chrome_gets_a_file_uri(self):
|
|
190
|
-
path, msg, _, fake = self.mac()
|
|
191
|
-
self.assertEqual(msg, f"pdf: {path}")
|
|
192
|
-
url = fake.cmds[0][-1]
|
|
193
|
-
self.assertEqual(url, Path(self.tmp, "report.print.html").resolve().as_uri())
|
|
194
|
-
self.assertIn("%23", url); self.assertNotIn(" ", url)
|
|
195
|
-
|
|
196
|
-
def test_chrome_that_keeps_running_after_printing_is_stopped(self):
|
|
197
|
-
path, msg, _, fake = self.mac(fake=FakeChrome(exits=False))
|
|
198
|
-
self.assertEqual((path, msg, fake.terminated), (os.path.join(self.tmp, "report.pdf"), f"pdf: {path}", True))
|
|
199
|
-
with open(path, "rb") as fh: self.assertEqual(fh.read(), PDF)
|
|
200
|
-
self.assertFalse(os.path.exists(os.path.join(self.tmp, ".chrome-profile")))
|
|
201
|
-
|
|
202
|
-
def test_failed_print_reports_stderr_and_keeps_the_last_pdf(self):
|
|
203
|
-
with open(os.path.join(self.tmp, "report.pdf"), "wb") as fh: fh.write(PDF)
|
|
204
|
-
path, msg, _, _ = self.mac(fake=FakeChrome(pdf=b"%PDF-1.4 cut short", stderr=b"\xff\xfe bad flag \xe2\x80\x94 exiting", exit_code=1))
|
|
205
|
-
self.assertIsNone(path); self.assertIn("PDF skipped, HTML is canonical (chrome exit 1:", msg); self.assertIn("bad flag — exiting", msg)
|
|
206
|
-
with open(os.path.join(self.tmp, "report.pdf"), "rb") as fh: self.assertEqual(fh.read(), PDF)
|
|
207
|
-
|
|
208
|
-
def test_chrome_that_never_prints_times_out(self):
|
|
209
|
-
path, msg, _, fake = self.mac(fake=FakeChrome(pdf=None, exits=False))
|
|
210
|
-
self.assertEqual((path, msg, fake.terminated), (None, "PDF skipped, HTML is canonical (chrome timed out)", True))
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
class Excerpts(unittest.TestCase):
|
|
214
|
-
def test_top_example_episode_is_listed_once(self):
|
|
215
|
-
d = load(os.path.join(_paths.FIXTURES, "report-1day.json")); day = d["timeline"]["mistakes_by_day"][0]
|
|
216
|
-
ep = dict(episode_id="EP-1", session="cs-ep", ts_pt="2026-09-18 10:00 PT", day_pt=day["day_pt"], pattern="P12_unclear", messages_n=1, low_usd=0.2, high_usd=0.3,
|
|
217
|
-
cost_status="measured_tokens", user_minutes=1.0, model=None, model_status="assumed", source="claude-code", device="local", excerpt="UNIQUE-EXCERPT-MARKER", wasted_keys=[])
|
|
218
|
-
d["behavior"]["episodes"] = [ep]
|
|
219
|
-
day["top_examples"] = [dict(mistake_id="MK-x", episode_id=ep["episode_id"], pattern=ep["pattern"], content_session_id=ep["session"], ts_pt=ep["ts_pt"])]
|
|
220
|
-
h = render.page(d)
|
|
221
|
-
self.assertEqual(h.count("UNIQUE-EXCERPT-MARKER"), 1); self.assertIn(ep["cost_status"], h)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
class Unmeasured(unittest.TestCase):
|
|
225
|
-
def test_no_ratio_never_prints_zero_extrapolated(self):
|
|
226
|
-
li = dict(has_transcript=False, cost_extrapolated=None, attributed_usd=0.0, cost_basis="extrapolated")
|
|
227
|
-
self.assertEqual((render._li_money(li), render._li_basis(li)), ("unmeasured", "unmeasured (no ratio)"))
|
|
228
|
-
li = dict(has_transcript=False, cost_extrapolated=1.5, attributed_usd=1.5, cost_basis="extrapolated")
|
|
229
|
-
self.assertEqual((render._li_money(li), render._li_basis(li)), ("$1.50", "extrapolated"))
|
|
230
|
-
d = load(FIXTURES[0]); d["spend"]["extrapolated_unmeasured_usd"] = None; d["spend"]["extrapolation_basis"] = "n/a (no measured session to derive a ratio from)"
|
|
231
|
-
for li in d["line_items"]:
|
|
232
|
-
if not li.get("has_transcript"): li["cost_extrapolated"] = None; li["attributed_usd"] = 0.0
|
|
233
|
-
h = render.page(d)
|
|
234
|
-
self.assertIn("unavailable (no measured session to derive a ratio from)", h); self.assertNotIn("$0.00 <span class=\"est extra\">", h)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if __name__ == "__main__":
|
|
238
|
-
unittest.main()
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"""Native file rendering under a legacy Windows code page."""
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
import re
|
|
5
|
-
import subprocess
|
|
6
|
-
import sys
|
|
7
|
-
import tempfile
|
|
8
|
-
import unittest
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
import _paths
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class NativeEncoding(unittest.TestCase):
|
|
15
|
-
@unittest.skipUnless(os.name == "nt", "Windows code-page regression")
|
|
16
|
-
def test_html_output_is_utf8_with_legacy_process_encoding(self):
|
|
17
|
-
fixture = Path(_paths.FIXTURES) / "report-empty.json"
|
|
18
|
-
data = json.loads(fixture.read_text(encoding="utf-8"))
|
|
19
|
-
data["scope"]["kind"] = "session"
|
|
20
|
-
data["window"]["start_pt"] = None
|
|
21
|
-
data["generated_at_pt"] = "中文 report"
|
|
22
|
-
data["by_day"] = []
|
|
23
|
-
data["timeline"] = {"wins_by_day": [], "mistakes_by_day": []}
|
|
24
|
-
with tempfile.TemporaryDirectory() as folder:
|
|
25
|
-
source = Path(folder) / "report.json"
|
|
26
|
-
source.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
|
|
27
|
-
script = """
|
|
28
|
-
import locale, pathlib, sys
|
|
29
|
-
sys.path.insert(0, sys.argv[1])
|
|
30
|
-
from acr import render
|
|
31
|
-
encoding = locale.getpreferredencoding(False) # locale.getencoding() is Python 3.11+; the skill supports 3.9+
|
|
32
|
-
assert encoding.lower() != "utf-8", encoding
|
|
33
|
-
for print_mode in (False, True):
|
|
34
|
-
path = render.render_file(sys.argv[2], sys.argv[3], print_mode=print_mode)
|
|
35
|
-
text = pathlib.Path(path).read_text(encoding="utf-8")
|
|
36
|
-
assert '<meta charset="utf-8">' in text
|
|
37
|
-
assert '‹' in text and '›' in text
|
|
38
|
-
assert '中文 report' in text
|
|
39
|
-
"""
|
|
40
|
-
process = subprocess.run(
|
|
41
|
-
[sys.executable, "-X", "utf8=0", "-c", script, _paths.SCRIPTS, str(source), folder],
|
|
42
|
-
capture_output=True, env=dict(os.environ, PYTHONUTF8="0"),
|
|
43
|
-
)
|
|
44
|
-
self.assertEqual(process.returncode, 0, process.stderr.decode("utf-8", errors="replace"))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class DateFormatting(unittest.TestCase):
|
|
48
|
-
def test_day_label_uses_unpadded_day(self):
|
|
49
|
-
from acr import render
|
|
50
|
-
self.assertEqual(render.day_label("2026-10-02"), "Fri Oct 2")
|
|
51
|
-
self.assertEqual(render.day_label("2026-10-02", short=True), "Oct 2")
|
|
52
|
-
|
|
53
|
-
def test_date_pill_retains_single_day_and_range_labels(self):
|
|
54
|
-
from acr import render
|
|
55
|
-
scope = {"kind": "period"}
|
|
56
|
-
cases = [
|
|
57
|
-
("2026-10-02", "2026-10-03", "Oct 2, 2026 (PT)"),
|
|
58
|
-
("2026-10-02", "2026-10-04", "Oct 2 – 3, 2026 (PT)"),
|
|
59
|
-
("2026-09-29", "2026-10-03", "Sep 29 – Oct 2, 2026 (PT)"),
|
|
60
|
-
]
|
|
61
|
-
for start, end, expected in cases:
|
|
62
|
-
with self.subTest(start=start, end=end):
|
|
63
|
-
self.assertEqual(render.date_pill({"start_pt": start, "end_exclusive_pt": end}, scope), expected)
|
|
64
|
-
|
|
65
|
-
def test_sources_use_no_platform_specific_strftime_flags(self):
|
|
66
|
-
sources = [Path(_paths.ACR_PY), *sorted(Path(_paths.SCRIPTS, "acr").glob("*.py"))]
|
|
67
|
-
hits = [f"{source.name}:{number}" for source in sources
|
|
68
|
-
for number, line in enumerate(source.read_text(encoding="utf-8").splitlines(), 1)
|
|
69
|
-
if re.search(r"%-[A-Za-z]", line)]
|
|
70
|
-
self.assertEqual(hits, [])
|