memindex 1.4.4 → 1.4.6
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 +9 -1
- package/dist/bug-report/index.js +94 -83
- package/dist/npx-cli/index.js +250 -249
- package/dist/pi-extension/TYPEBOX-PROVENANCE.json +4 -4
- package/dist/pi-extension/index.js +9 -9
- package/integrations/dsh/package.json +1 -1
- package/integrations/openclaw/openclaw.plugin.json +1 -5
- 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/package.json +1 -1
- package/plugin/scripts/context-generator.cjs +62 -61
- package/plugin/scripts/context-generator.cjs.map +3 -3
- package/plugin/scripts/mcp-server.cjs +2 -2
- package/plugin/scripts/transcript-watcher.cjs +2 -2
- package/plugin/scripts/transcript-watcher.cjs.map +1 -1
- package/plugin/scripts/worker-service.cjs +677 -669
- package/plugin/scripts/worker-service.cjs.map +3 -3
- 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/pin/SKILL.md +26 -0
- package/plugin/skills/savings/SKILL.md +22 -0
- 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,263 +0,0 @@
|
|
|
1
|
-
import copy
|
|
2
|
-
import datetime as dt
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
import shutil
|
|
6
|
-
import subprocess
|
|
7
|
-
import sys
|
|
8
|
-
import tempfile
|
|
9
|
-
import unittest
|
|
10
|
-
|
|
11
|
-
import _paths
|
|
12
|
-
import _db
|
|
13
|
-
from acr import costs, evidence, labels, period, rollup
|
|
14
|
-
from acr.period import PT
|
|
15
|
-
|
|
16
|
-
PRICES = json.load(open(os.path.join(_paths.FIXTURES, "prices_sample.json")))
|
|
17
|
-
PRICES["models"]["test/no-output"] = dict(input=1.0, output=None, cache_read=0.1, cache_write=1.25, cache_write_1h=None)
|
|
18
|
-
PRICES["models"]["test/negative"] = dict(input=-1.0, output=-1.0, cache_read=-1.0, cache_write=-1.0, cache_write_1h=None)
|
|
19
|
-
PRICES["models"]["google/gemini-2.5-flash-lite"] = dict(input=0.1, output=0.4, cache_read=None, cache_write=None, cache_write_1h=None)
|
|
20
|
-
NOW = dt.datetime(2026, 9, 25, 12, 0, tzinfo=PT)
|
|
21
|
-
W = period.resolve_window("2026-09-18", "2026-09-21", now=NOW)
|
|
22
|
-
S = W.start_epoch_ms
|
|
23
|
-
H = 3600 * 1000
|
|
24
|
-
REMOTE_UUID = "45b12c6b-d8b8-49ad-bb7f-ef49a85bab44"
|
|
25
|
-
CS4 = dict(inp=100000, out=10000)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def ms(day_offset, hours):
|
|
29
|
-
return S + day_offset * 24 * H + int(hours * H)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def ts(m):
|
|
33
|
-
return dt.datetime.fromtimestamp(m / 1000, PT).isoformat()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def row(session, m, model="claude-fable-5-1", inp=1000, out=100, cw5=0, cw1h=0, cr=0, file="/t/a.jsonl", cwd="/w/p"):
|
|
37
|
-
return dict(src="claude-code", file=file, dir="-w-p", cwd=cwd, session=session, sidechain=False, model=model, ts=ts(m), input=inp, output=out,
|
|
38
|
-
cache_write=cw5 + cw1h, cache_write_1h=cw1h, cache_write_5m=cw5, cache_read=cr, cost_usd_reported=None, device="local")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def fable_usd(inp=1000, out=100, cw5=0, cw1h=0, cr=0):
|
|
42
|
-
return (inp * 10 + out * 50 + cw5 * 12.5 + cw1h * 20 + cr * 0.25) / 1e6
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class Fixture(unittest.TestCase):
|
|
46
|
-
"""S1: local session with a transcript, completed summary, ship observation, triplicated observer rows.
|
|
47
|
-
S2: remote replica (no transcript), completed. S3: trivial. S4: abandoned local with a recovery prompt."""
|
|
48
|
-
|
|
49
|
-
def setUp(self):
|
|
50
|
-
self.tmp = tempfile.mkdtemp(prefix="acr-rollup-"); self.dbp = os.path.join(self.tmp, "memindex.db")
|
|
51
|
-
db = _db.make_db(self.dbp)
|
|
52
|
-
_db.add_session(db, "cs1", "m1", "memindex", ms(0, 9), completed_ms=ms(0, 10), user_prompt="implement the rollup")
|
|
53
|
-
for _ in range(3): _db.add_obs(db, "m1", "memindex", "discovery", "read files", 5000, ms(0, 9.2))
|
|
54
|
-
self.ship_id = _db.add_obs(db, "m1", "memindex", "change", "PR #4125 merged to main", 7000, ms(0, 9.5))
|
|
55
|
-
_db.add_summary(db, "m1", "memindex", "implement the rollup", "Rollup implemented and merged", ms(0, 9.9))
|
|
56
|
-
_db.add_prompt(db, "cs1", 1, "implement the rollup", ms(0, 9))
|
|
57
|
-
_db.add_tool(db, "cs1", "memindex", ms(0, 9.1))
|
|
58
|
-
_db.add_session(db, "cs2", "m2", "memindex/wt", ms(1, 8), completed_ms=ms(1, 9), user_prompt="fix the bug")
|
|
59
|
-
_db.add_obs(db, "m2", "memindex/wt", "bugfix", "fixed it", 20000, ms(1, 8.5), device=REMOTE_UUID)
|
|
60
|
-
_db.add_summary(db, "m2", "memindex/wt", "fix the bug", "Fixed the bug in the sync path", ms(1, 8.9), device=REMOTE_UUID)
|
|
61
|
-
_db.add_session(db, "cs3", "m3", "helper", ms(0, 20), completed_ms=ms(0, 20))
|
|
62
|
-
_db.add_session(db, "cs4", "m4", "other", ms(1, 12), completed_ms=ms(1, 13), user_prompt="resume the dig after the usage-limit reset")
|
|
63
|
-
_db.add_obs(db, "m4", "other", "discovery", "poked around", 1000, ms(1, 12.5))
|
|
64
|
-
_db.add_prompt(db, "cs4", 1, "resume the dig after the usage-limit reset", ms(1, 12))
|
|
65
|
-
db.commit(); db.close()
|
|
66
|
-
self.rows = [row("cs1", ms(0, 9.3)), row("cs1", ms(0, 9.6), cw5=2000, cw1h=1000, cr=50000),
|
|
67
|
-
row("cs4", ms(1, 12.4), **CS4), row("orphan", ms(2, 5), inp=100, out=10, file="/t/o.jsonl")]
|
|
68
|
-
|
|
69
|
-
def tearDown(self):
|
|
70
|
-
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
71
|
-
|
|
72
|
-
def build(self, rows=None, scope=None, prices=None, behavior=False):
|
|
73
|
-
import sqlite3
|
|
74
|
-
db = sqlite3.connect(self.dbp); db.row_factory = sqlite3.Row
|
|
75
|
-
try:
|
|
76
|
-
usage = dict(window=W.block(), rows=copy.deepcopy(rows if rows is not None else self.rows))
|
|
77
|
-
return rollup.build(usage, prices or PRICES, db, scope or evidence.Scope("period", S=W.start_epoch_ms, E=W.end_epoch_ms), W.block(),
|
|
78
|
-
now=NOW, use_gh=False, remote=lambda cwd: None, behavior=behavior)
|
|
79
|
-
finally:
|
|
80
|
-
db.close()
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class Rollup(Fixture):
|
|
84
|
-
def test_observer_dedup_counts_triplicated_value_once(self):
|
|
85
|
-
r, ev, _ = self.build()
|
|
86
|
-
e1 = next(x for x in ev if x["memory_session_id"] == "m1")
|
|
87
|
-
self.assertEqual(e1["observer_tokens_raw"], 3 * 5000 + 7000)
|
|
88
|
-
self.assertEqual(e1["observer_tokens"], 5000 + 7000)
|
|
89
|
-
self.assertAlmostEqual(r["spend"]["observer_note_taker_est_usd"], round((12000 + 20000 + 1000) * 0.1 / 1e6, 2))
|
|
90
|
-
|
|
91
|
-
def test_observer_never_changes_agent_estimate_or_by_day(self):
|
|
92
|
-
base, _, _ = self.build()
|
|
93
|
-
expected = fable_usd() + fable_usd(cw5=2000, cw1h=1000, cr=50000) + fable_usd(**CS4) + fable_usd(100, 10)
|
|
94
|
-
self.assertAlmostEqual(base["spend"]["agent_estimated_usd"], round(expected, 2))
|
|
95
|
-
self.assertEqual(base["spend"]["headline_usd"], base["spend"]["agent_estimated_usd"])
|
|
96
|
-
import sqlite3
|
|
97
|
-
db = sqlite3.connect(self.dbp); db.execute("update observations set discovery_tokens = discovery_tokens * 100"); db.commit(); db.close()
|
|
98
|
-
big, _, _ = self.build()
|
|
99
|
-
self.assertEqual(big["spend"]["agent_estimated_usd"], base["spend"]["agent_estimated_usd"])
|
|
100
|
-
self.assertEqual([d["agent_estimated_usd"] for d in big["by_day"]], [d["agent_estimated_usd"] for d in base["by_day"]])
|
|
101
|
-
self.assertEqual([c["agent_estimated_usd"] for c in big["by_category"]], [c["agent_estimated_usd"] for c in base["by_category"]])
|
|
102
|
-
self.assertGreater(big["spend"]["observer_note_taker_est_usd"], base["spend"]["observer_note_taker_est_usd"])
|
|
103
|
-
|
|
104
|
-
def test_measured_is_null_with_status_never_zero(self):
|
|
105
|
-
r, _, _ = self.build()
|
|
106
|
-
self.assertIsNone(r["spend"]["agent_measured_usd"]); self.assertEqual(r["spend"]["measured_status"], "unavailable")
|
|
107
|
-
self.assertEqual(r["spend"]["grok_bot_usage"]["status"], "unavailable"); self.assertNotIn("seat", str(r["spend"]["grok_bot_usage"].get("status")))
|
|
108
|
-
self.assertTrue(all(li["cost_measured"] == "unavailable" for li in r["line_items"]))
|
|
109
|
-
|
|
110
|
-
def test_by_day_covers_every_day_including_empty(self):
|
|
111
|
-
r, _, _ = self.build()
|
|
112
|
-
self.assertEqual([d["day_pt"] for d in r["by_day"]], ["2026-09-18", "2026-09-19", "2026-09-20"])
|
|
113
|
-
d3 = r["by_day"][2]
|
|
114
|
-
self.assertFalse(d3["no_agent_work"])
|
|
115
|
-
r2, _, _ = self.build(rows=self.rows[:3])
|
|
116
|
-
self.assertTrue(r2["by_day"][2]["no_agent_work"]); self.assertEqual(r2["by_day"][2]["agent_estimated_usd"], 0)
|
|
117
|
-
self.assertEqual(len(r2["timeline"]["wins_by_day"]), 3)
|
|
118
|
-
|
|
119
|
-
def test_extrapolation_only_touches_sessions_without_transcript(self):
|
|
120
|
-
r, _, _ = self.build()
|
|
121
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
122
|
-
self.assertEqual(li["m1"]["cost_basis"], "estimated_usage"); self.assertIsNone(li["m1"]["cost_extrapolated"])
|
|
123
|
-
self.assertEqual(li["m2"]["cost_basis"], "extrapolated"); self.assertIsNone(li["m2"]["cost_estimated"])
|
|
124
|
-
measured_usd = fable_usd() + fable_usd(cw5=2000, cw1h=1000, cr=50000) + fable_usd(**CS4)
|
|
125
|
-
ratio = measured_usd / (12000 + 1000)
|
|
126
|
-
self.assertAlmostEqual(li["m2"]["cost_extrapolated"], round(20000 * ratio, 2), places=2)
|
|
127
|
-
self.assertAlmostEqual(r["spend"]["extrapolated_unmeasured_usd"], round(20000 * ratio, 2), places=2)
|
|
128
|
-
self.assertTrue(r["spend"]["extrapolation_basis"].startswith("EXTRAPOLATED (low confidence)"))
|
|
129
|
-
self.assertAlmostEqual(r["spend"]["total_estimate_usd"], round(r["spend"]["agent_estimated_usd"] + r["spend"]["extrapolated_unmeasured_usd"], 2))
|
|
130
|
-
|
|
131
|
-
def test_labels_start_keyword_and_only_review_changes_them(self):
|
|
132
|
-
r, _, review = self.build()
|
|
133
|
-
self.assertTrue(all(li["label_source"] == "keyword" for li in r["line_items"]))
|
|
134
|
-
self.assertEqual(r["labels"], dict(reviewed=0, total=5))
|
|
135
|
-
self.assertTrue(all(en["label_source"] == "keyword" and en["draft_category"] for en in review["items"]))
|
|
136
|
-
rollup.aggregate(r)
|
|
137
|
-
self.assertEqual(r["labels"]["reviewed"], 0)
|
|
138
|
-
n = labels.apply_review(r["line_items"], dict(items=[dict(work_item_id="WI-1", category="Feature", failure_type="Rework", reviewed_by="user"),
|
|
139
|
-
dict(work_item_id="WI-2", category="Bug fix", reviewed_by="anthropic/claude-x")]), "2026-09-25 12:00 PT")
|
|
140
|
-
rollup.aggregate(r)
|
|
141
|
-
self.assertEqual(n, 2); self.assertEqual(r["labels"], dict(reviewed=2, total=5))
|
|
142
|
-
li = {x["work_item_id"]: x for x in r["line_items"]}
|
|
143
|
-
self.assertEqual((li["WI-1"]["label_source"], li["WI-1"]["category"], li["WI-1"]["failure_type"]), ("human", "Feature", "Rework"))
|
|
144
|
-
self.assertEqual(li["WI-2"]["label_source"], "llm"); self.assertEqual(li["WI-3"]["label_source"], "keyword")
|
|
145
|
-
self.assertIn("Rework", [f["failure_type"] for f in r["failure_economics"]])
|
|
146
|
-
|
|
147
|
-
def test_unpriced_models_contribute_zero_with_flag(self):
|
|
148
|
-
rows = self.rows + [row("cs1", ms(0, 9.7), model="test/no-output"), row("cs1", ms(0, 9.8), model="test/negative"), row("cs1", ms(0, 9.85), model="<synthetic>")]
|
|
149
|
-
base, _, _ = self.build(); r, _, _ = self.build(rows=rows)
|
|
150
|
-
self.assertEqual(r["spend"]["agent_estimated_usd"], base["spend"]["agent_estimated_usd"])
|
|
151
|
-
self.assertEqual({(u["model"], u["reason"]) for u in r["unpriced_models"]},
|
|
152
|
-
{("test/no-output", "no output price listed"), ("test/negative", "negative (variable) price listed"), ("<synthetic>", "not in price list")})
|
|
153
|
-
self.assertEqual(r["totals"]["tokens"]["api_calls"], len(rows))
|
|
154
|
-
self.assertTrue(any(a["kind"] == "unpriced" for a in r["attention"]))
|
|
155
|
-
self.assertEqual(sum(m["unpriced_calls"] for m in r["by_model"]), 3)
|
|
156
|
-
|
|
157
|
-
def test_join_key_and_unmatched_still_counted(self):
|
|
158
|
-
r, _, _ = self.build()
|
|
159
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
160
|
-
self.assertTrue(li["m1"]["has_transcript"]); self.assertEqual(li["m1"]["agent_calls"], 2)
|
|
161
|
-
self.assertEqual(r["unmatched_transcripts"]["count"], 1); self.assertEqual(r["unmatched_transcripts"]["sessions"][0]["session"], "orphan")
|
|
162
|
-
self.assertAlmostEqual(r["unmatched_transcripts"]["usd"], round(fable_usd(100, 10), 2))
|
|
163
|
-
self.assertEqual(r["totals"]["tokens"]["input"], 1000 + 1000 + CS4["inp"] + 100)
|
|
164
|
-
|
|
165
|
-
def test_devices_labeled_never_uuid(self):
|
|
166
|
-
r, ev, review = self.build()
|
|
167
|
-
self.assertEqual([d["device"] for d in r["devices"]], ["local", "remote-1"])
|
|
168
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
169
|
-
self.assertEqual(li["m2"]["device"], ["remote-1"]); self.assertEqual(li["m1"]["device"], ["local"])
|
|
170
|
-
self.assertNotIn(REMOTE_UUID, json.dumps([r, ev, review])); self.assertEqual(r["totals"]["devices"], 2)
|
|
171
|
-
|
|
172
|
-
def test_statuses_trivial_and_totals(self):
|
|
173
|
-
r, _, _ = self.build()
|
|
174
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
175
|
-
self.assertEqual(li["m1"]["status"], "shipped"); self.assertEqual(li["m2"]["status"], "completed")
|
|
176
|
-
self.assertEqual(li["m3"]["status"], "abandoned"); self.assertTrue(li["m3"]["trivial"]); self.assertEqual(li["m4"]["status"], "abandoned")
|
|
177
|
-
self.assertEqual(li["m4"]["failure_signals"], ["Recovery after miss"]); self.assertEqual(li["m4"]["failure_type"], "Recovery after miss")
|
|
178
|
-
t = r["totals"]
|
|
179
|
-
self.assertEqual((t["sessions"], t["real_work_sessions"], t["finished_outcomes"], t["ship_events"], t["projects"], t["repos"]), (4, 3, 2, 1, 4, 3)); self.assertEqual(t["transcript_only_sessions"], 1)
|
|
180
|
-
orphan = next(li for li in r["line_items"] if li["content_session_id"] == "orphan")
|
|
181
|
-
self.assertEqual((orphan["status"], orphan["cost_basis"], orphan["has_transcript"], orphan["confidence"]), ("in_progress", "estimated_usage", True, "low"))
|
|
182
|
-
self.assertEqual(li["m4"]["wasted_cost"], li["m4"]["attributed_usd"]); self.assertGreater(t["waste_rate"], 0)
|
|
183
|
-
self.assertEqual(r["trivial_sessions"][0]["work_item_id"], li["m3"]["work_item_id"])
|
|
184
|
-
self.assertIsInstance(r["failure_economics"], list); self.assertLessEqual(len(r["attention"]), 3)
|
|
185
|
-
self.assertNotIn("Rework", [c["category"] for c in r["by_category"]])
|
|
186
|
-
|
|
187
|
-
def test_session_scope_on_transcript_only_id_builds(self):
|
|
188
|
-
r, _, _ = self.build(scope=evidence.Scope("session", session="orphan"))
|
|
189
|
-
self.assertEqual([li["work_item_id"] for li in r["line_items"]], ["WI-1"]); self.assertTrue(r["line_items"][0]["orphan"])
|
|
190
|
-
self.assertEqual(r["unmatched_transcripts"]["count"], 1)
|
|
191
|
-
|
|
192
|
-
def test_usage_rows_outside_window_are_not_priced(self):
|
|
193
|
-
r, _, _ = self.build(rows=self.rows + [row("cs1", ms(-1, 5), inp=999999), row("cs1", ms(3, 0), inp=999999)])
|
|
194
|
-
self.assertEqual(r["window"]["usage_rows_outside_window"], 2)
|
|
195
|
-
self.assertEqual(r["totals"]["tokens"]["input"], 1000 + 1000 + CS4["inp"] + 100)
|
|
196
|
-
self.assertEqual(r["spend"]["agent_estimated_usd"], self.build()[0]["spend"]["agent_estimated_usd"])
|
|
197
|
-
|
|
198
|
-
def test_no_ratio_marks_sessions_without_transcript_unmeasured(self):
|
|
199
|
-
r, _, _ = self.build(rows=[])
|
|
200
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
201
|
-
self.assertEqual((li["m2"]["cost_status"], li["m2"]["cost_extrapolated"], li["m2"]["attributed_usd"]), ("unmeasured", None, 0.0))
|
|
202
|
-
self.assertIsNone(r["spend"]["extrapolated_unmeasured_usd"]); self.assertTrue(r["spend"]["extrapolation_basis"].startswith("n/a"))
|
|
203
|
-
r, _, _ = self.build()
|
|
204
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}
|
|
205
|
-
self.assertEqual((li["m1"]["cost_status"], li["m2"]["cost_status"]), ("estimated", "extrapolated"))
|
|
206
|
-
|
|
207
|
-
def test_project_scope_metadata_excludes_other_projects(self):
|
|
208
|
-
r, _, _ = self.build(scope=evidence.Scope("project", S=W.start_epoch_ms, E=W.end_epoch_ms, project="memindex"))
|
|
209
|
-
self.assertEqual(r["observer"]["rows_in_scope"], dict(observations=5, summaries=2, prompts=1, tool_uses=1))
|
|
210
|
-
self.assertEqual(r["totals"]["devices"], 2)
|
|
211
|
-
|
|
212
|
-
def test_review_recomputes_per_day_finished_outcomes(self):
|
|
213
|
-
r, _, _ = self.build()
|
|
214
|
-
self.assertEqual(sum(d["finished_outcomes"] for d in r["by_day"]), r["totals"]["finished_outcomes"])
|
|
215
|
-
li = {x["session_ids"][0]: x for x in r["line_items"]}; self.assertEqual(li["m4"]["status"], "abandoned")
|
|
216
|
-
labels.apply_review(r["line_items"], [dict(work_item_id=li["m4"]["work_item_id"], category="Investigation", reviewed_by="user", status="completed")], "t")
|
|
217
|
-
rollup.aggregate(r)
|
|
218
|
-
self.assertEqual(r["totals"]["finished_outcomes"], 3); self.assertEqual(sum(d["finished_outcomes"] for d in r["by_day"]), 3)
|
|
219
|
-
self.assertEqual(next(d for d in r["by_day"] if d["day_pt"] == li["m4"]["date_pt"])["finished_outcomes"], 2)
|
|
220
|
-
orphan = next(x for x in r["line_items"] if x.get("orphan"))
|
|
221
|
-
labels.apply_review(r["line_items"], [dict(work_item_id=orphan["work_item_id"], category="Feature", reviewed_by="user", status="shipped")], "t")
|
|
222
|
-
rollup.aggregate(r)
|
|
223
|
-
self.assertEqual((r["totals"]["finished_outcomes"], sum(d["finished_outcomes"] for d in r["by_day"])), (3, 3))
|
|
224
|
-
|
|
225
|
-
def test_project_scope_includes_worktrees_and_session_scope(self):
|
|
226
|
-
r, _, _ = self.build(scope=evidence.Scope("project", S=W.start_epoch_ms, E=W.end_epoch_ms, project="memindex"))
|
|
227
|
-
self.assertEqual({x["session_ids"][0] for x in r["line_items"]}, {"m1", "m2"}); self.assertEqual(r["unmatched_transcripts"]["count"], 0)
|
|
228
|
-
r, _, _ = self.build(scope=evidence.Scope("session", session="cs1"))
|
|
229
|
-
self.assertEqual(len(r["line_items"]), 1); self.assertEqual([d["day_pt"] for d in r["by_day"]], ["2026-09-18"])
|
|
230
|
-
self.assertEqual(r["spend"]["agent_estimated_usd"], round(fable_usd() + fable_usd(cw5=2000, cw1h=1000, cr=50000), 2))
|
|
231
|
-
self.assertEqual(r["totals"]["tokens"]["api_calls"], 2); self.assertEqual(r["unmatched_transcripts"]["count"], 0)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
class Cli(Fixture):
|
|
235
|
-
def test_rollup_and_review_cli(self):
|
|
236
|
-
out = os.path.join(self.tmp, "out"); os.makedirs(out)
|
|
237
|
-
json.dump(dict(window=W.block(), collector={}, rows=self.rows), open(os.path.join(out, "usage.json"), "w"))
|
|
238
|
-
pf = os.path.join(self.tmp, "prices.json"); json.dump(PRICES, open(pf, "w"))
|
|
239
|
-
r = subprocess.run([sys.executable, _paths.ACR_PY, "rollup", "--start", "2026-09-18", "--end", "2026-09-21", "--out", out, "--prices", pf,
|
|
240
|
-
"--db", self.dbp, "--no-gh"], capture_output=True, text=True)
|
|
241
|
-
self.assertEqual(r.returncode, 0, r.stderr)
|
|
242
|
-
for f in ("report.json", "line-items.csv", "evidence.json", "labels.review.json", "snapshot.db"):
|
|
243
|
-
self.assertTrue(os.path.exists(os.path.join(out, f)), f)
|
|
244
|
-
rep = json.load(open(os.path.join(out, "report.json")))
|
|
245
|
-
self.assertEqual(rep["spend"]["measured_status"], "unavailable"); self.assertEqual(rep["labels"]["reviewed"], 0)
|
|
246
|
-
rv = json.load(open(os.path.join(out, "labels.review.json")))
|
|
247
|
-
rv["items"][0].update(category="Feature", reviewed_by="user")
|
|
248
|
-
rf = os.path.join(self.tmp, "reviewed.json"); json.dump(rv, open(rf, "w"))
|
|
249
|
-
r = subprocess.run([sys.executable, _paths.ACR_PY, "review", "--apply", rf, "--out", out], capture_output=True, text=True)
|
|
250
|
-
self.assertEqual(r.returncode, 0, r.stderr)
|
|
251
|
-
rep = json.load(open(os.path.join(out, "report.json")))
|
|
252
|
-
self.assertEqual(rep["labels"], dict(reviewed=1, total=5)); self.assertEqual(rep["line_items"][0]["label_source"], "human")
|
|
253
|
-
rv["items"][1].update(category="Feature", failure_type="Made-up type", reviewed_by="user"); json.dump(rv, open(rf, "w"))
|
|
254
|
-
r = subprocess.run([sys.executable, _paths.ACR_PY, "review", "--apply", rf, "--out", out], capture_output=True, text=True)
|
|
255
|
-
self.assertNotEqual(r.returncode, 0); self.assertIn("unknown failure type", r.stderr)
|
|
256
|
-
|
|
257
|
-
def test_rollup_rejects_session_with_period(self):
|
|
258
|
-
r = subprocess.run([sys.executable, _paths.ACR_PY, "rollup", "--session", "x", "--start", "2026-09-18", "--out", self.tmp], capture_output=True, text=True)
|
|
259
|
-
self.assertNotEqual(r.returncode, 0); self.assertIn("--session", r.stderr)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if __name__ == "__main__":
|
|
263
|
-
unittest.main()
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import shutil
|
|
3
|
-
import sqlite3
|
|
4
|
-
import tempfile
|
|
5
|
-
import unittest
|
|
6
|
-
|
|
7
|
-
import _paths # noqa: F401
|
|
8
|
-
from acr import snapshot
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class DbPath(unittest.TestCase):
|
|
12
|
-
def test_env_override(self):
|
|
13
|
-
self.assertEqual(snapshot.db_path({"MEMINDEX_DATA_DIR": "/data/mem"}), "/data/mem/memindex.db")
|
|
14
|
-
|
|
15
|
-
def test_default_is_home_memindex(self):
|
|
16
|
-
self.assertEqual(snapshot.db_path({}), os.path.expanduser("~/.memindex/memindex.db"))
|
|
17
|
-
self.assertEqual(snapshot.db_path({"MEMINDEX_DATA_DIR": ""}), os.path.expanduser("~/.memindex/memindex.db"))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class Backup(unittest.TestCase):
|
|
21
|
-
def setUp(self):
|
|
22
|
-
self.tmp = tempfile.mkdtemp(prefix="acr-snap-")
|
|
23
|
-
self.live = os.path.join(self.tmp, "live", "memindex.db")
|
|
24
|
-
os.makedirs(os.path.dirname(self.live))
|
|
25
|
-
db = sqlite3.connect(self.live)
|
|
26
|
-
db.execute("PRAGMA journal_mode=WAL")
|
|
27
|
-
db.execute("CREATE TABLE sdk_sessions (content_session_id TEXT, project TEXT, started_at_epoch INTEGER)")
|
|
28
|
-
db.executemany("INSERT INTO sdk_sessions VALUES (?,?,?)", [("s1", "p", 1), ("s2", "q", 2)])
|
|
29
|
-
db.commit()
|
|
30
|
-
db.close()
|
|
31
|
-
|
|
32
|
-
def tearDown(self):
|
|
33
|
-
shutil.rmtree(self.tmp, ignore_errors=True)
|
|
34
|
-
|
|
35
|
-
def test_snapshot_is_a_faithful_copy_and_live_is_untouched(self):
|
|
36
|
-
before = os.stat(self.live)
|
|
37
|
-
out = os.path.join(self.tmp, "out")
|
|
38
|
-
snap = snapshot.snapshot(out, live=self.live)
|
|
39
|
-
self.assertEqual(snap, os.path.join(out, "snapshot.db"))
|
|
40
|
-
after = os.stat(self.live)
|
|
41
|
-
self.assertEqual((before.st_mtime_ns, before.st_size), (after.st_mtime_ns, after.st_size))
|
|
42
|
-
db = snapshot.open_snapshot(snap)
|
|
43
|
-
rows = db.execute("SELECT content_session_id, project FROM sdk_sessions ORDER BY 1").fetchall()
|
|
44
|
-
db.close()
|
|
45
|
-
self.assertEqual([tuple(r) for r in rows], [("s1", "p"), ("s2", "q")])
|
|
46
|
-
snap2 = snapshot.snapshot(out, live=self.live)
|
|
47
|
-
self.assertEqual(snap, snap2)
|
|
48
|
-
|
|
49
|
-
def test_env_resolution_used_when_live_not_given(self):
|
|
50
|
-
os.environ["MEMINDEX_DATA_DIR"] = os.path.dirname(self.live)
|
|
51
|
-
try:
|
|
52
|
-
snap = snapshot.snapshot(os.path.join(self.tmp, "out2"))
|
|
53
|
-
finally:
|
|
54
|
-
del os.environ["MEMINDEX_DATA_DIR"]
|
|
55
|
-
self.assertTrue(os.path.exists(snap))
|
|
56
|
-
|
|
57
|
-
def test_missing_db_is_a_clear_error(self):
|
|
58
|
-
with self.assertRaises(FileNotFoundError):
|
|
59
|
-
snapshot.snapshot(os.path.join(self.tmp, "out3"), live=os.path.join(self.tmp, "nope.db"))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if __name__ == "__main__":
|
|
63
|
-
unittest.main()
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"""Phase 7.2 tests: shipped-file list, CHECKSUMS.txt, drift detection and --write against temp destinations."""
|
|
2
|
-
import os
|
|
3
|
-
import shutil
|
|
4
|
-
import subprocess
|
|
5
|
-
import sys
|
|
6
|
-
import tempfile
|
|
7
|
-
import unittest
|
|
8
|
-
|
|
9
|
-
import _paths # noqa: F401
|
|
10
|
-
from acr import sync
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class Sync(unittest.TestCase):
|
|
14
|
-
def setUp(self):
|
|
15
|
-
self.tmp = tempfile.mkdtemp(); self.src = os.path.join(self.tmp, "plugin", "skills", "agent-cost-report")
|
|
16
|
-
os.makedirs(os.path.join(self.src, "scripts", "acr")); os.makedirs(os.path.join(self.src, "scripts", "__pycache__"))
|
|
17
|
-
for rel, body in (("SKILL.md", "# skill\n"), ("scripts/acr.py", "print(1)\n"), ("scripts/acr/x.py", "x = 1\n"), ("scripts/__pycache__/x.pyc", "junk"), ("README.md", "not shipped\n")):
|
|
18
|
-
with open(os.path.join(self.src, rel), "w") as fh: fh.write(body)
|
|
19
|
-
self.dests = [os.path.join(self.tmp, "mirror-a", "skills", "agent-cost-report"), os.path.join(self.tmp, "mirror-b", "skills", "agent-cost-report")]
|
|
20
|
-
|
|
21
|
-
def tearDown(self):
|
|
22
|
-
shutil.rmtree(self.tmp)
|
|
23
|
-
|
|
24
|
-
def test_shipped_files_and_checksums(self):
|
|
25
|
-
self.assertEqual(sync.shipped_files(self.src), ["SKILL.md", "scripts/acr.py", "scripts/acr/x.py"])
|
|
26
|
-
lines = sync.write_checksums(self.src)
|
|
27
|
-
self.assertEqual(len(lines), 3); self.assertTrue(all(len(l.split(" ")[0]) == 64 for l in lines))
|
|
28
|
-
r = subprocess.run(["sha256sum", "-c", sync.CHECKSUMS], cwd=self.src, capture_output=True, text=True)
|
|
29
|
-
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
|
|
30
|
-
|
|
31
|
-
def test_drift_then_write(self):
|
|
32
|
-
out = []
|
|
33
|
-
self.assertEqual(sync.run(dests=self.dests, src=self.src, out=out.append), 8)
|
|
34
|
-
self.assertTrue(all(l.startswith("DRIFT") for l in out))
|
|
35
|
-
out.clear(); self.assertEqual(sync.run(write=True, dests=self.dests, src=self.src, out=out.append), 0)
|
|
36
|
-
self.assertTrue(all(l.startswith("ok") for l in out))
|
|
37
|
-
self.assertFalse(os.path.exists(os.path.join(self.dests[0], "README.md")))
|
|
38
|
-
self.assertFalse(os.path.exists(os.path.join(self.dests[0], "scripts", "__pycache__")))
|
|
39
|
-
with open(os.path.join(self.dests[1], "scripts", "acr", "x.py"), "w") as fh: fh.write("x = 2\n")
|
|
40
|
-
self.assertEqual(sync.run(dests=self.dests, src=self.src, out=out.append), 1)
|
|
41
|
-
|
|
42
|
-
def test_default_destinations_are_the_four_mirrors_only(self):
|
|
43
|
-
d = sync.destinations(repo_root="/r")
|
|
44
|
-
self.assertEqual(d, [f"/r/{m}/skills/agent-cost-report" for m in ("integrations/cursor", "integrations/grok-bot", "integrations/cowork", "integrations/openclaw")])
|
|
45
|
-
|
|
46
|
-
def test_cli_exit_code(self):
|
|
47
|
-
r = subprocess.run([sys.executable, _paths.ACR_PY, "sync-check", "--dest", self.dests[0]], capture_output=True, text=True)
|
|
48
|
-
self.assertEqual(r.returncode, 1, r.stdout + r.stderr); self.assertIn("DRIFT", r.stdout)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if __name__ == "__main__":
|
|
52
|
-
unittest.main()
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"""Read the UTF-8 transcript contract under native Windows legacy encoding, and keep every text read and
|
|
2
|
-
write in the skill on an explicit encoding (the guard runs on every OS)."""
|
|
3
|
-
import argparse
|
|
4
|
-
import ast
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
import shutil
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
import tempfile
|
|
11
|
-
import unittest
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
|
|
14
|
-
import _paths
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class ExplicitEncoding(unittest.TestCase):
|
|
18
|
-
def test_every_text_open_and_text_subprocess_names_an_encoding(self):
|
|
19
|
-
missing = []
|
|
20
|
-
for source in [Path(_paths.ACR_PY), *sorted(Path(_paths.SCRIPTS, "acr").glob("*.py"))]:
|
|
21
|
-
for node in ast.walk(ast.parse(source.read_text(encoding="utf-8"))):
|
|
22
|
-
if not isinstance(node, ast.Call): continue
|
|
23
|
-
kw = {k.arg: k.value for k in node.keywords}
|
|
24
|
-
if "encoding" in kw: continue
|
|
25
|
-
mode = node.args[1] if len(node.args) > 1 else kw.get("mode")
|
|
26
|
-
binary = isinstance(mode, ast.Constant) and isinstance(mode.value, str) and "b" in mode.value
|
|
27
|
-
text_open = isinstance(node.func, ast.Name) and node.func.id == "open" and not binary
|
|
28
|
-
text_run = any(isinstance(kw.get(k), ast.Constant) and kw[k].value is True for k in ("text", "universal_newlines"))
|
|
29
|
-
if text_open or text_run: missing.append(f"{source.name}:{node.lineno}")
|
|
30
|
-
self.assertEqual(missing, [])
|
|
31
|
-
|
|
32
|
-
def test_review_apply_accepts_a_reviewed_file_saved_with_a_bom(self):
|
|
33
|
-
from acr import rollup
|
|
34
|
-
tmp = tempfile.mkdtemp(); self.addCleanup(shutil.rmtree, tmp, True)
|
|
35
|
-
shutil.copy(os.path.join(_paths.FIXTURES, "report-7day.json"), os.path.join(tmp, "report.json"))
|
|
36
|
-
reviewed = dict(reviewed_by="user", items=[dict(work_item_id="WI-1", category="Feature", title="Résumé — naïve ✓")])
|
|
37
|
-
with open(os.path.join(tmp, "reviewed.json"), "wb") as fh:
|
|
38
|
-
fh.write(b"\xef\xbb\xbf" + json.dumps(reviewed, ensure_ascii=False).encode("utf-8"))
|
|
39
|
-
rollup.run_review(argparse.Namespace(out=tmp, apply=os.path.join(tmp, "reviewed.json")))
|
|
40
|
-
with open(os.path.join(tmp, "report.json"), encoding="utf-8") as fh: item = next(li for li in json.load(fh)["line_items"] if li["work_item_id"] == "WI-1")
|
|
41
|
-
self.assertEqual((item["reviewed_by"], item["label_source"], item["title"]), ("user", "human", "Résumé — naïve ✓"))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@unittest.skipUnless(os.name == "nt", "Native Windows default-encoding regression")
|
|
45
|
-
class TranscriptEncoding(unittest.TestCase):
|
|
46
|
-
def check_reader(self, kind):
|
|
47
|
-
program = r'''
|
|
48
|
-
import json, locale, pathlib, sys, tempfile
|
|
49
|
-
sys.path.insert(0, sys.argv[1])
|
|
50
|
-
from acr import transcripts, behavior, wins, rules
|
|
51
|
-
encoding = locale.getpreferredencoding(False)
|
|
52
|
-
assert encoding.lower() != "utf-8", encoding
|
|
53
|
-
with tempfile.TemporaryDirectory() as folder:
|
|
54
|
-
source = pathlib.Path(folder) / "session.jsonl"
|
|
55
|
-
usage = {"input_tokens": 10, "output_tokens": 2}
|
|
56
|
-
a = {"type": "assistant", "timestamp": "2026-09-18T12:00:00Z", "sessionId": "session",
|
|
57
|
-
"cwd": "C:/workspace/中文", "requestId": "request", "message": {"id": "message", "usage": usage,
|
|
58
|
-
"content": [{"type": "text", "text": "完成工作"}, {"type": "tool_use", "id": "tool", "name": "Bash",
|
|
59
|
-
"input": {"command": "gh pr merge 42"}}]}}
|
|
60
|
-
u = {"type": "user", "timestamp": "2026-09-18T12:00:01Z", "sessionId": "session",
|
|
61
|
-
"message": {"content": [{"type": "tool_result", "tool_use_id": "tool", "content": "合并完成"}]}}
|
|
62
|
-
source.write_text("\n".join(json.dumps(x, ensure_ascii=False) for x in (a, u))+"\n", encoding="utf-8")
|
|
63
|
-
if sys.argv[2] == "codex":
|
|
64
|
-
events = [{"type": "turn_context", "payload": {"model": "gpt-5-é"}},
|
|
65
|
-
{"type": "event_msg", "timestamp": "2026-09-18T12:00:00Z",
|
|
66
|
-
"payload": {"type": "token_count", "info": {"total_token_usage": usage}}}]
|
|
67
|
-
source.write_text("\n".join(json.dumps(x, ensure_ascii=False) for x in events)+"\n", encoding="utf-8")
|
|
68
|
-
rows, _ = transcripts.collect_codex(None, None, pattern=str(source))
|
|
69
|
-
assert len(rows) == 1 and rows[0]["input"] == 10 and rows[0]["output"] == 2, repr(rows)
|
|
70
|
-
assert rows[0]["model"] == "gpt-5-é", repr(rows[0]["model"])
|
|
71
|
-
elif sys.argv[2] == "usage":
|
|
72
|
-
rows, _ = transcripts.collect_claude(None, None, session="session", pattern=str(source))
|
|
73
|
-
assert len(rows) == 1 and rows[0]["input"] == 10
|
|
74
|
-
assert rows[0]["cwd"] == "C:/workspace/中文", repr(rows[0]["cwd"])
|
|
75
|
-
elif sys.argv[2] == "behavior":
|
|
76
|
-
sessions, _ = behavior.scan(None, None, session="session", pattern=str(source))
|
|
77
|
-
turn = next(iter(sessions["session"]["turns"].values()))
|
|
78
|
-
assert turn["text"] == "完成工作", repr(turn["text"])
|
|
79
|
-
elif sys.argv[2] == "wins":
|
|
80
|
-
items = list(wins.scan_transcripts([str(source)]))
|
|
81
|
-
assert len(items) == 1
|
|
82
|
-
assert items[0]["cwd"] == "C:/workspace/中文", repr(items[0]["cwd"])
|
|
83
|
-
assert "合并完成" in items[0]["result"], repr(items[0]["result"])
|
|
84
|
-
else:
|
|
85
|
-
rule = pathlib.Path(folder) / "rules.md"
|
|
86
|
-
rule.write_text("# 保留证据 (HARD — owner 2026-09-18)\n", encoding="utf-8")
|
|
87
|
-
items = rules.scan_rule_files(folder)
|
|
88
|
-
assert len(items) == 1 and items[0]["name"] == "保留证据", repr(items)
|
|
89
|
-
'''
|
|
90
|
-
result = subprocess.run(
|
|
91
|
-
[sys.executable, "-X", "utf8=0", "-c", program, _paths.SCRIPTS, kind],
|
|
92
|
-
env=dict(os.environ, PYTHONUTF8="0"), capture_output=True,
|
|
93
|
-
)
|
|
94
|
-
self.assertEqual(result.returncode, 0, result.stderr.decode("utf-8", errors="replace"))
|
|
95
|
-
|
|
96
|
-
def test_usage_retains_unicode_workspace(self):
|
|
97
|
-
self.check_reader("usage")
|
|
98
|
-
|
|
99
|
-
def test_behavior_retains_unicode_evidence(self):
|
|
100
|
-
self.check_reader("behavior")
|
|
101
|
-
|
|
102
|
-
def test_wins_retain_unicode_workspace_and_result(self):
|
|
103
|
-
self.check_reader("wins")
|
|
104
|
-
|
|
105
|
-
def test_rule_names_retain_unicode(self):
|
|
106
|
-
self.check_reader("rules")
|
|
107
|
-
|
|
108
|
-
def test_codex_retains_unicode_model(self):
|
|
109
|
-
self.check_reader("codex")
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import datetime as dt
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
import platform
|
|
5
|
-
import shutil
|
|
6
|
-
import tempfile
|
|
7
|
-
import unittest
|
|
8
|
-
|
|
9
|
-
import _paths
|
|
10
|
-
from acr import period, transcripts
|
|
11
|
-
from acr.period import PT
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class Collector(unittest.TestCase):
|
|
15
|
-
"""Fixtures are copied into a temp dir so their mtime is 'now' (the reader prefilters on mtime)."""
|
|
16
|
-
|
|
17
|
-
@classmethod
|
|
18
|
-
def setUpClass(cls):
|
|
19
|
-
cls.tmp = tempfile.mkdtemp(prefix="acr-tests-")
|
|
20
|
-
shutil.copytree(os.path.join(_paths.FIXTURES, "projects"), os.path.join(cls.tmp, "projects"), copy_function=shutil.copy)
|
|
21
|
-
shutil.copytree(os.path.join(_paths.FIXTURES, "codex"), os.path.join(cls.tmp, "codex"), copy_function=shutil.copy)
|
|
22
|
-
cls.claude_glob = os.path.join(cls.tmp, "projects", "**", "*.jsonl")
|
|
23
|
-
cls.codex_glob = os.path.join(cls.tmp, "codex", "sessions", "**", "*.jsonl")
|
|
24
|
-
cls.now = dt.datetime(2026, 9, 25, 16, 42, tzinfo=PT)
|
|
25
|
-
cls.window = period.resolve_window("2026-09-18", "2026-09-19", now=cls.now)
|
|
26
|
-
|
|
27
|
-
@classmethod
|
|
28
|
-
def tearDownClass(cls):
|
|
29
|
-
shutil.rmtree(cls.tmp, ignore_errors=True)
|
|
30
|
-
|
|
31
|
-
def collect(self, **kw):
|
|
32
|
-
return transcripts.collect(kw.pop("window", self.window), claude_glob=self.claude_glob,
|
|
33
|
-
codex_glob=self.codex_glob, **kw)
|
|
34
|
-
|
|
35
|
-
def by_msg(self, doc):
|
|
36
|
-
out = {}
|
|
37
|
-
for r in doc["rows"]:
|
|
38
|
-
if r["src"] == "claude-code":
|
|
39
|
-
out.setdefault((r["session"], r["input"]), r)
|
|
40
|
-
return out
|
|
41
|
-
|
|
42
|
-
def test_dedup_on_message_id_and_request_id(self):
|
|
43
|
-
doc = self.collect()
|
|
44
|
-
claude = [r for r in doc["rows"] if r["src"] == "claude-code"]
|
|
45
|
-
self.assertEqual(len(claude), 4)
|
|
46
|
-
self.assertEqual(doc["collector"]["dedup_dropped"], 1)
|
|
47
|
-
self.assertEqual(sum(1 for r in claude if r["input"] == 10), 1)
|
|
48
|
-
|
|
49
|
-
def test_window_edges_start_included_end_excluded(self):
|
|
50
|
-
doc = self.collect()
|
|
51
|
-
inputs = sorted(r["input"] for r in doc["rows"] if r["src"] == "claude-code")
|
|
52
|
-
self.assertIn(10, inputs)
|
|
53
|
-
self.assertNotIn(1000, inputs)
|
|
54
|
-
row = next(r for r in doc["rows"] if r["input"] == 10)
|
|
55
|
-
self.assertEqual(row["ts"], "2026-09-18T00:00:00-07:00")
|
|
56
|
-
|
|
57
|
-
def test_cache_split_direct_ephemeral_5m_field(self):
|
|
58
|
-
row = self.by_msg(self.collect())[("sess-aaaa", 10)]
|
|
59
|
-
self.assertEqual((row["cache_write"], row["cache_write_1h"], row["cache_write_5m"]), (100, 40, 60))
|
|
60
|
-
|
|
61
|
-
def test_cache_split_fallback_subtraction(self):
|
|
62
|
-
rows = self.by_msg(self.collect())
|
|
63
|
-
r3 = rows[("sess-aaaa", 1)]
|
|
64
|
-
self.assertEqual((r3["cache_write"], r3["cache_write_1h"], r3["cache_write_5m"]), (100, 30, 70))
|
|
65
|
-
r4 = rows[("sess-aaaa", 3)]
|
|
66
|
-
self.assertEqual((r4["cache_write"], r4["cache_write_1h"], r4["cache_write_5m"]), (100, 0, 100))
|
|
67
|
-
|
|
68
|
-
def test_row_fields_and_extensions(self):
|
|
69
|
-
rows = self.by_msg(self.collect())
|
|
70
|
-
r = rows[("sess-bbbb", 50)]
|
|
71
|
-
self.assertEqual(set(r), {"src", "file", "dir", "cwd", "session", "sidechain", "model", "ts", "input", "output",
|
|
72
|
-
"cache_write", "cache_write_1h", "cache_write_5m", "cache_read", "cost_usd_reported", "device"})
|
|
73
|
-
self.assertEqual(r["dir"], "-workspace-proj-b")
|
|
74
|
-
self.assertEqual(r["cwd"], "/workspace/proj-b")
|
|
75
|
-
self.assertTrue(r["sidechain"])
|
|
76
|
-
self.assertEqual(r["device"], "local")
|
|
77
|
-
self.assertEqual(r["cost_usd_reported"], 0.0123)
|
|
78
|
-
self.assertEqual(r["model"], "claude-fable-5-1")
|
|
79
|
-
self.assertIsNone(rows[("sess-aaaa", 10)]["cost_usd_reported"])
|
|
80
|
-
|
|
81
|
-
def test_collector_block(self):
|
|
82
|
-
doc = self.collect()
|
|
83
|
-
c = doc["collector"]
|
|
84
|
-
self.assertEqual(c["host_label"], platform.node())
|
|
85
|
-
self.assertNotRegex(c["host_label"], r"^[0-9a-f]{8}-[0-9a-f]{4}-")
|
|
86
|
-
self.assertEqual(c["files_seen"], 3)
|
|
87
|
-
self.assertEqual(c["files_seen_by_src"], {"claude-code": 2, "codex": 1})
|
|
88
|
-
self.assertEqual(c["rows"], len(doc["rows"]))
|
|
89
|
-
self.assertEqual(c["window"], doc["window"])
|
|
90
|
-
self.assertEqual(doc["window"]["start_pt"], "2026-09-18")
|
|
91
|
-
self.assertFalse(doc["window"]["partial_last_day"])
|
|
92
|
-
self.assertEqual(c["glob"], [self.claude_glob, self.codex_glob])
|
|
93
|
-
|
|
94
|
-
def test_codex_cumulative_counter_becomes_per_event_growth_in_window(self):
|
|
95
|
-
doc = self.collect()
|
|
96
|
-
codex = [r for r in doc["rows"] if r["src"] == "codex"]
|
|
97
|
-
self.assertEqual(len(codex), 2)
|
|
98
|
-
self.assertEqual([(r["input"], r["output"], r["cache_read"]) for r in codex], [(100 - 40, 10, 40), (400 - 160, 70, 160)])
|
|
99
|
-
self.assertEqual((sum(r["input"] for r in codex), sum(r["output"] for r in codex), sum(r["cache_read"] for r in codex)), (500 - 200, 80, 200))
|
|
100
|
-
r = codex[0]
|
|
101
|
-
self.assertEqual(r["model"], "gpt-5-codex")
|
|
102
|
-
self.assertEqual(r["session"], "rollout-codex-1.jsonl")
|
|
103
|
-
self.assertEqual(r["device"], "local")
|
|
104
|
-
self.assertEqual(r["cache_write_5m"], 0)
|
|
105
|
-
|
|
106
|
-
def test_codex_usage_before_the_window_is_subtracted(self):
|
|
107
|
-
d = os.path.join(self.tmp, "codex", "sessions", "2026", "09", "17"); os.makedirs(d, exist_ok=True); self.addCleanup(shutil.rmtree, d, ignore_errors=True)
|
|
108
|
-
ev = lambda t, i, c, o: json.dumps(dict(timestamp=t, type="event_msg", payload=dict(type="token_count", info=dict(total_token_usage=dict(input_tokens=i, cached_input_tokens=c, output_tokens=o)))))
|
|
109
|
-
with open(os.path.join(d, "rollout-boundary.jsonl"), "w") as fh:
|
|
110
|
-
fh.write(json.dumps(dict(timestamp="2026-09-17T20:00:00.000Z", type="turn_context", payload=dict(model="gpt-5-codex"))) + "\n")
|
|
111
|
-
fh.write(ev("2026-09-17T20:00:05.000Z", 300000, 100000, 50000) + "\n")
|
|
112
|
-
fh.write(ev("2026-09-18T15:00:00.000Z", 300000, 100000, 50000) + "\n")
|
|
113
|
-
fh.write(ev("2026-09-18T16:00:00.000Z", 350000, 120000, 60000) + "\n")
|
|
114
|
-
fh.write(ev("2026-09-18T23:00:00.000Z", 360000, 120000, 61000) + "\n")
|
|
115
|
-
doc = self.collect()
|
|
116
|
-
rows = [r for r in doc["rows"] if r["src"] == "codex" and r["session"] == "rollout-boundary.jsonl"]
|
|
117
|
-
self.assertEqual([(r["input"], r["cache_read"], r["output"]) for r in rows], [(30000, 20000, 10000), (10000, 0, 1000)])
|
|
118
|
-
self.assertEqual(sum(r["input"] + r["cache_read"] for r in rows), 360000 - 300000)
|
|
119
|
-
|
|
120
|
-
def test_session_filter_has_no_period_filter(self):
|
|
121
|
-
block = period.session_block("sess-aaaa", now=self.now)
|
|
122
|
-
doc = self.collect(window=None, session="sess-aaaa", window_block=block)
|
|
123
|
-
sessions = {r["session"] for r in doc["rows"]}
|
|
124
|
-
self.assertEqual(sessions, {"sess-aaaa"})
|
|
125
|
-
inputs = sorted(r["input"] for r in doc["rows"])
|
|
126
|
-
self.assertEqual(inputs, [1, 3, 10, 1000])
|
|
127
|
-
self.assertEqual(doc["collector"]["dedup_dropped"], 1)
|
|
128
|
-
self.assertEqual(doc["window"]["session"], "sess-aaaa")
|
|
129
|
-
self.assertIsNone(doc["window"]["start_pt"])
|
|
130
|
-
|
|
131
|
-
def test_session_filter_other_session(self):
|
|
132
|
-
doc = self.collect(window=None, session="sess-bbbb", window_block=period.session_block("sess-bbbb", now=self.now))
|
|
133
|
-
self.assertEqual([r["session"] for r in doc["rows"]], ["sess-bbbb"])
|
|
134
|
-
|
|
135
|
-
def test_window_outside_fixture_dates_yields_no_rows(self):
|
|
136
|
-
w = period.resolve_window("2026-09-20", "2026-09-21", now=self.now)
|
|
137
|
-
self.assertEqual(self.collect(window=w)["rows"], [])
|
|
138
|
-
|
|
139
|
-
def test_session_without_window_block_builds_one(self):
|
|
140
|
-
doc = self.collect(window=None, session="sess-bbbb")
|
|
141
|
-
self.assertEqual(doc["window"]["session"], "sess-bbbb")
|
|
142
|
-
self.assertIsNone(doc["window"]["start_pt"])
|
|
143
|
-
self.assertEqual([r["session"] for r in doc["rows"]], ["sess-bbbb"])
|
|
144
|
-
|
|
145
|
-
def test_needs_window_or_session(self):
|
|
146
|
-
with self.assertRaises(ValueError):
|
|
147
|
-
transcripts.collect(None, claude_glob=self.claude_glob, codex_glob=self.codex_glob)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if __name__ == "__main__":
|
|
151
|
-
unittest.main()
|