test(#115): unit tests for _parse_log_summary, _age_str, and cmd_cost#116
Conversation
26 new tests covering the log-parsing infrastructure that drives clauck history, clauck trace, and clauck cost. All three functions were entirely dark until now.
|
🤖 Autonomous Agent Disclosure This PR was produced entirely without human oversight by an autonomous agent (Model: claude-sonnet-4-6). Readiness: Draft. Implementation is complete — 26/26 tests pass, 203/203 full suite passes. Known limitations: None identified. All tests are isolated from `~/.clauck` via `tempfile.TemporaryDirectory` and `JOBS_DIR` patching. This PR must remain in draft status until a human reviewer explicitly promotes it to ready-for-review. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 625e935838
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) | ||
| out = self._run() | ||
| # The failure count should appear in the output (failures != "–") | ||
| self.assertIn("1", out) |
There was a problem hiding this comment.
Check fails column value explicitly
self.assertIn("1", out) can pass even when failure accounting is broken, because cmd_cost output already contains 1 in other fields (for example the runs count for a single job). In that scenario this test would still be green and would not catch a regression in the fails column logic, so it should assert the failure cell specifically (e.g., via a row-level pattern) rather than any digit anywhere in the table output.
Useful? React with 👍 / 👎.
Closes #115
Motivation
`_parse_log_summary` is the core log-parsing function that drives both `clauck history` and `clauck trace`. It landed in #93 with zero unit test coverage. `cmd_cost`'s log-glob + regex parse loop is pure IO + computation — entirely testable with temp files. `_age_str` is a pure function called from both commands.
If any of these silently mis-parse (missed exit code format, wrong cost regex, wrong invocation_id composition), `clauck history` and `clauck cost` would display incorrect data with no test catching the regression.
Before / After
Before:
python3 -m pytest tests/runs 177 tests._parse_log_summary,_age_str, andcmd_costare entirely dark.After: 26 new tests in
tests/test_clauck_history_cost.py.python3 -m pytest tests/runs 203 tests, all green.What's covered
_parse_log_summary(11 tests):invocation_idcomposed as{ts}-{pid}running=True,exit_code=None"total_cost_usd":N.NNNNlinecost_usd=Noneterminal_reasonextracted from JSON-embedded lineNonerunning=True, all fields Nonepathfield is the original path object_age_str(6 tests):cmd_cost(9 tests):--namefilter: only named job shown, others excluded-dag-pattern) excluded--daysfilter: old log (mtime 60 days ago) excluded from 30-day window--all-time: same old log appears when filter bypassedCost-to-Value
282-line test file. Zero production code changes. Zero new dependencies. CI adds ~0.1s.
Confidence
lib/clauckviaSourceFileLoader(same pattern as other clauck test files)cmd_costtests patchJOBS_DIRwith atempfile.TemporaryDirectory— fully isolated from~/.clauckValidation Steps