Add erp5_log_tail dev tool for live-test/script debugging
Summary
Adds erp5_log_tail, a dev-mode tool that wraps portal_introspections/tailEventLog. Pairs with Products.ERP5Type.Log.log(...) on the write side and replaces the
print() / self.fail() pattern that either loses output or aborts the live-test run.
Why
When debugging a live test or a portal_skins Python Script, the existing options are bad:
-
print()output is swallowed by the live-test runner. -
self.fail("DEBUG: %r" % x)aborts the test at the first probe — only one checkpoint per run, and the test is red.
The Zope event log is the right surface: tests and components can already call from Products.ERP5Type.Log import log, and ERP5 itself logs heavily there (RuleTool,
builders, SQLCatalog warnings, deprecation notices). We just needed a read path through MCP.
Token-conscious by default
Follows the path-based I/O pattern introduced in 22c61e06 ("Add path-based I/O for full uploads and large dumps"):
-
Inline response is capped to
max_entries(default 50, max 500). Only the most-recent matching entries are kept; if more existed the response setstruncated=trueand reportsdropped_entry_countso the model knows to narrowgrepor spill to disk. -
save_to_pathwrites the full filtered content to disk and returns only metadata (entry_count,line_count,saved_to,size_bytes,sha256) plus a shortfirst_entry/last_entrypreview (each truncated at 280 chars).max_entriesis ignored on the disk side — everything matched goes to the file. -
grepis documented as the cheapest token-saving knob — a distinctive marker (e.g.log('my_probe', ...)) cuts response size to just the lines you care about. -
New dev guide
erp5_guide(tutorial="tail_event_log")walks through the full emit-and-read loop. -
The existing
run_live_testsguide gains a section pointing here, so anyone debugging a test will land on it. -
CLAUDE.mdtool table gains the entry plus a one-liner in the call-sequence cheat sheet.
Tests
10 new unit tests covering: full tail, grep filter, no-match, max_entries truncation, default 50 cap, save_to_path, save_to_path + max_entries interaction (disk
side ignores the cap), oversize-entry preview truncation, missing ERP5_SITE_ROOT, HTTP error path. Full suite: 400 passing.
Live-verified end-to-end
Confirmed against a SlapOS-deployed ERP5 instance:
- Wrote a marker via
log('my_probe', 'PROBE_MARKER_NEW_TOOL_001')from aportal_skinsPython Script. -
erp5_log_tail(grep="my_probe")returned the marker line with the token-conscious envelope (entry_count: 2,truncated: false, ~3 lines of content). -
erp5_log_tail(save_to_path="/tmp/x.log")wrote 134 entries / 498 lines (29 KB) to disk and returned only metadata + first/last preview — no log body in the response.
Test plan
-
python -m pytest test_erp5_mcp.py— 400 passing -
Live-verified inline (grep) and save_to_pathpaths on an ERP5 instance